Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CreateFaces entirely #951

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"args": [
"--gtest_break_on_failure",
"--gtest_catch_exceptions=0",
"--gtest_filter=Boolean.Cubes"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/test",
Expand All @@ -25,4 +26,4 @@
"externalConsole": false
}
]
}
}
4 changes: 1 addition & 3 deletions bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ NB_MODULE(manifold3d, m) {
"Get the surface area of the manifold\n This is clamped to zero for "
"a given face if they are within the Precision().")
.def("original_id", &Manifold::OriginalID, manifold__original_id)
.def("as_original", &Manifold::AsOriginal,
nb::arg("property_tolerance") = nb::list(),
manifold__as_original__property_tolerance)
.def("as_original", &Manifold::AsOriginal, manifold__as_original)
.def("is_empty", &Manifold::IsEmpty, manifold__is_empty)
.def("decompose", &Manifold::Decompose, manifold__decompose)
.def("split", &Manifold::Split, nb::arg("cutter"),
Expand Down
13 changes: 5 additions & 8 deletions include/manifold/manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ struct MeshGLP {
/// This matrix is stored in column-major order and the length of the overall
/// vector is 12 * runOriginalID.size().
std::vector<Precision> runTransform;
/// Optional: Length NumTri, contains an ID of the source face this triangle
/// comes from. When auto-generated, this ID will be a triangle index into the
/// original mesh. All neighboring coplanar triangles from that input mesh
/// will refer to a single triangle of that group as the faceID. When
/// supplying faceIDs, ensure that triangles with the same ID are in fact
/// coplanar and have consistent properties (within some tolerance) or the
/// output will be surprising.
/// Optional: Length NumTri, contains the source face ID this
/// triangle comes from. When auto-generated, this ID will be a triangle index
/// into the original mesh. This index/ID is purely for external use (e.g.
/// recreating polygonal faces) and will not affect Manifold's algorithms.
std::vector<I> faceID;
/// Optional: The X-Y-Z-W weighted tangent vectors for smooth Refine(). If
/// non-empty, must be exactly four times as long as Mesh.triVerts. Indexed
Expand Down Expand Up @@ -246,7 +243,7 @@ class Manifold {
*/
///@{
int OriginalID() const;
Manifold AsOriginal(const std::vector<double>& propertyTolerance = {}) const;
Manifold AsOriginal() const;
static uint32_t ReserveIDs(uint32_t);
///@}

Expand Down
10 changes: 6 additions & 4 deletions src/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Manifold Manifold::Smooth(const MeshGL& meshGL,
"rather than Smooth().");

std::shared_ptr<Impl> impl = std::make_shared<Impl>(meshGL);
impl->CreateTangents(impl->UpdateSharpenedEdges(sharpenedEdges));
const Vec<bool> internalEdges = impl->InternalEdges();
impl->CreateTangents(impl->UpdateSharpenedEdges(sharpenedEdges),
internalEdges);
return Manifold(impl);
}

Expand Down Expand Up @@ -92,7 +94,9 @@ Manifold Manifold::Smooth(const MeshGL64& meshGL64,
"rather than Smooth().");

std::shared_ptr<Impl> impl = std::make_shared<Impl>(meshGL64);
impl->CreateTangents(impl->UpdateSharpenedEdges(sharpenedEdges));
const Vec<bool> internalEdges = impl->InternalEdges();
impl->CreateTangents(impl->UpdateSharpenedEdges(sharpenedEdges),
internalEdges);
return Manifold(impl);
}

Expand Down Expand Up @@ -274,7 +278,6 @@ Manifold Manifold::Extrude(const Polygons& crossSection, double height,
pImpl_->CreateHalfedges(triVertsDH);
pImpl_->Finish();
pImpl_->InitializeOriginal();
pImpl_->CreateFaces();
return Manifold(pImpl_);
}

Expand Down Expand Up @@ -418,7 +421,6 @@ Manifold Manifold::Revolve(const Polygons& crossSection, int circularSegments,
pImpl_->CreateHalfedges(triVertsDH);
pImpl_->Finish();
pImpl_->InitializeOriginal();
pImpl_->CreateFaces();
return Manifold(pImpl_);
}

Expand Down
70 changes: 27 additions & 43 deletions src/edge_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,6 @@ struct ShortEdge {
}
};

struct FlagEdge {
VecView<const Halfedge> halfedge;
VecView<const TriRef> triRef;

bool operator()(int edge) const {
if (halfedge[edge].pairedHalfedge < 0) return false;
// Flag redundant edges - those where the startVert is surrounded by only
// two original triangles.
const TriRef ref0 = triRef[edge / 3];
int current = NextHalfedge(halfedge[edge].pairedHalfedge);
const TriRef ref1 = triRef[current / 3];
while (current != edge) {
current = NextHalfedge(halfedge[current].pairedHalfedge);
int tri = current / 3;
const TriRef ref = triRef[tri];
if (!ref.SameFace(ref0) && !ref.SameFace(ref1)) return false;
}
return true;
}
};

struct SwappableEdge {
VecView<const Halfedge> halfedge;
VecView<const vec3> vertPos;
Expand Down Expand Up @@ -227,10 +206,19 @@ void Manifold::Impl::SimplifyTopology() {

{
ZoneScopedN("CollapseFlaggedEdge");
const Vec<bool> internalEdges = InternalEdges();
numFlagged = 0;
FlagEdge se{halfedge_, meshRelation_.triRef};
for_each_n(policy, countAt(0_uz), nbEdges,
[&](size_t i) { bFlags[i] = se(i); });
[this, &internalEdges, &bFlags](size_t edge) {
if (halfedge_[edge].pairedHalfedge < 0) return;
// Flag redundant edges - those where the startVert is
// surrounded by only two original triangles.
int numExternal = internalEdges[edge] ? 2 : 0;
ForVert(edge, [&numExternal, &internalEdges](int current) {
numExternal += internalEdges[current] ? 0 : 1;
});
bFlags[edge] = numExternal < 3;
});
for (size_t i = 0; i < nbEdges; ++i) {
if (bFlags[i]) {
CollapseEdge(i, scratchBuffer);
Expand Down Expand Up @@ -484,30 +472,26 @@ void Manifold::Impl::CollapseEdge(const int edge, std::vector<int>& edges) {
int start = halfedge_[tri1edge[1]].pairedHalfedge;
if (!shortEdge) {
current = start;
TriRef refCheck = triRef[toRemove.pairedHalfedge / 3];
int numExternal = Internal(edge) ? 2 : 1;
numExternal += Internal(tri1edge[1]) ? 0 : 1;
vec3 pLast = vertPos_[halfedge_[tri1edge[1]].endVert];
while (current != tri0edge[2]) {
current = NextHalfedge(current);
vec3 pNext = vertPos_[halfedge_[current].endVert];
const int tri = current / 3;
const TriRef ref = triRef[tri];
const mat3x2 projection = GetAxisAlignedProjection(faceNormal_[tri]);

// Don't collapse if the edge is not redundant (this may have changed due
// to the collapse of neighbors).
if (!ref.SameFace(refCheck)) {
refCheck = triRef[edge / 3];
if (!ref.SameFace(refCheck)) {
return;
} else {
// Don't collapse if the edges separating the faces are not colinear
// (can happen when the two faces are coplanar).
if (CCW(projection * pOld, projection * pLast, projection * pNew,
precision_) != 0)
return;
}
}
// to the collapse of neighbors).
numExternal += Internal(current) ? 0 : 1;
if (numExternal > 2) return;

// Don't collapse edge if it would cause a triangle to invert.
const vec3 pNext = vertPos_[halfedge_[current].endVert];
const mat3x2 projection =
GetAxisAlignedProjection(faceNormal_[current / 3]);
// Don't collapse if the edges separating the faces are not colinear
// (can happen when the two faces are coplanar).
if (CCW(projection * pOld, projection * pLast, projection * pNew,
precision_) != 0)
return;
if (CCW(projection * pNext, projection * pLast, projection * pNew,
precision_) < 0)
return;
Expand All @@ -534,9 +518,9 @@ void Manifold::Impl::CollapseEdge(const int edge, std::vector<int>& edges) {
// Update the shifted triangles to the vertBary of endVert
const int tri = current / 3;
const int vIdx = current - 3 * tri;
if (triRef[tri].SameFace(triRef[tri0])) {
if (triProp[tri][vIdx] == triProp[tri0][Prev3(triVert0)]) {
triProp[tri][vIdx] = triProp[tri0][triVert0];
} else if (triRef[tri].SameFace(triRef[tri1])) {
} else if (triProp[tri][vIdx] == triProp[tri1][Next3(triVert1)]) {
triProp[tri][vIdx] = triProp[tri1][triVert1];
}
}
Expand Down
Loading
Loading