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) {
SSurface *sa;
for(sa = surface.First(); sa; sa = surface.NextAfter(sa)) {
#pragma omp parallel for
for(int i = 0; i< surface.n; i++) {
SSurface *sa = &surface[i];
SSurface *sb;
for(sb = agnst->surface.First(); sb; sb = agnst->surface.NextAfter(sb)){
// 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;
sbrev.Reverse();
bool backwards = false;
#pragma omp critical(into)
{
for(se = into->curve.First(); se; se = into->curve.NextAfter(se)) {
if(se->isExact) {
if(sb->Equals(&(se->exact))) {
@ -40,6 +42,7 @@ void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
}
}
}
}// end omp critical
if(existing) {
SCurvePt *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");
split.source = SCurve::Source::INTERSECTION;
#pragma omp critical(into)
{
into->curve.AddAndAssignId(&split);
}
}
void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
SShell *into)
@ -456,8 +462,11 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
// And now we split and insert the curve
SCurve split = sc.MakeCopySplitAgainst(agnstA, agnstB, this, b);
sc.Clear();
#pragma omp critical(into)
{
into->curve.AddAndAssignId(&split);
}
}
spl.Clear();
}
}