diff --git a/libsrc/csg/edgeflw.cpp b/libsrc/csg/edgeflw.cpp index 6afa4957..b2afbfdc 100644 --- a/libsrc/csg/edgeflw.cpp +++ b/libsrc/csg/edgeflw.cpp @@ -617,7 +617,9 @@ namespace netgen (*testout) << "Point on edge" << endl << "seg = " << i2 << ", p = " << pi << endl << "pos = " << p << ", projected = " << hp << endl - << "seg is = " << mesh.Point(i2.I1()) << " - " << mesh.Point(i2.I2()) << endl; + << "seg is = " + << mesh.Point(PointIndex(i2.I1())) << " - " + << mesh.Point(PointIndex(i2.I2())) << endl; } } } diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 566f94a1..fb4a8f14 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -759,8 +759,9 @@ namespace netgen << "time = " << GetTime() << " sec" << endl << "points: " << mesh->GetNP() << endl; #endif - - if (mparam.uselocalh && 0) + + /* + if (mparam.uselocalh) { mesh->CalcLocalH(mparam.grading); mesh->DeleteMesh(); @@ -773,6 +774,7 @@ namespace netgen MeshSurface (geom, *mesh, mparam); if (multithread.terminate) return TCL_OK; } + */ #ifdef LOG_STREAM (*logout) << "Surfaces remeshed" << endl diff --git a/libsrc/csg/vscsg.cpp b/libsrc/csg/vscsg.cpp index b35b4b10..1f10a003 100644 --- a/libsrc/csg/vscsg.cpp +++ b/libsrc/csg/vscsg.cpp @@ -130,18 +130,18 @@ namespace netgen int hasp = 0; for (int i = 0; i < geometry->GetNTopLevelObjects(); i++) { - const TriangleApproximation & ta = - *geometry->GetTriApprox(i); - if (!&ta) continue; + const TriangleApproximation * ta = + geometry->GetTriApprox(i); + if (!ta) continue; - for (int j = 0; j < ta.GetNP(); j++) + for (int j = 0; j < ta->GetNP(); j++) { if (hasp) - box.Add (ta.GetPoint(j)); + box.Add (ta->GetPoint(j)); else { hasp = 1; - box.Set (ta.GetPoint(j)); + box.Set (ta->GetPoint(j)); } } } @@ -167,18 +167,18 @@ namespace netgen trilists.Append (glGenLists (1)); glNewList (trilists.Last(), GL_COMPILE); glEnable (GL_NORMALIZE); - const TriangleApproximation & ta = - *geometry->GetTriApprox(i); - if (&ta) + const TriangleApproximation * ta = + geometry->GetTriApprox(i); + if (ta) { glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(3, GL_DOUBLE, 0, &ta.GetPoint(0)(0)); + glVertexPointer(3, GL_DOUBLE, 0, &ta->GetPoint(0)(0)); glEnableClientState(GL_NORMAL_ARRAY); - glNormalPointer(GL_DOUBLE, 0, &ta.GetNormal(0)(0)); + glNormalPointer(GL_DOUBLE, 0, &ta->GetNormal(0)(0)); - for (int j = 0; j < ta.GetNT(); j++) - glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, & (ta.GetTriangle(j)[0])); + for (int j = 0; j < ta->GetNT(); j++) + glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, & (ta->GetTriangle(j)[0])); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); @@ -382,13 +382,20 @@ namespace netgen glDisable (GL_COLOR_MATERIAL); glDisable (GL_LIGHTING); glDisable (GL_CLIP_PLANE0); - + + /* for (int i = 1; i <= mesh -> GetNP(); i++) { const Point3d & p = mesh -> Point(i); glRasterPos3d (p.X(), p.Y(), p.Z()); glBitmap (7, 7, 3, 3, 0, 0, &knoedel[0]); } + */ + for (const Point3d & p : mesh->Points()) + { + glRasterPos3d (p.X(), p.Y(), p.Z()); + glBitmap (7, 7, 3, 3, 0, 0, &knoedel[0]); + } } if (vispar.drawedpointnrs) @@ -403,7 +410,8 @@ namespace netgen // glListBase (fontbase); char buf[20]; - for (int i = 1; i <= mesh->GetNP(); i++) + // for (int i = 1; i <= mesh->GetNP(); i++) + for (auto i : mesh->Points().Range()) { const Point3d & p = mesh->Point(i); glRasterPos3d (p.X(), p.Y(), p.Z()); diff --git a/libsrc/include/mydefs.hpp b/libsrc/include/mydefs.hpp index f9118daf..bf3cb1e9 100644 --- a/libsrc/include/mydefs.hpp +++ b/libsrc/include/mydefs.hpp @@ -38,7 +38,8 @@ - +// #define BASE0 +// #define DEBUG #define noDEMOVERSION diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 5955c0a6..5371a97e 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -14,6 +14,9 @@ namespace netgen { + + static constexpr int POINTINDEX_BASE = 1; + struct T_EDGE2 { // int orient:1; @@ -37,7 +40,7 @@ namespace netgen const int * ptr; int Size() const { return num; } - int operator[] (int i) const { return ptr[i]-1; } + int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } }; @@ -48,7 +51,7 @@ namespace netgen const int * ptr; int Size() const { return num; } - int operator[] (int i) const { return ptr[i]-1; } + int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } }; class Ng_Edges @@ -145,7 +148,7 @@ namespace netgen const int * ptr; int Size() const { return 2; } - int operator[] (int i) const { return ptr[i]-1; } + int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } }; @@ -165,7 +168,7 @@ namespace netgen const int * ptr; int Size() const { return nv; } - int operator[] (int i) const { return ptr[i]-1; } + int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } }; class Ng_Edges diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 5f41a35e..78b829e2 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -1,6 +1,6 @@ NGX_INLINE DLL_HEADER Ng_Point Ngx_Mesh :: GetPoint (int nr) const { - return Ng_Point (&mesh->Point(nr + PointIndex::BASE)(0)); + return Ng_Point (&mesh->Point(PointIndex(nr+PointIndex::BASE))(0)); } diff --git a/libsrc/interface/writejcm.cpp b/libsrc/interface/writejcm.cpp index 0b2ced88..59b64101 100644 --- a/libsrc/interface/writejcm.cpp +++ b/libsrc/interface/writejcm.cpp @@ -33,7 +33,7 @@ void WriteJCMFormat (const Mesh & mesh, int np = mesh.GetNP(); // Identic points - Array identmap1, identmap2, identmap3; + Array identmap1, identmap2, identmap3; mesh.GetIdentifications().GetMap(1, identmap1); mesh.GetIdentifications().GetMap(2, identmap2); mesh.GetIdentifications().GetMap(3, identmap3); diff --git a/libsrc/meshing/adfront2.hpp b/libsrc/meshing/adfront2.hpp index 4d76faaf..1bb21c40 100644 --- a/libsrc/meshing/adfront2.hpp +++ b/libsrc/meshing/adfront2.hpp @@ -35,7 +35,7 @@ /// FrontPoint2 () { - globalindex = -1; + globalindex.Invalidate(); // = -1; nlinetopoint = 0; frontnr = INT_MAX-10; // attention: overflow on calculating INT_MAX + 1 mgi = NULL; diff --git a/libsrc/meshing/adfront3.cpp b/libsrc/meshing/adfront3.cpp index 14d721d7..7a93e030 100644 --- a/libsrc/meshing/adfront3.cpp +++ b/libsrc/meshing/adfront3.cpp @@ -9,7 +9,7 @@ namespace netgen FrontPoint3 :: FrontPoint3 () { - globalindex = -1; + globalindex.Invalidate(); // = -1; nfacetopoint = 0; frontnr = 1000; cluster = 0; diff --git a/libsrc/meshing/adfront3.hpp b/libsrc/meshing/adfront3.hpp index 11993733..8954cd36 100644 --- a/libsrc/meshing/adfront3.hpp +++ b/libsrc/meshing/adfront3.hpp @@ -17,15 +17,15 @@ class FrontPoint3 { /// coordinates -Point<3> p; + Point<3> p; /// global node index -PointIndex globalindex; + PointIndex globalindex; /// number of faces connected to point -int nfacetopoint; + int nfacetopoint; /// distance to original boundary -int frontnr; + int frontnr; /// -int cluster; + int cluster; public: /// FrontPoint3 (); @@ -43,7 +43,7 @@ public: void AddFace () { nfacetopoint++; } - /// + /// if last face is removed, then point is invalidated void RemoveFace() { nfacetopoint--; @@ -51,7 +51,7 @@ public: } /// - int Valid () const + bool Valid () const { return nfacetopoint >= 0; } /// @@ -74,7 +74,7 @@ class MiniElement2d { protected: int np; - PointIndex pnum[4]; + PointIndex pnum[4]; // can be global or local nums bool deleted; public: MiniElement2d () @@ -89,8 +89,8 @@ public: const PointIndex PNum (int i) const { return pnum[i-1]; } PointIndex & PNum (int i) { return pnum[i-1]; } const PointIndex PNumMod (int i) const { return pnum[(i-1)%np]; } - - void Delete () { deleted = 1; pnum[0] = pnum[1] = pnum[2] = pnum[3] = PointIndex::BASE-1; } + auto PNums() const { return FlatArray (np, &pnum[0]); } + void Delete () { deleted = true; for (PointIndex & p : pnum) p.Invalidate(); } bool IsDeleted () const { return deleted; } }; @@ -120,7 +120,7 @@ private: int hashvalue; /// int cluster; - + public: /// FrontFace (); @@ -178,43 +178,43 @@ class AdFront3 /// Array points; /// -Array faces; + Array faces; /// -Array delpointl; - + Array delpointl; + /// which points are connected to pi ? -TABLE * connectedpairs; + TABLE * connectedpairs; /// number of total front faces; -int nff; + int nff; /// number of quads in front -int nff4; + int nff4; /// -double vol; - + double vol; + /// -GeomSearch3d hashtable; - + GeomSearch3d hashtable; + /// -int hashon; + int hashon; /// -int hashcreated; - + int hashcreated; + /// counter for rebuilding internal tables -int rebuildcounter; + int rebuildcounter; /// last base element -int lasti; + int lasti; /// minimal selection-value of baseelements -int minval; - Array invpindex; + int minval; + Array invpindex; Array pingroup; /// -class Box3dTree * facetree; + class Box3dTree * facetree; public: - + /// AdFront3 (); /// diff --git a/libsrc/meshing/curvedelems.cpp b/libsrc/meshing/curvedelems.cpp index 14b0d4df..48538359 100644 --- a/libsrc/meshing/curvedelems.cpp +++ b/libsrc/meshing/curvedelems.cpp @@ -3873,7 +3873,7 @@ namespace netgen Mat _dxdxi; if (!EvaluateMapping (info, _xi, _x, _dxdxi)) { ok = false; break; } - // cout << "x = " << _x << ", dxdxi = " << _dxdxi << endl; + // *testout << "x = " << _x << ", dxdxi = " << _dxdxi << endl; if (x) for (int j = 0; j < DIM_SPACE; j++) x[i*sx+j] = _x[j]; diff --git a/libsrc/meshing/delaunay.cpp b/libsrc/meshing/delaunay.cpp index 9cb37644..69bffb0f 100644 --- a/libsrc/meshing/delaunay.cpp +++ b/libsrc/meshing/delaunay.cpp @@ -415,9 +415,9 @@ namespace netgen INDEX_3 i3 = tempels.Get(helind).GetFace (k-1); - const Point3d & p1 = mesh.Point ( i3.I1()); - const Point3d & p2 = mesh.Point ( i3.I2()); - const Point3d & p3 = mesh.Point ( i3.I3()); + const Point3d & p1 = mesh.Point ( PointIndex (i3.I1()) ); + const Point3d & p2 = mesh.Point ( PointIndex (i3.I2()) ); + const Point3d & p3 = mesh.Point ( PointIndex (i3.I3()) ); Vec3d v1(p1, p2); @@ -612,20 +612,20 @@ namespace netgen for (int i = 1; i <= adfront->GetNF(); i++) { const MiniElement2d & face = adfront->GetFace(i); - for (int j = 0; j < face.GetNP(); j++) + for (PointIndex pi : face.PNums()) { - pmin.SetToMin (mesh.Point (face[j])); - pmax.SetToMax (mesh.Point (face[j])); + pmin.SetToMin (mesh.Point (pi)); + pmax.SetToMax (mesh.Point (pi)); } } - for (int i = 0; i < mesh.LockedPoints().Size(); i++) + for (PointIndex pi : mesh.LockedPoints()) { - pmin.SetToMin (mesh.Point (mesh.LockedPoints()[i])); - pmax.SetToMax (mesh.Point (mesh.LockedPoints()[i])); + pmin.SetToMin (mesh.Point (pi)); + pmax.SetToMax (mesh.Point (pi)); } - - + + Vec3d vdiag(pmin, pmax); // double r1 = vdiag.Length(); diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index d09b7c98..1ac00716 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -216,8 +216,10 @@ namespace netgen int GetNP () const { return points.Size(); } + // [[deprecated("Use Point(PointIndex) instead of int !")]] MeshPoint & Point(int i) { return points.Elem(i); } MeshPoint & Point(PointIndex pi) { return points[pi]; } + // [[deprecated("Use Point(PointIndex) instead of int !")]] const MeshPoint & Point(int i) const { return points.Get(i); } const MeshPoint & Point(PointIndex pi) const { return points[pi]; } @@ -231,8 +233,8 @@ namespace netgen DLL_HEADER SegmentIndex AddSegment (const Segment & s); void DeleteSegment (int segnr) { - segments.Elem(segnr)[0] = PointIndex::BASE-1; - segments.Elem(segnr)[1] = PointIndex::BASE-1; + segments.Elem(segnr)[0].Invalidate(); + segments.Elem(segnr)[1].Invalidate(); } void FullDeleteSegment (int segnr) // von wem ist das ??? { @@ -257,9 +259,9 @@ namespace netgen void DeleteSurfaceElement (int eli) { surfelements.Elem(eli).Delete(); - surfelements.Elem(eli).PNum(1) = -1; - surfelements.Elem(eli).PNum(2) = -1; - surfelements.Elem(eli).PNum(3) = -1; + surfelements.Elem(eli).PNum(1).Invalidate(); + surfelements.Elem(eli).PNum(2).Invalidate(); + surfelements.Elem(eli).PNum(3).Invalidate(); timestamp = NextTimeStamp(); } @@ -290,7 +292,9 @@ namespace netgen int GetNE () const { return volelements.Size(); } + // [[deprecated("Use VolumeElement(ElementIndex) instead of int !")]] Element & VolumeElement(int i) { return volelements.Elem(i); } + // [[deprecated("Use VolumeElement(ElementIndex) instead of int !")]] const Element & VolumeElement(int i) const { return volelements.Get(i); } Element & VolumeElement(ElementIndex i) { return volelements[i]; } const Element & VolumeElement(ElementIndex i) const { return volelements[i]; } diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index b4476e00..e2dea8f4 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -538,6 +538,9 @@ namespace netgen shape(3) = (1-p(0))* p(1) ; break; } + + default: + throw NgException ("illegal element type in GetShapeNew"); } } @@ -562,6 +565,8 @@ namespace netgen shape(3) = (1-p(0))* p(1) ; break; } + default: + throw NgException ("illegal element type in GetShapeNew"); } } diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 3703c6b6..ec467c99 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -125,6 +125,8 @@ namespace netgen PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; } PointIndex operator++ () { i++; return *this; } PointIndex operator-- () { i--; return *this; } + void Invalidate() { i = PointIndex::BASE-1; } + bool IsValid() const { return i != PointIndex::BASE-1; } #ifdef BASE0 enum { BASE = 0 }; #else @@ -134,7 +136,7 @@ namespace netgen inline istream & operator>> (istream & ist, PointIndex & pi) { - int i; ist >> i; pi = i; return ist; + int i; ist >> i; pi = PointIndex(i); return ist; } inline ostream & operator<< (ostream & ost, const PointIndex & pi) @@ -471,8 +473,14 @@ namespace netgen int pi, Vec2d & dir, double & dd) const; - - void Delete () { deleted = 1; pnum[0] = pnum[1] = pnum[2] = pnum[3] = PointIndex::BASE-1; } + + void Delete () + { + deleted = 1; + for (PointIndex & p : pnum) + p.Invalidate(); + } + bool IsDeleted () const { #ifdef DEBUG diff --git a/libsrc/meshing/smoothing3.cpp b/libsrc/meshing/smoothing3.cpp index 8cb318ea..6efb8f9b 100644 --- a/libsrc/meshing/smoothing3.cpp +++ b/libsrc/meshing/smoothing3.cpp @@ -1422,19 +1422,18 @@ void Mesh :: ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal) if(lochfunc) { - for(int i=1; i<=points.Size(); i++) - pointh[i] = GetH(points.Get(i)); + for (PointIndex pi : points.Range()) + pointh[pi] = GetH(points[pi]); } else { pointh = 0; - for(int i=0; i pointh[el.PNum(j)]) - pointh[el.PNum(j)] = h; + for (PointIndex pi : el.PNums()) + if (h > pointh[pi]) + pointh[pi] = h; } } @@ -1455,21 +1454,15 @@ void Mesh :: ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal) const char * savetask = multithread.task; multithread.task = "Smooth Mesh"; - - for (PointIndex pi = points.Begin(); pi < points.End(); pi++) + + for (PointIndex pi : points.Range()) if ( (*this)[pi].Type() == INNERPOINT && perrs[pi] > 0.01 * badmax) { if (multithread.terminate) throw NgException ("Meshing stopped"); multithread.percent = 100.0 * (pi+1-PointIndex::BASE) / points.Size(); - /* - if (points.Size() < 1000) - PrintDot (); - else - if ( (i+1-PointIndex::BASE) % 10 == 0) - PrintDot ('+'); - */ + if ( (pi+1-PointIndex::BASE) % printmod == 0) PrintDot (printdot); double lh = pointh[pi]; @@ -1503,7 +1496,6 @@ void Mesh :: ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal) } PrintDot ('\n'); - delete pf; multithread.task = savetask; diff --git a/libsrc/visualization/mvdraw.cpp b/libsrc/visualization/mvdraw.cpp index 04d98e6c..f5d00922 100644 --- a/libsrc/visualization/mvdraw.cpp +++ b/libsrc/visualization/mvdraw.cpp @@ -63,8 +63,8 @@ namespace netgen int VisualScene :: selface; int VisualScene :: selelement; - int VisualScene :: selpoint; - int VisualScene :: selpoint2; + PointIndex VisualScene :: selpoint; + PointIndex VisualScene :: selpoint2; int VisualScene :: locpi; int VisualScene :: seledge; diff --git a/libsrc/visualization/mvdraw.hpp b/libsrc/visualization/mvdraw.hpp index a1977572..39efbc5f 100644 --- a/libsrc/visualization/mvdraw.hpp +++ b/libsrc/visualization/mvdraw.hpp @@ -26,8 +26,8 @@ namespace netgen static int DLL_HEADER selface; static int selelement; - static int DLL_HEADER selpoint; - static int selpoint2; + static PointIndex DLL_HEADER selpoint; + static PointIndex selpoint2; static int locpi; static int DLL_HEADER seledge; @@ -235,8 +235,8 @@ namespace netgen const Point3d & center, const double rad, const int displaylist, - int & selelement, int & selface, int & seledge, int & selpoint, - int & selpoint2, int & locpi); + int & selelement, int & selface, int & seledge, PointIndex & selpoint, + PointIndex & selpoint2, int & locpi); } diff --git a/libsrc/visualization/vsmesh.cpp b/libsrc/visualization/vsmesh.cpp index 2a58e6e6..cd366aa5 100644 --- a/libsrc/visualization/vsmesh.cpp +++ b/libsrc/visualization/vsmesh.cpp @@ -3343,8 +3343,8 @@ namespace netgen const Point3d & center, const double rad, const int displaylist, - int & selelement, int & selface, int & seledge, int & selpoint, - int & selpoint2, int & locpi) + int & selelement, int & selface, int & seledge, PointIndex & selpoint, + PointIndex & selpoint2, int & locpi) { auto mesh = vsmesh.GetMesh();