From f22cb4883235bc1fccb9ee3977ba9cb05b11df9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Fri, 20 Sep 2019 23:07:39 +0200 Subject: [PATCH] STLPointId --- libsrc/stlgeom/stltool.cpp | 16 +++++++--------- libsrc/stlgeom/stltopology.cpp | 3 ++- libsrc/stlgeom/stltopology.hpp | 31 +++++++++++++++++-------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/libsrc/stlgeom/stltool.cpp b/libsrc/stlgeom/stltool.cpp index 53bb6a2c..545da33f 100644 --- a/libsrc/stlgeom/stltool.cpp +++ b/libsrc/stlgeom/stltool.cpp @@ -488,7 +488,7 @@ void STLTriangle :: ProjectInPlain(const Array,STLPointId>& ap, pp = pp + (nfact) * nt; } -int STLTriangle :: PointInside(const Array,STLPointId> & ap, +bool STLTriangle :: PointInside(const Array,STLPointId> & ap, const Point<3> & pp) const { const Point<3> & p1 = ap[PNum(1)]; @@ -560,14 +560,12 @@ double STLTriangle :: GetNearestPoint(const Array,STLPointId>& ap, } } -int STLTriangle :: HasEdge(int p1, int p2) const +bool STLTriangle :: HasEdge(STLPointId p1, STLPointId p2) const { - int i; - for (i = 1; i <= 3; i++) - { - if (p1 == PNum(i) && p2 == PNumMod(i+1)) {return 1;} - } - return 0; + for (int i = 1; i <= 3; i++) + if (p1 == PNum(i) && p2 == PNumMod(i+1)) + return true; + return false; } ostream& operator<<(ostream& os, const STLTriangle& t) @@ -590,7 +588,7 @@ STLTopEdge :: STLTopEdge () status = ED_UNDEFINED; } -STLTopEdge :: STLTopEdge (int p1, int p2, int trig1, int trig2) +STLTopEdge :: STLTopEdge (STLPointId p1, STLPointId p2, int trig1, int trig2) { pts[0] = p1; pts[1] = p2; diff --git a/libsrc/stlgeom/stltopology.cpp b/libsrc/stlgeom/stltopology.cpp index bc8ee62d..beb899b4 100644 --- a/libsrc/stlgeom/stltopology.cpp +++ b/libsrc/stlgeom/stltopology.cpp @@ -711,7 +711,8 @@ void STLTopology :: FindNeighbourTrigs() - for (STLTrigId ti = 0; ti < GetNT(); ti++) + // for (STLTrigId ti = 0; ti < GetNT(); ti++) + for (STLTrigId ti : Range(trias)) { STLTriangle & trig = trias[ti]; for (int k = 0; k < 3; k++) diff --git a/libsrc/stlgeom/stltopology.hpp b/libsrc/stlgeom/stltopology.hpp index dd5e9d97..9aad9f10 100644 --- a/libsrc/stlgeom/stltopology.hpp +++ b/libsrc/stlgeom/stltopology.hpp @@ -28,10 +28,11 @@ public: constexpr STLPointId (int ai) : i(ai) { ; } STLPointId & operator= (const STLPointId & ai) { i = ai.i; return *this; } STLPointId & operator= (int ai) { i = ai; return *this; } - operator int () const { return i; } + constexpr operator int () const { return i; } STLPointId operator++ (int) { return i++; } STLPointId operator-- (int) { return i--; } - + STLPointId & operator++ () { i++; return *this; } + void DoArchive(Archive& ar) { ar & i; } }; @@ -45,9 +46,11 @@ public: constexpr STLTrigId (int ai) : i(ai) { ; } STLTrigId & operator= (const STLTrigId & ai) { i = ai.i; return *this; } STLTrigId & operator= (int ai) { i = ai; return *this; } - operator int () const { return i; } + constexpr operator int () const { return i; } STLTrigId operator++ (int) { return i++; } STLTrigId operator-- (int) { return i--; } + STLTrigId & operator++ () { i++; return *this; } + }; @@ -199,7 +202,7 @@ public: const Vec<3> & nproj, Point<3> & pp, Vec<3> & lam) const; - int PointInside(const Array,STLPointId>& ap, const Point<3> & pp) const; + bool PointInside(const Array,STLPointId>& ap, const Point<3> & pp) const; //get nearest point on triangle and distance to it double GetNearestPoint(const Array,STLPointId>& ap, @@ -214,7 +217,7 @@ public: int GetFaceNum() {return facenum;} void SetFaceNum(int i) {facenum = i;} - int HasEdge(int p1, int p2) const; + bool HasEdge(STLPointId p1, STLPointId p2) const; }; @@ -225,22 +228,22 @@ public: */ class STLTopEdge { - int pts[2]; + STLPointId pts[2]; int trigs[2]; double cosangle; int status; // excluded, confirmed, candidate, undefined public: STLTopEdge (); - STLTopEdge (int p1, int p2, int trig1, int trig2); + STLTopEdge (STLPointId p1, STLPointId p2, int trig1, int trig2); - int operator[] (int i) const { return pts[i]; } - int & operator[] (int i) { return pts[i]; } + STLPointId operator[] (int i) const { return pts[i]; } + STLPointId & operator[] (int i) { return pts[i]; } - int PNum(int i) const { return pts[(i-1)]; } - int & PNum(int i) { return pts[(i-1)]; } - int PNumMod(int i) const { return pts[(i-1)%2]; } - int & PNumMod(int i) { return pts[(i-1)%2]; } + STLPointId PNum(int i) const { return pts[(i-1)]; } + STLPointId & PNum(int i) { return pts[(i-1)]; } + STLPointId PNumMod(int i) const { return pts[(i-1)%2]; } + STLPointId & PNumMod(int i) { return pts[(i-1)%2]; } int TrigNum(int i) const { return trigs[(i-1)]; } int & TrigNum(int i) { return trigs[(i-1)]; } @@ -275,7 +278,7 @@ protected: // mapping of sorted pair of points to topedge INDEX_2_HASHTABLE * ht_topedges; // mapping of node to trigs - TABLE trigsperpoint; + TABLE()> trigsperpoint; // mapping of node to edges TABLE topedgesperpoint;