From 5b45c7a9723944c55fa3bcbc3c055812ee98f8c3 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 28 Oct 2019 13:44:51 +0100 Subject: [PATCH] implement meshing2 functionality for 3d geometries --- libsrc/csg/genmesh.cpp | 2 +- libsrc/csg/meshsurf.cpp | 15 +++++---- libsrc/csg/meshsurf.hpp | 4 ++- libsrc/geom2d/genmesh2d.cpp | 2 +- libsrc/meshing/meshing2.cpp | 56 ++++++++++++++++++------------- libsrc/meshing/meshing2.hpp | 10 ++++-- libsrc/occ/occgenmesh.cpp | 2 +- libsrc/occ/occmeshsurf.cpp | 6 ++-- libsrc/occ/occmeshsurf.hpp | 3 +- libsrc/stlgeom/meshstlsurface.cpp | 2 +- 10 files changed, 60 insertions(+), 42 deletions(-) diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 9ac96715..6e3c76c2 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -422,7 +422,7 @@ namespace netgen geom.GetSurface((mesh.GetFaceDescriptor(k).SurfNr())); - Meshing2Surfaces meshing(*surf, mparam, geom.BoundingBox()); + Meshing2Surfaces meshing(geom, *surf, mparam, geom.BoundingBox()); meshing.SetStartTime (starttime); double eps = 1e-8 * geom.MaxSize(); diff --git a/libsrc/csg/meshsurf.cpp b/libsrc/csg/meshsurf.cpp index f7b8d3fb..234c7c40 100644 --- a/libsrc/csg/meshsurf.cpp +++ b/libsrc/csg/meshsurf.cpp @@ -14,13 +14,14 @@ Meshing2Surfaces :: Meshing2Surfaces (const Surface & asurface) ; } */ -Meshing2Surfaces :: Meshing2Surfaces (const Surface & asurf, - const MeshingParameters & mp, - const Box<3> & abb) - : Meshing2(mp, abb), surface(asurf), mparam (mp) -{ - ; -} + Meshing2Surfaces :: Meshing2Surfaces (const CSGeometry& geo, + const Surface & asurf, + const MeshingParameters & mp, + const Box<3> & abb) + : Meshing2(geo, mp, abb), surface(asurf), mparam (mp) + { + ; + } void Meshing2Surfaces :: DefineTransformation (const Point<3> & p1, const Point<3> & p2, diff --git a/libsrc/csg/meshsurf.hpp b/libsrc/csg/meshsurf.hpp index 25e23857..11fec3bf 100644 --- a/libsrc/csg/meshsurf.hpp +++ b/libsrc/csg/meshsurf.hpp @@ -16,7 +16,9 @@ namespace netgen /// // Meshing2Surfaces (const Surface & asurf); /// - Meshing2Surfaces (const Surface & asurf, const MeshingParameters & mp, + Meshing2Surfaces (const CSGeometry& geo, + const Surface & asurf, + const MeshingParameters & mp, const Box<3> & aboundingbox); protected: diff --git a/libsrc/geom2d/genmesh2d.cpp b/libsrc/geom2d/genmesh2d.cpp index 59405dc1..09ef0260 100644 --- a/libsrc/geom2d/genmesh2d.cpp +++ b/libsrc/geom2d/genmesh2d.cpp @@ -565,7 +565,7 @@ namespace netgen mp.quad = hquad || geometry.GetDomainQuadMeshing (domnr); - Meshing2 meshing (mp, Box<3> (pmin, pmax)); + Meshing2 meshing (geometry, mp, Box<3> (pmin, pmax)); NgArray compress(bnp); compress = -1; diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index e4cabded..070a31ef 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -38,8 +38,10 @@ namespace netgen static Array> global_quad_rules; - Meshing2 :: Meshing2 (const MeshingParameters & mp, const Box<3> & aboundingbox) - : adfront(aboundingbox), boundingbox(aboundingbox) + Meshing2 :: Meshing2 (const NetgenGeometry& ageo, + const MeshingParameters & mp, + const Box<3> & aboundingbox) + : geo(ageo), adfront(aboundingbox), boundingbox(aboundingbox) { static Timer t("Mesing2::Meshing2"); RegionTimer r(t); @@ -133,29 +135,38 @@ namespace netgen // static Vec3d ex, ey; // static Point3d globp1; - void Meshing2 :: DefineTransformation (const Point<3> & p1, const Point<3> & p2, - const PointGeomInfo * geominfo1, - const PointGeomInfo * geominfo2) + void Meshing2 :: DefineTransformation (const Point<3> & ap1, + const Point<3> & ap2, + const PointGeomInfo * gi1, + const PointGeomInfo * gi2) { - globp1 = p1; - ex = p2 - p1; - ex /= ex.Length(); - ey.X() = -ex.Y(); - ey.Y() = ex.X(); - ey.Z() = 0; + p1 = ap1; + p2 = ap2; + auto n1 = geo.GetNormal(gi1->trignum, p1, *gi1); + auto n2 = geo.GetNormal(gi2->trignum, p2, *gi2); + + ez = 0.5 * (n1+n2); + ez.Normalize(); + ex = (p2-p1).Normalize(); + ez -= (ez*ex)*ex; + ez.Normalize(); + ey = Cross(ez, ex); } void Meshing2 :: TransformToPlain (const Point<3> & locpoint, - const MultiPointGeomInfo & geominf, + const MultiPointGeomInfo & geominfo, Point<2> & plainpoint, double h, int & zone) { - Vec3d p1p (globp1, locpoint); + auto& gi = geominfo.GetPGI(1); + auto n = geo.GetNormal(gi.trignum, locpoint, gi); + auto p1p = locpoint - p1; + plainpoint(0) = (p1p * ex) / h; + plainpoint(1) = (p1p * ey) / h; - // p1p = locpoint - globp1; - p1p /= h; - plainpoint[0] = p1p * ex; - plainpoint[1] = p1p * ey; - zone = 0; + if(n*ez < 0) + zone = -1; + else + zone = 0; } int Meshing2 :: TransformFromPlain (const Point<2> & plainpoint, @@ -163,12 +174,9 @@ namespace netgen PointGeomInfo & gi, double h) { - Vec3d p1p; - gi.trignum = 1; - - p1p = plainpoint[0] * ex + plainpoint[1] * ey; - p1p *= h; - locpoint = globp1 + p1p; + locpoint = p1 + (h*plainpoint(0)) * ex + (h* plainpoint(1)) * ey; + if (!geo.ProjectPointGI(gi.trignum, locpoint, gi)) + geo.ProjectPoint(gi.trignum, locpoint); return 0; } diff --git a/libsrc/meshing/meshing2.hpp b/libsrc/meshing/meshing2.hpp index d7a638c0..dfaa06ab 100644 --- a/libsrc/meshing/meshing2.hpp +++ b/libsrc/meshing/meshing2.hpp @@ -41,12 +41,16 @@ class Meshing2 /// double maxarea; - Vec3d ex, ey; - Point3d globp1; + Vec3d ex, ey, ez; + Point<3> p1, p2; + + const NetgenGeometry& geo; public: /// - DLL_HEADER Meshing2 (const MeshingParameters & mp, const Box<3> & aboundingbox); + DLL_HEADER Meshing2 (const NetgenGeometry& geo, + const MeshingParameters & mp, + const Box<3> & aboundingbox); /// DLL_HEADER virtual ~Meshing2 (); diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index 88384d6a..bc63203b 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -651,7 +651,7 @@ namespace netgen static Timer tinit("init"); tinit.Start(); - Meshing2OCCSurfaces meshing(TopoDS::Face(geom.fmap(k)), bb, projecttype, mparam); + Meshing2OCCSurfaces meshing(geom, TopoDS::Face(geom.fmap(k)), bb, projecttype, mparam); tinit.Stop(); diff --git a/libsrc/occ/occmeshsurf.cpp b/libsrc/occ/occmeshsurf.cpp index 847907b1..7fa5d237 100644 --- a/libsrc/occ/occmeshsurf.cpp +++ b/libsrc/occ/occmeshsurf.cpp @@ -492,10 +492,12 @@ namespace netgen } - Meshing2OCCSurfaces :: Meshing2OCCSurfaces (const TopoDS_Shape & asurf, + Meshing2OCCSurfaces :: Meshing2OCCSurfaces (const NetgenGeometry& geo, + const TopoDS_Shape & asurf, const Box<3> & abb, int aprojecttype, const MeshingParameters & mparam) - : Meshing2(mparam, Box<3>(abb.PMin(), abb.PMax())), surface(TopoDS::Face(asurf), aprojecttype) + : Meshing2(geo, mparam, Box<3>(abb.PMin(), abb.PMax())), + surface(TopoDS::Face(asurf), aprojecttype) { ; } diff --git a/libsrc/occ/occmeshsurf.hpp b/libsrc/occ/occmeshsurf.hpp index 3a74b170..2488a18f 100644 --- a/libsrc/occ/occmeshsurf.hpp +++ b/libsrc/occ/occmeshsurf.hpp @@ -113,7 +113,8 @@ class Meshing2OCCSurfaces : public Meshing2 public: /// - Meshing2OCCSurfaces (const TopoDS_Shape & asurf, const Box<3> & aboundingbox, + Meshing2OCCSurfaces (const NetgenGeometry& geo, + const TopoDS_Shape & asurf, const Box<3> & aboundingbox, int aprojecttype, const MeshingParameters & mparam); /// diff --git a/libsrc/stlgeom/meshstlsurface.cpp b/libsrc/stlgeom/meshstlsurface.cpp index 9259aba6..039f5538 100644 --- a/libsrc/stlgeom/meshstlsurface.cpp +++ b/libsrc/stlgeom/meshstlsurface.cpp @@ -897,7 +897,7 @@ void STLSurfaceOptimization (STLGeometry & geom, MeshingSTLSurface :: MeshingSTLSurface (STLGeometry & ageom, const MeshingParameters & mp) - : Meshing2(mp, ageom.GetBoundingBox()), geom(ageom) + : Meshing2(ageom, mp, ageom.GetBoundingBox()), geom(ageom) { ; }