From d7bf88e0cdbb31a6cb93152650c2184ed12097c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Sun, 29 Jul 2018 12:03:56 +0200 Subject: [PATCH] modernize STL-meshing --- libsrc/gprim/geomobjects.hpp | 6 ++ libsrc/stlgeom/stlgeom.cpp | 1 + libsrc/stlgeom/stlgeom.hpp | 2 + libsrc/stlgeom/stlgeomchart.cpp | 3 +- libsrc/stlgeom/stlgeommesh.cpp | 24 +++++-- libsrc/stlgeom/stltool.cpp | 120 ++++++++++++++++++-------------- libsrc/stlgeom/stltool.hpp | 39 ++++++----- 7 files changed, 117 insertions(+), 78 deletions(-) diff --git a/libsrc/gprim/geomobjects.hpp b/libsrc/gprim/geomobjects.hpp index ef5da2c5..388e9a54 100644 --- a/libsrc/gprim/geomobjects.hpp +++ b/libsrc/gprim/geomobjects.hpp @@ -229,6 +229,12 @@ namespace netgen } } + Box (const Point & p1, const Point & p2, const Point & p3) + : Box(p1,p2) + { + Add (p3); + } + enum EB_TYPE { EMPTY_BOX = 1 }; Box ( EB_TYPE et ) { diff --git a/libsrc/stlgeom/stlgeom.cpp b/libsrc/stlgeom/stlgeom.cpp index 8c2e5a1f..79e57ab8 100644 --- a/libsrc/stlgeom/stlgeom.cpp +++ b/libsrc/stlgeom/stlgeom.cpp @@ -62,6 +62,7 @@ void STLMeshing (STLGeometry & geom, STLGeometry :: ~STLGeometry() { + for (auto p : atlas) delete p; delete edgedata; delete ref; } diff --git a/libsrc/stlgeom/stlgeom.hpp b/libsrc/stlgeom/stlgeom.hpp index 7b1d814d..dfed02de 100644 --- a/libsrc/stlgeom/stlgeom.hpp +++ b/libsrc/stlgeom/stlgeom.hpp @@ -26,6 +26,7 @@ namespace netgen { + /* inline int IsInArray(int n, const Array& ia) { return ia.Contains(n); @@ -37,6 +38,7 @@ namespace netgen list.Append(x); return true; } + */ extern DLL_HEADER MeshingParameters mparam; diff --git a/libsrc/stlgeom/stlgeomchart.cpp b/libsrc/stlgeom/stlgeomchart.cpp index 81158d3a..5962ac82 100644 --- a/libsrc/stlgeom/stlgeomchart.cpp +++ b/libsrc/stlgeom/stlgeomchart.cpp @@ -818,7 +818,8 @@ void STLGeometry :: GetDirtyChartTrigs(int chartnum, STLChart& chart, if (GetChartNr(tn2) != chartnum && outercharttrigs.Get(tn2) != chartnum) {problem = 1;} } - if (problem && !IsInArray(j,dirtytrigs)) + // if (problem && !IsInArray(j,dirtytrigs)) + if (problem && !dirtytrigs.Contains(j)) { dirtytrigs.Append(j); cnt++; diff --git a/libsrc/stlgeom/stlgeommesh.cpp b/libsrc/stlgeom/stlgeommesh.cpp index a028987f..bc4613d3 100644 --- a/libsrc/stlgeom/stlgeommesh.cpp +++ b/libsrc/stlgeom/stlgeommesh.cpp @@ -1174,14 +1174,18 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, Array& acttrig { Point3d p3p1 = GetPoint(np1); Point3d p3p2 = GetPoint(np2); - if (AddIfNotExists(limes1,np1)) + // if (AddIfNotExists(limes1,np1)) + if (!limes1.Contains(np1)) { + limes1.Append(np1); plimes1.Append(p3p1); plimes1trigs.Append(t); plimes1origin.Append(np1); } - if (AddIfNotExists(limes1,np2)) + // if (AddIfNotExists(limes1,np2)) + if (!limes1.Contains(np2)) { + limes1.Append(np2); plimes1.Append(p3p2); plimes1trigs.Append(t); plimes1origin.Append(np2); @@ -1226,8 +1230,20 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, Array& acttrig Point3d p3p1 = GetPoint(np1); Point3d p3p2 = GetPoint(np2); - if (AddIfNotExists(limes2,np1)) {plimes2.Append(p3p1); plimes2trigs.Append(t);} - if (AddIfNotExists(limes2,np2)) {plimes2.Append(p3p2); plimes2trigs.Append(t);} + // if (AddIfNotExists(limes2,np1)) {plimes2.Append(p3p1); plimes2trigs.Append(t);} + // if (AddIfNotExists(limes2,np2)) {plimes2.Append(p3p2); plimes2trigs.Append(t);} + if (!limes2.Contains(np1)) + { + limes2.Append(np1); + plimes2.Append(p3p1); + plimes2trigs.Append(t); + } + if (!limes2.Contains(np2)) + { + limes2.Append(np2); + plimes2.Append(p3p2); + plimes2trigs.Append(t); + } chart.AddOLimit(twoint(np1,np2)); for (int di = 1; di <= divisions; di++) diff --git a/libsrc/stlgeom/stltool.cpp b/libsrc/stlgeom/stltool.cpp index 54b8c31f..41f0f1d7 100644 --- a/libsrc/stlgeom/stltool.cpp +++ b/libsrc/stlgeom/stltool.cpp @@ -609,40 +609,62 @@ STLTopEdge :: STLTopEdge (int p1, int p2, int trig1, int trig2) STLChart :: STLChart(STLGeometry * ageometry) { - charttrigs = new Array (0,0); - outertrigs = new Array (0,0); - ilimit = new Array (0,0); - olimit = new Array (0,0); + // charttrigs = new Array (0,0); + // outertrigs = new Array (0,0); + // ilimit = new Array (0,0); + // olimit = new Array (0,0); geometry = ageometry; if ( stlparam.usesearchtree == 1) - searchtree = new BoxTree<3> (geometry->GetBoundingBox().PMin() - Vec3d(1,1,1), - geometry->GetBoundingBox().PMax() + Vec3d(1,1,1)); + { + Box<3> box = geometry->GetBoundingBox(); + box.Increase (0.2*box.Diam()+1e-12); + searchtree = new BoxTree<3> (box); + /* + searchtree = new BoxTree<3> (geometry->GetBoundingBox().PMin() - Vec3d(1,1,1), + geometry->GetBoundingBox().PMax() + Vec3d(1,1,1)); + */ + } else searchtree = NULL; } +STLChart :: ~STLChart() +{ + delete searchtree; +} + void STLChart :: AddChartTrig(int i) { // static int timer = NgProfiler::CreateTimer ("STLChart::AddChartTrig"); // NgProfiler::RegionTimer reg(timer); - charttrigs->Append(i); + charttrigs.Append(i); const STLTriangle & trig = geometry->GetTriangle(i); - const Point3d & p1 = geometry->GetPoint (trig.PNum(1)); - const Point3d & p2 = geometry->GetPoint (trig.PNum(2)); - const Point3d & p3 = geometry->GetPoint (trig.PNum(3)); + const Point<3> & p1 = geometry->GetPoint (trig.PNum(1)); + const Point<3> & p2 = geometry->GetPoint (trig.PNum(2)); + const Point<3> & p3 = geometry->GetPoint (trig.PNum(3)); + /* Point3d pmin(p1), pmax(p1); pmin.SetToMin (p2); pmin.SetToMin (p3); pmax.SetToMax (p2); pmax.SetToMax (p3); - + */ + /* + Box<3> box(p1); + box.Add(p2); + box.Add(p3); + */ + Box<3> box(p1,p2,p3); if (!geomsearchtreeon && (stlparam.usesearchtree == 1)) - {searchtree->Insert (pmin, pmax, i);} + // {searchtree->Insert (pmin, pmax, i);} + { + searchtree->Insert (box, i); + } } void STLChart :: AddOuterTrig(int i) @@ -650,7 +672,7 @@ void STLChart :: AddOuterTrig(int i) // static int timer = NgProfiler::CreateTimer ("STLChart::AddOuterTrig"); // NgProfiler::RegionTimer reg(timer); - outertrigs->Append(i); + outertrigs.Append(i); const STLTriangle & trig = geometry->GetTriangle(i); const Point3d & p1 = geometry->GetPoint (trig.PNum(1)); @@ -669,11 +691,11 @@ void STLChart :: AddOuterTrig(int i) int STLChart :: IsInWholeChart(int nr) const { - for (int i = 1; i <= charttrigs->Size(); i++) - if (charttrigs->Get(i) == nr) return 1; + for (int i = 1; i <= charttrigs.Size(); i++) + if (charttrigs.Get(i) == nr) return 1; - for (int i = 1; i <= outertrigs->Size(); i++) - if (outertrigs->Get(i) == nr) return 1; + for (int i = 1; i <= outertrigs.Size(); i++) + if (outertrigs.Get(i) == nr) return 1; return 0; } @@ -688,9 +710,8 @@ void STLChart :: GetTrianglesInBox (const Point3d & pmin, searchtree -> GetIntersecting (pmin, pmax, trias); else { - Box3d box1(pmin, pmax); - box1.Increase (1e-4); - Box3d box2; + Box<3> box1(pmin, pmax); + box1.Increase (1e-2*box1.Diam()); trias.SetSize(0); @@ -699,9 +720,9 @@ void STLChart :: GetTrianglesInBox (const Point3d & pmin, { int trignum = GetTrig(i); const STLTriangle & trig = geometry->GetTriangle(trignum); - box2.SetPoint (geometry->GetPoint (trig.PNum(1))); - box2.AddPoint (geometry->GetPoint (trig.PNum(2))); - box2.AddPoint (geometry->GetPoint (trig.PNum(3))); + Box<3> box2(geometry->GetPoint (trig.PNum(1)), + geometry->GetPoint (trig.PNum(2)), + geometry->GetPoint (trig.PNum(3))); if (box1.Intersect (box2)) trias.Append (trignum); @@ -712,12 +733,12 @@ void STLChart :: GetTrianglesInBox (const Point3d & pmin, //trigs may contain the same triangle double void STLChart :: MoveToOuterChart(const Array& trigs) { - if (!trigs.Size()) {return;} + if (!trigs.Size()) return; for (int i = 1; i <= trigs.Size(); i++) { - if (charttrigs->Get(trigs.Get(i)) != -1) - {AddOuterTrig(charttrigs->Get(trigs.Get(i)));} - charttrigs->Elem(trigs.Get(i)) = -1; + if (charttrigs.Get(trigs.Get(i)) != -1) + {AddOuterTrig(charttrigs.Get(trigs.Get(i)));} + charttrigs.Elem(trigs.Get(i)) = -1; } DelChartTrigs(trigs); } @@ -725,27 +746,22 @@ void STLChart :: MoveToOuterChart(const Array& trigs) //trigs may contain the same triangle double void STLChart :: DelChartTrigs(const Array& trigs) { - if (!trigs.Size()) {return;} + if (!trigs.Size()) return; for (int i = 1; i <= trigs.Size(); i++) - { - charttrigs->Elem(trigs.Get(i)) = -1; - } + charttrigs.Elem(trigs.Get(i)) = -1; int cnt = 0; - for (int i = 1; i <= charttrigs->Size(); i++) + for (int i = 1; i <= charttrigs.Size(); i++) { - if (charttrigs->Elem(i) == -1) - { - cnt++; - } - if (cnt != 0 && i < charttrigs->Size()) - { - charttrigs->Elem(i-cnt+1) = charttrigs->Get(i+1); - } + if (charttrigs.Elem(i) == -1) + cnt++; + if (cnt != 0 && i < charttrigs.Size()) + charttrigs.Elem(i-cnt+1) = charttrigs.Get(i+1); } - int i = charttrigs->Size() - trigs.Size(); - charttrigs->SetSize(i); + + int i = charttrigs.Size() - trigs.Size(); + charttrigs.SetSize(i); if (!geomsearchtreeon && stlparam.usesearchtree == 1) { @@ -754,7 +770,7 @@ void STLChart :: DelChartTrigs(const Array& trigs) searchtree = new BoxTree<3> (geometry->GetBoundingBox().PMin() - Vec3d(1,1,1), geometry->GetBoundingBox().PMax() + Vec3d(1,1,1)); - for (int i = 1; i <= charttrigs->Size(); i++) + for (int i = 1; i <= charttrigs.Size(); i++) { const STLTriangle & trig = geometry->GetTriangle(i); const Point3d & p1 = geometry->GetPoint (trig.PNum(1)); @@ -767,7 +783,7 @@ void STLChart :: DelChartTrigs(const Array& trigs) pmax.SetToMax (p2); pmax.SetToMax (p3); - searchtree->Insert (pmin, pmax, i); + searchtree->Insert (pmin, pmax, i); } } } @@ -831,21 +847,17 @@ void STLBoundarySeg :: Swap () STLBoundary :: STLBoundary (STLGeometry * ageometry) - : // boundary(), - geometry(ageometry) -{ - ; -} + : geometry(ageometry) +{ ; } void STLBoundary :: AddOrDelSegment(const STLBoundarySeg & seg) { - int i; - int found = 0; - for (i = 1; i <= boundary.Size(); i++) + bool found = false; + for (int i = 1; i <= boundary.Size(); i++) { - if (found) {boundary.Elem(i-1) = boundary.Get(i);} - if (boundary.Get(i) == seg) {found = 1;} + if (found) { boundary.Elem(i-1) = boundary.Get(i); } + if (boundary.Get(i) == seg) { found = true; } } if (!found) { diff --git a/libsrc/stlgeom/stltool.hpp b/libsrc/stlgeom/stltool.hpp index c572c077..1f2478a4 100644 --- a/libsrc/stlgeom/stltool.hpp +++ b/libsrc/stlgeom/stltool.hpp @@ -43,49 +43,50 @@ class STLChart { private: STLGeometry * geometry; - Array* charttrigs; // trigs which only belong to this chart - Array* outertrigs; // trigs which belong to other charts + Array charttrigs; // trigs which only belong to this chart + Array outertrigs; // trigs which belong to other charts BoxTree<3> * searchtree; // ADT containing outer trigs - Array* olimit; //outer limit of outer chart - Array* ilimit; //outer limit of inner chart + Array olimit; //outer limit of outer chart + Array ilimit; //outer limit of inner chart public: STLChart(STLGeometry * ageometry); + ~STLChart(); void AddChartTrig(int i); void AddOuterTrig(int i); int IsInWholeChart(int nr) const; - int GetChartTrig(int i) const {return charttrigs->Get(i);} - int GetOuterTrig(int i) const {return outertrigs->Get(i);} + int GetChartTrig(int i) const {return charttrigs.Get(i);} + int GetOuterTrig(int i) const {return outertrigs.Get(i);} //get all trigs: int GetTrig(int i) const { - if (i <= charttrigs->Size()) {return charttrigs->Get(i);} - else {return outertrigs->Get(i-charttrigs->Size());} + if (i <= charttrigs.Size()) {return charttrigs.Get(i);} + else {return outertrigs.Get(i-charttrigs.Size());} } - int GetNChartT() const {return charttrigs->Size();} - int GetNOuterT() const {return outertrigs->Size();} - int GetNT() const {return charttrigs->Size()+outertrigs->Size(); } + int GetNChartT() const {return charttrigs.Size();} + int GetNOuterT() const {return outertrigs.Size();} + int GetNT() const {return charttrigs.Size()+outertrigs.Size(); } void GetTrianglesInBox (const Point3d & pmin, const Point3d & pmax, Array & trias) const; - void AddOLimit(twoint l) {olimit->Append(l);} - void AddILimit(twoint l) {ilimit->Append(l);} + void AddOLimit(twoint l) {olimit.Append(l);} + void AddILimit(twoint l) {ilimit.Append(l);} - void ClearOLimit() {olimit->SetSize(0);} - void ClearILimit() {ilimit->SetSize(0);} + void ClearOLimit() {olimit.SetSize(0);} + void ClearILimit() {ilimit.SetSize(0);} - int GetNOLimit() const {return olimit->Size();} - int GetNILimit() const {return ilimit->Size();} + int GetNOLimit() const {return olimit.Size();} + int GetNILimit() const {return ilimit.Size();} - twoint GetOLimit(int i) const {return olimit->Get(i);} - twoint GetILimit(int i) const {return ilimit->Get(i);} + twoint GetOLimit(int i) const {return olimit.Get(i);} + twoint GetILimit(int i) const {return ilimit.Get(i);} //move triangles trigs (local chart-trig numbers) to outer chart void MoveToOuterChart(const Array& trigs);