OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unittests_trimesh_circulators.hh
1 #ifndef INCLUDE_UNITTESTS_TRIMESH_CIRCULATORS_HH
2 #define INCLUDE_UNITTESTS_TRIMESH_CIRCULATORS_HH
3 
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6 
7 #include <iostream>
8 
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 
24  // Member already defined in OpenMeshBase
25  //Mesh mesh_;
26 };
27 
28 /*
29  * ====================================================================
30  * Define tests below
31  * ====================================================================
32  */
33 
34 
35 /*
36  * Small VertexFaceIterator Test with holes in it
37  *
38  * WARNING!!! Basically this is an illegal configuration!
39  * But this way we can still detect if it breaks!
40  */
41 TEST_F(OpenMeshCirculators, VertexFaceIterWithHoles) {
42 
43  mesh_.clear();
44 
45  // Add some vertices
46  Mesh::VertexHandle vhandle[5];
47 
48  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
49  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
50  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
51  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
52  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
53 
54  // Add two faces
55  std::vector<Mesh::VertexHandle> face_vhandles;
56 
57  face_vhandles.push_back(vhandle[0]);
58  face_vhandles.push_back(vhandle[1]);
59  face_vhandles.push_back(vhandle[2]);
60  mesh_.add_face(face_vhandles);
61 
62  face_vhandles.clear();
63 
64  face_vhandles.push_back(vhandle[1]);
65  face_vhandles.push_back(vhandle[3]);
66  face_vhandles.push_back(vhandle[4]);
67  mesh_.add_face(face_vhandles);
68 
69  /* Test setup:
70  0 ==== 2
71  \ /
72  \ /
73  1
74  / \
75  / \
76  3 ==== 4 */
77 
78  // Iterate around vertex 1 at the middle (with holes in between)
79  Mesh::VertexFaceIter vf_it = mesh_.vf_begin(vhandle[1]);
80  Mesh::VertexFaceIter vf_end = mesh_.vf_end(vhandle[1]);
81  EXPECT_EQ(0, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at initialization";
82  EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at initialization";
83  ++vf_it ;
84  EXPECT_EQ(1, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 1";
85  EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 1";
86  ++vf_it ;
87  EXPECT_EQ(-1, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at end";
88  EXPECT_FALSE(vf_it) << "Iterator not invalid in VertexFaceIter at end";
89  EXPECT_TRUE( vf_it == vf_end ) << "End iterator for VertexFaceIter not matching";
90 
91  // Iterate around vertex 1 at the middle (with holes in between) with const iterator
92  Mesh::ConstVertexFaceIter cvf_it = mesh_.cvf_begin(vhandle[1]);
93  Mesh::ConstVertexFaceIter cvf_end = mesh_.cvf_end(vhandle[1]);
94  EXPECT_EQ(0, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at initialization";
95  EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at initialization";
96  ++cvf_it ;
97  EXPECT_EQ(1, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step one";
98  EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step one";
99  ++cvf_it ;
100  EXPECT_EQ(-1, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at end";
101  EXPECT_FALSE(cvf_it) << "Iterator not invalid in ConstVertexFaceIter at end";
102  EXPECT_TRUE( cvf_it == cvf_end ) << "End iterator for ConstVertexFaceIter not matching";
103 
104 }
105 
106 /*
107  * Small VertexFaceIterator Test without holes in it
108  */
109 TEST_F(OpenMeshCirculators, VertexFaceIterWithoutHoles) {
110 
111  mesh_.clear();
112 
113  // Add some vertices
114  Mesh::VertexHandle vhandle[5];
115 
116  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
117  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
118  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
119  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
120  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
121 
122  // Add two faces
123  std::vector<Mesh::VertexHandle> face_vhandles;
124 
125  face_vhandles.push_back(vhandle[0]);
126  face_vhandles.push_back(vhandle[1]);
127  face_vhandles.push_back(vhandle[2]);
128  mesh_.add_face(face_vhandles);
129 
130  face_vhandles.clear();
131 
132  face_vhandles.push_back(vhandle[1]);
133  face_vhandles.push_back(vhandle[3]);
134  face_vhandles.push_back(vhandle[4]);
135  mesh_.add_face(face_vhandles);
136 
137  face_vhandles.clear();
138 
139  face_vhandles.push_back(vhandle[0]);
140  face_vhandles.push_back(vhandle[3]);
141  face_vhandles.push_back(vhandle[1]);
142  mesh_.add_face(face_vhandles);
143 
144  face_vhandles.clear();
145 
146  face_vhandles.push_back(vhandle[2]);
147  face_vhandles.push_back(vhandle[1]);
148  face_vhandles.push_back(vhandle[4]);
149  mesh_.add_face(face_vhandles);
150 
151  /* Test setup:
152  0 ==== 2
153  |\ 0 /|
154  | \ / |
155  |2 1 3|
156  | / \ |
157  |/ 1 \|
158  3 ==== 4 */
159 
160  Mesh::VertexFaceIter vfa_it = mesh_.vf_begin(vhandle[1]);
161 
162  // Iterate around vertex 1 at the middle (with holes in between)
163  Mesh::VertexFaceIter vf_it = mesh_.vf_begin(vhandle[1]);
164  Mesh::VertexFaceIter vf_end = mesh_.vf_end(vhandle[1]);
165  EXPECT_EQ(3, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at initialization";
166  EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at initialization";
167  ++vf_it ;
168  EXPECT_EQ(1, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 1";
169  EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 1";
170  ++vf_it ;
171  EXPECT_EQ(2, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 2";
172  EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 2";
173  ++vf_it ;
174  EXPECT_EQ(0, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 3";
175  EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 3";
176  ++vf_it ;
177  EXPECT_EQ(3, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at end";
178  EXPECT_FALSE(vf_it) << "Iterator not invalid in VertexFaceIter at end";
179  EXPECT_TRUE( vf_it == vf_end ) << "End iterator for VertexFaceIter not matching";
180 
181  // Iterate around vertex 1 at the middle (with holes in between) with const iterator
182  Mesh::ConstVertexFaceIter cvf_it = mesh_.cvf_begin(vhandle[1]);
183  Mesh::ConstVertexFaceIter cvf_end = mesh_.cvf_end(vhandle[1]);
184  EXPECT_EQ(3, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at initialization";
185  EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at initialization";
186  ++cvf_it ;
187  EXPECT_EQ(1, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step 1";
188  EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step 1";
189  ++cvf_it ;
190  EXPECT_EQ(2, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step 2";
191  EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step 2";
192  ++cvf_it ;
193  EXPECT_EQ(0, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step 3";
194  EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step 3";
195  ++cvf_it ;
196  EXPECT_EQ(3, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at end";
197  EXPECT_FALSE(cvf_it) << "Iterator not invalid in VertexFaceIter at end";
198  EXPECT_TRUE( cvf_it == cvf_end ) << "End iterator for ConstVertexFaceIter not matching";
199 
200 
201 }
202 
203 /*
204  * Small VertexFaceIterator Test without holes in it
205  */
206 TEST_F(OpenMeshCirculators, VertexOutgoingHalfedgeWithoutHoles) {
207 
208  mesh_.clear();
209 
210  // Add some vertices
211  Mesh::VertexHandle vhandle[5];
212 
213  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
214  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
215  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
216  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
217  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
218 
219  // Add two faces
220  std::vector<Mesh::VertexHandle> face_vhandles;
221 
222  face_vhandles.push_back(vhandle[0]);
223  face_vhandles.push_back(vhandle[1]);
224  face_vhandles.push_back(vhandle[2]);
225  mesh_.add_face(face_vhandles);
226 
227  face_vhandles.clear();
228 
229  face_vhandles.push_back(vhandle[1]);
230  face_vhandles.push_back(vhandle[3]);
231  face_vhandles.push_back(vhandle[4]);
232  mesh_.add_face(face_vhandles);
233 
234  face_vhandles.clear();
235 
236  face_vhandles.push_back(vhandle[0]);
237  face_vhandles.push_back(vhandle[3]);
238  face_vhandles.push_back(vhandle[1]);
239  mesh_.add_face(face_vhandles);
240 
241  face_vhandles.clear();
242 
243  face_vhandles.push_back(vhandle[2]);
244  face_vhandles.push_back(vhandle[1]);
245  face_vhandles.push_back(vhandle[4]);
246  mesh_.add_face(face_vhandles);
247 
248  /* Test setup:
249  0 ==== 2
250  |\ 0 /|
251  | \ / |
252  |2 1 3|
253  | / \ |
254  |/ 1 \|
255  3 ==== 4 */
256 
257 
258  // Iterate around vertex 1 at the middle (with holes in between)
259  Mesh::VertexOHalfedgeIter voh_it = mesh_.voh_begin(vhandle[1]);
260  Mesh::VertexOHalfedgeIter voh_end = mesh_.voh_end(vhandle[1]);
261 
262  EXPECT_EQ(11, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter begin at initialization";
263  EXPECT_EQ(11, voh_end.handle().idx() ) << "Index wrong in VertexOHalfedgeIter end at initialization";
264  EXPECT_EQ(3, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter begin at initialization";
265  EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at initialization";
266 
267  ++voh_it ;
268 
269  EXPECT_EQ(6, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 1";
270  EXPECT_EQ(1, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 1";
271  EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 1";
272 
273  ++voh_it ;
274 
275  EXPECT_EQ(1, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 2";
276  EXPECT_EQ(2, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 2";
277  EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 2";
278 
279  ++voh_it ;
280 
281  EXPECT_EQ(2, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 3";
282  EXPECT_EQ(0, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 3";
283  EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 3";
284 
285  ++voh_it ;
286 
287  EXPECT_EQ(11, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 4";
288  EXPECT_EQ(3, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 4";
289  EXPECT_FALSE(voh_it) << "Iterator still valid in VertexOHalfedgeIter at step 4";
290  EXPECT_TRUE( voh_it == voh_end ) << "Miss matched end iterator";
291 
292  ++voh_it ;
293 
294  EXPECT_EQ(6, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 5";
295  EXPECT_EQ(1, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 5";
296  //EXPECT_FALSE(voh_it) << "Iterator still valid in VertexOHalfedgeIter at step 5";
297 
298 
299 
300  // Iterate around vertex 1 at the middle (with holes in between)
301  Mesh::ConstVertexOHalfedgeIter cvoh_it = mesh_.cvoh_begin(vhandle[1]);
302  Mesh::ConstVertexOHalfedgeIter cvoh_end = mesh_.cvoh_end(vhandle[1]);
303 
304  EXPECT_EQ(11, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter begin at initialization";
305  EXPECT_EQ(11, cvoh_end.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter end at initialization";
306  EXPECT_EQ(3, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter begin at initialization";
307  EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at initialization";
308 
309  ++cvoh_it ;
310 
311  EXPECT_EQ(6, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 1";
312  EXPECT_EQ(1, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 1";
313  EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at step 1";
314 
315  ++cvoh_it ;
316 
317  EXPECT_EQ(1, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 2";
318  EXPECT_EQ(2, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 2";
319  EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at step 2";
320 
321  ++cvoh_it ;
322 
323  EXPECT_EQ(2, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 3";
324  EXPECT_EQ(0, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 3";
325  EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at step 3";
326 
327  ++cvoh_it ;
328 
329  EXPECT_EQ(11, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 4";
330  EXPECT_EQ(3, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 4";
331  EXPECT_FALSE(cvoh_it) << "Iterator still valid in ConstVertexOHalfedgeIter at step 4";
332  EXPECT_TRUE( cvoh_it == cvoh_end ) << "Miss matched end iterator";
333 
334  ++cvoh_it ;
335 
336  EXPECT_EQ(6, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 5";
337  EXPECT_EQ(1, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 5";
338  //EXPECT_FALSE(cvoh_it) << "Iterator still valid in ConstVertexOHalfedgeIter at step 5";
339 
340 
341 }
342 
343 /*
344  * Small FaceFaceIterator Test with holes in it
345  */
346 TEST_F(OpenMeshCirculators, FaceFaceIterWithHoles) {
347 
348  mesh_.clear();
349 
350  // Add some vertices
351  Mesh::VertexHandle vhandle[5];
352 
353  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
354  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
355  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
356  vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
357  vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
358 
359  // Add three faces
360  std::vector<Mesh::VertexHandle> face_vhandles;
361 
362  face_vhandles.push_back(vhandle[0]);
363  face_vhandles.push_back(vhandle[1]);
364  face_vhandles.push_back(vhandle[2]);
365  mesh_.add_face(face_vhandles);
366 
367  face_vhandles.clear();
368 
369  face_vhandles.push_back(vhandle[2]);
370  face_vhandles.push_back(vhandle[1]);
371  face_vhandles.push_back(vhandle[3]);
372  mesh_.add_face(face_vhandles);
373 
374  face_vhandles.clear();
375 
376  face_vhandles.push_back(vhandle[2]);
377  face_vhandles.push_back(vhandle[3]);
378  face_vhandles.push_back(vhandle[4]);
379  mesh_.add_face(face_vhandles);
380 
381  /* Test setup:
382  *
383  * 0 ------ 2 ------ 4
384  * \ / \ /
385  * \ 0 / \ 2 /
386  * \ / 1 \ /
387  * 1 ------- 3
388  */
389 
390 
391  Mesh::FaceFaceIter ff_it = mesh_.ff_begin(mesh_.face_handle(1));
392  Mesh::FaceFaceIter ff_end = mesh_.ff_end(mesh_.face_handle(1));
393 
394  EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at initialization";
395  EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at initialization";
396  ++ff_it;
397  EXPECT_EQ(0, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at step 1";
398  EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at step 1";
399  ++ff_it;
400  EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at end";
401  EXPECT_FALSE(ff_it) << "Iterator invalid in FaceFaceIter at end";
402  EXPECT_TRUE( ff_it == ff_end ) << "End iterator for FaceFaceIter not matching";
403 
404  Mesh::ConstFaceFaceIter cff_it = mesh_.cff_begin(mesh_.face_handle(1));
405  Mesh::ConstFaceFaceIter cff_end = mesh_.cff_end(mesh_.face_handle(1));
406 
407  EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at initialization";
408  EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at initialization";
409  ++cff_it;
410  EXPECT_EQ(0, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at step 1";
411  EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at step 1";
412  ++cff_it;
413  EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at end";
414  EXPECT_FALSE(cff_it) << "Iterator invalid in ConstFaceFaceIter at end";
415  EXPECT_TRUE( cff_it == cff_end ) << "End iterator for ConstFaceFaceIter not matching";
416 
417 }
418 
419 /*
420  * Small FaceFaceIterator Test with holes in it
421  */
422 TEST_F(OpenMeshCirculators, FaceFaceIterWithoutHoles) {
423 
424  mesh_.clear();
425 
426  // Add some vertices
427  Mesh::VertexHandle vhandle[6];
428 
429  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
430  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
431  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
432  vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
433  vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
434  vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
435 
436  // Add three faces
437  std::vector<Mesh::VertexHandle> face_vhandles;
438 
439  face_vhandles.push_back(vhandle[0]);
440  face_vhandles.push_back(vhandle[1]);
441  face_vhandles.push_back(vhandle[2]);
442  mesh_.add_face(face_vhandles);
443 
444  face_vhandles.clear();
445 
446  face_vhandles.push_back(vhandle[2]);
447  face_vhandles.push_back(vhandle[1]);
448  face_vhandles.push_back(vhandle[3]);
449  mesh_.add_face(face_vhandles);
450 
451  face_vhandles.clear();
452 
453  face_vhandles.push_back(vhandle[2]);
454  face_vhandles.push_back(vhandle[3]);
455  face_vhandles.push_back(vhandle[4]);
456  mesh_.add_face(face_vhandles);
457 
458  face_vhandles.clear();
459 
460  face_vhandles.push_back(vhandle[1]);
461  face_vhandles.push_back(vhandle[5]);
462  face_vhandles.push_back(vhandle[3]);
463  mesh_.add_face(face_vhandles);
464 
465  /* Test setup:
466  *
467  * 0 ------ 2 ------ 4
468  * \ / \ /
469  * \ 0 / \ 2 /
470  * \ / 1 \ /
471  * 1 ------- 3
472  * \ /
473  * \ 3 /
474  * \ /
475  * \ /
476  * 5
477  */
478 
479 
480  Mesh::FaceFaceIter ff_it = mesh_.ff_begin(mesh_.face_handle(1));
481  Mesh::FaceFaceIter ff_end = mesh_.ff_end(mesh_.face_handle(1));
482 
483  EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at initialization";
484  EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at initialization";
485  ++ff_it;
486  EXPECT_EQ(0, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at step 1";
487  EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at step 1";
488  ++ff_it;
489  EXPECT_EQ(3, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at step 2";
490  EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at step 2";
491  ++ff_it;
492  EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at end";
493  EXPECT_FALSE(ff_it) << "Iterator invalid in FaceFaceIter at end";
494  EXPECT_TRUE( ff_it == ff_end ) << "End iterator for FaceFaceIter not matching";
495 
496  Mesh::ConstFaceFaceIter cff_it = mesh_.cff_begin(mesh_.face_handle(1));
497  Mesh::ConstFaceFaceIter cff_end = mesh_.cff_end(mesh_.face_handle(1));
498 
499  EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at initialization";
500  EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at initialization";
501  ++cff_it;
502  EXPECT_EQ(0, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at step 1";
503  EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at step 1";
504  ++cff_it;
505  EXPECT_EQ(3, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at step 2";
506  EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at step 2";
507  ++cff_it;
508  EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at end";
509  EXPECT_FALSE(cff_it) << "Iterator invalid in ConstFaceFaceIter at end";
510  EXPECT_TRUE( cff_it == cff_end ) << "End iterator for ConstFaceFaceIter not matching";
511 
512 }
513 
514 /*
515  * Small FaceFaceIterator Test for getting handles and faces from the facefaceiterator
516  */
517 TEST_F(OpenMeshCirculators, FaceFaceIteratorHandleConversion) {
518 
519  mesh_.clear();
520 
521  // Add some vertices
522  Mesh::VertexHandle vhandle[4];
523 
524  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
525  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
526  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
527  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
528 
529 
530  // Add two faces
531  std::vector<Mesh::VertexHandle> face_vhandles;
532 
533  face_vhandles.push_back(vhandle[0]);
534  face_vhandles.push_back(vhandle[2]);
535  face_vhandles.push_back(vhandle[1]);
536  Mesh::FaceHandle fh1 = mesh_.add_face(face_vhandles);
537 
538  face_vhandles.clear();
539 
540  face_vhandles.push_back(vhandle[0]);
541  face_vhandles.push_back(vhandle[3]);
542  face_vhandles.push_back(vhandle[2]);
543  Mesh::FaceHandle fh2 = mesh_.add_face(face_vhandles);
544 
545  face_vhandles.clear();
546 
547  /* Test setup:
548  *
549  * 1 -------- 2
550  * | f0 / |
551  * | / f1 |
552  * 0 -------- 3
553  */
554 
555  // Check setup
556  EXPECT_EQ(4u , mesh_.n_vertices() ) << "Wrong number of vertices";
557  EXPECT_EQ(2u , mesh_.n_faces() ) << "Wrong number of faces";
558 
559 
560  Mesh::ConstFaceFaceIter face_iter = mesh_.cff_iter(fh1);
561 
562 
563  // Get the face via the handle
564  Mesh::FaceHandle faceHandle1 = mesh_.handle(*face_iter);
565  const Mesh::Face& face1 = mesh_.face(faceHandle1);
566 
567  EXPECT_EQ(1, faceHandle1.idx() ) << "Wrong face handle index when getting from iterator via handle";
568 
569  // Get the face via the face itself
570  const Mesh::Face& face = *face_iter;
571  Mesh::FaceHandle fh = mesh_.handle(face);
572 
573 
574  EXPECT_EQ(1, fh.idx() ) << "Wrong face handle index when getting from iterator via face";
575 
576  bool correct = (&face == &face1);
577 
578  // Compare the faces
579  EXPECT_TRUE(correct) << "The faces are different although both ways should give the same one";
580 
581 }
582 
583 /*
584  * Small Test to check dereferencing the iterator
585  * No real result
586  */
587 TEST_F(OpenMeshCirculators, VertexOutgoingHalfedgeDereference) {
588 
589  mesh_.clear();
590 
591  // Add some vertices
592  Mesh::VertexHandle vhandle[5];
593 
594  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
595  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
596  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
597  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
598  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
599 
600  std::vector<Mesh::VertexHandle> face_vhandles;
601 
602  face_vhandles.push_back(vhandle[0]);
603  face_vhandles.push_back(vhandle[1]);
604  face_vhandles.push_back(vhandle[2]);
605  mesh_.add_face(face_vhandles);
606 
607  face_vhandles.clear();
608 
609  face_vhandles.push_back(vhandle[1]);
610  face_vhandles.push_back(vhandle[3]);
611  face_vhandles.push_back(vhandle[4]);
612  mesh_.add_face(face_vhandles);
613 
614  face_vhandles.clear();
615 
616  face_vhandles.push_back(vhandle[0]);
617  face_vhandles.push_back(vhandle[3]);
618  face_vhandles.push_back(vhandle[1]);
619  mesh_.add_face(face_vhandles);
620 
621  face_vhandles.clear();
622 
623  face_vhandles.push_back(vhandle[2]);
624  face_vhandles.push_back(vhandle[1]);
625  face_vhandles.push_back(vhandle[4]);
626  mesh_.add_face(face_vhandles);
627 
628  /* Test setup:
629  0 ==== 2
630  |\ 0 /|
631  | \ / |
632  |2 1 3|
633  | / \ |
634  |/ 1 \|
635  3 ==== 4 */
636 
637  // Iterate around vertex 1 at the middle (with holes in between)
638  Mesh::VertexOHalfedgeIter voh_it = mesh_.voh_iter(vhandle[1]);
639 
640  // TODO: If called without handle, it won't build
641  Mesh::EdgeHandle eh = mesh_.edge_handle(voh_it.handle());
642  Mesh::HalfedgeHandle heh = mesh_.halfedge_handle(voh_it);
643  Mesh::VertexHandle vh2 = mesh_.to_vertex_handle(voh_it);
644 
645  EXPECT_EQ(eh.idx() , 5 ) << "Wrong edge handle after dereferencing";
646  EXPECT_EQ(heh.idx() , 1 ) << "Wrong half edge handle after dereferencing";
647  EXPECT_EQ(vh2.idx() , 4 ) << "Wrong vertex handle after dereferencing";
648 
649 }
650 
651 
652 
653 
654 #endif // INCLUDE GUARD

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .