Revert "CSG2d - faster AddIntersections (search tree per loop)"

This reverts commit 307c2a3bbb.
This commit is contained in:
Matthias Hochsteger 2020-10-14 19:59:36 +02:00
parent bdb04f9784
commit 7a8e10738b

View File

@ -670,14 +670,20 @@ void AddIntersectionPoint(Edge edgeP, Edge edgeQ, IntersectionType i, double alp
} }
} }
void ComputeIntersections(Loop & l1, Loop & l2) void ComputeIntersections(Solid2d & s1, Solid2d & s2)
{ {
static Timer tall("ComputeIntersections"); RegionTimer rtall(tall);
static Timer t_tree("build search trees");
static Timer t_intersect("find intersections"); static Timer t_intersect("find intersections");
static Timer t_split("split splines"); static Timer t_split("split splines");
auto & PP = s1.polys;
auto & QQ = s2.polys;
t_intersect.Start(); t_intersect.Start();
for (Edge edgeP : l1.Edges(SOURCE)) for (Loop& P : PP)
for (Edge edgeQ : l2.Edges(SOURCE)) for (Edge edgeP : P.Edges(SOURCE))
for (Loop& Q : QQ)
for (Edge edgeQ : Q.Edges(SOURCE))
{ {
double alpha = 0.0; double alpha = 0.0;
double beta = 0.0; double beta = 0.0;
@ -737,21 +743,14 @@ void ComputeIntersections(Loop & l1, Loop & l2)
} while(!curr->is_source); } while(!curr->is_source);
}; };
for (Vertex* v : l1.Vertices(SOURCE)) for (Loop& P : PP)
for (Vertex* v : P.Vertices(SOURCE))
split_spline_at_vertex(v); split_spline_at_vertex(v);
for (Vertex* v : l2.Vertices(SOURCE)) for (Loop& Q : QQ)
for (Vertex* v : Q.Vertices(SOURCE))
split_spline_at_vertex(v); split_spline_at_vertex(v);
} }
void ComputeIntersections(Solid2d & s1, Solid2d & s2)
{
static Timer tall("ComputeIntersections"); RegionTimer rtall(tall);
for (Loop& l1 : s1.polys)
for (Loop& l2 : s2.polys)
ComputeIntersections(l1, l2);
}
enum RelativePositionType enum RelativePositionType
{ {
LEFT, LEFT,
@ -1252,11 +1251,12 @@ void CleanUpResult(Solid2d & sr)
RR.RemoveElement(i); RR.RemoveElement(i);
} }
void RemoveDuplicates(Loop & poly) void RemoveDuplicates(Solid2d & sr)
{ {
if(poly.first==nullptr) static Timer tall("RemoveDuplicates"); RegionTimer rtall(tall);
return; for(auto & poly : sr.polys)
{
if(poly.first==nullptr) continue;
Vertex * last = poly.first->prev; Vertex * last = poly.first->prev;
for(auto v : poly.Vertices(ALL)) for(auto v : poly.Vertices(ALL))
{ {
@ -1264,13 +1264,7 @@ void RemoveDuplicates(Loop & poly)
poly.Remove(last); poly.Remove(last);
last = v; last = v;
} }
} }
void RemoveDuplicates(Solid2d & sr)
{
static Timer tall("RemoveDuplicates"); RegionTimer rtall(tall);
for(auto & poly : sr.polys)
RemoveDuplicates(poly);
} }
Loop RectanglePoly(double x0, double x1, double y0, double y1, string bc) Loop RectanglePoly(double x0, double x1, double y0, double y1, string bc)
@ -1322,14 +1316,6 @@ void AddIntersectionPoints ( Solid2d & s1, Solid2d & s2 )
RemoveDuplicates(s2); RemoveDuplicates(s2);
} }
void AddIntersectionPoints ( Loop & l1, Loop & l2 )
{
ComputeIntersections(l1, l2);
RemoveDuplicates(l1);
RemoveDuplicates(l2);
}
Solid2d ClipSolids ( const Solid2d & s1, const Solid2d & s2, char op) Solid2d ClipSolids ( const Solid2d & s1, const Solid2d & s2, char op)
{ {
return ClipSolids(Solid2d{s1}, Solid2d{s2}, op); return ClipSolids(Solid2d{s1}, Solid2d{s2}, op);
@ -1739,7 +1725,6 @@ shared_ptr<netgen::SplineGeometry2d> CSG2d :: GenerateSplineGeometry()
static Timer t_is_inside("is inside check"); static Timer t_is_inside("is inside check");
static Timer t_segments("add segments"); static Timer t_segments("add segments");
static Timer t_intersections("add intersections"); static Timer t_intersections("add intersections");
static Timer t_segtree("seg trees");
RegionTimer rt(tall); RegionTimer rt(tall);
struct Seg struct Seg
@ -1771,27 +1756,18 @@ shared_ptr<netgen::SplineGeometry2d> CSG2d :: GenerateSplineGeometry()
box.Add(sbox.PMax()); box.Add(sbox.PMax());
} }
netgen::BoxTree <2> solid_tree(box); netgen::BoxTree <2, int> solid_tree(box);
Array<INT<2>> loop_list;
for(auto i : Range(solids)) for(auto i : Range(solids))
for(auto li : Range(solids[i].polys)) solid_tree.Insert(solids[i].GetBoundingBox(), i);
{
solid_tree.Insert(solids[i].polys[li].GetBoundingBox(), loop_list.Size());
loop_list.Append(INT<2>(i, li));
}
for(auto i1 : Range(solids)) for(auto i1 : Range(solids))
for(auto li1 : Range(solids[i1].polys))
{ {
auto & poly1 = solids[i1].polys[li1]; auto sbox = solids[i1].GetBoundingBox();
auto box = poly1.GetBoundingBox(); solid_tree.GetFirstIntersecting(sbox.PMin(), sbox.PMax(), [&] (int i2)
solid_tree.GetFirstIntersecting(box.PMin(), box.PMax(), [&] (int ii)
{ {
auto i2 = loop_list[ii][0];
auto li2 = loop_list[ii][1];
if(i1<i2) if(i1<i2)
AddIntersectionPoints(poly1, solids[i2].polys[li2]); AddIntersectionPoints(solids[i1], solids[i2]);
return false; return false;
}); });
} }