23
23
24
24
using namespace manifold ;
25
25
26
+ // Check if the mesh remains convex after adding new faces
27
+ bool isMeshConvex (manifold::Manifold hullManifold) {
28
+ // Get the mesh from the manifold
29
+ manifold::Mesh mesh = hullManifold.GetMesh ();
30
+
31
+ const auto &vertPos = mesh.vertPos ;
32
+
33
+ // Iterate over each triangle
34
+ for (const auto &tri : mesh.triVerts ) {
35
+ // Get the vertices of the triangle
36
+ glm::vec3 v0 = vertPos[tri[0 ]];
37
+ glm::vec3 v1 = vertPos[tri[1 ]];
38
+ glm::vec3 v2 = vertPos[tri[2 ]];
39
+
40
+ // Compute the normal of the triangle
41
+ glm::vec3 normal = glm::normalize (glm::cross (v1 - v0, v2 - v0));
42
+
43
+ // Check all other vertices
44
+ for (int i = 0 ; i < (int )vertPos.size (); ++i) {
45
+ if (i == tri[0 ] || i == tri[2 ] || i == tri[3 ])
46
+ continue ; // Skip vertices of the current triangle
47
+
48
+ // Get the vertex
49
+ glm::vec3 v = vertPos[i];
50
+
51
+ // Compute the signed distance from the plane
52
+ double distance = glm::dot (normal , v - v0);
53
+
54
+ // If any vertex lies on the opposite side of the normal direction
55
+ if (distance > 0 ) {
56
+ // The manifold is not convex
57
+ return false ;
58
+ }
59
+ }
60
+ }
61
+ // If we didn't find any vertex on the opposite side for any triangle, it's
62
+ // convex
63
+ return true ;
64
+ }
65
+
26
66
TEST (Hull, Tictac) {
27
67
const float tictacRad = 100 ;
28
68
const float tictacHeight = 500 ;
@@ -95,53 +135,57 @@ TEST(Hull, Sphere) {
95
135
sphere.GetProperties ().volume );
96
136
}
97
137
98
- // TEST(Hull, FailingTest1) {
99
- // const std::vector<glm::vec3> hullPts = {
100
- // {-24.983196259f, -43.272167206f, 52.710712433f},
101
- // {-25.0f, -12.7726717f, 49.907142639f},
102
- // {-23.016393661f, 39.865562439f, 79.083930969f},
103
- // {-24.983196259f, -40.272167206f, 52.710712433f},
104
- // {-4.5177311897f, -28.633184433f, 50.405872345f},
105
- // {11.176083565f, -22.357545853f, 45.275596619f},
106
- // {-25.0f, 21.885698318f, 49.907142639f},
107
- // {-17.633232117f, -17.341972351f, 89.96282196f},
108
- // {26.922552109f, 10.344738007f, 57.146999359f},
109
- // {-24.949174881f, 1.5f, 54.598075867f},
110
- // {9.2058267593f, -23.47851944f, 55.334011078f},
111
- // {13.26748085f, -19.979951859f, 28.117856979f},
112
- // {-18.286884308f, 31.673814774f, 2.1749999523f},
113
- // {18.419618607f, -18.215343475f, 52.450099945f},
114
- // {-24.983196259f, 43.272167206f, 52.710712433f},
115
- // {-1.6232370138f, -29.794223785f, 48.394889832f},
116
- // {49.865573883f, -0.0f, 55.507141113f},
117
- // {-18.627283096f, -39.544368744f, 55.507141113f},
118
- // {-20.442623138f, -35.407661438f, 8.2749996185f},
119
- // {10.229375839f, -14.717799187f, 10.508025169f}};
120
- // auto hull = Manifold::Hull(hullPts);
121
- // }
122
-
123
- // TEST(Hull, FailingTest2) {
124
- // const std::vector<glm::vec3> hullPts = {
125
- // {174.17001343f, -12.022000313f, 29.562002182f},
126
- // {174.51400757f, -10.858000755f, -3.3340001106f},
127
- // {187.50801086f, 22.826000214f, 23.486001968f},
128
- // {172.42800903f, 12.018000603f, 28.120000839f},
129
- // {180.98001099f, -26.866001129f, 6.9100003242f},
130
- // {172.42800903f, -12.022000313f, 28.120000839f},
131
- // {174.17001343f, 19.498001099f, 29.562002182f},
132
- // {213.96600342f, 2.9400000572f, -11.100000381f},
133
- // {182.53001404f, -22.49200058f, 23.644001007f},
134
- // {175.89401245f, 19.900001526f, 16.118000031f},
135
- // {211.38601685f, 3.0200002193f, -14.250000954f},
136
- // {183.7440033f, 12.018000603f, 18.090000153f},
137
- // {210.51000977f, 2.5040001869f, -11.100000381f},
138
- // {204.13601685f, 34.724002838f, -11.250000954f},
139
- // {193.23400879f, -24.704000473f, 17.768001556f},
140
- // {171.62800598f, -19.502000809f, 27.320001602f},
141
- // {189.67401123f, 8.486000061f, -5.4080004692f},
142
- // {193.23800659f, 24.704000473f, 17.758001328f},
143
- // {165.36801147f, -6.5600004196f, -14.250000954f},
144
- // {174.17001343f, -19.502000809f, 29.562002182f},
145
- // {190.06401062f, -0.81000006199f, -14.250000954f}};
146
- // auto hull = Manifold::Hull(hullPts);
147
- // }
138
+ TEST (Hull, DISABLED_FailingTest1) {
139
+ // 39202.stl
140
+ const std::vector<glm::vec3> hullPts = {
141
+ {-24 .983196259f , -43 .272167206f , 52 .710712433f },
142
+ {-25 .0f , -12 .7726717f , 49 .907142639f },
143
+ {-23 .016393661f , 39 .865562439f , 79 .083930969f },
144
+ {-24 .983196259f , -40 .272167206f , 52 .710712433f },
145
+ {-4 .5177311897f , -28 .633184433f , 50 .405872345f },
146
+ {11 .176083565f , -22 .357545853f , 45 .275596619f },
147
+ {-25 .0f , 21 .885698318f , 49 .907142639f },
148
+ {-17 .633232117f , -17 .341972351f , 89 .96282196f },
149
+ {26 .922552109f , 10 .344738007f , 57 .146999359f },
150
+ {-24 .949174881f , 1 .5f , 54 .598075867f },
151
+ {9 .2058267593f , -23 .47851944f , 55 .334011078f },
152
+ {13 .26748085f , -19 .979951859f , 28 .117856979f },
153
+ {-18 .286884308f , 31 .673814774f , 2 .1749999523f },
154
+ {18 .419618607f , -18 .215343475f , 52 .450099945f },
155
+ {-24 .983196259f , 43 .272167206f , 52 .710712433f },
156
+ {-1 .6232370138f , -29 .794223785f , 48 .394889832f },
157
+ {49 .865573883f , -0 .0f , 55 .507141113f },
158
+ {-18 .627283096f , -39 .544368744f , 55 .507141113f },
159
+ {-20 .442623138f , -35 .407661438f , 8 .2749996185f },
160
+ {10 .229375839f , -14 .717799187f , 10 .508025169f }};
161
+ auto hull = Manifold::Hull (hullPts);
162
+ EXPECT_TRUE (isMeshConvex (hull));
163
+ }
164
+
165
+ TEST (Hull, DISABLED_FailingTest2) {
166
+ // 1750623.stl
167
+ const std::vector<glm::vec3> hullPts = {
168
+ {174 .17001343f , -12 .022000313f , 29 .562002182f },
169
+ {174 .51400757f , -10 .858000755f , -3 .3340001106f },
170
+ {187 .50801086f , 22 .826000214f , 23 .486001968f },
171
+ {172 .42800903f , 12 .018000603f , 28 .120000839f },
172
+ {180 .98001099f , -26 .866001129f , 6 .9100003242f },
173
+ {172 .42800903f , -12 .022000313f , 28 .120000839f },
174
+ {174 .17001343f , 19 .498001099f , 29 .562002182f },
175
+ {213 .96600342f , 2 .9400000572f , -11 .100000381f },
176
+ {182 .53001404f , -22 .49200058f , 23 .644001007f },
177
+ {175 .89401245f , 19 .900001526f , 16 .118000031f },
178
+ {211 .38601685f , 3 .0200002193f , -14 .250000954f },
179
+ {183 .7440033f , 12 .018000603f , 18 .090000153f },
180
+ {210 .51000977f , 2 .5040001869f , -11 .100000381f },
181
+ {204 .13601685f , 34 .724002838f , -11 .250000954f },
182
+ {193 .23400879f , -24 .704000473f , 17 .768001556f },
183
+ {171 .62800598f , -19 .502000809f , 27 .320001602f },
184
+ {189 .67401123f , 8 .486000061f , -5 .4080004692f },
185
+ {193 .23800659f , 24 .704000473f , 17 .758001328f },
186
+ {165 .36801147f , -6 .5600004196f , -14 .250000954f },
187
+ {174 .17001343f , -19 .502000809f , 29 .562002182f },
188
+ {190 .06401062f , -0 .81000006199f , -14 .250000954f }};
189
+ auto hull = Manifold::Hull (hullPts);
190
+ EXPECT_TRUE (isMeshConvex (hull));
191
+ }
0 commit comments