Skip to content

Commit

Permalink
Fix DedupePropVerts (#1092)
Browse files Browse the repository at this point in the history
* added test

* fixed dedupePropVerts

* size_t
  • Loading branch information
elalish authored Dec 3, 2024
1 parent fb29e85 commit f1a8693
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ int GetLabels(std::vector<int>& components,
}

void DedupePropVerts(manifold::Vec<ivec3>& triProp,
const Vec<std::pair<int, int>>& vert2vert) {
const Vec<std::pair<int, int>>& vert2vert,
size_t numPropVert) {
ZoneScoped;
std::vector<int> vertLabels;
const int numLabels = GetLabels(vertLabels, vert2vert, vert2vert.size());
const int numLabels = GetLabels(vertLabels, vert2vert, numPropVert);

std::vector<int> label2vert(numLabels);
for (size_t v = 0; v < vert2vert.size(); ++v) label2vert[vertLabels[v]] = v;
for (size_t v = 0; v < numPropVert; ++v) label2vert[vertLabels[v]] = v;
for (auto& prop : triProp)
for (int i : {0, 1, 2}) prop[i] = label2vert[vertLabels[prop[i]]];
}
Expand Down Expand Up @@ -343,6 +344,8 @@ void Manifold::Impl::CreateFaces() {
const int prop1 =
meshRelation_
.triProperties[pairFace][jointNum == 2 ? 0 : jointNum + 1];
if (prop0 == prop1) return;

bool propEqual = true;
for (size_t p = 0; p < numProp; ++p) {
if (meshRelation_.properties[numProp * prop0 + p] !=
Expand All @@ -355,7 +358,7 @@ void Manifold::Impl::CreateFaces() {
vert2vert[edgeIdx] = std::make_pair(prop0, prop1);
}
});
DedupePropVerts(meshRelation_.triProperties, vert2vert);
DedupePropVerts(meshRelation_.triProperties, vert2vert, NumPropVert());
}

for_each_n(autoPolicy(halfedge_.size(), 1e4), countAt(0), halfedge_.size(),
Expand Down
48 changes: 48 additions & 0 deletions test/manifold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,54 @@ TEST(Manifold, Merge) {
CheckCube(cubeSTL);
}

TEST(Manifold, MergeEmpty) {
MeshGL shape;
shape.numProp = 7;
shape.triVerts = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35};
shape.vertProperties = {0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 1.0,
0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 0.0,
0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
-0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
-0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0,
-0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0,
0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
-0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0,
0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0,
-0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0,
0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
-0.0, 0.5, 0.434500008821487, 0.0, 0.0, 1.0, 0.0,
-0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0,
-0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0,
-0.0, 0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0,
-0.0, -0.5, 0.434500008821487, 0.0, 0.0, 1.0, 1.0,
-0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0,
-0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0,
-0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 1.0,
0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
-0.0, -0.5, 0.434500008821487, 0.0, 0.0, 0.0, 0.0,
-0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0,
0.0, -0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0,
-0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
0.0, 0.5, -0.43450000882149, 0.0, 0.0, 0.0, 1.0,
-0.0, 0.5, -0.43450000882149, 0.0, 0.0, 1.0, 1.0,
0.0, -0.5, -0.43450000882149, 0.0, 0.0, 0.0, 0.0,
-0.0, -0.5, -0.43450000882149, 0.0, 0.0, 1.0, 0.0};
EXPECT_TRUE(shape.Merge());
Manifold man(shape);
EXPECT_EQ(man.Status(), Manifold::Error::NoError);
EXPECT_TRUE(man.IsEmpty());
}

TEST(Manifold, PinchedVert) {
MeshGL shape;
shape.numProp = 3;
Expand Down

0 comments on commit f1a8693

Please sign in to comment.