From bf217b9934db58ed2c1c860e73412040e41273a3 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Sun, 29 Sep 2019 16:22:00 +0200 Subject: [PATCH] change PointNd to Point adfront2 --- libsrc/gprim/geomobjects.hpp | 35 +++++++++++++++++++++ libsrc/meshing/adfront2.cpp | 2 +- libsrc/meshing/adfront2.hpp | 2 +- libsrc/meshing/meshing2.cpp | 8 ++--- libsrc/meshing/meshing2.hpp | 2 +- libsrc/meshing/meshtype.cpp | 14 ++++----- libsrc/meshing/meshtype.hpp | 8 ++--- libsrc/meshing/netrule2.cpp | 55 ++++++++++----------------------- libsrc/meshing/parser2.cpp | 4 +-- libsrc/meshing/ruler2.cpp | 12 +++---- libsrc/meshing/ruler2.hpp | 20 ++++++------ libsrc/meshing/smoothing2.cpp | 4 +-- libsrc/visualization/mvdraw.hpp | 4 +-- 13 files changed, 92 insertions(+), 78 deletions(-) diff --git a/libsrc/gprim/geomobjects.hpp b/libsrc/gprim/geomobjects.hpp index 48142356..1c55592b 100644 --- a/libsrc/gprim/geomobjects.hpp +++ b/libsrc/gprim/geomobjects.hpp @@ -162,8 +162,43 @@ namespace netgen Vec GetNormal () const; }; + template + inline Vec operator-(const Point& p1, const Point& p2) + { + Vec result; + for(auto i : Range(D)) + result[i] = p1[i] - p2[i]; + return result; + } + inline double Cross2(const Vec<2>& v1, const Vec<2>& v2) + { + return v1[0] * v2[1] - v1[1] * v2[0]; + } + // are points clockwise? + inline bool CW(const Point<2>& p1, const Point<2>& p2, + const Point<2>& p3) + { + return Cross2(p2-p1, p3-p2) < 0; + } + + // are points counterclockwise? + inline bool CCW(const Point<2>& p1, const Point<2>& p2, + const Point<2>& p3) + { + return Cross2(p2-p1, p3-p2) > 0; + } + + // are strictly points counterclockwise? + inline bool CCW(const Point<2>& p1, const Point<2>& p2, + const Point<2>& p3, double eps) + { + auto v1 = p2-p1; + auto v2 = p3-p2; + return Cross2(v1, v2) > eps*eps*max2(v1.Length2(), + v2.Length2()); + } template diff --git a/libsrc/meshing/adfront2.cpp b/libsrc/meshing/adfront2.cpp index f6e78102..3295f706 100644 --- a/libsrc/meshing/adfront2.cpp +++ b/libsrc/meshing/adfront2.cpp @@ -274,7 +274,7 @@ namespace netgen int AdFront2 :: GetLocals (int baselineindex, - NgArray & locpoints, + NgArray> & locpoints, NgArray & pgeominfo, NgArray & loclines, // local index NgArray & pindex, diff --git a/libsrc/meshing/adfront2.hpp b/libsrc/meshing/adfront2.hpp index dd5bf128..5758c184 100644 --- a/libsrc/meshing/adfront2.hpp +++ b/libsrc/meshing/adfront2.hpp @@ -216,7 +216,7 @@ public: /// int GetLocals (int baseline, - NgArray & locpoints, + NgArray> & locpoints, NgArray & pgeominfo, NgArray & loclines, // local index NgArray & pindex, diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index 1ae2f474..0e2942ca 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -246,11 +246,11 @@ namespace netgen // double h; - auto locpointsptr = make_shared>(); + auto locpointsptr = make_shared>>(); vssurfacemeshing.locpointsptr = locpointsptr; auto& locpoints = *locpointsptr; NgArray legalpoints; - auto plainpointsptr = make_shared>(); + auto plainpointsptr = make_shared>>(); auto& plainpoints = *plainpointsptr; vssurfacemeshing.plainpointsptr = plainpointsptr; NgArray plainzones; @@ -698,7 +698,7 @@ namespace netgen double avy = 0; for (size_t i = 0; i < plainpoints.Size(); i++) - avy += plainpoints[i].Y(); + avy += plainpoints[i][1]; avy *= 1./plainpoints.Size(); @@ -715,7 +715,7 @@ namespace netgen } - if (plainpoints[i].Y() < -1e-10*avy) // changed + if (plainpoints[i][1] < -1e-10*avy) // changed { legalpoints[i] = 0; } diff --git a/libsrc/meshing/meshing2.hpp b/libsrc/meshing/meshing2.hpp index 1cf2d52e..08e275b6 100644 --- a/libsrc/meshing/meshing2.hpp +++ b/libsrc/meshing/meshing2.hpp @@ -135,7 +135,7 @@ protected: /** Applies 2D rules. Tests all 2D rules */ - int ApplyRules (NgArray & lpoints, + int ApplyRules (NgArray> & lpoints, NgArray & legalpoints, int maxlegalpoint, NgArray & llines, diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index 7f5862e1..fd1ed051 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -439,7 +439,7 @@ namespace netgen } void Element2d :: - GetTransformation (int ip, const NgArray & points, + GetTransformation (int ip, const NgArray> & points, DenseMatrix & trans) const { int np = GetNP(); @@ -658,7 +658,7 @@ namespace netgen void Element2d :: - GetPointMatrix (const NgArray & points, + GetPointMatrix (const NgArray> & points, DenseMatrix & pmat) const { int np = GetNP(); @@ -673,9 +673,9 @@ namespace netgen for (int i = 1; i <= np; i++) { - const Point2d & p = points.Get(PNum(i)); - pmat.Elem(1, i) = p.X(); - pmat.Elem(2, i) = p.Y(); + const auto& p = points.Get(PNum(i)); + pmat.Elem(1, i) = p[0]; + pmat.Elem(2, i) = p[1]; } } @@ -683,7 +683,7 @@ namespace netgen - double Element2d :: CalcJacobianBadness (const NgArray & points) const + double Element2d :: CalcJacobianBadness (const NgArray> & points) const { int i, j; int nip = GetNIP(); @@ -727,7 +727,7 @@ namespace netgen }; double Element2d :: - CalcJacobianBadnessDirDeriv (const NgArray & points, + CalcJacobianBadnessDirDeriv (const NgArray> & points, int pi, Vec2d & dir, double & dd) const { if (typ == QUAD) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 236d8a16..a2b00f3b 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -580,7 +580,7 @@ namespace netgen int GetNIP () const; void GetIntegrationPoint (int ip, Point2d & p, double & weight) const; - void GetTransformation (int ip, const NgArray & points, + void GetTransformation (int ip, const NgArray> & points, class DenseMatrix & trans) const; void GetTransformation (int ip, class DenseMatrix & pmat, class DenseMatrix & trans) const; @@ -595,16 +595,16 @@ namespace netgen void GetDShapeNew (const Point<2,T> & p, class MatrixFixWidth<2,T> & dshape) const; /// matrix 2 * np - void GetPointMatrix (const NgArray & points, + void GetPointMatrix (const NgArray> & points, class DenseMatrix & pmat) const; void ComputeIntegrationPointData () const; - double CalcJacobianBadness (const NgArray & points) const; + double CalcJacobianBadness (const NgArray> & points) const; double CalcJacobianBadness (const T_POINTS & points, const Vec<3> & n) const; - double CalcJacobianBadnessDirDeriv (const NgArray & points, + double CalcJacobianBadnessDirDeriv (const NgArray> & points, int pi, Vec2d & dir, double & dd) const; diff --git a/libsrc/meshing/netrule2.cpp b/libsrc/meshing/netrule2.cpp index a26209a6..b9b7ba06 100644 --- a/libsrc/meshing/netrule2.cpp +++ b/libsrc/meshing/netrule2.cpp @@ -39,11 +39,11 @@ void netrule :: SetFreeZoneTransformation (const Vector & devp, int tolclass) { oldutofreearea_i[tolclass-1] -> Mult (devp, devfree); - NgArray & fzi = *freezone_i[tolclass-1]; + auto& fzi = *freezone_i[tolclass-1]; for (int i = 0; i < fzs; i++) { - transfreezone[i].X() = fzi[i].X() + devfree[2*i]; - transfreezone[i].Y() = fzi[i].Y() + devfree[2*i+1]; + transfreezone[i][0] = fzi[i][0] + devfree[2*i]; + transfreezone[i][1] = fzi[i][1] + devfree[2*i+1]; } } else @@ -57,24 +57,24 @@ void netrule :: SetFreeZoneTransformation (const Vector & devp, int tolclass) for (int i = 0; i < fzs; i++) { - transfreezone[i].X() = lam1 * freezone[i].X() + lam2 * freezonelimit[i].X() + devfree[2*i]; - transfreezone[i].Y() = lam1 * freezone[i].Y() + lam2 * freezonelimit[i].Y() + devfree[2*i+1]; + transfreezone[i][0] = lam1 * freezone[i][0] + lam2 * freezonelimit[i][0] + devfree[2*i]; + transfreezone[i][1] = lam1 * freezone[i][1] + lam2 * freezonelimit[i][1] + devfree[2*i+1]; } } if (fzs > 0) { - fzmaxx = fzminx = transfreezone[0].X(); - fzmaxy = fzminy = transfreezone[0].Y(); + fzmaxx = fzminx = transfreezone[0][0]; + fzmaxy = fzminy = transfreezone[0][1]; } for (int i = 1; i < fzs; i++) { - if (transfreezone[i].X() > fzmaxx) fzmaxx = transfreezone[i].X(); - if (transfreezone[i].X() < fzminx) fzminx = transfreezone[i].X(); - if (transfreezone[i].Y() > fzmaxy) fzmaxy = transfreezone[i].Y(); - if (transfreezone[i].Y() < fzminy) fzminy = transfreezone[i].Y(); + if (transfreezone[i][0] > fzmaxx) fzmaxx = transfreezone[i][0]; + if (transfreezone[i][0] < fzminx) fzminx = transfreezone[i][0]; + if (transfreezone[i][1] > fzmaxy) fzmaxy = transfreezone[i][1]; + if (transfreezone[i][1] < fzminy) fzminy = transfreezone[i][1]; } for (int i = 0; i < fzs; i++) @@ -147,8 +147,8 @@ int netrule :: IsLineInFreeZone2 (const Point2d & p1, const Point2d & p2) const for (int i = 1; i <= transfreezone.Size(); i++) { - bool left = transfreezone.Get(i).X() * nx + transfreezone.Get(i).Y() * ny + c < 1e-7; - bool right = transfreezone.Get(i).X() * nx + transfreezone.Get(i).Y() * ny + c > -1e-7; + bool left = transfreezone.Get(i)[0] * nx + transfreezone.Get(i)[1] * ny + c < 1e-7; + bool right = transfreezone.Get(i)[0] * nx + transfreezone.Get(i)[1] * ny + c > -1e-7; if (!left) allleft = false; if (!right) allright = false; } @@ -187,33 +187,12 @@ float netrule :: CalcPointDist (int pi, const Point2d & p) const } */ -float netrule :: CalcLineError (int li, const Vec2d & v) const +float netrule :: CalcLineError (int li, const Vec<2> & v) const { - float dx = v.X() - linevecs.Get(li).X(); - float dy = v.Y() - linevecs.Get(li).Y(); + float dx = v[0] - linevecs.Get(li)[0]; + float dy = v[1] - linevecs.Get(li)[1]; const threefloat * ltf = &linetolerances.Get(li); return ltf->f1 * dx * dx + ltf->f2 * dx * dy + ltf->f3 * dy * dy; } - - - - -/* -int GetNRules () - { - return rules.Size(); - } -*/ - - - - - - - - - - - -} +} // namespace netgen diff --git a/libsrc/meshing/parser2.cpp b/libsrc/meshing/parser2.cpp index b0fb1bc7..a1419704 100644 --- a/libsrc/meshing/parser2.cpp +++ b/libsrc/meshing/parser2.cpp @@ -480,8 +480,8 @@ void netrule :: LoadRule (istream & ist) for (int k = 0; k < oldutofreearea.Width(); k++) mati(j,k) = lam1 * oldutofreearea(j,k) + (1 - lam1) * oldutofreearealimit(j,k); - freezone_i[i] = new NgArray (freezone.Size()); - NgArray & fzi = *freezone_i[i]; + freezone_i[i] = new NgArray> (freezone.Size()); + auto& fzi = *freezone_i[i]; for (int j = 0; j < freezone.Size(); j++) fzi[j] = freezonelimit[j] + lam1 * (freezone[j] - freezonelimit[j]); } diff --git a/libsrc/meshing/ruler2.cpp b/libsrc/meshing/ruler2.cpp index 30085de1..f69df682 100644 --- a/libsrc/meshing/ruler2.cpp +++ b/libsrc/meshing/ruler2.cpp @@ -5,13 +5,13 @@ namespace netgen { - static double CalcElementBadness (const NgArray & points, + static double CalcElementBadness (const NgArray> & points, const Element2d & elem) { // badness = sqrt(3) /36 * circumference^2 / area - 1 + // h / li + li / h - 2 - Vec2d v12, v13, v23; + Vec<2> v12, v13, v23; double l12, l13, l23, cir, area; static const double c = sqrt(3.0) / 36; @@ -24,7 +24,7 @@ namespace netgen l23 = v23.Length(); cir = l12 + l13 + l23; - area = 0.5 * (v12.X() * v13.Y() - v12.Y() * v13.X()); + area = 0.5 * (v12[0] * v13[1] - v12[1] * v13[0]); if (area < 1e-6) { return 1e8; @@ -45,7 +45,7 @@ namespace netgen - int Meshing2 ::ApplyRules (NgArray & lpoints, + int Meshing2 ::ApplyRules (NgArray> & lpoints, NgArray & legalpoints, int maxlegalpoint, NgArray & llines1, @@ -69,7 +69,7 @@ namespace netgen NgArrayMem pmap, pfixed, lmap; - NgArrayMem tempnewpoints; + NgArrayMem,100> tempnewpoints; NgArrayMem tempnewlines; NgArrayMem tempdellines; NgArrayMem tempelements; @@ -263,7 +263,7 @@ namespace netgen ok = 1; INDEX_2 loclin = llines.Get(locli); - Vec2d linevec = lpoints.Get(loclin.I2()) - lpoints.Get(loclin.I1()); + auto linevec = lpoints.Get(loclin.I2()) - lpoints.Get(loclin.I1()); if (rule->CalcLineError (nlok, linevec) > maxerr) { diff --git a/libsrc/meshing/ruler2.hpp b/libsrc/meshing/ruler2.hpp index 0341faf2..2bef2ae6 100644 --- a/libsrc/meshing/ruler2.hpp +++ b/libsrc/meshing/ruler2.hpp @@ -23,15 +23,15 @@ private: /// char * name; /// - NgArray points; + NgArray> points; /// NgArray lines; /// - NgArray freezone, freezonelimit; + NgArray> freezone, freezonelimit; /// - NgArray*> freezone_i; + NgArray>*> freezone_i; /// - NgArray transfreezone; + NgArray> transfreezone; /// NgArray dellines; @@ -49,7 +49,7 @@ private: MatrixFixWidth<3> freesetinequ; /// - NgArray linevecs; + NgArray> linevecs; /// int noldp, noldl; @@ -86,7 +86,7 @@ public: int GetLNearness (int li) const { return lnearness.Get(li); } /// - const Point2d & GetPoint (int i) const { return points.Get(i); } + const Point<2>& GetPoint (int i) const { return points.Get(i); } /// const INDEX_2 & GetLine (int i) const { return lines.Get(i); } /// @@ -103,14 +103,14 @@ public: double CalcPointDist (int pi, const Point2d & p) const { - double dx = p.X() - points.Get(pi).X(); - double dy = p.Y() - points.Get(pi).Y(); + double dx = p.X() - points.Get(pi)[0]; + double dy = p.Y() - points.Get(pi)[1]; const threefloat * tfp = &tolerances.Get(pi); return tfp->f1 * dx * dx + tfp->f2 * dx * dy + tfp->f3 * dy * dy; } /// - float CalcLineError (int li, const Vec2d & v) const; + float CalcLineError (int li, const Vec<2>& v) const; /// void SetFreeZoneTransformation (const Vector & u, int tolclass); @@ -144,7 +144,7 @@ public: /// int ConvexFreeZone () const; /// - const NgArray & GetTransFreeZone () { return transfreezone; } + const NgArray> & GetTransFreeZone () { return transfreezone; } /// int GetPointNr (int ln, int endp) const { return lines.Get(ln).I(endp); } diff --git a/libsrc/meshing/smoothing2.cpp b/libsrc/meshing/smoothing2.cpp index 5b91dc3a..cba80b87 100644 --- a/libsrc/meshing/smoothing2.cpp +++ b/libsrc/meshing/smoothing2.cpp @@ -584,7 +584,7 @@ namespace netgen // meshthis -> ProjectPoint (surfi, pp1); // meshthis -> GetNormalVector (surfi, pp1, n); - static NgArray pts2d; + static NgArray> pts2d; pts2d.SetSize(mesh.GetNP()); grad = 0; @@ -655,7 +655,7 @@ namespace netgen // pp1.Add2 (x.Get(1), t1, x.Get(2), t2); pp1 = ld.sp1 + x(0) * ld.t1 + x(1) * ld.t2; - static NgArray pts2d; + static NgArray> pts2d; pts2d.SetSize(mesh.GetNP()); deriv = 0; diff --git a/libsrc/visualization/mvdraw.hpp b/libsrc/visualization/mvdraw.hpp index 2f0fa643..264dd6a4 100644 --- a/libsrc/visualization/mvdraw.hpp +++ b/libsrc/visualization/mvdraw.hpp @@ -97,9 +97,9 @@ namespace netgen { double scalex = 1., scaley = 1., shiftx = 0., shifty = 0.; public: - shared_ptr> locpointsptr; + shared_ptr>> locpointsptr; shared_ptr> loclinesptr; - shared_ptr> plainpointsptr; + shared_ptr>> plainpointsptr; int oldnl; bool clearptr; VisualSceneSurfaceMeshing ();