From d6b16870fa27932afcee1480259f72ebdbb75724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 12 Dec 2016 11:47:46 +0100 Subject: [PATCH] PointIndex::BASE = 0 and STL, PointIndices --- libsrc/meshing/meshclass.cpp | 23 +++++++++++------------ libsrc/meshing/meshclass.hpp | 2 +- libsrc/meshing/meshtype.hpp | 13 ++++++++++++- libsrc/meshing/refine.cpp | 28 +++++++++++----------------- libsrc/stlgeom/meshstlsurface.cpp | 8 ++++---- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index d76248a4..c7f5a7c0 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -2148,7 +2148,7 @@ namespace netgen INDEX_2 seg (el.PNumMod(j), el.PNumMod(j+1)); INDEX_2 data; - if (seg.I1() <= 0 || seg.I2() <= 0) + if (seg.I1() < PointIndex::BASE || seg.I2() < PointIndex::BASE) cerr << "seg = " << seg << endl; if (faceht.Used(seg)) @@ -2355,34 +2355,33 @@ namespace netgen void Mesh :: RemoveOneLayerSurfaceElements () { - int i, j; int np = GetNP(); FindOpenSegments(); - BitArray frontpoints(np); - + BitArray frontpoints(np+1); // for 0- and 1-based frontpoints.Clear(); - for (i = 1; i <= GetNOpenSegments(); i++) + + for (int i = 1; i <= GetNOpenSegments(); i++) { const Segment & seg = GetOpenSegment(i); frontpoints.Set (seg[0]); frontpoints.Set (seg[1]); } - for (i = 1; i <= GetNSE(); i++) + for (int i = 1; i <= GetNSE(); i++) { Element2d & sel = surfelements.Elem(i); - int remove = 0; - for (j = 1; j <= sel.GetNP(); j++) + bool remove = false; + for (int j = 1; j <= sel.GetNP(); j++) if (frontpoints.Test(sel.PNum(j))) - remove = 1; + remove = true; if (remove) - sel.PNum(1) = 0; + sel.PNum(1).Invalidate(); } - for (i = surfelements.Size(); i >= 1; i--) + for (int i = surfelements.Size(); i >= 1; i--) { - if (surfelements.Elem(i).PNum(1) == 0) + if (!surfelements.Elem(i).PNum(1).IsValid()) { surfelements.Elem(i) = surfelements.Last(); surfelements.DeleteLast(); diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 83565105..2fe0d45d 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -170,7 +170,7 @@ namespace netgen /// number of refinement levels int mglevels; /// refinement hierarchy - Array mlbetweennodes; + Array,PointIndex::BASE> mlbetweennodes; /// parent element of volume element Array mlparentelement; /// parent element of surface element diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index a38bcad0..04be6d0c 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -144,7 +144,18 @@ namespace netgen return (ost << int(pi)); } - + template class PointIndices; + template <> class PointIndices<2> : public INDEX_2 + { + public: + PointIndices () = default; + PointIndices (INDEX_2 i2) : INDEX_2(i2) { ; } + PointIndices (PointIndex i1, PointIndex i2) : INDEX_2(i1,i2) { ; } + PointIndex operator[] (int i) const { return PointIndex(INDEX_2::operator[](i)); } + PointIndex & operator[] (int i) { return reinterpret_cast(INDEX_2::operator[](i)); } + static PointIndices Sort(PointIndex i1, PointIndex i2) { return INDEX_2::Sort(i1, i2); } + }; + class ElementIndex diff --git a/libsrc/meshing/refine.cpp b/libsrc/meshing/refine.cpp index 4e8a5ae7..3cb40d18 100644 --- a/libsrc/meshing/refine.cpp +++ b/libsrc/meshing/refine.cpp @@ -54,14 +54,13 @@ namespace netgen case TRIG: case TRIG6: { - static int betw[3][3] = - { { 2, 3, 4 }, - { 1, 3, 5 }, - { 1, 2, 6 } }; - + static int betw[3][3] = + { { 1, 2, 3 }, + { 0, 2, 4 }, + { 0, 1, 5 } }; for (int j = 0; j < 3; j++) { - INDEX_2 i2 = INDEX_2::Sort(el.PNum(betw[j][0]),el.PNum(betw[j][1])); + auto i2 = PointIndices<2>::Sort(el[betw[j][0]],el[betw[j][1]]); if (!between.Used(i2)) { between.Set (i2, 0); @@ -771,12 +770,9 @@ namespace netgen BitArray boundp(np); boundp.Clear(); - for (int i = 1; i <= mesh.GetNSE(); i++) - { - const Element2d & sel = mesh.SurfaceElement(i); - for (int j = 1; j <= sel.GetNP(); j++) - boundp.Set(sel.PNum(j)); - } + for (auto & sel : mesh.SurfaceElements()) + for (auto pi : sel.PNums()) + boundp.Set(pi); double lam = 0.5; @@ -835,11 +831,9 @@ namespace netgen (*testout) << "p " << i << endl; (*testout) << "surf points: " << endl; - for (int i = 1; i <= mesh.GetNSE(); i++) - for (int j = 1; j <= 3; j++) - (*testout) << mesh.SurfaceElement(i).PNum(j) << endl; - - + for (auto & sel : mesh.SurfaceElements()) + for (auto pi : sel.PNums()) + (*testout) << pi << endl; mesh.CalcSurfacesOfNode(); free.Invert(); diff --git a/libsrc/stlgeom/meshstlsurface.cpp b/libsrc/stlgeom/meshstlsurface.cpp index 98c1567a..41b2f489 100644 --- a/libsrc/stlgeom/meshstlsurface.cpp +++ b/libsrc/stlgeom/meshstlsurface.cpp @@ -121,8 +121,8 @@ static void STLFindEdges (STLGeometry & geom, */ Point3d hp, hp2; Segment seg; - seg[0] = p1; - seg[1] = p2; + seg[0] = p1 + PointIndex::BASE-1; + seg[1] = p2 + PointIndex::BASE-1; seg.si = geom.GetTriangle(trig1).GetFaceNum(); seg.edgenr = i; @@ -177,8 +177,8 @@ static void STLFindEdges (STLGeometry & geom, Segment seg2; - seg2[0] = p2; - seg2[1] = p1; + seg2[0] = p2 + PointIndex::BASE-1;; + seg2[1] = p1 + PointIndex::BASE-1;; seg2.si = geom.GetTriangle(trig2).GetFaceNum(); seg2.edgenr = i;