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_trimesh_iterators.hh
1 #ifndef INCLUDE_UNITTESTS_TRIMESH_ITERATORS_HH
2 #define INCLUDE_UNITTESTS_TRIMESH_ITERATORS_HH
3
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6
7 #include <iostream>
8
9 class OpenMeshIterators : public OpenMeshBase {
10
11 protected:
12
13 // This function is called before each test is run
14 virtual void SetUp() {
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 /*
28 * ====================================================================
29 * Define tests below
30 * ====================================================================
31 */
32
33 /*
34 * Small VertexIterator Test
35 */
36 TEST_F(OpenMeshIterators, VertexIter) {
37
38 mesh_.clear();
39
40 // Add some vertices
41 Mesh::VertexHandle vhandle[4];
42
43 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
44 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
45 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
46 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
47
48 // Add two faces
49 std::vector<Mesh::VertexHandle> face_vhandles;
50
51 face_vhandles.push_back(vhandle[2]);
52 face_vhandles.push_back(vhandle[1]);
53 face_vhandles.push_back(vhandle[0]);
54 mesh_.add_face(face_vhandles);
55
56 face_vhandles.clear();
57
58 face_vhandles.push_back(vhandle[2]);
59 face_vhandles.push_back(vhandle[0]);
60 face_vhandles.push_back(vhandle[3]);
61 mesh_.add_face(face_vhandles);
62
63 // Test setup:
64 // 1 === 2
65 // | / |
66 // | / |
67 // | / |
68 // 0 === 3
69
70 Mesh::VertexIter v_it = mesh_.vertices_begin();
71 Mesh::VertexIter v_end = mesh_.vertices_end();
72
73 EXPECT_EQ(0, v_it.handle().idx()) << "Index wrong for vertex iterator vertices_begin()";
74 ++v_it;
75 EXPECT_EQ(1, v_it.handle().idx()) << "Index wrong in vertex iterator";
76 ++v_it;
77 EXPECT_EQ(2, v_it.handle().idx()) << "Index wrong in vertex iterator";
78 ++v_it;
79 EXPECT_EQ(3, v_it.handle().idx()) << "Index wrong in vertex iterator";
80 ++v_it;
81 EXPECT_EQ(4, v_it.handle().idx()) << "Index wrong in vertex iterator";
82
83 // Check end iterator
84 EXPECT_EQ(4, v_end.handle().idx()) << "Index wrong in vertex iterator for vertices_end()";
85
86
87 // Second iterator test to start at a specific position
88
89 }
90
91 /*
92 * Small VertexIterator Test to check if we can start iterating at a specific handle
93 */
94 TEST_F(OpenMeshIterators, VertexIterStartPosition) {
95
96 mesh_.clear();
97
98 // Add some vertices
99 Mesh::VertexHandle vhandle[4];
100
101 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
102 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
103 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
104 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
105
106 // Add two faces
107 std::vector<Mesh::VertexHandle> face_vhandles;
108
109 face_vhandles.push_back(vhandle[2]);
110 face_vhandles.push_back(vhandle[1]);
111 face_vhandles.push_back(vhandle[0]);
112 mesh_.add_face(face_vhandles);
113
114 face_vhandles.clear();
115
116 face_vhandles.push_back(vhandle[2]);
117 face_vhandles.push_back(vhandle[0]);
118 face_vhandles.push_back(vhandle[3]);
119 mesh_.add_face(face_vhandles);
120
121 // Test setup:
122 // 1 === 2
123 // | / |
124 // | / |
125 // | / |
126 // 0 === 3
127
128 Mesh::VertexIter v_it = Mesh::VertexIter(mesh_,mesh_.vertex_handle(2));
129 Mesh::VertexIter v_end = mesh_.vertices_end();
130
131 EXPECT_EQ(2, v_it.handle().idx()) << "Index wrong in vertex iterator";
132 ++v_it;
133 EXPECT_EQ(3, v_it.handle().idx()) << "Index wrong in vertex iterator";
134 ++v_it;
135 EXPECT_EQ(4, v_it.handle().idx()) << "Index wrong in vertex iterator";
136
137 // Check end iterator
138 EXPECT_EQ(4, v_end.handle().idx()) << "Index wrong in vertex iterator for vertices_end()";
139
140
141 }
142
143 /*
144 * Small EdgeIterator Test
145 */
146 TEST_F(OpenMeshIterators, EdgeIter) {
147
148 mesh_.clear();
149
150 // Add some vertices
151 Mesh::VertexHandle vhandle[4];
152
153 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
154 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
155 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
156 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
157
158 // Add two faces
159 std::vector<Mesh::VertexHandle> face_vhandles;
160
161 face_vhandles.push_back(vhandle[2]);
162 face_vhandles.push_back(vhandle[1]);
163 face_vhandles.push_back(vhandle[0]);
164 mesh_.add_face(face_vhandles);
165
166 face_vhandles.clear();
167
168 face_vhandles.push_back(vhandle[2]);
169 face_vhandles.push_back(vhandle[0]);
170 face_vhandles.push_back(vhandle[3]);
171 mesh_.add_face(face_vhandles);
172
173 // Test setup:
174 // 1 === 2
175 // | / |
176 // | / |
177 // | / |
178 // 0 === 3
179
180
181 Mesh::EdgeIter e_it = mesh_.edges_begin();
182 Mesh::EdgeIter e_end = mesh_.edges_end();
183
184 EXPECT_EQ(0, e_it.handle().idx()) << "Wrong start index in edge iterator";
185 EXPECT_EQ(5, e_end.handle().idx()) << "Wrong end index in edge iterator";
186
187 EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "1: Wrong to vertex handle of halfedge 0";
188 EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "1: Wrong from vertex handle of halfedge 0";
189 EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "1: Wrong to vertex handle of halfedge 1";
190 EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "1: Wrong from vertex handle of halfedge 1";
191
192 ++e_it;
193 EXPECT_EQ(1, e_it.handle().idx()) << "Wrong index in edge iterator";
194
195 EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "2: Wrong to vertex handle of halfedge 0";
196 EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "2: Wrong from vertex handle of halfedge 0";
197 EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "2: Wrong to vertex handle of halfedge 1";
198 EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "2: Wrong from vertex handle of halfedge 1";
199
200
201 ++e_it;
202 EXPECT_EQ(2, e_it.handle().idx()) << "Wrong index in edge iterator";
203
204 EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "3: Wrong to vertex handle of halfedge 0";
205 EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "3: Wrong from vertex handle of halfedge 0";
206 EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "3: Wrong to vertex handle of halfedge 1";
207 EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "3: Wrong from vertex handle of halfedge 1";
208
209
210 ++e_it;
211 EXPECT_EQ(3, e_it.handle().idx()) << "Wrong index in edge iterator";
212
213 EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "4: Wrong to vertex handle of halfedge 0";
214 EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "4: Wrong from vertex handle of halfedge 0";
215 EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "4: Wrong to vertex handle of halfedge 1";
216 EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "4: Wrong from vertex handle of halfedge 1";
217
218
219 ++e_it;
220 EXPECT_EQ(4, e_it.handle().idx()) << "Wrong index in edge iterator";
221
222 EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "5: Wrong to vertex handle of halfedge 0";
223 EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "5: Wrong from vertex handle of halfedge 0";
224 EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "5: Wrong to vertex handle of halfedge 1";
225 EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "5: Wrong from vertex handle of halfedge 1";
226
227
228 }
229
230 /* Adds a cube to a trimesh and runs over all halfedges
231 */
232 TEST_F(OpenMeshIterators, HalfedgeIterSkipping) {
233
234 mesh_.clear();
235
236 // Add some vertices
237 Mesh::VertexHandle vhandle[8];
238 vhandle[0] = mesh_.add_vertex(Mesh::Point(-1, -1, 1));
239 vhandle[1] = mesh_.add_vertex(Mesh::Point( 1, -1, 1));
240 vhandle[2] = mesh_.add_vertex(Mesh::Point( 1, 1, 1));
241 vhandle[3] = mesh_.add_vertex(Mesh::Point(-1, 1, 1));
242 vhandle[4] = mesh_.add_vertex(Mesh::Point(-1, -1, -1));
243 vhandle[5] = mesh_.add_vertex(Mesh::Point( 1, -1, -1));
244 vhandle[6] = mesh_.add_vertex(Mesh::Point( 1, 1, -1));
245 vhandle[7] = mesh_.add_vertex(Mesh::Point(-1, 1, -1));
246
247 // Add six faces to form a cube
248 std::vector<Mesh::VertexHandle> face_vhandles;
249
250 face_vhandles.clear();
251 face_vhandles.push_back(vhandle[0]);
252 face_vhandles.push_back(vhandle[1]);
253 face_vhandles.push_back(vhandle[3]);
254 mesh_.add_face(face_vhandles);
255
256 face_vhandles.clear();
257 face_vhandles.push_back(vhandle[1]);
258 face_vhandles.push_back(vhandle[2]);
259 face_vhandles.push_back(vhandle[3]);
260 mesh_.add_face(face_vhandles);
261
262 //=======================
263
264 face_vhandles.clear();
265 face_vhandles.push_back(vhandle[7]);
266 face_vhandles.push_back(vhandle[6]);
267 face_vhandles.push_back(vhandle[5]);
268 mesh_.add_face(face_vhandles);
269
270 face_vhandles.clear();
271 face_vhandles.push_back(vhandle[7]);
272 face_vhandles.push_back(vhandle[5]);
273 face_vhandles.push_back(vhandle[4]);
274 mesh_.add_face(face_vhandles);
275
276 //=======================
277
278 face_vhandles.clear();
279 face_vhandles.push_back(vhandle[1]);
280 face_vhandles.push_back(vhandle[0]);
281 face_vhandles.push_back(vhandle[4]);
282 mesh_.add_face(face_vhandles);
283
284 face_vhandles.clear();
285 face_vhandles.push_back(vhandle[1]);
286 face_vhandles.push_back(vhandle[4]);
287 face_vhandles.push_back(vhandle[5]);
288 mesh_.add_face(face_vhandles);
289
290 //=======================
291
292 face_vhandles.clear();
293 face_vhandles.push_back(vhandle[2]);
294 face_vhandles.push_back(vhandle[1]);
295 face_vhandles.push_back(vhandle[5]);
296 mesh_.add_face(face_vhandles);
297
298 face_vhandles.clear();
299 face_vhandles.push_back(vhandle[2]);
300 face_vhandles.push_back(vhandle[5]);
301 face_vhandles.push_back(vhandle[6]);
302 mesh_.add_face(face_vhandles);
303
304
305 //=======================
306
307 face_vhandles.clear();
308 face_vhandles.push_back(vhandle[3]);
309 face_vhandles.push_back(vhandle[2]);
310 face_vhandles.push_back(vhandle[6]);
311 mesh_.add_face(face_vhandles);
312
313 face_vhandles.clear();
314 face_vhandles.push_back(vhandle[3]);
315 face_vhandles.push_back(vhandle[6]);
316 face_vhandles.push_back(vhandle[7]);
317 mesh_.add_face(face_vhandles);
318
319 //=======================
320
321 face_vhandles.clear();
322 face_vhandles.push_back(vhandle[0]);
323 face_vhandles.push_back(vhandle[3]);
324 face_vhandles.push_back(vhandle[7]);
325 mesh_.add_face(face_vhandles);
326
327 face_vhandles.clear();
328 face_vhandles.push_back(vhandle[0]);
329 face_vhandles.push_back(vhandle[7]);
330 face_vhandles.push_back(vhandle[4]);
331 mesh_.add_face(face_vhandles);
332
333
334 // Test setup:
335 //
336 //
337 // 3 ======== 2
338 // / /|
339 // / / | z
340 // 0 ======== 1 | |
341 // | | | | y
342 // | 7 | 6 | /
343 // | | / | /
344 // | |/ |/
345 // 4 ======== 5 -------> x
346 //
347
348 // Check setup
349 EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges";
350 EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
351 EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
352 EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
353
354
355 // Run over all halfedges
356 unsigned int heCounter = 0;
357
358 mesh_.request_face_status();
359 mesh_.request_vertex_status();
360 mesh_.request_halfedge_status();
361
362 // Get second edge
363 Mesh::EdgeHandle eh = mesh_.edge_handle(2);
364
365 // Delete one edge
366 mesh_.delete_edge(eh);
367
368 // Check setup ( No garbage collection, so nothing should change!)
369 EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges after delete";
370 EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after delete";
371 EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after delete";
372 EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces after delete";
373
374 Mesh::HalfedgeIter he_it = mesh_.halfedges_sbegin();
375 Mesh::HalfedgeIter he_end = mesh_.halfedges_end();
376
377 EXPECT_EQ(0, he_it.handle().idx()) << "Wrong start index in halfedge iterator";
378 EXPECT_EQ(36, he_end.handle().idx()) << "Wrong end index in halfedge iterator";
379
380
381 // =====================================================
382 // Check skipping iterator
383 // =====================================================
384 bool ok_4 = true;
385 bool ok_5 = true;
386
387 unsigned int count = 0;
388
389 while (he_it != he_end) {
390 if ( he_it.handle().idx() == 4 )
391 ok_4 = false;
392
393 if ( he_it.handle().idx() == 5 )
394 ok_5 = false;
395
396 ++he_it;
397 ++count;
398 }
399
400 EXPECT_EQ(34u,count) << "Skipping iterator count error";
401 EXPECT_TRUE( ok_4 ) << "Skipping iterator hit deleted halfedge 4";
402 EXPECT_TRUE( ok_5 ) << "Skipping iterator hit deleted halfedge 5";
403
404 // =====================================================
405 // Check non skipping iterator
406 // =====================================================
407 he_it = mesh_.halfedges_begin();
408
409 count = 0;
410 ok_4 = false;
411 ok_5 = false;
412
413 while (he_it != he_end) {
414 if ( he_it.handle().idx() == 4 )
415 ok_4 = true;
416
417 if ( he_it.handle().idx() == 5 )
418 ok_5 = true;
419
420
421 ++he_it;
422 ++count;
423 }
424
425 EXPECT_EQ(36u,count) << "Non-skipping iterator count error";
426 EXPECT_TRUE( ok_4 ) << "Non-skipping iterator missed deleted halfedge 4";
427 EXPECT_TRUE( ok_5 ) << "Non-skipping iterator missed deleted halfedge 5";
428 }
429
430 /* Adds a cube to a trimesh and runs over all halfedges
431 */
432 TEST_F(OpenMeshIterators, HalfedgeIterSkippingLowLevel) {
433
434 mesh_.clear();
435
436 // Add some vertices
437 Mesh::VertexHandle vhandle[8];
438 vhandle[0] = mesh_.add_vertex(Mesh::Point(-1, -1, 1));
439 vhandle[1] = mesh_.add_vertex(Mesh::Point( 1, -1, 1));
440 vhandle[2] = mesh_.add_vertex(Mesh::Point( 1, 1, 1));
441 vhandle[3] = mesh_.add_vertex(Mesh::Point(-1, 1, 1));
442 vhandle[4] = mesh_.add_vertex(Mesh::Point(-1, -1, -1));
443 vhandle[5] = mesh_.add_vertex(Mesh::Point( 1, -1, -1));
444 vhandle[6] = mesh_.add_vertex(Mesh::Point( 1, 1, -1));
445 vhandle[7] = mesh_.add_vertex(Mesh::Point(-1, 1, -1));
446
447 // Add six faces to form a cube
448 std::vector<Mesh::VertexHandle> face_vhandles;
449
450 face_vhandles.clear();
451 face_vhandles.push_back(vhandle[0]);
452 face_vhandles.push_back(vhandle[1]);
453 face_vhandles.push_back(vhandle[3]);
454 mesh_.add_face(face_vhandles);
455
456 face_vhandles.clear();
457 face_vhandles.push_back(vhandle[1]);
458 face_vhandles.push_back(vhandle[2]);
459 face_vhandles.push_back(vhandle[3]);
460 mesh_.add_face(face_vhandles);
461
462 //=======================
463
464 face_vhandles.clear();
465 face_vhandles.push_back(vhandle[7]);
466 face_vhandles.push_back(vhandle[6]);
467 face_vhandles.push_back(vhandle[5]);
468 mesh_.add_face(face_vhandles);
469
470 face_vhandles.clear();
471 face_vhandles.push_back(vhandle[7]);
472 face_vhandles.push_back(vhandle[5]);
473 face_vhandles.push_back(vhandle[4]);
474 mesh_.add_face(face_vhandles);
475
476 //=======================
477
478 face_vhandles.clear();
479 face_vhandles.push_back(vhandle[1]);
480 face_vhandles.push_back(vhandle[0]);
481 face_vhandles.push_back(vhandle[4]);
482 mesh_.add_face(face_vhandles);
483
484 face_vhandles.clear();
485 face_vhandles.push_back(vhandle[1]);
486 face_vhandles.push_back(vhandle[4]);
487 face_vhandles.push_back(vhandle[5]);
488 mesh_.add_face(face_vhandles);
489
490 //=======================
491
492 face_vhandles.clear();
493 face_vhandles.push_back(vhandle[2]);
494 face_vhandles.push_back(vhandle[1]);
495 face_vhandles.push_back(vhandle[5]);
496 mesh_.add_face(face_vhandles);
497
498 face_vhandles.clear();
499 face_vhandles.push_back(vhandle[2]);
500 face_vhandles.push_back(vhandle[5]);
501 face_vhandles.push_back(vhandle[6]);
502 mesh_.add_face(face_vhandles);
503
504
505 //=======================
506
507 face_vhandles.clear();
508 face_vhandles.push_back(vhandle[3]);
509 face_vhandles.push_back(vhandle[2]);
510 face_vhandles.push_back(vhandle[6]);
511 mesh_.add_face(face_vhandles);
512
513 face_vhandles.clear();
514 face_vhandles.push_back(vhandle[3]);
515 face_vhandles.push_back(vhandle[6]);
516 face_vhandles.push_back(vhandle[7]);
517 mesh_.add_face(face_vhandles);
518
519 //=======================
520
521 face_vhandles.clear();
522 face_vhandles.push_back(vhandle[0]);
523 face_vhandles.push_back(vhandle[3]);
524 face_vhandles.push_back(vhandle[7]);
525 mesh_.add_face(face_vhandles);
526
527 face_vhandles.clear();
528 face_vhandles.push_back(vhandle[0]);
529 face_vhandles.push_back(vhandle[7]);
530 face_vhandles.push_back(vhandle[4]);
531 mesh_.add_face(face_vhandles);
532
533
534 // Test setup:
535 //
536 //
537 // 3 ======== 2
538 // / /|
539 // / / | z
540 // 0 ======== 1 | |
541 // | | | | y
542 // | 7 | 6 | /
543 // | | / | /
544 // | |/ |/
545 // 4 ======== 5 -------> x
546 //
547
548 // Check setup
549 EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges";
550 EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
551 EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
552 EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
553
554
555 // Run over all halfedges
556 unsigned int heCounter = 0;
557
558 mesh_.request_face_status();
559 mesh_.request_vertex_status();
560 mesh_.request_halfedge_status();
561
562 // Get second edge
563 Mesh::EdgeHandle eh = mesh_.edge_handle(2);
564
565 // Check setup ( No garbage collection, so nothing should change!)
566 EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges after delete";
567 EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after delete";
568 EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after delete";
569 EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces after delete";
570
571 Mesh::HalfedgeIter he_it = mesh_.halfedges_sbegin();
572 Mesh::HalfedgeIter he_end = mesh_.halfedges_end();
573
574 EXPECT_EQ(0, he_it.handle().idx()) << "Wrong start index in halfedge iterator";
575 EXPECT_EQ(36, he_end.handle().idx()) << "Wrong end index in halfedge iterator";
576
577 // =====================================================
578 // Try to add low level edge with invalid incidents and
579 // check skipping iterator
580 // =====================================================
581
582 // Add a low level edge without handles
583 Mesh::EdgeHandle eh_test = mesh_.edge_handle(mesh_.new_edge(Mesh::VertexHandle(),Mesh::VertexHandle()));
584
585 he_it = mesh_.halfedges_sbegin();
586 he_end = mesh_.halfedges_end();
587
588 unsigned int count = 0;
589 bool found_36 = false;
590 bool found_37 = false;
591
592 while (he_it != he_end) {
593 if ( he_it.handle().idx() == 36 )
594 found_36 = true;
595
596 if ( he_it.handle().idx() == 37 )
597 found_37 = true;
598
599 ++he_it;
600 ++count;
601 }
602
603 EXPECT_EQ(38u,count) << "Skipping iterator count error";
604 EXPECT_TRUE( found_36 ) << "Skipping iterator missed halfedge 36";
605 EXPECT_TRUE( found_37 ) << "Skipping iterator missed halfedge 37";
606
607 // =====================================================
608 // Try to delete one edge with valid incidents and
609 // check skipping iterator
610 // =====================================================
611
612 // delete one edge and recheck (Halfedges 4 and 5)
613 mesh_.delete_edge(eh);
614
615 he_it = mesh_.halfedges_sbegin();
616 he_end = mesh_.halfedges_end();
617
618 count = 0;
619 bool found_4 = false;
620 bool found_5 = false;
621 found_36 = false;
622 found_37 = false;
623
624 while (he_it != he_end) {
625
626 if ( he_it.handle().idx() == 4 )
627 found_4 = true;
628
629 if ( he_it.handle().idx() == 5 )
630 found_5 = true;
631
632 if ( he_it.handle().idx() == 36 )
633 found_36 = true;
634
635 if ( he_it.handle().idx() == 37 )
636 found_37 = true;
637
638 ++he_it;
639 ++count;
640 }
641
642 EXPECT_EQ(36u,count) << "Deleted valid: Skipping iterator count error";
643 EXPECT_FALSE( found_4 ) << "Deleted valid: Skipping iterator hit deleted halfedge 4";
644 EXPECT_FALSE( found_5 ) << "Deleted valid: Skipping iterator hit deleted halfedge 5";
645 EXPECT_TRUE( found_36 ) << "Deleted valid: Skipping iterator missed halfedge 36";
646 EXPECT_TRUE( found_37 ) << "Deleted valid: Skipping iterator missed halfedge 37";
647
648 // =====================================================
649 // Try to delete one edge with invalid incidents and
650 // check skipping iterator
651 // =====================================================
652
653 // delete one edge and recheck (Halfedges 4 and 5)
654 mesh_.delete_edge(eh_test);
655
656 he_it = mesh_.halfedges_sbegin();
657 he_end = mesh_.halfedges_end();
658
659 count = 0;
660 found_4 = false;
661 found_5 = false;
662 found_36 = false;
663 found_37 = false;
664
665 while (he_it != he_end) {
666
667 if ( he_it.handle().idx() == 4 )
668 found_4 = true;
669
670 if ( he_it.handle().idx() == 5 )
671 found_5 = true;
672
673 if ( he_it.handle().idx() == 36 )
674 found_36 = true;
675
676 if ( he_it.handle().idx() == 37 )
677 found_37 = true;
678
679 ++he_it;
680 ++count;
681 }
682
683 EXPECT_EQ(34u,count) << "Deleted invalid: Skipping iterator count error";
684 EXPECT_FALSE( found_4 ) << "Deleted invalid: Skipping iterator hit deleted halfedge 4";
685 EXPECT_FALSE( found_5 ) << "Deleted invalid: Skipping iterator hit deleted halfedge 5";
686 EXPECT_FALSE( found_36 ) << "Deleted invalid: Skipping iterator hit deleted halfedge 36";
687 EXPECT_FALSE( found_37 ) << "Deleted invalid: Skipping iterator hit deleted halfedge 37";
688
689 }
690
691 /*
692 * Test with a mesh with one deleted face
693 */
694 TEST_F(OpenMeshIterators, FaceIterEmptyMeshOneDeletedFace) {
695
696 mesh_.clear();
697
698 // request delete_face capability
699 mesh_.request_vertex_status();
700 mesh_.request_edge_status();
701 mesh_.request_face_status();
702
703 // Add some vertices
704 Mesh::VertexHandle vhandle[4];
705
706 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
707 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
708 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
709
710 // Add two faces
711 std::vector<Mesh::VertexHandle> face_vhandles;
712
713 face_vhandles.push_back(vhandle[2]);
714 face_vhandles.push_back(vhandle[1]);
715 face_vhandles.push_back(vhandle[0]);
716 Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
717
718 // Delete face but keep vertices
719 bool const is_delete_isolated_vertex = false;
720 mesh_.delete_face(fh, is_delete_isolated_vertex);
721
722 // Test setup (Face deleted but vertices kept.
723 // 1 === 2
724 // | /
725 // | /
726 // | /
727 // 0
728
729 Mesh::FaceIter f_it = mesh_.faces_begin();
730 Mesh::FaceIter f_end = mesh_.faces_end();
731
732 EXPECT_EQ(0, f_it.handle().idx()) << "Wrong start index in FaceIterator";
733
734 EXPECT_EQ(1, f_end.handle().idx()) << "Wrong end index in FaceIterator";
735
736 ++f_it;
737 EXPECT_EQ(1, f_it.handle().idx()) << "Wrong end index in FaceIterator after one step";
738 EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator after one step";
739
740 Mesh::ConstFaceIter cf_it = mesh_.faces_begin();
741 Mesh::ConstFaceIter cf_end = mesh_.faces_end();
742
743 EXPECT_EQ(0, cf_it.handle().idx()) << "Wrong start index in ConstFaceIterator";
744
745 EXPECT_EQ(1, cf_end.handle().idx()) << "Wrong end index in ConstFaceIterator";
746
747 ++cf_it;
748 EXPECT_EQ(1, cf_it.handle().idx()) << "Wrong end index in ConstFaceIterator after one step";
749 EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator after one step";
750
751
752 // Same with skipping iterators:
753 f_it = mesh_.faces_sbegin();
754 f_end = mesh_.faces_end();
755
756 EXPECT_EQ(1, f_it.handle().idx()) << "Wrong start index in FaceIterator with skipping";
757
758 EXPECT_EQ(1, f_end.handle().idx()) << "Wrong end index in FaceIterator with skipping";
759
760 EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator with skipping";
761
762 // Same with skipping iterators:
763 cf_it = mesh_.faces_sbegin();
764 cf_end = mesh_.faces_end();
765
766 EXPECT_EQ(1, cf_it.handle().idx()) << "Wrong start index in ConstFaceIterator with skipping";
767
768 EXPECT_EQ(1, cf_end.handle().idx()) << "Wrong end index in ConstFaceIterator with skipping";
769
770 EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator with skipping";
771
772
773 mesh_.release_vertex_status();
774 mesh_.release_edge_status();
775 mesh_.release_face_status();
776
777 }
778
779 #endif // INCLUDE GUARD