OpenMesh

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
254 EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
255
256 }
257
258 /* Adds a quite strange configuration to the mesh
259 */
260 TEST_F(OpenMeshAddFaceTriangleMesh, CreateStrangeConfig) {
261
262
263 Mesh::VertexHandle vh[7];
264 Mesh::FaceHandle fh[4];
265
266 //
267 // 2 x-----------x 1
268 // \ /
269 // \ /
270 // \ /
271 // \ /
272 // \ /
273 // 0 x ---x 6
274 // /|\ |
275 // / | \ |
276 // / | \ |
277 // / | \|
278 // x----x x
279 // 3 4 5
280 //
281 //
282 //
283
284 // Add vertices
285 vh[0] = mesh_.add_vertex (Mesh::Point (0, 0, 0));
286 vh[1] = mesh_.add_vertex (Mesh::Point (1, 1, 1));
287 vh[2] = mesh_.add_vertex (Mesh::Point (2, 2, 2));
288 vh[3] = mesh_.add_vertex (Mesh::Point (3, 3, 3));
289 vh[4] = mesh_.add_vertex (Mesh::Point (4, 4, 4));
290 vh[5] = mesh_.add_vertex (Mesh::Point (5, 5, 5));
291 vh[6] = mesh_.add_vertex (Mesh::Point (6, 6, 6));
292
293 mesh_.add_face( vh[0], vh[1], vh[2] );
294 mesh_.add_face( vh[0], vh[3], vh[4] );
295 mesh_.add_face( vh[0], vh[5], vh[6] );
296
297 // non-manifold!
298 mesh_.add_face( vh[3], vh[0], vh[4] );
299
300 // Check setup
301 EXPECT_EQ(7u, mesh_.n_vertices() ) << "Wrong number of vertices";
302 EXPECT_EQ(4u, mesh_.n_faces() ) << "Wrong number of faces";
303
304 }
305
306
307 /* Adds a quad to a polymesh (should be a quad afterwards)
308 */
309 TEST_F(OpenMeshAddFacePolyMesh, AddQuadToPolymesh) {
310
311 mesh_.clear();
312
313 // Add some vertices
314 Mesh::VertexHandle vhandle[4];
315
316 vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 0, 0));
317 vhandle[1] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
318 vhandle[2] = mesh_.add_vertex(PolyMesh::Point(1, 1, 0));
319 vhandle[3] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
320
321 // Add two faces
322 std::vector<Mesh::VertexHandle> face_vhandles;
323
324 face_vhandles.push_back(vhandle[0]);
325 face_vhandles.push_back(vhandle[1]);
326 face_vhandles.push_back(vhandle[2]);
327 face_vhandles.push_back(vhandle[3]);
328
329 mesh_.add_face(face_vhandles);
330
331 // Test setup:
332 // 1 === 2
333 // | |
334 // | |
335 // | |
336 // 0 === 3
337
338 // Check setup
339 EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
340 EXPECT_EQ(1u, mesh_.n_faces() ) << "Wrong number of faces";
341
342 }
343
344 /* Adds a cube to a polymesh
345 */
346 TEST_F(OpenMeshAddFacePolyMesh, CreatePolyMeshCube) {
347
348 mesh_.clear();
349
350 // Add some vertices
351 Mesh::VertexHandle vhandle[8];
352 vhandle[0] = mesh_.add_vertex(PolyMesh::Point(-1, -1, 1));
353 vhandle[1] = mesh_.add_vertex(PolyMesh::Point( 1, -1, 1));
354 vhandle[2] = mesh_.add_vertex(PolyMesh::Point( 1, 1, 1));
355 vhandle[3] = mesh_.add_vertex(PolyMesh::Point(-1, 1, 1));
356 vhandle[4] = mesh_.add_vertex(PolyMesh::Point(-1, -1, -1));
357 vhandle[5] = mesh_.add_vertex(PolyMesh::Point( 1, -1, -1));
358 vhandle[6] = mesh_.add_vertex(PolyMesh::Point( 1, 1, -1));
359 vhandle[7] = mesh_.add_vertex(PolyMesh::Point(-1, 1, -1));
360
361 // Add six faces to form a cube
362 std::vector<Mesh::VertexHandle> face_vhandles;
363
364 face_vhandles.clear();
365 face_vhandles.push_back(vhandle[0]);
366 face_vhandles.push_back(vhandle[1]);
367 face_vhandles.push_back(vhandle[2]);
368 face_vhandles.push_back(vhandle[3]);
369 mesh_.add_face(face_vhandles);
370
371 face_vhandles.clear();
372 face_vhandles.push_back(vhandle[7]);
373 face_vhandles.push_back(vhandle[6]);
374 face_vhandles.push_back(vhandle[5]);
375 face_vhandles.push_back(vhandle[4]);
376 mesh_.add_face(face_vhandles);
377
378 face_vhandles.clear();
379 face_vhandles.push_back(vhandle[1]);
380 face_vhandles.push_back(vhandle[0]);
381 face_vhandles.push_back(vhandle[4]);
382 face_vhandles.push_back(vhandle[5]);
383 mesh_.add_face(face_vhandles);
384
385 face_vhandles.clear();
386 face_vhandles.push_back(vhandle[2]);
387 face_vhandles.push_back(vhandle[1]);
388 face_vhandles.push_back(vhandle[5]);
389 face_vhandles.push_back(vhandle[6]);
390 mesh_.add_face(face_vhandles);
391
392 face_vhandles.clear();
393 face_vhandles.push_back(vhandle[3]);
394 face_vhandles.push_back(vhandle[2]);
395 face_vhandles.push_back(vhandle[6]);
396 face_vhandles.push_back(vhandle[7]);
397 mesh_.add_face(face_vhandles);
398
399 face_vhandles.clear();
400 face_vhandles.push_back(vhandle[0]);
401 face_vhandles.push_back(vhandle[3]);
402 face_vhandles.push_back(vhandle[7]);
403 face_vhandles.push_back(vhandle[4]);
404 mesh_.add_face(face_vhandles);
405
406
407 // Test setup:
408 //
409 //
410 // 3 ======== 2
411 // / /|
412 // / / | z
413 // 0 ======== 1 | |
414 // | | | | y
415 // | 7 | 6 | /
416 // | | / | /
417 // | |/ |/
418 // 4 ======== 5 -------> x
419 //
420
421 // Check setup
422 EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
423 EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces";
424
425 }
426
427
428 #endif // INCLUDE GUARD