Bring some parallelism to boolean code

pull/623/head
phkahler 2020-05-19 20:42:06 -04:00
parent c89a2e4f62
commit 89e6559e2d
2 changed files with 20 additions and 12 deletions

View File

@ -403,7 +403,8 @@ void SSurface::EdgeNormalsWithinSurface(Point2d auv, Point2d buv,
SSurface SSurface::MakeCopyTrimAgainst(SShell *parent, SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
SShell *sha, SShell *shb, SShell *sha, SShell *shb,
SShell *into, SShell *into,
SSurface::CombineAs type) SSurface::CombineAs type,
int dbg_index)
{ {
bool opA = (parent == sha); bool opA = (parent == sha);
SShell *agnst = opA ? shb : sha; SShell *agnst = opA ? shb : sha;
@ -594,9 +595,11 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
SPolygon poly = {}; SPolygon poly = {};
final.l.ClearTags(); final.l.ClearTags();
if(!final.AssemblePolygon(&poly, NULL, /*keepDir=*/true)) { if(!final.AssemblePolygon(&poly, NULL, /*keepDir=*/true))
#pragma omp critical
{
into->booleanFailed = true; into->booleanFailed = true;
dbp("failed: I=%d, avoid=%d", I, choosing.l.n); dbp("failed: I=%d, avoid=%d", I+dbg_index, choosing.l.n);
DEBUGEDGELIST(&final, &ret); DEBUGEDGELIST(&final, &ret);
} }
poly.Clear(); poly.Clear();
@ -609,13 +612,18 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
} }
void SShell::CopySurfacesTrimAgainst(SShell *sha, SShell *shb, SShell *into, SSurface::CombineAs type) { void SShell::CopySurfacesTrimAgainst(SShell *sha, SShell *shb, SShell *into, SSurface::CombineAs type) {
SSurface *ss; #pragma omp parallel for
for(ss = surface.First(); ss; ss = surface.NextAfter(ss)) { for (int i = 0; i < surface.n; i++)
{
SSurface *ss = &surface[i];
SSurface ssn; SSurface ssn;
ssn = ss->MakeCopyTrimAgainst(this, sha, shb, into, type); ssn = ss->MakeCopyTrimAgainst(this, sha, shb, into, type, i);
ss->newH = into->surface.AddAndAssignId(&ssn); #pragma omp critical
I++; {
ss->newH = into->surface.AddAndAssignId(&ssn);
}
} }
I += surface.n;
} }
void SShell::MakeIntersectionCurvesAgainst(SShell *agnst, SShell *into) { void SShell::MakeIntersectionCurvesAgainst(SShell *agnst, SShell *into) {
@ -758,9 +766,9 @@ void SShell::MakeFromBoolean(SShell *a, SShell *b, SSurface::CombineAs type) {
// All of the BSP routines that we use to perform and accelerate polygon ops. // All of the BSP routines that we use to perform and accelerate polygon ops.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SShell::MakeClassifyingBsps(SShell *useCurvesFrom) { void SShell::MakeClassifyingBsps(SShell *useCurvesFrom) {
SSurface *ss; #pragma omp parallel for
for(ss = surface.First(); ss; ss = surface.NextAfter(ss)) { for(int i = 0; i<surface.n; i++) {
ss->MakeClassifyingBsp(this, useCurvesFrom); surface[i].MakeClassifyingBsp(this, useCurvesFrom);
} }
} }

View File

@ -299,7 +299,7 @@ public:
SShell *shell, SShell *sha, SShell *shb); SShell *shell, SShell *sha, SShell *shb);
void FindChainAvoiding(SEdgeList *src, SEdgeList *dest, SPointList *avoid); void FindChainAvoiding(SEdgeList *src, SEdgeList *dest, SPointList *avoid);
SSurface MakeCopyTrimAgainst(SShell *parent, SShell *a, SShell *b, SSurface MakeCopyTrimAgainst(SShell *parent, SShell *a, SShell *b,
SShell *into, SSurface::CombineAs type); SShell *into, SSurface::CombineAs type, int dbg_index);
void TrimFromEdgeList(SEdgeList *el, bool asUv); void TrimFromEdgeList(SEdgeList *el, bool asUv);
void IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB, void IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
SShell *into); SShell *into);