Skip to content

Commit 8d67ba3

Browse files
authored
Revert "Use ForVert" (#788)
Revert "Use ForVert (#778)" This reverts commit 32eefe9.
1 parent 3258152 commit 8d67ba3

File tree

3 files changed

+86
-71
lines changed

3 files changed

+86
-71
lines changed

src/manifold/src/edge_op.cpp

+25-14
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ struct FlagEdge {
7373
current = NextHalfedge(halfedge[current].pairedHalfedge);
7474
int tri = current / 3;
7575
const TriRef ref = triRef[tri];
76-
if (!ref.SameFace(ref0) && !ref.SameFace(ref1)) return false;
76+
if ((ref.meshID != ref0.meshID || ref.tri != ref0.tri) &&
77+
(ref.meshID != ref1.meshID || ref.tri != ref1.tri))
78+
return false;
7779
}
7880
return true;
7981
}
@@ -323,10 +325,12 @@ void Manifold::Impl::DedupeEdge(const int edge) {
323325
vertPos_.push_back(vertPos_[endVert]);
324326
if (vertNormal_.size() > 0) vertNormal_.push_back(vertNormal_[endVert]);
325327

326-
ForVert(current, [this, newVert](int current) {
328+
do {
327329
halfedge_[current].endVert = newVert;
328-
halfedge_[halfedge_[current].pairedHalfedge].startVert = newVert;
329-
});
330+
current = NextHalfedge(current);
331+
halfedge_[current].startVert = newVert;
332+
current = halfedge_[current].pairedHalfedge;
333+
} while (current != edge);
330334
}
331335

332336
// Orbit startVert
@@ -346,10 +350,12 @@ void Manifold::Impl::DedupeEdge(const int edge) {
346350
vertPos_.push_back(vertPos_[endVert]);
347351
if (vertNormal_.size() > 0) vertNormal_.push_back(vertNormal_[endVert]);
348352

349-
ForVert(current, [this, newVert](int current) {
353+
do {
350354
halfedge_[current].endVert = newVert;
351-
halfedge_[halfedge_[current].pairedHalfedge].startVert = newVert;
352-
});
355+
current = NextHalfedge(current);
356+
halfedge_[current].startVert = newVert;
357+
current = halfedge_[current].pairedHalfedge;
358+
} while (current != pair);
353359
}
354360
}
355361

