Skip to content

Commit c738f1e

Browse files
authored
Smooth quads (#793)
* switched to ivec4, tests still pass * added partition quad support * added quad support for property interp * forming quad tangents * convex barycentric * fix interpolation * added linear quad interp * added quad smoothing * fixed vec out of range * all tests pass * fixed quad tangents * tightened quad test * cleanup * avoid dome duplicate work * added docs * update test
1 parent a8b8bf7 commit c738f1e

File tree

9 files changed

+627
-312
lines changed

9 files changed

+627
-312
lines changed

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"program": "${workspaceFolder}/build/test/manifold_test",
1313
"args": [
1414
"--gtest_break_on_failure",
15-
"--gtest_filter=Manifold.HullFail"
15+
"--gtest_filter=Manifold.RefineQuads"
1616
],
1717
"stopAtEntry": false,
1818
"cwd": "${workspaceFolder}/build/test",

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,4 @@
150150
},
151151
"python.formatting.provider": "none",
152152
"clang-format.executable": "clang-format",
153-
}
153+
}

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ else()
9191
else()
9292
set(WARNING_FLAGS -Werror -Wall -Wno-sign-compare -Wno-unused)
9393
endif()
94-
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} ${WARNING_FLAGS} -O3)
94+
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} ${WARNING_FLAGS})
9595
endif()
9696

9797
if(CODE_COVERAGE AND NOT MSVC)

src/manifold/src/impl.h

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ struct Manifold::Impl {
4242
Vec<TriRef> triRef;
4343
Vec<glm::ivec3> triProperties;
4444
};
45+
struct BaryIndices {
46+
int tri, start4, end4;
47+
};
4548

4649
Box bBox_;
4750
float precision_ = -1;
@@ -161,7 +164,13 @@ struct Manifold::Impl {
161164
void SplitPinchedVerts();
162165

163166
// smoothing.cu
167+
bool IsInsideQuad(int halfedge) const;
168+
bool IsMarkedInsideQuad(int halfedge) const;
164169
glm::vec3 GetNormal(int halfedge, int normalIdx) const;
170+
int GetNeighbor(int tri) const;
171+
glm::ivec4 GetHalfedges(int tri) const;
172+
BaryIndices GetIndices(int halfedge) const;
173+
void FillRetainedVerts(Vec<Barycentric>& vertBary) const;
165174
std::vector<Smoothness> UpdateSharpenedEdges(
166175
const std::vector<Smoothness>&) const;
167176
Vec<bool> FlatFaces() const;

src/manifold/src/manifold.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,8 @@ Manifold Manifold::CalculateNormals(int normalIdx, float minSharpAngle) const {
681681
* Smooths out the Manifold by filling in the halfedgeTangent vectors. The
682682
* geometry will remain unchanged until Refine or RefineToLength is called to
683683
* interpolate the surface. This version uses the supplied vertex normal
684-
* properties to define the tangent vectors.
684+
* properties to define the tangent vectors. Faces of two coplanar triangles
685+
* will be marked as quads, while faces with three or more will be flat.
685686
*
686687
* @param normalIdx The first property channel of the normals. NumProp must be
687688
* at least normalIdx + 3. Any vertex where multiple normals exist and don't
@@ -699,7 +700,8 @@ Manifold Manifold::SmoothByNormals(int normalIdx) const {
699700
* Smooths out the Manifold by filling in the halfedgeTangent vectors. The
700701
* geometry will remain unchanged until Refine or RefineToLength is called to
701702
* interpolate the surface. This version uses the geometry of the triangles and
702-
* pseudo-normals to define the tangent vectors.
703+
* pseudo-normals to define the tangent vectors. Faces of two coplanar triangles
704+
* will be marked as quads.
703705
*
704706
* @param minSharpAngle degrees, default 60. Any edges with angles greater than
705707
* this value will remain sharp. The rest will be smoothed to G1 continuity,
@@ -722,11 +724,12 @@ Manifold Manifold::SmoothOut(float minSharpAngle, float minSmoothness) const {
722724

723725
/**
724726
* Increase the density of the mesh by splitting every edge into n pieces. For
725-
* instance, with n = 2, each triangle will be split into 4 triangles. These
726-
* will all be coplanar (and will not be immediately collapsed) unless the
727-
* Mesh/Manifold has halfedgeTangents specified (e.g. from the Smooth()
728-
* constructor), in which case the new vertices will be moved to the
729-
* interpolated surface according to their barycentric coordinates.
727+
* instance, with n = 2, each triangle will be split into 4 triangles. Quads
728+
* will ignore their interior triangle bisector. These will all be coplanar (and
729+
* will not be immediately collapsed) unless the Mesh/Manifold has
730+
* halfedgeTangents specified (e.g. from the Smooth() constructor), in which
731+
* case the new vertices will be moved to the interpolated surface according to
732+
* their barycentric coordinates.
730733
*
731734
* @param n The number of pieces to split every edge into. Must be > 1.
732735
*/
@@ -743,7 +746,8 @@ Manifold Manifold::Refine(int n) const {
743746
* roughly the input length. Interior verts are added to keep the rest of the
744747
* triangulation edges also of roughly the same length. If halfedgeTangents are
745748
* present (e.g. from the Smooth() constructor), the new vertices will be moved
746-
* to the interpolated surface according to their barycentric coordinates.
749+
* to the interpolated surface according to their barycentric coordinates. Quads
750+
* will ignore their interior triangle bisector.
747751
*
748752
* @param length The length that edges will be broken down to.
749753
*/

src/manifold/src/shared.h

+1-11
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ inline int NextHalfedge(int current) {
4040
return current;
4141
}
4242

43-
inline glm::vec3 UVW(int vert, const glm::vec3* barycentric) {
44-
glm::vec3 uvw(0.0f);
45-
if (vert < 0) {
46-
uvw[vert + 3] = 1;
47-
} else {
48-
uvw = barycentric[vert];
49-
}
50-
return uvw;
51-
}
52-
5343
inline glm::mat3 NormalTransform(const glm::mat4x3& transform) {
5444
return glm::inverse(glm::transpose(glm::mat3(transform)));
5545
}
@@ -143,7 +133,7 @@ struct Halfedge {
143133

144134
struct Barycentric {
145135
int tri;
146-
glm::vec3 uvw;
136+
glm::vec4 uvw;
147137
};
148138

149139
struct TriRef {

0 commit comments

Comments
 (0)