Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_trimesh_circulator_vertex_vertex.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3 
4 #include <iostream>
5 
6 namespace {
7 
8 class OpenMeshTrimeshCirculatorVertexVertex : public OpenMeshBase {
9 
10  protected:
11 
12  // This function is called before each test is run
13  virtual void SetUp() {
14  }
15 
16  // This function is called after all tests are through
17  virtual void TearDown() {
18 
19  // Do some final stuff with the member data here...
20  }
21 
22 
23  // Member already defined in OpenMeshBase
24  //Mesh mesh_;
25 };
26 
27 /*
28  * ====================================================================
29  * Define tests below
30  * ====================================================================
31  */
32 
33 
34 
35 /*
36  * Small VertexFaceOutgoingHalfedgeIterator Test without holes in it
37  */
38 TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexIncrement) {
39 
40  mesh_.clear();
41 
42  // Add some vertices
43  Mesh::VertexHandle vhandle[5];
44 
45  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
46  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
47  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
48  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
49  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
50 
51  // Add two faces
52  std::vector<Mesh::VertexHandle> face_vhandles;
53 
54  face_vhandles.push_back(vhandle[0]);
55  face_vhandles.push_back(vhandle[1]);
56  face_vhandles.push_back(vhandle[2]);
57  mesh_.add_face(face_vhandles);
58 
59  face_vhandles.clear();
60 
61  face_vhandles.push_back(vhandle[1]);
62  face_vhandles.push_back(vhandle[3]);
63  face_vhandles.push_back(vhandle[4]);
64  mesh_.add_face(face_vhandles);
65 
66  face_vhandles.clear();
67 
68  face_vhandles.push_back(vhandle[0]);
69  face_vhandles.push_back(vhandle[3]);
70  face_vhandles.push_back(vhandle[1]);
71  mesh_.add_face(face_vhandles);
72 
73  face_vhandles.clear();
74 
75  face_vhandles.push_back(vhandle[2]);
76  face_vhandles.push_back(vhandle[1]);
77  face_vhandles.push_back(vhandle[4]);
78  mesh_.add_face(face_vhandles);
79 
80  /* Test setup:
81  0 ==== 2
82  |\ 0 /|
83  | \ / |
84  |2 1 3|
85  | / \ |
86  |/ 1 \|
87  3 ==== 4 */
88  // Starting vertex is 1->4
89 
90 
91  // Iterate around vertex 1 at the middle (with holes in between)
92  Mesh::VertexVertexIter vv_it = mesh_.vv_begin(vhandle[1]);
93  Mesh::VertexVertexIter vv_end = mesh_.vv_end(vhandle[1]);
94 
95  EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter begin at initialization";
96  EXPECT_EQ(4, vv_end->idx() ) << "Index wrong in VertexVertexIter end at initialization";
97  EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at initialization";
98 
99  ++vv_it ;
100 
101  EXPECT_EQ(3, vv_it->idx() ) << "Index wrong in VertexVertexIter step 1";
102  EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 1";
103 
104  ++vv_it ;
105 
106  EXPECT_EQ(0, vv_it->idx() ) << "Index wrong in VertexVertexIter step 2";
107  EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 2";
108 
109  ++vv_it ;
110 
111  EXPECT_EQ(2, vv_it->idx() ) << "Index wrong in VertexVertexIter step 3";
112  EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 3";
113 
114  ++vv_it ;
115 
116  EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter step 4";
117  EXPECT_FALSE(vv_it.is_valid()) << "Iterator still valid in VertexVertexIter at step 4";
118  EXPECT_TRUE( vv_it == vv_end ) << "Miss matched end iterator";
119 
120 }
121 
122 /*
123  * Small VertexFaceOutgoingHalfedgeIterator Test at boundary vertex
124  */
125 TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexBoundaryIncrement) {
126 
127  mesh_.clear();
128 
129  // Add some vertices
130  Mesh::VertexHandle vhandle[5];
131 
132  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
133  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
134  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
135  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
136  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
137 
138  // Add two faces
139  std::vector<Mesh::VertexHandle> face_vhandles;
140 
141  face_vhandles.push_back(vhandle[0]);
142  face_vhandles.push_back(vhandle[1]);
143  face_vhandles.push_back(vhandle[2]);
144  mesh_.add_face(face_vhandles);
145 
146  face_vhandles.clear();
147 
148  face_vhandles.push_back(vhandle[1]);
149  face_vhandles.push_back(vhandle[3]);
150  face_vhandles.push_back(vhandle[4]);
151  mesh_.add_face(face_vhandles);
152 
153  face_vhandles.clear();
154 
155  face_vhandles.push_back(vhandle[0]);
156  face_vhandles.push_back(vhandle[3]);
157  face_vhandles.push_back(vhandle[1]);
158  mesh_.add_face(face_vhandles);
159 
160  face_vhandles.clear();
161 
162  face_vhandles.push_back(vhandle[2]);
163  face_vhandles.push_back(vhandle[1]);
164  face_vhandles.push_back(vhandle[4]);
165  mesh_.add_face(face_vhandles);
166 
167  /* Test setup:
168  0 ==== 2
169  |\ 0 /|
170  | \ / |
171  |2 1 3|
172  | / \ |
173  |/ 1 \|
174  3 ==== 4 */
175  // Starting vertex is 1->4
176 
177 
178  // Iterate around vertex 1 at the middle (with holes in between)
179  Mesh::VertexVertexIter vv_it = mesh_.vv_begin(vhandle[2]);
180  Mesh::VertexVertexIter vv_end = mesh_.vv_end(vhandle[2]);
181 
182  EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter begin at initialization";
183  EXPECT_EQ(4, vv_end->idx() ) << "Index wrong in VertexVertexIter end at initialization";
184  EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at initialization";
185 
186  ++vv_it ;
187 
188  EXPECT_EQ(1, vv_it->idx() ) << "Index wrong in VertexVertexIter step 1";
189  EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 1";
190 
191  ++vv_it ;
192 
193  EXPECT_EQ(0, vv_it->idx() ) << "Index wrong in VertexVertexIter step 2";
194  EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 2";
195 
196  ++vv_it ;
197 
198  EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter step 3";
199  EXPECT_FALSE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 3";
200  EXPECT_TRUE( vv_it == vv_end ) << "Miss matched end iterator";
201 }
202 
203 
204 /*
205  * Test if the end iterator stays invalid after one lap
206  * DISABLED as long as the normal iterators using old behavior
207  */
208 //TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexIterCheckInvalidationAtEnds) {
209 //
210 // mesh_.clear();
211 //
212 // // Add some vertices
213 // Mesh::VertexHandle vhandle[5];
214 //
215 // vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
216 // vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
217 // vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
218 // vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
219 // vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
220 //
221 // // Add two faces
222 // std::vector<Mesh::VertexHandle> face_vhandles;
223 //
224 // face_vhandles.push_back(vhandle[0]);
225 // face_vhandles.push_back(vhandle[1]);
226 // face_vhandles.push_back(vhandle[2]);
227 // Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles);
228 //
229 // face_vhandles.clear();
230 //
231 // face_vhandles.push_back(vhandle[1]);
232 // face_vhandles.push_back(vhandle[3]);
233 // face_vhandles.push_back(vhandle[4]);
234 // mesh_.add_face(face_vhandles);
235 //
236 // face_vhandles.clear();
237 //
238 // face_vhandles.push_back(vhandle[0]);
239 // face_vhandles.push_back(vhandle[3]);
240 // face_vhandles.push_back(vhandle[1]);
241 // mesh_.add_face(face_vhandles);
242 //
243 // face_vhandles.clear();
244 //
245 // face_vhandles.push_back(vhandle[2]);
246 // face_vhandles.push_back(vhandle[1]);
247 // face_vhandles.push_back(vhandle[4]);
248 // mesh_.add_face(face_vhandles);
249 //
250 // /* Test setup:
251 // 0 ==== 2
252 // |\ 0 /|
253 // | \ / |
254 // |2 1 3|
255 // | / \ |
256 // |/ 1 \|
257 // 3 ==== 4 */
258 //
259 //
260 // // Check if the end iterator stays invalid after end
261 // Mesh::VertexVertexIter endIter = mesh_.vv_end(vhandle[1]);
262 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
263 // ++endIter ;
264 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid after increment";
265 //
266 // // Check if the end iterators becomes valid after decrement
267 // endIter = mesh_.vv_end(vhandle[1]);
268 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
269 // --endIter;
270 // EXPECT_TRUE(endIter.is_valid()) << "EndIter is invalid after decrement";
271 // EXPECT_EQ(2,endIter->idx()) << "EndIter points on the wrong element";
272 //
273 //
274 // // Check if the start iterator decrement is invalid
275 // Mesh::VertexVertexIter startIter = mesh_.vv_begin(vhandle[1]);
276 // EXPECT_TRUE(startIter.is_valid()) << "StartIter is not valid";
277 // --startIter;
278 // EXPECT_FALSE(startIter.is_valid()) << "StartIter decrement is not invalid";
279 //
280 // // Check if the start iterator becomes valid
281 // ++startIter;
282 // EXPECT_TRUE(startIter.is_valid()) << "StartIter is invalid after re-incrementing";
283 // EXPECT_EQ(startIter->idx(), mesh_.vv_begin(vhandle[1])->idx()) << "StartIter points on the wrong element";
284 //
285 //}
286 
287 /*
288  * Test CW and CCW iterators
289  */
290 TEST_F(OpenMeshTrimeshCirculatorVertexVertex, CWAndCCWCheck) {
291 
292  mesh_.clear();
293 
294  // Add some vertices
295  Mesh::VertexHandle vhandle[5];
296 
297  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
298  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
299  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
300  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
301  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
302 
303  // Add two faces
304  std::vector<Mesh::VertexHandle> face_vhandles;
305 
306  face_vhandles.push_back(vhandle[0]);
307  face_vhandles.push_back(vhandle[1]);
308  face_vhandles.push_back(vhandle[2]);
309  mesh_.add_face(face_vhandles);
310 
311  face_vhandles.clear();
312 
313  face_vhandles.push_back(vhandle[1]);
314  face_vhandles.push_back(vhandle[3]);
315  face_vhandles.push_back(vhandle[4]);
316  mesh_.add_face(face_vhandles);
317 
318  face_vhandles.clear();
319 
320  face_vhandles.push_back(vhandle[0]);
321  face_vhandles.push_back(vhandle[3]);
322  face_vhandles.push_back(vhandle[1]);
323  mesh_.add_face(face_vhandles);
324 
325  face_vhandles.clear();
326 
327  face_vhandles.push_back(vhandle[2]);
328  face_vhandles.push_back(vhandle[1]);
329  face_vhandles.push_back(vhandle[4]);
330  mesh_.add_face(face_vhandles);
331 
332  /* Test setup:
333  0 ==== 2
334  |\ 0 /|
335  | \ / |
336  |2 1 3|
337  | / \ |
338  |/ 1 \|
339  3 ==== 4 */
340 
341 
342  int indices[5] = {4, 2, 0, 3, 4};
343  int rev_indices[5];
344  std::reverse_copy(indices,indices+5,rev_indices);
345 
346  Mesh::VertexHandle vh = vhandle[1];
347 
348  //CCW
349  Mesh::VertexVertexCCWIter vv_ccwit = mesh_.vv_ccwbegin(vh);
350  Mesh::VertexVertexCCWIter vv_ccwend = mesh_.vv_ccwend(vh);
351  size_t i = 0;
352  for (;vv_ccwit != vv_ccwend; ++vv_ccwit, ++i)
353  {
354  EXPECT_EQ(indices[i], vv_ccwit->idx()) << "Index wrong in VertexVertexCCWIter";
355  }
356 
357  EXPECT_FALSE(vv_ccwit.is_valid()) << "Iterator invalid in VertexVertexCCWIter at end";
358  EXPECT_TRUE( vv_ccwit == vv_ccwend ) << "End iterator for VertexVertexCCWIter not matching";
359 
360  //constant CCW
361  Mesh::ConstVertexVertexCCWIter cvv_ccwit = mesh_.cvv_ccwbegin(vh);
362  Mesh::ConstVertexVertexCCWIter cvv_ccwend = mesh_.cvv_ccwend(vh);
363  i = 0;
364  for (;cvv_ccwit != cvv_ccwend; ++cvv_ccwit, ++i)
365  {
366  EXPECT_EQ(indices[i], cvv_ccwit->idx()) << "Index wrong in ConstVertexVertexCCWIter";
367  }
368 
369  EXPECT_FALSE(cvv_ccwit.is_valid()) << "Iterator invalid in ConstVertexVertexCCWIter at end";
370  EXPECT_TRUE( cvv_ccwit == cvv_ccwend ) << "End iterator for ConstVertexVertexCCWIter not matching";
371 
372  //CW
373  Mesh::VertexVertexCWIter vv_cwit = mesh_.vv_cwbegin(vh);
374  Mesh::VertexVertexCWIter vv_cwend = mesh_.vv_cwend(vh);
375  i = 0;
376  for (;vv_cwit != vv_cwend; ++vv_cwit, ++i)
377  {
378  EXPECT_EQ(rev_indices[i], vv_cwit->idx()) << "Index wrong in VertexVertexCWIter";
379  }
380  EXPECT_FALSE(vv_cwit.is_valid()) << "Iterator invalid in VertexVertexCWIter at end";
381  EXPECT_TRUE( vv_cwit == vv_cwend ) << "End iterator for VertexVertexCWIter not matching";
382 
383  //constant CW
384  Mesh::ConstVertexVertexCWIter cvv_cwit = mesh_.cvv_cwbegin(vh);
385  Mesh::ConstVertexVertexCWIter cvv_cwend = mesh_.cvv_cwend(vh);
386  i = 0;
387  for (;cvv_cwit != cvv_cwend; ++cvv_cwit, ++i)
388  {
389  EXPECT_EQ(rev_indices[i], cvv_cwit->idx()) << "Index wrong in ConstVertexVertexCWIter";
390  }
391  EXPECT_FALSE(cvv_cwit.is_valid()) << "Iterator invalid in ConstVertexVertexCWIter at end";
392  EXPECT_TRUE( cvv_cwit == cvv_cwend ) << "End iterator for ConstVertexVertexCWIter not matching";
393 
394  /*
395  * conversion properties:
396  * a) cw_begin == CWIter(ccw_begin())
397  * b) cw_iter->idx() == CCWIter(cw_iter)->idx() for valid iterators
398  * c) --cw_iter == CWIter(++ccwIter) for valid iterators
399  * d) cw_end == CWIter(ccw_end()) => --cw_end != CWIter(++ccw_end()) *
400  */
401  Mesh::VertexVertexCWIter vv_cwIter = mesh_.vv_cwbegin(vh);
402  // a)
403  EXPECT_TRUE( vv_cwIter == Mesh::VertexVertexCWIter(mesh_.vv_ccwbegin(vh)) ) << "ccw to cw convvrsion failed";
404  EXPECT_TRUE( Mesh::VertexVertexCCWIter(vv_cwIter) == mesh_.vv_ccwbegin(vh) ) << "cw to ccw convvrsion failed";
405  // b)
406  EXPECT_EQ( vv_cwIter->idx(), Mesh::VertexVertexCCWIter(vv_cwIter)->idx()) << "iterators doesnt point on the same element";
407  // c)
408  ++vv_cwIter;
409  vv_ccwend = mesh_.vv_ccwend(vh);
410  --vv_ccwend;
411  EXPECT_EQ(vv_cwIter->idx(),vv_ccwend->idx()) << "iteratoes are not equal after inc/dec";
412  // additional conversion check
413  vv_ccwend = Mesh::VertexVertexCCWIter(vv_cwIter);
414  EXPECT_EQ(vv_cwIter->idx(),vv_ccwend->idx())<< "iterators doesnt point on the same element";
415  // d)
416  vv_cwIter = Mesh::VertexVertexCWIter(mesh_.vv_ccwend(vh));
417  EXPECT_FALSE(vv_cwIter.is_valid()) << "end iterator is not invalid";
418  EXPECT_TRUE(Mesh::VertexVertexCCWIter(mesh_.vv_cwend(vh)) == mesh_.vv_ccwend(vh)) << "end iterators are not equal";
419 
420 
421 }
422 
423 
424 
425 }
Kernel::VertexVertexIter VertexVertexIter
Circulator.
Definition: PolyMeshT.hh:165
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139