@@ -476,9 +482,9 @@ void Manifold::Impl::CollapseEdge(const int edge, std::vector<int>& edges) {
476482
const glm::mat3x2 projection = GetAxisAlignedProjection(faceNormal_[tri]);
477483
// Don't collapse if the edge is not redundant (this may have changed due
478484
// to the collapse of neighbors).
479-
if (!ref.SameFace(refCheck)) {
485+
if (ref.meshID != refCheck.meshID || ref.tri != refCheck.tri) {
480486
refCheck = triRef[edge / 3];
481-
if (!ref.SameFace(refCheck)) {
487+
if (ref.meshID != refCheck.meshID || ref.tri != refCheck.tri) {
482488
return;
483489
} else {
484490
// Don't collapse if the edges separating the faces are not colinear
@@ -516,9 +522,11 @@ void Manifold::Impl::CollapseEdge(const int edge, std::vector<int>& edges) {
516522
// Update the shifted triangles to the vertBary of endVert
517523
const int tri = current / 3;
518524
const int vIdx = current - 3 * tri;
519-
if (triRef[tri].SameFace(triRef[tri0])) {
525+
if (triRef[tri].meshID == triRef[tri0].meshID &&
526+
triRef[tri].tri == triRef[tri0].tri) {
520527
triProp[tri][vIdx] = triProp[tri0][triVert0];
521-
} else if (triRef[tri].SameFace(triRef[tri1])) {
528+
} else if (triRef[tri].meshID == triRef[tri1].meshID &&
529+
triRef[tri].tri == triRef[tri1].tri) {
522530
triProp[tri][vIdx] = triProp[tri1][triVert1];
523531
}
524532
}
@@ -668,11 +676,14 @@ void Manifold::Impl::SplitPinchedVerts() {
668676
} else {
669677
vertProcessed[vert] = true;
670678
}
671-
ForVert(i, [this, &halfedgeProcessed, vert](int current) {
679+
int current = i;
680+
do {
672681
halfedgeProcessed[current] = true;
673682
halfedge_[current].startVert = vert;
674-
halfedge_[halfedge_[current].pairedHalfedge].endVert = vert;
675-
});
683+
current = halfedge_[current].pairedHalfedge;
684+
halfedge_[current].endVert = vert;
685+
current = NextHalfedge(current);
686+
} while (current != i);
676687
}
677688
}
678689
} // namespace manifold

src/manifold/src/impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ struct Manifold::Impl {
6969
inline void ForVert(int halfedge, std::function<void(int halfedge)> func) {
7070
int current = halfedge;
7171
do {
72-
current = NextHalfedge(halfedge_[current].pairedHalfedge);
7372
func(current);
73+
current = NextHalfedge(halfedge_[current].pairedHalfedge);
7474
} while (current != halfedge);
7575
}
7676

src/manifold/src/smoothing.cpp

+60-56
Original file line numberDiff line numberDiff line change
@@ -663,35 +663,36 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
663663
for (int tri = 0; tri < numTri; ++tri) {
664664
for (const int i : {0, 1, 2}) {
665665
if (meshRelation_.triProperties[tri][i] >= 0) continue;
666-
int startEdge = 3 * tri + i;
667-
const int vert = halfedge_[startEdge].startVert;
666+
int current = 3 * tri + i;
667+
const int startEdge = current;
668+
const int vert = halfedge_[current].startVert;
668669

669670
if (vertNumSharp[vert] < 2) {
670671
const glm::vec3 normal = vertFlatFace[vert] >= 0
671672
? faceNormal_[vertFlatFace[vert]]
672673
: vertNormal_[vert];
673674
int lastProp = -1;
674-
ForVert(startEdge, [&](int current) {
675+
do {
676+
current = NextHalfedge(halfedge_[current].pairedHalfedge);
675677
const int thisTri = current / 3;
676678
const int j = current - 3 * thisTri;
677679
const int prop = oldTriProp[thisTri][j];
678680
meshRelation_.triProperties[thisTri][j] = prop;
679-
if (prop == lastProp) return;
681+
if (prop == lastProp) continue;
680682
lastProp = prop;
681683
auto start = oldProperties.begin() + prop * oldNumProp;
682684
std::copy(start, start + oldNumProp,
683685
meshRelation_.properties.begin() + prop * numProp);
684686
for (const int i : {0, 1, 2})
685687
meshRelation_.properties[prop * numProp + normalIdx + i] =
686688
normal[i];
687-
});
689+
} while (current != startEdge);
688690
} else {
689691
const glm::vec3 centerPos = vertPos_[vert];
690692
// Length degree
691693
std::vector<int> group;
692694
// Length number of normals
693695
std::vector<glm::vec3> normals;
694-
int current = startEdge;
695696
int prevFace = halfedge_[current].face;
696697

697698
do {
@@ -712,38 +713,34 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
712713
} while (current != startEdge);
713714

714715
const int endEdge = current;
716+
glm::vec3 prevEdgeVec =
717+
glm::normalize(vertPos_[halfedge_[current].endVert] - centerPos);
715718

716-
struct FaceEdge {
717-
int face;
718-
glm::vec3 edgeVec;
719-
};
720-
721-
ForVert<FaceEdge>(
722-
endEdge,
723-
[this, centerPos](int current) {
724-
return FaceEdge(
725-
{halfedge_[current].face,
726-
glm::normalize(vertPos_[halfedge_[current].endVert] -
727-
centerPos)});
728-
},
729-
[this, &triIsFlatFace, &normals, &group, minSharpAngle](
730-
int current, const FaceEdge& here, const FaceEdge& next) {
731-
const float dihedral = glm::degrees(glm::acos(
732-
glm::dot(faceNormal_[here.face], faceNormal_[next.face])));
733-
if (dihedral > minSharpAngle ||
734-
triIsFlatFace[here.face] != triIsFlatFace[next.face] ||
735-
(triIsFlatFace[here.face] && triIsFlatFace[next.face] &&
736-
!meshRelation_.triRef[here.face].SameFace(
737-
meshRelation_.triRef[next.face]))) {
738-
normals.push_back(glm::vec3(0));
739-
}
740-
group.push_back(normals.size() - 1);
741-
float dot = glm::dot(here.edgeVec, next.edgeVec);
742-
const float phi =
743-
dot >= 1 ? 0
744-
: (dot <= -1 ? glm::pi<float>() : glm::acos(dot));
745-
normals.back() += faceNormal_[next.face] * phi;
746-
});
719+
do {
720+
current = NextHalfedge(halfedge_[current].pairedHalfedge);
721+
const int face = halfedge_[current].face;
722+
723+
const float dihedral = glm::degrees(
724+
glm::acos(glm::dot(faceNormal_[face], faceNormal_[prevFace])));
725+
if (dihedral > minSharpAngle ||
726+
triIsFlatFace[face] != triIsFlatFace[prevFace] ||
727+
(triIsFlatFace[face] && triIsFlatFace[prevFace] &&
728+
!meshRelation_.triRef[face].SameFace(
729+
meshRelation_.triRef[prevFace]))) {
730+
normals.push_back(glm::vec3(0));
731+
}
732+
group.push_back(normals.size() - 1);
733+
734+
const glm::vec3 edgeVec =
735+
glm::normalize(vertPos_[halfedge_[current].endVert] - centerPos);
736+
float dot = glm::dot(prevEdgeVec, edgeVec);
737+
const float phi =
738+
dot >= 1 ? 0 : (dot <= -1 ? glm::pi<float>() : glm::acos(dot));
739+
normals.back() += faceNormal_[face] * phi;
740+
741+
prevFace = face;
742+
prevEdgeVec = edgeVec;
743+
} while (current != endEdge);
747744

748745
for (auto& normal : normals) {
749746
normal = glm::normalize(normal);
@@ -753,9 +750,10 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
753750
int lastProp = -1;
754751
int newProp = -1;
755752
int idx = 0;
756-
ForVert(endEdge, [&](int current1) {
757-
const int thisTri = current1 / 3;
758-
const int j = current1 - 3 * thisTri;
753+
do {
754+
current = NextHalfedge(halfedge_[current].pairedHalfedge);
755+
const int thisTri = current / 3;
756+
const int j = current - 3 * thisTri;
759757
const int prop = oldTriProp[thisTri][j];
760758
auto start = oldProperties.begin() + prop * oldNumProp;
761759

@@ -782,7 +780,7 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
782780

783781
meshRelation_.triProperties[thisTri][j] = newProp;
784782
++idx;
785-
});
783+
} while (current != endEdge);
786784
}
787785
}
788786
}
@@ -857,9 +855,11 @@ void Manifold::Impl::CreateTangents(int normalIdx) {
857855
}
858856
});
859857
} else { // Sharpen vertex uniformly
860-
ForVert(first, [this](int current) {
858+
int current = first;
859+
do {
861860
halfedgeTangent_[current] = glm::vec4(0);
862-
});
861+
current = NextHalfedge(halfedge_[current].pairedHalfedge);
862+
} while (current != first);
863863
}
864864
}
865865
}
@@ -947,17 +947,18 @@ void Manifold::Impl::CreateTangents(std::vector<Smoothness> sharpenedEdges) {
947947
tangent[second] = CircularTangent(
948948
-newTangent, vertPos_[halfedge_[second].endVert] - pos);
949949

950-
float smoothness =
951-
(vert[0].second.smoothness + vert[1].first.smoothness) / 2;
952-
ForVert(
953-
first, [&tangent, &smoothness, &vert, first, second](int current) {
954-
if (current == second) {
955-
smoothness =
956-
(vert[1].second.smoothness + vert[0].first.smoothness) / 2;
957-
} else if (current != first) {
958-
tangent[current] = smoothness * tangent[current];
959-
}
960-
});
950+
auto SmoothHalf = [&](int first, int last, float smoothness) {
951+
int current = NextHalfedge(halfedge_[first].pairedHalfedge);
952+
while (current != last) {
953+
tangent[current] = smoothness * tangent[current];
954+
current = NextHalfedge(halfedge_[current].pairedHalfedge);
955+
}
956+
};
957+
958+
SmoothHalf(first, second,
959+
(vert[0].second.smoothness + vert[1].first.smoothness) / 2);
960+
SmoothHalf(second, first,
961+
(vert[1].second.smoothness + vert[0].first.smoothness) / 2);
961962
} else { // Sharpen vertex uniformly
962963
float smoothness = 0;
963964
for (const Pair& pair : vert) {
@@ -966,9 +967,12 @@ void Manifold::Impl::CreateTangents(std::vector<Smoothness> sharpenedEdges) {
966967
}
967968
smoothness /= 2 * vert.size();
968969

969-
ForVert(vert[0].first.halfedge, [&tangent, smoothness](int current) {
970+
const int start = vert[0].first.halfedge;
971+
int current = start;
972+
do {
970973
tangent[current] = smoothness * tangent[current];
971-
});
974+
current = NextHalfedge(halfedge_[current].pairedHalfedge);
975+
} while (current != start);
972976
}
973977
}
974978
}

0 commit comments

Comments
 (0)