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.
This commit is contained in:
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,6 +27,8 @@ void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
SBezier sbrev = *sb; SBezier sbrev = *sb;
sbrev.Reverse(); sbrev.Reverse();
bool backwards = false; bool backwards = false;
#pragma omp critical(into)
{
for(se = into->curve.First(); se; se = into->curve.NextAfter(se)) { for(se = into->curve.First(); se; se = into->curve.NextAfter(se)) {
if(se->isExact) { if(se->isExact) {
if(sb->Equals(&(se->exact))) { if(sb->Equals(&(se->exact))) {
@ -40,6 +42,7 @@ void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
} }
} }
} }
}// 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,8 +104,11 @@ 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;
#pragma omp critical(into)
{
into->curve.AddAndAssignId(&split); into->curve.AddAndAssignId(&split);
} }
}
void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB, void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
SShell *into) SShell *into)
@ -456,8 +462,11 @@ 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();
#pragma omp critical(into)
{
into->curve.AddAndAssignId(&split); into->curve.AddAndAssignId(&split);
} }
}
spl.Clear(); spl.Clear();
} }
} }