NFC, Performance: Use OpenMP for boolean function MakeItersectionCurvesAgainst.

This is the last long-running single-threaded part of the boolean code. On one test model this took Regenerate form 27 seconds down to 18s. The critical sections needed a name (into) because that object must not be modified while in use in different places.
pull/694/head
phkahler 2020-09-06 10:39:37 -04:00
parent 360b347ad7
commit b208cd8cae
2 changed files with 26 additions and 15 deletions

View File

@ -640,8 +640,10 @@ void SShell::CopySurfacesTrimAgainst(SShell *sha, SShell *shb, SShell *into, SSu
} }
void SShell::MakeIntersectionCurvesAgainst(SShell *agnst, SShell *into) { void SShell::MakeIntersectionCurvesAgainst(SShell *agnst, SShell *into) {
SSurface *sa; #pragma omp parallel for
for(sa = surface.First(); sa; sa = surface.NextAfter(sa)) { for(int i = 0; i< surface.n; i++) {
SSurface *sa = &surface[i];
SSurface *sb; SSurface *sb;
for(sb = agnst->surface.First(); sb; sb = agnst->surface.NextAfter(sb)){ for(sb = agnst->surface.First(); sb; sb = agnst->surface.NextAfter(sb)){
// Intersect every surface from our shell against every surface // Intersect every surface from our shell against every surface

View File

@ -27,19 +27,22 @@ void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
SBezier sbrev = *sb; SBezier sbrev = *sb;
sbrev.Reverse(); sbrev.Reverse();
bool backwards = false; bool backwards = false;
for(se = into->curve.First(); se; se = into->curve.NextAfter(se)) { #pragma omp critical(into)
if(se->isExact) { {
if(sb->Equals(&(se->exact))) { for(se = into->curve.First(); se; se = into->curve.NextAfter(se)) {
existing = se; if(se->isExact) {
break; if(sb->Equals(&(se->exact))) {
} existing = se;
if(sbrev.Equals(&(se->exact))) { break;
existing = se; }
backwards = true; if(sbrev.Equals(&(se->exact))) {
break; existing = se;
backwards = true;
break;
}
} }
} }
} }// end omp critical
if(existing) { if(existing) {
SCurvePt *v; SCurvePt *v;
for(v = existing->pts.First(); v; v = existing->pts.NextAfter(v)) { for(v = existing->pts.First(); v; v = existing->pts.NextAfter(v)) {
@ -101,7 +104,10 @@ void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
"Unexpected zero-length edge"); "Unexpected zero-length edge");
split.source = SCurve::Source::INTERSECTION; split.source = SCurve::Source::INTERSECTION;
into->curve.AddAndAssignId(&split); #pragma omp critical(into)
{
into->curve.AddAndAssignId(&split);
}
} }
void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB, void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
@ -456,7 +462,10 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
// And now we split and insert the curve // And now we split and insert the curve
SCurve split = sc.MakeCopySplitAgainst(agnstA, agnstB, this, b); SCurve split = sc.MakeCopySplitAgainst(agnstA, agnstB, this, b);
sc.Clear(); sc.Clear();
into->curve.AddAndAssignId(&split); #pragma omp critical(into)
{
into->curve.AddAndAssignId(&split);
}
} }
spl.Clear(); spl.Clear();
} }