Developer Documentation
unittests_trimesh_circulator_vertex_edge.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3 
4 #include <iostream>
5 
6 namespace {
7 
8 class OpenMeshTrimeshCirculatorVertexEdge : 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 VertexEdgeIterator Test without holes in it
37  */
38 TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterWithoutHolesIncrement) {
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 
89  // Iterate around vertex 1 at the middle (with holes in between)
90  Mesh::VertexEdgeIter ve_it = mesh_.ve_begin(vhandle[1]);
91  Mesh::VertexEdgeIter ve_end = mesh_.ve_end(vhandle[1]);
92  EXPECT_EQ(5, ve_it->idx() ) << "Index wrong in VertexEdgeIter at initialization";
93  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at initialization";
94  ++ve_it ;
95  EXPECT_EQ(3, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 1";
96  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 1";
97  ++ve_it ;
98  EXPECT_EQ(0, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 2";
99  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 2";
100  ++ve_it ;
101  EXPECT_EQ(1, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 3";
102  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 3";
103  ++ve_it ;
104  EXPECT_EQ(5, ve_it->idx() ) << "Index wrong in VertexEdgeIter at end";
105  EXPECT_FALSE(ve_it.is_valid()) << "Iterator not invalid in VertexEdgeIter at end";
106  EXPECT_TRUE( ve_it == ve_end ) << "End iterator for VertexEdgeIter not matching";
107 
108  // Iterate around vertex 1 at the middle (with holes in between) with const iterator
109  Mesh::ConstVertexEdgeIter cve_it = mesh_.cve_begin(vhandle[1]);
110  Mesh::ConstVertexEdgeIter cve_end = mesh_.cve_end(vhandle[1]);
111  EXPECT_EQ(5, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at initialization";
112  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at initialization";
113  ++cve_it ;
114  EXPECT_EQ(3, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at step 1";
115  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at step 1";
116  ++cve_it ;
117  EXPECT_EQ(0, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at step 2";
118  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at step 2";
119  ++cve_it ;
120  EXPECT_EQ(1, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at step 3";
121  EXPECT_TRUE(cve_it.is_valid()) << "Iterator invalid in ConstVertexEdgeIter at step 3";
122  ++cve_it ;
123  EXPECT_EQ(5, cve_it->idx() ) << "Index wrong in ConstVertexEdgeIter at end";
124  EXPECT_FALSE(cve_it.is_valid()) << "Iterator not invalid in VertexEdgeIter at end";
125  EXPECT_TRUE( cve_it == cve_end ) << "End iterator for ConstVertexEdgeIter not matching";
126 }
127 
128 /*
129  * Small VertexEdgeIterator Test without holes in it
130  */
131 TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterBoundaryIncrement) {
132 
133  mesh_.clear();
134 
135  // Add some vertices
136  Mesh::VertexHandle vhandle[5];
137 
138  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
139  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
140  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
141  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
142  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
143 
144  // Add two faces
145  std::vector<Mesh::VertexHandle> face_vhandles;
146 
147  face_vhandles.push_back(vhandle[0]);
148  face_vhandles.push_back(vhandle[1]);
149  face_vhandles.push_back(vhandle[2]);
150  mesh_.add_face(face_vhandles);
151 
152  face_vhandles.clear();
153 
154  face_vhandles.push_back(vhandle[1]);
155  face_vhandles.push_back(vhandle[3]);
156  face_vhandles.push_back(vhandle[4]);
157  mesh_.add_face(face_vhandles);
158 
159  face_vhandles.clear();
160 
161  face_vhandles.push_back(vhandle[0]);
162  face_vhandles.push_back(vhandle[3]);
163  face_vhandles.push_back(vhandle[1]);
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[1]);
170  face_vhandles.push_back(vhandle[4]);
171  mesh_.add_face(face_vhandles);
172 
173  /* Test setup:
174  0 ==== 2
175  |\ 0 /|
176  | \ / |
177  |2 1 3|
178  | / \ |
179  |/ 1 \|
180  3 ==== 4 */
181 
182  // Iterate around vertex 1 at the middle (with holes in between)
183  Mesh::VertexEdgeIter ve_it = mesh_.ve_begin(vhandle[2]);
184  Mesh::VertexEdgeIter ve_end = mesh_.ve_end(vhandle[2]);
185  EXPECT_EQ(7, ve_it->idx() ) << "Index wrong in VertexEdgeIter at initialization";
186  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at initialization";
187  ++ve_it ;
188  EXPECT_EQ(1, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 1";
189  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 1";
190  ++ve_it ;
191  EXPECT_EQ(2, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 2";
192  EXPECT_TRUE(ve_it.is_valid()) << "Iterator invalid in VertexEdgeIter at step 2";
193  ++ve_it ;
194  EXPECT_EQ(7, ve_it->idx() ) << "Index wrong in VertexEdgeIter at step 3";
195  EXPECT_FALSE(ve_it.is_valid()) << "Iterator not invalid in VertexEdgeIter at end";
196  EXPECT_TRUE( ve_it == ve_end ) << "End iterator for VertexEdgeIter not matching";
197 
198 }
199 
200 
201 /*
202  * Test if the end iterator stays invalid after one lap
203  * DISABLED as long as the normal iterators using old behavior
204  */
205 //TEST_F(OpenMeshTrimeshCirculatorVertexEdge, VertexEdgeIterCheckInvalidationAtEnds) {
206 //
207 // mesh_.clear();
208 //
209 // // Add some vertices
210 // Mesh::VertexHandle vhandle[5];
211 //
212 // vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
213 // vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
214 // vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
215 // vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
216 // vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
217 //
218 // // Add two faces
219 // std::vector<Mesh::VertexHandle> face_vhandles;
220 //
221 // face_vhandles.push_back(vhandle[0]);
222 // face_vhandles.push_back(vhandle[1]);
223 // face_vhandles.push_back(vhandle[2]);
224 // Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles);
225 //
226 // face_vhandles.clear();
227 //
228 // face_vhandles.push_back(vhandle[1]);
229 // face_vhandles.push_back(vhandle[3]);
230 // face_vhandles.push_back(vhandle[4]);
231 // mesh_.add_face(face_vhandles);
232 //
233 // face_vhandles.clear();
234 //
235 // face_vhandles.push_back(vhandle[0]);
236 // face_vhandles.push_back(vhandle[3]);
237 // face_vhandles.push_back(vhandle[1]);
238 // mesh_.add_face(face_vhandles);
239 //
240 // face_vhandles.clear();
241 //
242 // face_vhandles.push_back(vhandle[2]);
243 // face_vhandles.push_back(vhandle[1]);
244 // face_vhandles.push_back(vhandle[4]);
245 // mesh_.add_face(face_vhandles);
246 //
247 // /* Test setup:
248 // 0 ==== 2
249 // |\ 0 /|
250 // | \ / |
251 // |2 1 3|
252 // | / \ |
253 // |/ 1 \|
254 // 3 ==== 4 */
255 //
256 //
257 // // Check if the end iterator stays invalid after end
258 // Mesh::VertexEdgeIter endIter = mesh_.ve_end(vhandle[1]);
259 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
260 // ++endIter ;
261 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid after increment";
262 //
263 // // Check if the end iterators becomes valid after decrement
264 // endIter = mesh_.ve_end(vhandle[1]);
265 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
266 // --endIter;
267 // EXPECT_TRUE(endIter.is_valid()) << "EndIter is invalid after decrement";
268 // EXPECT_EQ(1,endIter->idx()) << "EndIter points on the wrong element";
269 //
270 //
271 // // Check if the start iterator decrement is invalid
272 // Mesh::VertexEdgeIter startIter = mesh_.ve_begin(vhandle[1]);
273 // EXPECT_TRUE(startIter.is_valid()) << "StartIter is not valid";
274 // --startIter;
275 // EXPECT_FALSE(startIter.is_valid()) << "StartIter decrement is not invalid";
276 //
277 // // Check if the start iterator becomes valid
278 // ++startIter;
279 // EXPECT_TRUE(startIter.is_valid()) << "StarIter is invalid after re-incrementing";
280 // EXPECT_EQ(startIter->idx(), mesh_.ve_begin(vhandle[1])->idx()) << "StartIter points on the wrong element";
281 //
282 //}
283 
284 /*
285  * Test CW and CCW iterators
286  */
287 TEST_F(OpenMeshTrimeshCirculatorVertexEdge, CWAndCCWCheck) {
288 
289  mesh_.clear();
290 
291  // Add some vertices
292  Mesh::VertexHandle vhandle[5];
293 
294  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
295  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
296  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
297  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
298  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
299 
300  // Add two faces
301  std::vector<Mesh::VertexHandle> face_vhandles;
302 
303  face_vhandles.push_back(vhandle[0]);
304  face_vhandles.push_back(vhandle[1]);
305  face_vhandles.push_back(vhandle[2]);
306  mesh_.add_face(face_vhandles);
307 
308  face_vhandles.clear();
309 
310  face_vhandles.push_back(vhandle[1]);
311  face_vhandles.push_back(vhandle[3]);
312  face_vhandles.push_back(vhandle[4]);
313  mesh_.add_face(face_vhandles);
314 
315  face_vhandles.clear();
316 
317  face_vhandles.push_back(vhandle[0]);
318  face_vhandles.push_back(vhandle[3]);
319  face_vhandles.push_back(vhandle[1]);
320  mesh_.add_face(face_vhandles);
321 
322  face_vhandles.clear();
323 
324  face_vhandles.push_back(vhandle[2]);
325  face_vhandles.push_back(vhandle[1]);
326  face_vhandles.push_back(vhandle[4]);
327  mesh_.add_face(face_vhandles);
328 
329  /* Test setup:
330  0 ==== 2
331  |\ 0 /|
332  | \ / |
333  |2 1 3|
334  | / \ |
335  |/ 1 \|
336  3 ==== 4 */
337 
338 
339  int indices[5] = {5, 1, 0, 3, 5};
340  int rev_indices[5];
341  std::reverse_copy(indices,indices+5,rev_indices);
342 
343  Mesh::VertexHandle vh = vhandle[1];
344 
345  //CCW
346  Mesh::VertexEdgeCCWIter ve_ccwit = mesh_.ve_ccwbegin(vh);
347  Mesh::VertexEdgeCCWIter ve_ccwend = mesh_.ve_ccwend(vh);
348  size_t i = 0;
349  for (;ve_ccwit != ve_ccwend; ++ve_ccwit, ++i)
350  {
351  EXPECT_EQ(indices[i], ve_ccwit->idx()) << "Index wrong in VertexEdgeCCWIter";
352  }
353 
354  EXPECT_FALSE(ve_ccwit.is_valid()) << "Iterator invalid in VertexEdgeCCWIter at end";
355  EXPECT_TRUE( ve_ccwit == ve_ccwend ) << "End iterator for VertexEdgeCCWIter not matching";
356 
357  //constant CCW
358  Mesh::ConstVertexEdgeCCWIter cve_ccwit = mesh_.cve_ccwbegin(vh);
359  Mesh::ConstVertexEdgeCCWIter cve_ccwend = mesh_.cve_ccwend(vh);
360  i = 0;
361  for (;cve_ccwit != cve_ccwend; ++cve_ccwit, ++i)
362  {
363  EXPECT_EQ(indices[i], cve_ccwit->idx()) << "Index wrong in ConstVertexEdgeCCWIter";
364  }
365 
366  EXPECT_FALSE(cve_ccwit.is_valid()) << "Iterator invalid in ConstVertexEdgeCCWIter at end";
367  EXPECT_TRUE( cve_ccwit == cve_ccwend ) << "End iterator for ConstVertexEdgeCCWIter not matching";
368 
369  //CW
370  Mesh::VertexEdgeCWIter ve_cwit = mesh_.ve_cwbegin(vh);
371  Mesh::VertexEdgeCWIter ve_cwend = mesh_.ve_cwend(vh);
372  i = 0;
373  for (;ve_cwit != ve_cwend; ++ve_cwit, ++i)
374  {
375  EXPECT_EQ(rev_indices[i], ve_cwit->idx()) << "Index wrong in VertexEdgeCWIter";
376  }
377  EXPECT_FALSE(ve_cwit.is_valid()) << "Iterator invalid in VertexEdgeCWIter at end";
378  EXPECT_TRUE( ve_cwit == ve_cwend ) << "End iterator for VertexEdgeCWIter not matching";
379 
380  //constant CW
381  Mesh::ConstVertexEdgeCWIter cve_cwit = mesh_.cve_cwbegin(vh);
382  Mesh::ConstVertexEdgeCWIter cve_cwend = mesh_.cve_cwend(vh);
383  i = 0;
384  for (;cve_cwit != cve_cwend; ++cve_cwit, ++i)
385  {
386  EXPECT_EQ(rev_indices[i], cve_cwit->idx()) << "Index wrong in ConstVertexEdgeCWIter";
387  }
388  EXPECT_FALSE(cve_cwit.is_valid()) << "Iterator invalid in ConstVertexEdgeCWIter at end";
389  EXPECT_TRUE( cve_cwit == cve_cwend ) << "End iterator for ConstVertexEdgeCWIter not matching";
390 
391  /*
392  * conversion properties:
393  * a) cw_begin == CWIter(ccw_begin())
394  * b) cw_iter->idx() == CCWIter(cw_iter)->idx() for valid iterators
395  * c) --cw_iter == CWIter(++ccwIter) for valid iterators
396  * d) cw_end == CWIter(ccw_end()) => --cw_end != CWIter(++ccw_end()) *
397  */
398  Mesh::VertexEdgeCWIter ve_cwIter = mesh_.ve_cwbegin(vh);
399  // a)
400  EXPECT_TRUE( ve_cwIter == Mesh::VertexEdgeCWIter(mesh_.ve_ccwbegin(vh)) ) << "ccw to cw conversion failed";
401  EXPECT_TRUE( Mesh::VertexEdgeCCWIter(ve_cwIter) == mesh_.ve_ccwbegin(vh) ) << "cw to ccw conversion failed";
402  // b)
403  EXPECT_EQ( ve_cwIter->idx(), Mesh::VertexEdgeCCWIter(ve_cwIter)->idx()) << "iterators doesnt point on the same element";
404  // c)
405  ++ve_cwIter;
406  ve_ccwend = mesh_.ve_ccwend(vh);
407  --ve_ccwend;
408  EXPECT_EQ(ve_cwIter->idx(),ve_ccwend->idx()) << "iteratoes are not equal after inc/dec";
409  // additional conversion check
410  ve_ccwend = Mesh::VertexEdgeCCWIter(ve_cwIter);
411  EXPECT_EQ(ve_cwIter->idx(),ve_ccwend->idx())<< "iterators doesnt point on the same element";
412  // d)
413  ve_cwIter = Mesh::VertexEdgeCWIter(mesh_.ve_ccwend(vh));
414  EXPECT_FALSE(ve_cwIter.is_valid()) << "end iterator is not invalid";
415  EXPECT_TRUE(Mesh::VertexEdgeCCWIter(mesh_.ve_cwend(vh)) == mesh_.ve_ccwend(vh)) << "end iterators are not equal";
416 
417 
418 }
419 
420 }
Kernel::ConstVertexEdgeIter ConstVertexEdgeIter
Circulator.
Definition: PolyMeshT.hh:178
Kernel::VertexEdgeIter VertexEdgeIter
Circulator.
Definition: PolyMeshT.hh:168
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115