Skip to content

Commit

Permalink
Added method to deal with huge numbers of triangles
Browse files Browse the repository at this point in the history
  • Loading branch information
QuimMoya committed Oct 28, 2024
1 parent b7932e8 commit 7add275
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
67 changes: 64 additions & 3 deletions src/cpp/geometry/operations/boolean-utils/shared-position.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ namespace fuzzybools
std::vector<Triangle> triangles;
std::map<std::pair<size_t, size_t>, size_t> segmentCounts;
std::vector<size_t> irrelevantFaces;
std::vector<size_t> irrelevantFaces_toTest;

std::map<size_t, std::vector<std::pair<size_t, size_t>>> planeSegments;
std::map<size_t, std::map<std::pair<size_t, size_t>, size_t>> planeSegmentCounts;
Expand Down Expand Up @@ -868,16 +869,16 @@ namespace fuzzybools
auto boxA = A.GetAABB();
auto boxB = B.GetAABB();

AddGeometry(A, boxB, true);
AddGeometry(B, boxA, false);
AddGeometry(A, B, boxB, true);
AddGeometry(B, A, boxA, false);

_linkedA = &A;
_linkedB = &B;
}

//============================================================================================

void AddGeometry(const Geometry& geom, const AABB& relevantBounds, bool isA)
void AddGeometry(const Geometry& geom, const Geometry& secondGeom, const AABB& relevantBounds, bool isA)
{
Geometry relevant;

Expand All @@ -901,6 +902,40 @@ namespace fuzzybools
continue;
}

// Arbitrary limit. If an element has more than 1000 faces only those that touch a face of the other solid will pass
// This limit allows terrains and other models containing too many planes to optimize the number of planes that are computed
// This method is only applied to huge models because it has some unexpected drawbacks

if(geom.numFaces > 1000)
{
bool contact = false;

for (size_t j = 0; j < secondGeom.numFaces; j++)
{
auto faceBox2 = secondGeom.GetFaceBox(j);

if (faceBox.intersects(faceBox2))
{
contact = true;
break;
}
}

if(!contact)
{
if (isA)
{
A.irrelevantFaces_toTest.push_back(i);
}
else
{
B.irrelevantFaces_toTest.push_back(i);
}

continue;
}
}

if (isA)
{
#ifdef CSG_DEBUG_OUTPUT
Expand Down Expand Up @@ -1743,6 +1778,32 @@ namespace fuzzybools
sp.TriangulatePlane(geom, plane);
}

// re-add irrelevant faces that should be tested
for (auto& faceIndex : sp.A.irrelevantFaces_toTest)
{
const Face& f = sp._linkedA->GetFace(faceIndex);

auto a = sp._linkedA->GetPoint(f.i0);
auto b = sp._linkedA->GetPoint(f.i1);
auto c = sp._linkedA->GetPoint(f.i2);

geom.AddFace(a, b, c);
}

if (UNION)
{
for (auto& faceIndex : sp.B.irrelevantFaces_toTest)
{
const Face& f = sp._linkedB->GetFace(faceIndex);

auto a = sp._linkedB->GetPoint(f.i0);
auto b = sp._linkedB->GetPoint(f.i1);
auto c = sp._linkedB->GetPoint(f.i2);

geom.AddFace(a, b, c);
}
}

geom.data = geom.numFaces;

// re-add irrelevant faces
Expand Down
5 changes: 0 additions & 5 deletions src/cpp/geometry/operations/geometryutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,6 @@ namespace webifc::geometry
spdlog::error("[TriangulateBounds() Expected outer bound first! {}", expressID);
}

if(bounds[0].curve.points.size() == 189)
{
bounds[0] = bounds[0];
}

glm::dvec3 v1, v2, v3;
if (!GetBasisFromCoplanarPoints(bounds[0].curve.points, v1, v2, v3))
{
Expand Down

0 comments on commit 7add275

Please sign in to comment.