Developer Documentation
unittests_trimesh_circulator_face_halfedge.cc
1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
3 
4 #include <iostream>
5 #include <algorithm>
6 
7 namespace {
8 
9 class OpenMeshTrimeshCirculatorFaceHalfEdge : 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 
24  // Member already defined in OpenMeshBase
25  //Mesh mesh_;
26 };
27 
28 /*
29  * ====================================================================
30  * Define tests below
31  * ====================================================================
32  */
33 
34 
35 
36 /*
37  * Small FaceHalfedgeIterator Test
38  */
39 //TEST_F(OpenMeshTrimeshCirculatorFaceHalfEdge, FaceHalfedgeIterWithoutHolesIncrement) {
40 //
41 // mesh_.clear();
42 //
43 // // Add some vertices
44 // Mesh::VertexHandle vhandle[6];
45 //
46 // vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
47 // vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
48 // vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
49 // vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
50 // vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
51 // vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
52 //
53 // // Add three faces
54 // std::vector<Mesh::VertexHandle> face_vhandles;
55 //
56 // face_vhandles.push_back(vhandle[0]);
57 // face_vhandles.push_back(vhandle[1]);
58 // face_vhandles.push_back(vhandle[2]);
59 // mesh_.add_face(face_vhandles);
60 //
61 // face_vhandles.clear();
62 //
63 // face_vhandles.push_back(vhandle[2]);
64 // face_vhandles.push_back(vhandle[1]);
65 // face_vhandles.push_back(vhandle[3]);
66 // mesh_.add_face(face_vhandles);
67 //
68 // face_vhandles.clear();
69 //
70 // face_vhandles.push_back(vhandle[2]);
71 // face_vhandles.push_back(vhandle[3]);
72 // face_vhandles.push_back(vhandle[4]);
73 // mesh_.add_face(face_vhandles);
74 //
75 // face_vhandles.clear();
76 //
77 // face_vhandles.push_back(vhandle[1]);
78 // face_vhandles.push_back(vhandle[5]);
79 // face_vhandles.push_back(vhandle[3]);
80 // mesh_.add_face(face_vhandles);
81 //
82 // /* Test setup:
83 // *
84 // * 0 ------ 2 ------ 4
85 // * \ / \ /
86 // * \ 0 / \ 2 /
87 // * \ / 1 \ /
88 // * 1 ------- 3
89 // * \ /
90 // * \ 3 /
91 // * \ /
92 // * \ /
93 // * 5
94 // */
95 //
96 //
97 // Mesh::FaceHalfedgeIter fh_it = mesh_.fh_begin(mesh_.face_handle(1));
98 // Mesh::FaceHalfedgeIter fh_end = mesh_.fh_end(mesh_.face_handle(1));
99 //
100 // EXPECT_EQ(8, fh_it->idx() ) << "Index wrong in FaceHalfedgeIter at initialization";
101 // EXPECT_TRUE(fh_it.is_valid()) << "Iterator invalid in FaceHalfedgeIter at initialization";
102 // ++fh_it;
103 // EXPECT_EQ(3, fh_it->idx() ) << "Index wrong in FaceHalfedgeIter at step 1";
104 // EXPECT_TRUE(fh_it.is_valid()) << "Iterator invalid in FaceHalfedgeIter at step 1";
105 // ++fh_it;
106 // EXPECT_EQ(6, fh_it->idx() ) << "Index wrong in FaceHalfedgeIter at step 2";
107 // EXPECT_TRUE(fh_it.is_valid()) << "Iterator invalid in FaceHalfedgeIter at step 2";
108 // ++fh_it;
109 // EXPECT_EQ(8, fh_it->idx() ) << "Index wrong in FaceHalfedgeIter at end";
110 // EXPECT_FALSE(fh_it.is_valid()) << "Iterator invalid in FaceHalfedgeIter at end";
111 // EXPECT_TRUE( fh_it == fh_end ) << "End iterator for FaceHalfedgeIter not matching";
112 //
113 // Mesh::ConstFaceHalfedgeIter cfh_it = mesh_.cfh_begin(mesh_.face_handle(1));
114 // Mesh::ConstFaceHalfedgeIter cfh_end = mesh_.cfh_end(mesh_.face_handle(1));
115 //
116 // EXPECT_EQ(8, cfh_it->idx() ) << "Index wrong in ConstFaceHalfedgeIter at initialization";
117 // EXPECT_TRUE(cfh_it.is_valid()) << "Iterator invalid in ConstFaceHalfedgeIter at initialization";
118 // ++cfh_it;
119 // EXPECT_EQ(3, cfh_it->idx() ) << "Index wrong in ConstFaceHalfedgeIter at step 1";
120 // EXPECT_TRUE(cfh_it.is_valid()) << "Iterator invalid in ConstFaceHalfedgeIter at step 1";
121 // ++cfh_it;
122 // EXPECT_EQ(6, cfh_it->idx() ) << "Index wrong in ConstFaceHalfedgeIter at step 2";
123 // EXPECT_TRUE(cfh_it.is_valid()) << "Iterator invalid in ConstFaceHalfedgeIter at step 2";
124 // ++cfh_it;
125 // EXPECT_EQ(8, cfh_it->idx() ) << "Index wrong in ConstFaceHalfedgeIter at end";
126 // EXPECT_FALSE(cfh_it.is_valid()) << "Iterator invalid in ConstFaceHalfedgeIter at end";
127 // EXPECT_TRUE( cfh_it == cfh_end ) << "End iterator for ConstFaceHalfedgeIter not matching";
128 //
129 //}
130 
131 /*
132  * test CW and CCW iterators
133  */
134 TEST_F(OpenMeshTrimeshCirculatorFaceHalfEdge, CWAndCCWTest) {
135 
136  mesh_.clear();
137 
138  // Add some vertices
139  Mesh::VertexHandle vhandle[6];
140 
141  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
142  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
143  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
144  vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
145  vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
146  vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
147 
148  // Add three faces
149  std::vector<Mesh::VertexHandle> face_vhandles;
150 
151  face_vhandles.push_back(vhandle[0]);
152  face_vhandles.push_back(vhandle[1]);
153  face_vhandles.push_back(vhandle[2]);
154  mesh_.add_face(face_vhandles);
155 
156  face_vhandles.clear();
157 
158  face_vhandles.push_back(vhandle[2]);
159  face_vhandles.push_back(vhandle[1]);
160  face_vhandles.push_back(vhandle[3]);
161  mesh_.add_face(face_vhandles);
162 
163  face_vhandles.clear();
164 
165  face_vhandles.push_back(vhandle[2]);
166  face_vhandles.push_back(vhandle[3]);
167  face_vhandles.push_back(vhandle[4]);
168  mesh_.add_face(face_vhandles);
169 
170  face_vhandles.clear();
171 
172  face_vhandles.push_back(vhandle[1]);
173  face_vhandles.push_back(vhandle[5]);
174  face_vhandles.push_back(vhandle[3]);
175  mesh_.add_face(face_vhandles);
176 
177  /* Test setup:
178  *
179  * 0 ------ 2 ------ 4
180  * \ / \ /
181  * \ 0 / \ 2 /
182  * \ / 1 \ /
183  * 1 ------- 3
184  * \ /
185  * \ 3 /
186  * \ /
187  * \ /
188  * 5
189  */
190 
191 
192  int indices[4] = {8, 3, 6, 8};
193  int rev_indices[4];
194  std::reverse_copy(indices,indices+4,rev_indices);
195 
196  //CCW
197  Mesh::FaceHalfedgeCCWIter fh_ccwit = mesh_.fh_ccwbegin(mesh_.face_handle(1));
198  Mesh::FaceHalfedgeCCWIter fh_ccwend = mesh_.fh_ccwend(mesh_.face_handle(1));
199  size_t i = 0;
200  for (;fh_ccwit != fh_ccwend; ++fh_ccwit, ++i)
201  {
202  EXPECT_EQ(indices[i], fh_ccwit->idx()) << "Index wrong in FaceHalfedgeIter";
203  }
204 
205  EXPECT_FALSE(fh_ccwit.is_valid()) << "Iterator invalid in FaceHalfedgeIter at end";
206  EXPECT_TRUE( fh_ccwit == fh_ccwend ) << "End iterator for FaceHalfedgeIter not matching";
207 
208  //constant CCW
209  Mesh::ConstFaceHalfedgeCCWIter cfh_ccwit = mesh_.cfh_ccwbegin(mesh_.face_handle(1));
210  Mesh::ConstFaceHalfedgeCCWIter cfh_ccwend = mesh_.cfh_ccwend(mesh_.face_handle(1));
211  i = 0;
212  for (;cfh_ccwit != cfh_ccwend; ++cfh_ccwit, ++i)
213  {
214  EXPECT_EQ(indices[i], cfh_ccwit->idx()) << "Index wrong in ConstFaceHalfedgeIter";
215  }
216 
217  EXPECT_FALSE(cfh_ccwit.is_valid()) << "Iterator invalid in ConstFaceHalfedgeIter at end";
218  EXPECT_TRUE( cfh_ccwit == cfh_ccwend ) << "End iterator for ConstFaceHalfedgeIter not matching";
219 
220  //CW
221  Mesh::FaceHalfedgeCWIter fh_cwit = mesh_.fh_cwbegin(mesh_.face_handle(1));
222  Mesh::FaceHalfedgeCWIter fh_cwend = mesh_.fh_cwend(mesh_.face_handle(1));
223  i = 0;
224  for (;fh_cwit != fh_cwend; ++fh_cwit, ++i)
225  {
226  EXPECT_EQ(rev_indices[i], fh_cwit->idx()) << "Index wrong in FaceHalfedgeCWIter";
227  }
228  EXPECT_FALSE(fh_cwit.is_valid()) << "Iterator invalid in FaceHalfedgeCWIter at end";
229  EXPECT_TRUE( fh_cwit == fh_cwend ) << "End iterator for FaceHalfedgeCWIter not matching";
230 
231  //constant CW
232  Mesh::ConstFaceHalfedgeCWIter cfh_cwit = mesh_.cfh_cwbegin(mesh_.face_handle(1));
233  Mesh::ConstFaceHalfedgeCWIter cfh_cwend = mesh_.cfh_cwend(mesh_.face_handle(1));
234  i = 0;
235  for (;cfh_cwit != cfh_cwend; ++cfh_cwit, ++i)
236  {
237  EXPECT_EQ(rev_indices[i], cfh_cwit->idx()) << "Index wrong in ConstFaceHalfedgeCWIter";
238  }
239  EXPECT_FALSE(cfh_cwit.is_valid()) << "Iterator invalid in ConstFaceHalfedgeCWIter at end";
240  EXPECT_TRUE( cfh_cwit == cfh_cwend ) << "End iterator for ConstFaceHalfedgeCWIter not matching";
241 
242  /*
243  * conversion properties:
244  * a) cw_begin == CWIter(ccw_begin())
245  * b) cw_iter->idx() == CCWIter(cw_iter)->idx() for valid iterators
246  * c) --cw_iter == CWIter(++ccwIter) for valid iterators
247  * d) cw_end == CWIter(ccw_end()) => --cw_end != CWIter(++ccw_end()) *
248  */
249  Mesh::FaceHalfedgeCWIter fh_cwIter = mesh_.fh_cwbegin(mesh_.face_handle(1));
250  // a)
251  EXPECT_TRUE( fh_cwIter == Mesh::FaceHalfedgeCWIter(mesh_.fh_ccwbegin(mesh_.face_handle(1))) ) << "ccw to cw conversion failed";
252  EXPECT_TRUE( Mesh::FaceHalfedgeCCWIter(fh_cwIter) == mesh_.fh_ccwbegin(mesh_.face_handle(1)) ) << "cw to ccw conversion failed";
253  // b)
254  EXPECT_EQ( fh_cwIter->idx(), Mesh::FaceHalfedgeCCWIter(fh_cwIter)->idx()) << "iterators doesnt point on the same element";
255  // c)
256  ++fh_cwIter;
257  fh_ccwend = mesh_.fh_ccwend(mesh_.face_handle(1));
258  --fh_ccwend;
259  EXPECT_EQ(fh_cwIter->idx(),fh_ccwend->idx()) << "iteratoes are not equal after inc/dec";
260  // additional conversion check
261  fh_ccwend = Mesh::FaceHalfedgeCCWIter(fh_cwIter);
262  EXPECT_EQ(fh_cwIter->idx(),fh_ccwend->idx())<< "iterators doesnt point on the same element";
263  // d)
264  fh_cwIter = Mesh::FaceHalfedgeCWIter(mesh_.fh_ccwend(mesh_.face_handle(1)));
265  EXPECT_FALSE(fh_cwIter.is_valid()) << "end iterator is not invalid";
266  EXPECT_TRUE(Mesh::FaceHalfedgeCCWIter(mesh_.fh_cwend(mesh_.face_handle(1))) == mesh_.fh_ccwend(mesh_.face_handle(1))) << "end iterators are not equal";
267 
268 
269 }
270 
271 
272 /*
273  * Test if the end iterator stays invalid after one lap
274  */
275 //TEST_F(OpenMeshTrimeshCirculatorFaceHalfEdge, FaceHalfedgeIterCheckInvalidationAtEnds) {
276 //
277 // mesh_.clear();
278 //
279 // // Add some vertices
280 // Mesh::VertexHandle vhandle[5];
281 //
282 // vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
283 // vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
284 // vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
285 // vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
286 // vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
287 //
288 // // Add two faces
289 // std::vector<Mesh::VertexHandle> face_vhandles;
290 //
291 // face_vhandles.push_back(vhandle[0]);
292 // face_vhandles.push_back(vhandle[1]);
293 // face_vhandles.push_back(vhandle[2]);
294 // Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles);
295 //
296 // face_vhandles.clear();
297 //
298 // face_vhandles.push_back(vhandle[1]);
299 // face_vhandles.push_back(vhandle[3]);
300 // face_vhandles.push_back(vhandle[4]);
301 // mesh_.add_face(face_vhandles);
302 //
303 // face_vhandles.clear();
304 //
305 // face_vhandles.push_back(vhandle[0]);
306 // face_vhandles.push_back(vhandle[3]);
307 // face_vhandles.push_back(vhandle[1]);
308 // mesh_.add_face(face_vhandles);
309 //
310 // face_vhandles.clear();
311 //
312 // face_vhandles.push_back(vhandle[2]);
313 // face_vhandles.push_back(vhandle[1]);
314 // face_vhandles.push_back(vhandle[4]);
315 // mesh_.add_face(face_vhandles);
316 //
317 // /* Test setup:
318 // 0 ==== 2
319 // |\ 0 /|
320 // | \ / |
321 // |2 1 3|
322 // | / \ |
323 // |/ 1 \|
324 // 3 ==== 4 */
325 //
326 //
327 // // Check if the end iterator stays invalid after end
328 // Mesh::FaceHalfedgeIter endIter = mesh_.fh_end(fh0);
329 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
330 // ++endIter ;
331 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid after increment";
332 //
333 // // Check if the end iterators becomes valid after decrement
334 // endIter = mesh_.fh_end(fh0);
335 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
336 // --endIter;
337 // EXPECT_TRUE(endIter.is_valid()) << "EndIter is invalid after decrement";
338 // EXPECT_EQ(2,endIter->idx()) << "EndIter points on the wrong element";
339 //
340 //
341 // // Check if the start iterator decrement is invalid
342 // Mesh::FaceHalfedgeIter startIter = mesh_.fh_begin(fh0);
343 // EXPECT_TRUE(startIter.is_valid()) << "StartIter is not valid";
344 // --startIter;
345 // EXPECT_FALSE(startIter.is_valid()) << "StartIter decrement is not invalid";
346 //
347 // // Check if the start iterator becomes valid
348 // ++startIter;
349 // EXPECT_TRUE(startIter.is_valid()) << "StartIter is invalid after re-incrementing";
350 // EXPECT_EQ(startIter->idx(), mesh_.fh_begin(fh0)->idx()) << "StartIter points on the wrong element";
351 //
352 //}
353 
354 }
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