OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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