Developer Documentation

unittests_add_face.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3 #include <iostream>
4
5 namespace {
6
7 class OpenMeshAddFaceTriangleMesh : public OpenMeshBase {
8
9 protected:
10
11 // This function is called before each test is run
12 virtual void SetUp() {
13
14 // Do some initial stuff with the member data here...
15 }
16
17 // This function is called after all tests are through
18 virtual void TearDown() {
19
20 // Do some final stuff with the member data here...
21 }
22
23 // Member already defined in OpenMeshBase
24 //Mesh mesh_;
25 };
26
27 class OpenMeshAddFacePolyMesh : public OpenMeshBasePoly {
28
29 protected:
30
31 // This function is called before each test is run
32 virtual void SetUp() {
33
34 // Do some initial stuff with the member data here...
35 }
36
37 // This function is called after all tests are through
38 virtual void TearDown() {
39
40 // Do some final stuff with the member data here...
41 }
42
43 // Member already defined in OpenMeshBase
44 //Mesh mesh_;
45 };
46
47 /*
48 * ====================================================================
49 * Define tests below
50 * ====================================================================
51 */
52
53 /* Adds two triangles to a tri mesh
54 */
55 TEST_F(OpenMeshAddFaceTriangleMesh, AddTrianglesToTrimesh) {
56
57 mesh_.clear();
58
59 // Add some vertices
60 Mesh::VertexHandle vhandle[4];
61
62 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
63 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
64 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
65 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
66
67 // Add two faces
68 std::vector<Mesh::VertexHandle> face_vhandles;
69
70 face_vhandles.push_back(vhandle[2]);
71 face_vhandles.push_back(vhandle[1]);
72 face_vhandles.push_back(vhandle[0]);
73
74 mesh_.add_face(face_vhandles);
75
76 face_vhandles.clear();
77
78 face_vhandles.push_back(vhandle[2]);
79 face_vhandles.push_back(vhandle[0]);
80 face_vhandles.push_back(vhandle[3]);
81 mesh_.add_face(face_vhandles);
82
83 // Test setup:
84 // 1 === 2
85 // | / |
86 // | / |
87 // | / |
88 // 0 === 3
89
90 // Check setup
91 EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
92 EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces";
93
94 }
95
96 /* Adds a quad to a trimesh (should be triangulated afterwards)
97 */
98 TEST_F(OpenMeshAddFaceTriangleMesh, AddQuadToTrimesh) {
99
100 mesh_.clear();
101
102 // Add some vertices
103 Mesh::VertexHandle vhandle[4];
104
105 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
106 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
107 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
108 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
109
110 // Add two faces
111 std::vector<Mesh::VertexHandle> face_vhandles;
112
113 face_vhandles.push_back(vhandle[0]);
114 face_vhandles.push_back(vhandle[1]);
115 face_vhandles.push_back(vhandle[2]);
116 face_vhandles.push_back(vhandle[3]);
117
118 mesh_.add_face(face_vhandles);
119
120 // Test setup:
121 // 1 === 2
122 // | / |
123 // | / |
124 // | / |
125 // 0 === 3
126
127 // Check setup
128 EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
129 EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces";
130
131 }
132
133 /* Adds a cube to a trimesh
134 */
135 TEST_F(OpenMeshAddFaceTriangleMesh, CreateTriangleMeshCube) {
136
137 mesh_.clear();
138
139 // Add some vertices
140 Mesh::VertexHandle vhandle[8];
141 vhandle[0] = mesh_.add_vertex(Mesh::Point(-1, -1, 1));
142 vhandle[1] = mesh_.add_vertex(Mesh::Point( 1, -1, 1));
143 vhandle[2] = mesh_.add_vertex(Mesh::Point( 1, 1, 1));
144 vhandle[3] = mesh_.add_vertex(Mesh::Point(-1, 1, 1));
145 vhandle[4] = mesh_.add_vertex(Mesh::Point(-1, -1, -1));
146 vhandle[5] = mesh_.add_vertex(Mesh::Point( 1, -1, -1));
147 vhandle[6] = mesh_.add_vertex(Mesh::Point( 1, 1, -1));
148 vhandle[7] = mesh_.add_vertex(Mesh::Point(-1, 1, -1));
149
150 // Add six faces to form a cube
151 std::vector<Mesh::VertexHandle> face_vhandles;
152
153 face_vhandles.clear();
154 face_vhandles.push_back(vhandle[0]);
155 face_vhandles.push_back(vhandle[1]);
156 face_vhandles.push_back(vhandle[3]);
157 mesh_.add_face(face_vhandles);
158
159 face_vhandles.clear();
160 face_vhandles.push_back(vhandle[1]);
161 face_vhandles.push_back(vhandle[2]);
162 face_vhandles.push_back(vhandle[3]);
163 mesh_.add_face(face_vhandles);
164
165 //=======================
166
167 face_vhandles.clear();
168 face_vhandles.push_back(vhandle[7]);
169 face_vhandles.push_back(vhandle[6]);
170 face_vhandles.push_back(vhandle[5]);
171 mesh_.add_face(face_vhandles);
172
173 face_vhandles.clear();
174 face_vhandles.push_back(vhandle[7]);
175 face_vhandles.push_back(vhandle[5]);
176 face_vhandles.push_back(vhandle[4]);
177 mesh_.add_face(face_vhandles);
178
179 //=======================
180
181 face_vhandles.clear();
182 face_vhandles.push_back(vhandle[1]);
183 face_vhandles.push_back(vhandle[0]);
184 face_vhandles.push_back(vhandle[4]);
185 mesh_.add_face(face_vhandles);
186
187 face_vhandles.clear();
188 face_vhandles.push_back(vhandle[1]);
189 face_vhandles.push_back(vhandle[4]);
190 face_vhandles.push_back(vhandle[5]);
191 mesh_.add_face(face_vhandles);
192
193 //=======================
194
195 face_vhandles.clear();
196 face_vhandles.push_back(vhandle[2]);
197 face_vhandles.push_back(vhandle[1]);
198 face_vhandles.push_back(vhandle[5]);
199 mesh_.add_face(face_vhandles);
200
201 face_vhandles.clear();
202 face_vhandles.push_back(vhandle[2]);
203 face_vhandles.push_back(vhandle[5]);
204 face_vhandles.push_back(vhandle[6]);
205 mesh_.add_face(face_vhandles);
206
207
208 //=======================
209
210 face_vhandles.clear();
211 face_vhandles.push_back(vhandle[3]);
212 face_vhandles.push_back(vhandle[2]);
213 face_vhandles.push_back(vhandle[6]);
214 mesh_.add_face(face_vhandles);
215
216 face_vhandles.clear();
217 face_vhandles.push_back(vhandle[3]);
218 face_vhandles.push_back(vhandle[6]);
219 face_vhandles.push_back(vhandle[7]);
220 mesh_.add_face(face_vhandles);
221
222 //=======================
223
224 face_vhandles.clear();
225 face_vhandles.push_back(vhandle[0]);
226 face_vhandles.push_back(vhandle[3]);
227 face_vhandles.push_back(vhandle[7]);
228 mesh_.add_face(face_vhandles);
229
230 face_vhandles.clear();
231 face_vhandles.push_back(vhandle[0]);
232 face_vhandles.push_back(vhandle[7]);
233 face_vhandles.push_back(vhandle[4]);
234 mesh_.add_face(face_vhandles);
235
236
237 // Test setup:
238 //
239 //
240 // 3 ======== 2
241 // / /|
242 // / / | z
243 // 0 ======== 1 | |
244 // | | | | y
245 // | 7 | 6 | /
246 // | | / | /
247 // | |/ |/
248 // 4 ======== 5 -------> x
249 //
250
251 // Check setup
252 EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges";
253 EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
254 EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
255 EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
256
257
258 }
259
260 /* Adds a quite strange configuration to the mesh
261 */
262 TEST_F(OpenMeshAddFaceTriangleMesh, CreateStrangeConfig) {
263
264
265 Mesh::VertexHandle vh[7];
266
267 //
268 // 2 x-----------x 1
269 // \ /
270 // \ /
271 // \ /
272 // \ /
273 // \ /
274 // 0 x ---x 6
275 // /|\ |
276 // / | \ |
277 // / | \ |
278 // / | \|
279 // x----x x
280 // 3 4 5
281 //
282 //
283 //
284
285 // Add vertices
286 vh[0] = mesh_.add_vertex (Mesh::Point (0, 0, 0));
287 vh[1] = mesh_.add_vertex (Mesh::Point (1, 1, 1));
288 vh[2] = mesh_.add_vertex (Mesh::Point (2, 2, 2));
289 vh[3] = mesh_.add_vertex (Mesh::Point (3, 3, 3));
290 vh[4] = mesh_.add_vertex (Mesh::Point (4, 4, 4));
291 vh[5] = mesh_.add_vertex (Mesh::Point (5, 5, 5));
292 vh[6] = mesh_.add_vertex (Mesh::Point (6, 6, 6));
293
294 mesh_.add_face( vh[0], vh[1], vh[2] );
295 mesh_.add_face( vh[0], vh[3], vh[4] );
296 mesh_.add_face( vh[0], vh[5], vh[6] );
297
298 // non-manifold!
299 Mesh::FaceHandle invalidFH = mesh_.add_face( vh[3], vh[0], vh[4] );
300
301 // Check setup
302 EXPECT_EQ(7u, mesh_.n_vertices() ) << "Wrong number of vertices";
303 EXPECT_EQ(3u, mesh_.n_faces() ) << "Wrong number of faces";
304 EXPECT_EQ(invalidFH, Mesh::InvalidFaceHandle ) << "non manifold face is valid";
305
306 }
307
308
309 /* Adds a quad to a polymesh (should be a quad afterwards)
310 */
311 TEST_F(OpenMeshAddFacePolyMesh, AddQuadToPolymesh) {
312
313 mesh_.clear();
314
315 // Add some vertices
316 Mesh::VertexHandle vhandle[4];
317
318 vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 0, 0));
319 vhandle[1] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
320 vhandle[2] = mesh_.add_vertex(PolyMesh::Point(1, 1, 0));
321 vhandle[3] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
322
323 // Add two faces
324 std::vector<Mesh::VertexHandle> face_vhandles;
325
326 face_vhandles.push_back(vhandle[0]);
327 face_vhandles.push_back(vhandle[1]);
328 face_vhandles.push_back(vhandle[2]);
329 face_vhandles.push_back(vhandle[3]);
330
331 mesh_.add_face(face_vhandles);
332
333 // Test setup:
334 // 1 === 2
335 // | |
336 // | |
337 // | |
338 // 0 === 3
339
340 // Check setup
341 EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
342 EXPECT_EQ(1u, mesh_.n_faces() ) << "Wrong number of faces";
343
344 }
345
346 /* Adds a cube to a polymesh
347 */
348 TEST_F(OpenMeshAddFacePolyMesh, CreatePolyMeshCube) {
349
350 mesh_.clear();
351
352 // Add some vertices
353 Mesh::VertexHandle vhandle[8];
354 vhandle[0] = mesh_.add_vertex(PolyMesh::Point(-1, -1, 1));
355 vhandle[1] = mesh_.add_vertex(PolyMesh::Point( 1, -1, 1));
356 vhandle[2] = mesh_.add_vertex(PolyMesh::Point( 1, 1, 1));
357 vhandle[3] = mesh_.add_vertex(PolyMesh::Point(-1, 1, 1));
358 vhandle[4] = mesh_.add_vertex(PolyMesh::Point(-1, -1, -1));
359 vhandle[5] = mesh_.add_vertex(PolyMesh::Point( 1, -1, -1));
360 vhandle[6] = mesh_.add_vertex(PolyMesh::Point( 1, 1, -1));
361 vhandle[7] = mesh_.add_vertex(PolyMesh::Point(-1, 1, -1));
362
363 // Add six faces to form a cube
364 std::vector<Mesh::VertexHandle> face_vhandles;
365
366 face_vhandles.clear();
367 face_vhandles.push_back(vhandle[0]);
368 face_vhandles.push_back(vhandle[1]);
369 face_vhandles.push_back(vhandle[2]);
370 face_vhandles.push_back(vhandle[3]);
371 mesh_.add_face(face_vhandles);
372
373 face_vhandles.clear();
374 face_vhandles.push_back(vhandle[7]);
375 face_vhandles.push_back(vhandle[6]);
376 face_vhandles.push_back(vhandle[5]);
377 face_vhandles.push_back(vhandle[4]);
378 mesh_.add_face(face_vhandles);
379
380 face_vhandles.clear();
381 face_vhandles.push_back(vhandle[1]);
382 face_vhandles.push_back(vhandle[0]);
383 face_vhandles.push_back(vhandle[4]);
384 face_vhandles.push_back(vhandle[5]);
385 mesh_.add_face(face_vhandles);
386
387 face_vhandles.clear();
388 face_vhandles.push_back(vhandle[2]);
389 face_vhandles.push_back(vhandle[1]);
390 face_vhandles.push_back(vhandle[5]);
391 face_vhandles.push_back(vhandle[6]);
392 mesh_.add_face(face_vhandles);
393
394 face_vhandles.clear();
395 face_vhandles.push_back(vhandle[3]);
396 face_vhandles.push_back(vhandle[2]);
397 face_vhandles.push_back(vhandle[6]);
398 face_vhandles.push_back(vhandle[7]);
399 mesh_.add_face(face_vhandles);
400
401 face_vhandles.clear();
402 face_vhandles.push_back(vhandle[0]);
403 face_vhandles.push_back(vhandle[3]);
404 face_vhandles.push_back(vhandle[7]);
405 face_vhandles.push_back(vhandle[4]);
406 mesh_.add_face(face_vhandles);
407
408
409 // Test setup:
410 //
411 //
412 // 3 ======== 2
413 // / /|
414 // / / | z
415 // 0 ======== 1 | |
416 // | | | | y
417 // | 7 | 6 | /
418 // | | / | /
419 // | |/ |/
420 // 4 ======== 5 -------> x
421 //
422
423 // Check setup
424 EXPECT_EQ(12u, mesh_.n_edges() ) << "Wrong number of Edges";
425 EXPECT_EQ(24u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
426 EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
427 EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces";
428
429 }
430
431 }
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
OpenMeshBasePoly
Definition: unittests_common.hh:53
OpenMesh::PolyMeshT::add_vertex
SmartVertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:235
OpenMeshBase
Definition: unittests_common.hh:29
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136