From 1b1c4700ad9ad231cdaae526101895e80257c185 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 4 Nov 2019 11:27:01 +0100 Subject: [PATCH] geo GetNormal and ProjectPointEdge with geoinfo pointer --- libsrc/csg/csgeom.cpp | 5 +++-- libsrc/csg/csgeom.hpp | 6 ++++-- libsrc/geom2d/geometry2d.cpp | 2 +- libsrc/geom2d/geometry2d.hpp | 2 +- libsrc/meshing/basegeom.hpp | 29 ++++++----------------------- libsrc/meshing/curvedelems.cpp | 6 +++--- libsrc/meshing/improve2.cpp | 6 +++--- libsrc/meshing/improve2gen.cpp | 2 +- libsrc/meshing/meshing2.cpp | 6 +++--- libsrc/meshing/smoothing2.cpp | 10 +++++----- libsrc/occ/occgeom.cpp | 31 +++++++++++++++---------------- libsrc/occ/occgeom.hpp | 6 +++--- libsrc/stlgeom/stlgeom.cpp | 11 ++++------- libsrc/stlgeom/stlgeom.hpp | 3 +-- 14 files changed, 53 insertions(+), 72 deletions(-) diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index ad3912d4..fa4c78f7 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -87,7 +87,7 @@ namespace netgen } void CSGeometry :: ProjectPointEdge(int surfind, INDEX surfind2, - Point<3> & p) const + Point<3> & p, EdgePointGeomInfo* /*unused*/) const { Point<3> hp = p; ProjectToEdge (GetSurface(surfind), @@ -96,7 +96,8 @@ namespace netgen } - Vec<3> CSGeometry :: GetNormal(int surfind, const Point<3> & p) const + Vec<3> CSGeometry :: GetNormal(int surfind, const Point<3> & p, + const PointGeomInfo* /*unused*/) const { Vec<3> hn; GetSurface(surfind)->CalcGradient(p, hn); diff --git a/libsrc/csg/csgeom.hpp b/libsrc/csg/csgeom.hpp index 32473ed0..c419c9a4 100644 --- a/libsrc/csg/csgeom.hpp +++ b/libsrc/csg/csgeom.hpp @@ -190,8 +190,10 @@ namespace netgen PointGeomInfo ProjectPoint(INDEX surfind, Point<3> & p) const override; bool ProjectPointGI (int surfind, Point<3> & p, PointGeomInfo & gi) const override; - void ProjectPointEdge(INDEX surfind, INDEX surfind2, Point<3> & p) const override; - Vec<3> GetNormal(int surfind, const Point<3> & p) const override; + void ProjectPointEdge(INDEX surfind, INDEX surfind2, Point<3> & p, + EdgePointGeomInfo* gi = nullptr) const override; + Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* gi = nullptr) const override; + void PointBetween(const Point<3> & p1, const Point<3> & p2, double secpoint, int surfi, const PointGeomInfo & gi1, diff --git a/libsrc/geom2d/geometry2d.cpp b/libsrc/geom2d/geometry2d.cpp index 43282cff..11ea2df9 100644 --- a/libsrc/geom2d/geometry2d.cpp +++ b/libsrc/geom2d/geometry2d.cpp @@ -86,7 +86,7 @@ namespace netgen } Vec<3> SplineGeometry2d :: GetNormal(int surfi1, const Point<3> & p, - const PointGeomInfo & gi) const + const PointGeomInfo* gi) const { return Vec<3> (0,0,1); } diff --git a/libsrc/geom2d/geometry2d.hpp b/libsrc/geom2d/geometry2d.hpp index 7dfcbe9f..ff4c459c 100644 --- a/libsrc/geom2d/geometry2d.hpp +++ b/libsrc/geom2d/geometry2d.hpp @@ -182,7 +182,7 @@ namespace netgen Vec<3> GetTangent (const Point<3> & p, int surfi1, int surfi2, const EdgePointGeomInfo & ap1) const override; Vec<3> GetNormal(int surfi1, const Point<3> & p, - const PointGeomInfo & gi) const override; + const PointGeomInfo* gi) const override; const SplineSegExt & GetSpline (const int i) const { diff --git a/libsrc/meshing/basegeom.hpp b/libsrc/meshing/basegeom.hpp index 53808739..05dd1a90 100644 --- a/libsrc/meshing/basegeom.hpp +++ b/libsrc/meshing/basegeom.hpp @@ -32,7 +32,7 @@ namespace netgen virtual double CalcStep(double t, double sag) const = 0; virtual bool OrientedLikeGlobal() const = 0; virtual size_t GetHash() const = 0; - virtual void ProjectPoint(Point<3>& p, EdgePointGeomInfo& gi) const = 0; + virtual void ProjectPoint(Point<3>& p, EdgePointGeomInfo* gi) const = 0; virtual void PointBetween(const Point<3>& p1, const Point<3>& p2, double secpoint, @@ -65,14 +65,8 @@ namespace netgen virtual double GetCurvature(const PointGeomInfo& gi) const = 0; virtual void RestrictH(Mesh& mesh, const MeshingParameters& mparam) const = 0; - virtual Vec<3> GetNormal(const Point<3>& p) const - { - return {0.,0.,1.}; - } - virtual Vec<3> GetNormal(const Point<3>& p, const PointGeomInfo& gi) const - { - return GetNormal(p); - } + virtual Vec<3> GetNormal(const Point<3>& p, const PointGeomInfo* gi = nullptr) const = 0; + virtual void PointBetween(const Point<3>& p1, const Point<3>& p2, double secpoint, @@ -129,13 +123,9 @@ namespace netgen return faces[surfind-1]->Project(p); } - virtual void ProjectPointEdge (int surfind, int surfind2, Point<3> & p) const - { - throw Exception("In ProjectPointEdge of basegeometry"); - } - virtual void ProjectPointEdge (int surfind, int surfind2, Point<3> & p, EdgePointGeomInfo& gi) const + virtual void ProjectPointEdge (int surfind, int surfind2, Point<3> & p, EdgePointGeomInfo* gi = nullptr) const { - edges[gi.edgenr]->ProjectPoint(p, gi); + edges[gi->edgenr]->ProjectPoint(p, gi); } virtual bool CalcPointGeomInfo(int surfind, PointGeomInfo& gi, const Point<3> & p3) const @@ -147,15 +137,8 @@ namespace netgen return faces[surfind-1]->ProjectPointGI(p, gi); } - virtual Vec<3> GetNormal(int surfind, const Point<3> & p) const - { return faces[surfind-1]->GetNormal(p); } - virtual Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo & gi) const + virtual Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* gi = nullptr) const { return faces[surfind-1]->GetNormal(p, gi); } - [[deprecated]] - void GetNormal(int surfind, const Point<3> & p, Vec<3> & n) const - { - n = GetNormal(surfind, p); - } virtual void PointBetween (const Point<3> & p1, const Point<3> & p2, double secpoint, diff --git a/libsrc/meshing/curvedelems.cpp b/libsrc/meshing/curvedelems.cpp index 43d8ae35..71fb7d83 100644 --- a/libsrc/meshing/curvedelems.cpp +++ b/libsrc/meshing/curvedelems.cpp @@ -839,8 +839,8 @@ namespace netgen { Point<3> pm = Center (p1, p2); - Vec<3> n1 = geo.GetNormal (surfnr[e], p1, gi0[e]); - Vec<3> n2 = geo.GetNormal (surfnr[e], p2, gi1[e]); + Vec<3> n1 = geo.GetNormal (surfnr[e], p1, &gi0[e]); + Vec<3> n2 = geo.GetNormal (surfnr[e], p2, &gi1[e]); // p3 = pm + alpha1 n1 + alpha2 n2 @@ -1084,7 +1084,7 @@ namespace netgen v05 /= 1 + (w-1) * 0.5; Point<3> p05 (v05), pp05(v05); geo.ProjectPointEdge(edge_surfnr1[edgenr], edge_surfnr2[edgenr], pp05, - edge_gi0[edgenr]); + &edge_gi0[edgenr]); double d = Dist (pp05, p05); if (d < dold) diff --git a/libsrc/meshing/improve2.cpp b/libsrc/meshing/improve2.cpp index 524ba239..fe40259f 100644 --- a/libsrc/meshing/improve2.cpp +++ b/libsrc/meshing/improve2.cpp @@ -85,11 +85,11 @@ namespace netgen nv1.Normalize(); nv2.Normalize(); - auto nvp3 = geo.GetNormal (surfnr, mesh.Point(pi3), gi3); + auto nvp3 = geo.GetNormal (surfnr, mesh.Point(pi3), &gi3); nvp3.Normalize(); - auto nvp4 = geo.GetNormal (surfnr, mesh.Point(pi4), gi4); + auto nvp4 = geo.GetNormal (surfnr, mesh.Point(pi4), &gi4); nvp4.Normalize(); @@ -648,7 +648,7 @@ namespace netgen { const int faceindex = hel.GetIndex(); const int surfnr = mesh.GetFaceDescriptor (faceindex).SurfNr(); - normals[pi] = geo.GetNormal (surfnr, mesh[pi], hel.GeomInfoPi(k+1)); + normals[pi] = geo.GetNormal (surfnr, mesh[pi], &hel.GeomInfoPi(k+1)); break; } } diff --git a/libsrc/meshing/improve2gen.cpp b/libsrc/meshing/improve2gen.cpp index 1d4ebbc9..ddbd397e 100644 --- a/libsrc/meshing/improve2gen.cpp +++ b/libsrc/meshing/improve2gen.cpp @@ -397,7 +397,7 @@ namespace netgen // calc metric badness double bad1 = 0, bad2 = 0; // SelectSurfaceOfPoint (mesh.Point(pmap.Get(1)), pgi.Get(1)); - auto n = geo.GetNormal(surfnr, mesh.Point(pmap.Get(1)), pgi.Elem(1)); + auto n = geo.GetNormal(surfnr, mesh.Point(pmap.Get(1)), &pgi.Elem(1)); for (int j = 0; j < rule.oldels.Size(); j++) bad1 += mesh[elmap[j]].CalcJacobianBadness (mesh.Points(), n); diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index e275bb22..bda90593 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -142,8 +142,8 @@ namespace netgen { p1 = ap1; p2 = ap2; - auto n1 = geo.GetNormal(gi1->trignum, p1, *gi1); - auto n2 = geo.GetNormal(gi2->trignum, p2, *gi2); + auto n1 = geo.GetNormal(gi1->trignum, p1, gi1); + auto n2 = geo.GetNormal(gi2->trignum, p2, gi2); ez = 0.5 * (n1+n2); ez.Normalize(); @@ -158,7 +158,7 @@ namespace netgen Point<2> & plainpoint, double h, int & zone) { auto& gi = geominfo.GetPGI(1); - auto n = geo.GetNormal(gi.trignum, locpoint, gi); + auto n = geo.GetNormal(gi.trignum, locpoint, &gi); auto p1p = locpoint - p1; plainpoint(0) = (p1p * ex) / h; plainpoint(1) = (p1p * ey) / h; diff --git a/libsrc/meshing/smoothing2.cpp b/libsrc/meshing/smoothing2.cpp index b4d5ab9a..11f21cb8 100644 --- a/libsrc/meshing/smoothing2.cpp +++ b/libsrc/meshing/smoothing2.cpp @@ -218,7 +218,7 @@ namespace netgen { double badness = 0; - auto n = geo.GetNormal(ld.surfi, ld.sp1, ld.gi1); + auto n = geo.GetNormal(ld.surfi, ld.sp1, &ld.gi1); Point<3> pp1 = ld.sp1 + x(0) * ld.t1 + x(1) * ld.t2; for (int j = 0; j < ld.locelements.Size(); j++) @@ -359,7 +359,7 @@ namespace netgen vgrad = 0; double badness = 0; - auto n = geo.GetNormal(ld.surfi, ld.sp1, ld.gi1); + auto n = geo.GetNormal(ld.surfi, ld.sp1, &ld.gi1); pp1 = ld.sp1 + x(0) * ld.t1 + x(1) * ld.t2; // meshthis -> ProjectPoint (surfi, pp1); @@ -414,7 +414,7 @@ namespace netgen vgrad = 0; double badness = 0; - auto n = geo.GetNormal(ld.surfi, ld.sp1, ld.gi1); + auto n = geo.GetNormal(ld.surfi, ld.sp1, &ld.gi1); pp1 = ld.sp1 + x(0) * ld.t1 + x(1) * ld.t2; for (int j = 0; j < ld.locelements.Size(); j++) @@ -577,7 +577,7 @@ namespace netgen vgrad = 0; badness = 0; - auto n = geo.GetNormal(ld.surfi, ld.sp1, ld.gi1); + // auto n = geo.GetNormal(ld.surfi, ld.sp1, &ld.gi1); pp1 = ld.sp1 + x(0) * ld.t1 + x(1) * ld.t2; @@ -933,7 +933,7 @@ namespace netgen } - ld.normal = geo.GetNormal(ld.surfi, ld.sp1, ld.gi1); + ld.normal = geo.GetNormal(ld.surfi, ld.sp1, &ld.gi1); ld.t1 = ld.normal.GetNormal (); ld.t2 = Cross (ld.normal, ld.t1); diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index 6b54ed66..6a441bf5 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -1072,7 +1072,7 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a } void OCCGeometry :: ProjectPointEdge(int surfind, INDEX surfind2, - Point<3> & p) const + Point<3> & p, EdgePointGeomInfo* gi) const { TopExp_Explorer exp0, exp1; bool done = false; @@ -1154,26 +1154,25 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a return true; } - Vec<3> OCCGeometry :: GetNormal(int surfind, const Point<3> & p, const PointGeomInfo & geominfo) const + Vec<3> OCCGeometry :: GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* geominfo) const { - gp_Pnt pnt; - gp_Vec du, dv; + if(geominfo) + { + gp_Pnt pnt; + gp_Vec du, dv; - Handle(Geom_Surface) occface; - occface = BRep_Tool::Surface(TopoDS::Face(fmap(surfind))); + Handle(Geom_Surface) occface; + occface = BRep_Tool::Surface(TopoDS::Face(fmap(surfind))); - occface->D1(geominfo.u,geominfo.v,pnt,du,dv); + occface->D1(geominfo->u,geominfo->v,pnt,du,dv); - auto n = Cross (Vec<3>(du.X(), du.Y(), du.Z()), - Vec<3>(dv.X(), dv.Y(), dv.Z())); - n.Normalize(); + auto n = Cross (Vec<3>(du.X(), du.Y(), du.Z()), + Vec<3>(dv.X(), dv.Y(), dv.Z())); + n.Normalize(); - if (fmap(surfind).Orientation() == TopAbs_REVERSED) n *= -1; - return n; - } - - Vec<3> OCCGeometry :: GetNormal(int surfind, const Point<3> & p) const - { + if (fmap(surfind).Orientation() == TopAbs_REVERSED) n *= -1; + return n; + } Standard_Real u,v; gp_Pnt pnt(p(0), p(1), p(2)); diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index 6dd2aab7..94f3fd27 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -281,10 +281,10 @@ namespace netgen void DoArchive(Archive& ar) override; PointGeomInfo ProjectPoint(int surfind, Point<3> & p) const override; - void ProjectPointEdge (int surfind, int surfind2, Point<3> & p) const override; + void ProjectPointEdge (int surfind, int surfind2, Point<3> & p, + EdgePointGeomInfo* gi = nullptr) const override; bool ProjectPointGI (int surfind, Point<3> & p, PointGeomInfo & gi) const override; - Vec<3> GetNormal(int surfind, const Point<3> & p) const override; - Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo & gi) const override; + Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* gi) const override; bool CalcPointGeomInfo(int surfind, PointGeomInfo& gi, const Point<3> & p3) const override; void PointBetweenEdge(const Point<3> & p1, const Point<3> & p2, double secpoint, diff --git a/libsrc/stlgeom/stlgeom.cpp b/libsrc/stlgeom/stlgeom.cpp index 8adcaaaa..e65c0090 100644 --- a/libsrc/stlgeom/stlgeom.cpp +++ b/libsrc/stlgeom/stlgeom.cpp @@ -100,14 +100,11 @@ int STLGeometry :: GenerateMesh (shared_ptr & mesh, MeshingParameters & mp return STLMeshingDummy (this, mesh, mparam, stlpar); } -Vec<3> STLGeometry :: GetNormal(INDEX surfind, const Point<3> & p) const +Vec<3> STLGeometry :: GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* gi) const { - throw Exception("STLGeometry::GetNormal without PointGeomInfo called"); -} - -Vec<3> STLGeometry :: GetNormal(int surfind, const Point<3> & p, const PointGeomInfo & gi) const -{ - return GetChart(GetChartNr(gi.trignum)).GetNormal(); + if(!gi) + throw Exception("STLGeometry::GetNormal without PointGeomInfo called"); + return GetChart(GetChartNr(gi->trignum)).GetNormal(); } bool STLGeometry :: CalcPointGeomInfo(int /*surfind*/, PointGeomInfo& gi, const Point<3> & p3) const diff --git a/libsrc/stlgeom/stlgeom.hpp b/libsrc/stlgeom/stlgeom.hpp index f542d11b..85212d55 100644 --- a/libsrc/stlgeom/stlgeom.hpp +++ b/libsrc/stlgeom/stlgeom.hpp @@ -195,8 +195,7 @@ namespace netgen bool CalcPointGeomInfo(int surfind, PointGeomInfo& gi, const Point<3> & p3) const override; PointGeomInfo ProjectPoint(INDEX surfind, Point<3> & p) const override; bool ProjectPointGI (int surfind, Point<3> & p, PointGeomInfo & gi) const override; - Vec<3> GetNormal(int surfind, const Point<3> & p) const override; - Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo & gi) const override; + Vec<3> GetNormal(int surfind, const Point<3> & p, const PointGeomInfo* gi = nullptr) const override; void PointBetween(const Point<3> & p1, const Point<3> & p2, double secpoint, int surfi, const PointGeomInfo & gi1,