From dbbfebcf1a0cb3ddf4d97a07b275c804601a9027 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Sun, 22 Sep 2019 15:49:06 +0200 Subject: [PATCH] only use hashtable in stlboundary --- libsrc/stlgeom/stltool.cpp | 52 +++++++++++++++----------------------- libsrc/stlgeom/stltool.hpp | 18 +++++++++---- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/libsrc/stlgeom/stltool.cpp b/libsrc/stlgeom/stltool.cpp index 64600335..0f389887 100644 --- a/libsrc/stlgeom/stltool.cpp +++ b/libsrc/stlgeom/stltool.cpp @@ -852,20 +852,25 @@ STLBoundary :: STLBoundary (STLGeometry * ageometry) void STLBoundary :: AddOrDelSegment(const STLBoundarySeg & seg) { - 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 = true; } - } - if (!found) - { - boundary.Append(seg); - } - else - { - boundary.SetSize(boundary.Size()-1); - } + INDEX_2 op(seg.I1(), seg.I2()); + if(boundary_ht.Used(op)) + boundary_ht.Delete(op); + else + boundary_ht[op] = seg; + // 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 = true; } + // } + // if (!found) + // { + // boundary.Append(seg); + // } + // else + // { + // boundary.SetSize(boundary.Size()-1); + // } } void STLBoundary ::AddTriangle(const STLTriangle & t) @@ -1009,18 +1014,7 @@ void STLBoundary ::AddTriangle(const STLTriangle & t) { STLBoundarySeg bseg(seg[0], seg[1], geometry->GetPoints(), chart); bseg.SetSmoothEdge (geometry->IsSmoothEdge (seg[0],seg[1])); - - INDEX_2 op(seg[1], seg[0]); - if (boundary_ht.Used(op)) - { - // cout << "delete " << op << endl; - boundary_ht.Delete(op); - } - else - { - // cout << "insert " << seg << endl; - boundary_ht[seg] = bseg; - } + AddOrDelSegment(bseg); } /* // cout << "bounds = " << boundary << endl; @@ -1106,12 +1100,8 @@ bool STLBoundary :: TestSeg(const Point<3>& p1, const Point<3> & p2, const Vec<3 Point<3> c = Center (p1, p2); double dist1 = Dist (c, p1); - int nseg = NOSegments(); - for (j = 1; j <= nseg; j++) + for (const auto& [index, seg] : boundary_ht) { - const STLBoundarySeg & seg = GetSegment(j); - - if (seg.IsSmoothEdge()) continue; diff --git a/libsrc/stlgeom/stltool.hpp b/libsrc/stlgeom/stltool.hpp index c2a6a493..7c20a384 100644 --- a/libsrc/stlgeom/stltool.hpp +++ b/libsrc/stlgeom/stltool.hpp @@ -187,23 +187,31 @@ class STLBoundary private: STLGeometry * geometry; const STLChart * chart; - NgArray boundary; + // NgArray boundary; ClosedHashTable boundary_ht; BoxTree<2,INDEX_2> * searchtree = nullptr; public: STLBoundary(STLGeometry * ageometry); ~STLBoundary() { delete searchtree; } - void Clear() {boundary.SetSize(0); boundary_ht = ClosedHashTable(); } + void Clear() {/* boundary.SetSize(0)*/; boundary_ht = ClosedHashTable(); } void SetChart (const STLChart * achart) { chart = achart; } //don't check, if already exists! - void AddNewSegment(const STLBoundarySeg & seg) {boundary.Append(seg);}; + void AddNewSegment(const STLBoundarySeg & seg) + { + // boundary.Append(seg); + INDEX_2 op(seg.I1(), seg.I2()); + boundary_ht[op] = seg; + }; //check if segment exists void AddOrDelSegment(const STLBoundarySeg & seg); //addordelsegment for all 3 triangle segments! void AddTriangle(const STLTriangle & t); - int NOSegments() {return boundary.Size();}; - const STLBoundarySeg & GetSegment(int i) {return boundary.Get(i);} + int NOSegments() { + return boundary_ht.Size(); + // return boundary.Size(); + }; + // const STLBoundarySeg & GetSegment(int i) {return boundary.Get(i);} void BuildSearchTree(); void DeleteSearchTree();