Revert "Use ForVert" (#788)

Revert "Use ForVert (#778)"

This reverts commit 32eefe9157.
This commit is contained in:
Emmett Lalish
2024-04-12 21:31:08 -07:00
committed by GitHub
parent 3258152e2c
commit 8d67ba3a3a
3 changed files with 85 additions and 70 deletions
+25 -14
View File
@@ -73,7 +73,9 @@ struct FlagEdge {
current = NextHalfedge(halfedge[current].pairedHalfedge);
int tri = current / 3;
const TriRef ref = triRef[tri];
if (!ref.SameFace(ref0) && !ref.SameFace(ref1)) return false;
if ((ref.meshID != ref0.meshID || ref.tri != ref0.tri) &&
(ref.meshID != ref1.meshID || ref.tri != ref1.tri))
return false;
}
return true;
}
@@ -323,10 +325,12 @@ void Manifold::Impl::DedupeEdge(const int edge) {
vertPos_.push_back(vertPos_[endVert]);
if (vertNormal_.size() > 0) vertNormal_.push_back(vertNormal_[endVert]);
ForVert(current, [this, newVert](int current) {
do {
halfedge_[current].endVert = newVert;
halfedge_[halfedge_[current].pairedHalfedge].startVert = newVert;
});
current = NextHalfedge(current);
halfedge_[current].startVert = newVert;
current = halfedge_[current].pairedHalfedge;
} while (current != edge);
}
// Orbit startVert
@@ -346,10 +350,12 @@ void Manifold::Impl::DedupeEdge(const int edge) {
vertPos_.push_back(vertPos_[endVert]);
if (vertNormal_.size() > 0) vertNormal_.push_back(vertNormal_[endVert]);
ForVert(current, [this, newVert](int current) {
do {
halfedge_[current].endVert = newVert;
halfedge_[halfedge_[current].pairedHalfedge].startVert = newVert;
});
current = NextHalfedge(current);
halfedge_[current].startVert = newVert;
current = halfedge_[current].pairedHalfedge;
} while (current != pair);
}
}
@@ -476,9 +482,9 @@ void Manifold::Impl::CollapseEdge(const int edge, std::vector<int>& edges) {
const glm::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)) {
if (ref.meshID != refCheck.meshID || ref.tri != refCheck.tri) {
refCheck = triRef[edge / 3];
if (!ref.SameFace(refCheck)) {
if (ref.meshID != refCheck.meshID || ref.tri != refCheck.tri) {
return;
} else {
// 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) {
// 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 (triRef[tri].meshID == triRef[tri0].meshID &&
triRef[tri].tri == triRef[tri0].tri) {
triProp[tri][vIdx] = triProp[tri0][triVert0];
} else if (triRef[tri].SameFace(triRef[tri1])) {
} else if (triRef[tri].meshID == triRef[tri1].meshID &&
triRef[tri].tri == triRef[tri1].tri) {
triProp[tri][vIdx] = triProp[tri1][triVert1];
}
}
@@ -668,11 +676,14 @@ void Manifold::Impl::SplitPinchedVerts() {
} else {
vertProcessed[vert] = true;
}
ForVert(i, [this, &halfedgeProcessed, vert](int current) {
int current = i;
do {
halfedgeProcessed[current] = true;
halfedge_[current].startVert = vert;
halfedge_[halfedge_[current].pairedHalfedge].endVert = vert;
});
current = halfedge_[current].pairedHalfedge;
halfedge_[current].endVert = vert;
current = NextHalfedge(current);
} while (current != i);
}
}
} // namespace manifold
+1 -1
View File
@@ -69,8 +69,8 @@ struct Manifold::Impl {
inline void ForVert(int halfedge, std::function<void(int halfedge)> func) {
int current = halfedge;
do {
current = NextHalfedge(halfedge_[current].pairedHalfedge);
func(current);
current = NextHalfedge(halfedge_[current].pairedHalfedge);
} while (current != halfedge);
}
+59 -55
View File
@@ -663,20 +663,22 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
for (int tri = 0; tri < numTri; ++tri) {
for (const int i : {0, 1, 2}) {
if (meshRelation_.triProperties[tri][i] >= 0) continue;
int startEdge = 3 * tri + i;
const int vert = halfedge_[startEdge].startVert;
int current = 3 * tri + i;
const int startEdge = current;
const int vert = halfedge_[current].startVert;
if (vertNumSharp[vert] < 2) {
const glm::vec3 normal = vertFlatFace[vert] >= 0
? faceNormal_[vertFlatFace[vert]]
: vertNormal_[vert];
int lastProp = -1;
ForVert(startEdge, [&](int current) {
do {
current = NextHalfedge(halfedge_[current].pairedHalfedge);
const int thisTri = current / 3;
const int j = current - 3 * thisTri;
const int prop = oldTriProp[thisTri][j];
meshRelation_.triProperties[thisTri][j] = prop;
if (prop == lastProp) return;
if (prop == lastProp) continue;
lastProp = prop;
auto start = oldProperties.begin() + prop * oldNumProp;
std::copy(start, start + oldNumProp,
@@ -684,14 +686,13 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
for (const int i : {0, 1, 2})
meshRelation_.properties[prop * numProp + normalIdx + i] =
normal[i];
});
} while (current != startEdge);
} else {
const glm::vec3 centerPos = vertPos_[vert];
// Length degree
std::vector<int> group;
// Length number of normals
std::vector<glm::vec3> normals;
int current = startEdge;
int prevFace = halfedge_[current].face;
do {
@@ -712,38 +713,34 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
} while (current != startEdge);
const int endEdge = current;
glm::vec3 prevEdgeVec =
glm::normalize(vertPos_[halfedge_[current].endVert] - centerPos);
struct FaceEdge {
int face;
glm::vec3 edgeVec;
};
do {
current = NextHalfedge(halfedge_[current].pairedHalfedge);
const int face = halfedge_[current].face;
ForVert<FaceEdge>(
endEdge,
[this, centerPos](int current) {
return FaceEdge(
{halfedge_[current].face,
glm::normalize(vertPos_[halfedge_[current].endVert] -
centerPos)});
},
[this, &triIsFlatFace, &normals, &group, minSharpAngle](
int current, const FaceEdge& here, const FaceEdge& next) {
const float dihedral = glm::degrees(glm::acos(
glm::dot(faceNormal_[here.face], faceNormal_[next.face])));
if (dihedral > minSharpAngle ||
triIsFlatFace[here.face] != triIsFlatFace[next.face] ||
(triIsFlatFace[here.face] && triIsFlatFace[next.face] &&
!meshRelation_.triRef[here.face].SameFace(
meshRelation_.triRef[next.face]))) {
normals.push_back(glm::vec3(0));
}
group.push_back(normals.size() - 1);
float dot = glm::dot(here.edgeVec, next.edgeVec);
const float phi =
dot >= 1 ? 0
: (dot <= -1 ? glm::pi<float>() : glm::acos(dot));
normals.back() += faceNormal_[next.face] * phi;
});
const float dihedral = glm::degrees(
glm::acos(glm::dot(faceNormal_[face], faceNormal_[prevFace])));
if (dihedral > minSharpAngle ||
triIsFlatFace[face] != triIsFlatFace[prevFace] ||
(triIsFlatFace[face] && triIsFlatFace[prevFace] &&
!meshRelation_.triRef[face].SameFace(
meshRelation_.triRef[prevFace]))) {
normals.push_back(glm::vec3(0));
}
group.push_back(normals.size() - 1);
const glm::vec3 edgeVec =
glm::normalize(vertPos_[halfedge_[current].endVert] - centerPos);
float dot = glm::dot(prevEdgeVec, edgeVec);
const float phi =
dot >= 1 ? 0 : (dot <= -1 ? glm::pi<float>() : glm::acos(dot));
normals.back() += faceNormal_[face] * phi;
prevFace = face;
prevEdgeVec = edgeVec;
} while (current != endEdge);
for (auto& normal : normals) {
normal = glm::normalize(normal);
@@ -753,9 +750,10 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
int lastProp = -1;
int newProp = -1;
int idx = 0;
ForVert(endEdge, [&](int current1) {
const int thisTri = current1 / 3;
const int j = current1 - 3 * thisTri;
do {
current = NextHalfedge(halfedge_[current].pairedHalfedge);
const int thisTri = current / 3;
const int j = current - 3 * thisTri;
const int prop = oldTriProp[thisTri][j];
auto start = oldProperties.begin() + prop * oldNumProp;
@@ -782,7 +780,7 @@ void Manifold::Impl::SetNormals(int normalIdx, float minSharpAngle) {
meshRelation_.triProperties[thisTri][j] = newProp;
++idx;
});
} while (current != endEdge);
}
}
}
@@ -857,9 +855,11 @@ void Manifold::Impl::CreateTangents(int normalIdx) {
}
});
} else { // Sharpen vertex uniformly
ForVert(first, [this](int current) {
int current = first;
do {
halfedgeTangent_[current] = glm::vec4(0);
});
current = NextHalfedge(halfedge_[current].pairedHalfedge);
} while (current != first);
}
}
}
@@ -947,17 +947,18 @@ void Manifold::Impl::CreateTangents(std::vector<Smoothness> sharpenedEdges) {
tangent[second] = CircularTangent(
-newTangent, vertPos_[halfedge_[second].endVert] - pos);
float smoothness =
(vert[0].second.smoothness + vert[1].first.smoothness) / 2;
ForVert(
first, [&tangent, &smoothness, &vert, first, second](int current) {
if (current == second) {
smoothness =
(vert[1].second.smoothness + vert[0].first.smoothness) / 2;
} else if (current != first) {
tangent[current] = smoothness * tangent[current];
}
});
auto SmoothHalf = [&](int first, int last, float smoothness) {
int current = NextHalfedge(halfedge_[first].pairedHalfedge);
while (current != last) {
tangent[current] = smoothness * tangent[current];
current = NextHalfedge(halfedge_[current].pairedHalfedge);
}
};
SmoothHalf(first, second,
(vert[0].second.smoothness + vert[1].first.smoothness) / 2);
SmoothHalf(second, first,
(vert[1].second.smoothness + vert[0].first.smoothness) / 2);
} else { // Sharpen vertex uniformly
float smoothness = 0;
for (const Pair& pair : vert) {
@@ -966,9 +967,12 @@ void Manifold::Impl::CreateTangents(std::vector<Smoothness> sharpenedEdges) {
}
smoothness /= 2 * vert.size();
ForVert(vert[0].first.halfedge, [&tangent, smoothness](int current) {
const int start = vert[0].first.halfedge;
int current = start;
do {
tangent[current] = smoothness * tangent[current];
});
current = NextHalfedge(halfedge_[current].pairedHalfedge);
} while (current != start);
}
}
}