Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_trimesh_circulator_face_edge.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 OpenMeshTrimeshCirculatorFaceEdge : 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 /*
38 * Small FaceEdgeIterator Test
39 */
40 TEST_F(OpenMeshTrimeshCirculatorFaceEdge, FaceEdgeIterWithoutHolesIncrement) {
41
42 mesh_.clear();
43
44 // Add some vertices
45 Mesh::VertexHandle vhandle[6];
46
47 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
48 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
49 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
50 vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
51 vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
52 vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
53
54 // Add three 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[2]);
65 face_vhandles.push_back(vhandle[1]);
66 face_vhandles.push_back(vhandle[3]);
67 mesh_.add_face(face_vhandles);
68
69 face_vhandles.clear();
70
71 face_vhandles.push_back(vhandle[2]);
72 face_vhandles.push_back(vhandle[3]);
73 face_vhandles.push_back(vhandle[4]);
74 mesh_.add_face(face_vhandles);
75
76 face_vhandles.clear();
77
78 face_vhandles.push_back(vhandle[1]);
79 face_vhandles.push_back(vhandle[5]);
80 face_vhandles.push_back(vhandle[3]);
81 mesh_.add_face(face_vhandles);
82
83 /* Test setup:
84 *
85 * 0 ------ 2 ------ 4
86 * \ / \ /
87 * \ 0 / \ 2 /
88 * \ / 1 \ /
89 * 1 ------- 3
90 * \ /
91 * \ 3 /
92 * \ /
93 * \ /
94 * 5
95 */
96
97
98 Mesh::FaceEdgeIter fe_it = mesh_.fe_begin(mesh_.face_handle(1));
99 Mesh::FaceEdgeIter fe_end = mesh_.fe_end(mesh_.face_handle(1));
100
101 EXPECT_EQ(4, fe_it->idx() ) << "Index wrong in FaceEdgeIter at initialization";
102 EXPECT_TRUE(fe_it.is_valid()) << "Iterator invalid in FaceEdgeIter at initialization";
103 ++fe_it;
104 EXPECT_EQ(1, fe_it->idx() ) << "Index wrong in FaceEdgeIter at step 1";
105 EXPECT_TRUE(fe_it.is_valid()) << "Iterator invalid in FaceEdgeIter at step 1";
106 ++fe_it;
107 EXPECT_EQ(3, fe_it->idx() ) << "Index wrong in FaceEdgeIter at step 2";
108 EXPECT_TRUE(fe_it.is_valid()) << "Iterator invalid in FaceEdgeIter at step 2";
109 ++fe_it;
110 EXPECT_EQ(4, fe_it->idx() ) << "Index wrong in FaceEdgeIter at end";
111 EXPECT_FALSE(fe_it.is_valid()) << "Iterator invalid in FaceEdgeIter at end";
112 EXPECT_TRUE( fe_it == fe_end ) << "End iterator for FaceEdgeIter not matching";
113
114 Mesh::ConstFaceEdgeIter cfe_it = mesh_.cfe_begin(mesh_.face_handle(1));
115 Mesh::ConstFaceEdgeIter cfe_end = mesh_.cfe_end(mesh_.face_handle(1));
116
117 EXPECT_EQ(4, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at initialization";
118 EXPECT_TRUE(cfe_it.is_valid()) << "Iterator invalid in ConstFaceEdgeIter at initialization";
119 ++cfe_it;
120 EXPECT_EQ(1, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at step 1";
121 EXPECT_TRUE(cfe_it.is_valid()) << "Iterator invalid in ConstFaceEdgeIter at step 1";
122 ++cfe_it;
123 EXPECT_EQ(3, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at step 2";
124 EXPECT_TRUE(cfe_it.is_valid()) << "Iterator invalid in ConstFaceEdgeIter at step 2";
125 ++cfe_it;
126 EXPECT_EQ(4, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at end";
127 EXPECT_FALSE(cfe_it.is_valid()) << "Iterator invalid in ConstFaceEdgeIter at end";
128 EXPECT_TRUE( cfe_it == cfe_end ) << "End iterator for ConstFaceEdgeIter not matching";
129
130 }
131 }
132
133 /*
134 * test CW and CCW iterators
135 */
136 TEST_F(OpenMeshTrimeshCirculatorFaceEdge, CWAndCCWTest) {
137
138 mesh_.clear();
139
140 // Add some vertices
141 Mesh::VertexHandle vhandle[6];
142
143 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
144 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
145 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
146 vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
147 vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
148 vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
149
150 // Add three faces
151 std::vector<Mesh::VertexHandle> face_vhandles;
152
153 face_vhandles.push_back(vhandle[0]);
154 face_vhandles.push_back(vhandle[1]);
155 face_vhandles.push_back(vhandle[2]);
156 mesh_.add_face(face_vhandles);
157
158 face_vhandles.clear();
159
160 face_vhandles.push_back(vhandle[2]);
161 face_vhandles.push_back(vhandle[1]);
162 face_vhandles.push_back(vhandle[3]);
163 mesh_.add_face(face_vhandles);
164
165 face_vhandles.clear();
166
167 face_vhandles.push_back(vhandle[2]);
168 face_vhandles.push_back(vhandle[3]);
169 face_vhandles.push_back(vhandle[4]);
170 mesh_.add_face(face_vhandles);
171
172 face_vhandles.clear();
173
174 face_vhandles.push_back(vhandle[1]);
175 face_vhandles.push_back(vhandle[5]);
176 face_vhandles.push_back(vhandle[3]);
177 mesh_.add_face(face_vhandles);
178
179 /* Test setup:
180 *
181 * 0 ------ 2 ------ 4
182 * \ / \ /
183 * \ 0 / \ 2 /
184 * \ / 1 \ /
185 * 1 ------- 3
186 * \ /
187 * \ 3 /
188 * \ /
189 * \ /
190 * 5
191 */
192
193
194 int indices[4] = {4, 1, 3, 4};
195 int rev_indices[4];
196 std::reverse_copy(indices,indices+4,rev_indices);
197
198 //CCW
199 Mesh::FaceEdgeCCWIter fe_ccwit = mesh_.fe_ccwbegin(mesh_.face_handle(1));
200 Mesh::FaceEdgeCCWIter fe_ccwend = mesh_.fe_ccwend(mesh_.face_handle(1));
201 size_t i = 0;
202 for (;fe_ccwit != fe_ccwend; ++fe_ccwit, ++i)
203 {
204 EXPECT_EQ(indices[i], fe_ccwit->idx()) << "Index wrong in FaceEdgeCCWIter";
205 }
206
207 EXPECT_FALSE(fe_ccwit.is_valid()) << "Iterator invalid in FaceEdgeCCWIter at end";
208 EXPECT_TRUE( fe_ccwit == fe_ccwend ) << "End iterator for FaceEdgeCCWIter not matching";
209
210 //constant CCW
211 Mesh::ConstFaceEdgeCCWIter cfe_ccwit = mesh_.cfe_ccwbegin(mesh_.face_handle(1));
212 Mesh::ConstFaceEdgeCCWIter cfe_ccwend = mesh_.cfe_ccwend(mesh_.face_handle(1));
213 i = 0;
214 for (;cfe_ccwit != cfe_ccwend; ++cfe_ccwit, ++i)
215 {
216 EXPECT_EQ(indices[i], cfe_ccwit->idx()) << "Index wrong in ConstFaceEdgeCCWIter";
217 }
218
219 EXPECT_FALSE(cfe_ccwit.is_valid()) << "Iterator invalid in ConstFaceEdgeCCWIter at end";
220 EXPECT_TRUE( cfe_ccwit == cfe_ccwend ) << "End iterator for ConstFaceEdgeCCWIter not matching";
221
222 //CW
223 Mesh::FaceEdgeCWIter fe_cwit = mesh_.fe_cwbegin(mesh_.face_handle(1));
224 Mesh::FaceEdgeCWIter fe_cwend = mesh_.fe_cwend(mesh_.face_handle(1));
225 i = 0;
226 for (;fe_cwit != fe_cwend; ++fe_cwit, ++i)
227 {
228 EXPECT_EQ(rev_indices[i], fe_cwit->idx()) << "Index wrong in FaceEdgeCWIter";
229 }
230 EXPECT_FALSE(fe_cwit.is_valid()) << "Iterator invalid in FaceEdgeCWIter at end";
231 EXPECT_TRUE( fe_cwit == fe_cwend ) << "End iterator for FaceEdgeCWIter not matching";
232
233 //constant CW
234 Mesh::ConstFaceEdgeCWIter cfe_cwit = mesh_.cfe_cwbegin(mesh_.face_handle(1));
235 Mesh::ConstFaceEdgeCWIter cfe_cwend = mesh_.cfe_cwend(mesh_.face_handle(1));
236 i = 0;
237 for (;cfe_cwit != cfe_cwend; ++cfe_cwit, ++i)
238 {
239 EXPECT_EQ(rev_indices[i], cfe_cwit->idx()) << "Index wrong in ConstFaceEdgeCWIter";
240 }
241 EXPECT_FALSE(cfe_cwit.is_valid()) << "Iterator invalid in ConstFaceEdgeCWIter at end";
242 EXPECT_TRUE( cfe_cwit == cfe_cwend ) << "End iterator for ConstFaceEdgeCWIter not matching";
243
244 /*
245 * conversion properties:
246 * a) cw_begin == CWIter(ccw_begin())
247 * b) cw_iter->idx() == CCWIter(cw_iter)->idx() for valid iterators
248 * c) --cw_iter == CWIter(++ccwIter) for valid iterators
249 * d) cw_end == CWIter(ccw_end()) => --cw_end != CWIter(++ccw_end()) *
250 */
251 Mesh::FaceEdgeCWIter fe_cwIter = mesh_.fe_cwbegin(mesh_.face_handle(1));
252 // a)
253 EXPECT_TRUE( fe_cwIter == Mesh::FaceEdgeCWIter(mesh_.fe_ccwbegin(mesh_.face_handle(1))) ) << "ccw to cw conversion failed";
254 EXPECT_TRUE( Mesh::FaceEdgeCCWIter(fe_cwIter) == mesh_.fe_ccwbegin(mesh_.face_handle(1)) ) << "cw to ccw conversion failed";
255 // b)
256 EXPECT_EQ( fe_cwIter->idx(), Mesh::FaceEdgeCCWIter(fe_cwIter)->idx()) << "iterators doesnt point on the same element";
257 // c)
258 ++fe_cwIter;
259 fe_ccwend = mesh_.fe_ccwend(mesh_.face_handle(1));
260 --fe_ccwend;
261 EXPECT_EQ(fe_cwIter->idx(),fe_ccwend->idx()) << "iteratoes are not equal after inc/dec";
262 // additional conversion check
263 fe_ccwend = Mesh::FaceEdgeCCWIter(fe_cwIter);
264 EXPECT_EQ(fe_cwIter->idx(),fe_ccwend->idx())<< "iterators doesnt point on the same element";
265 // d)
266 fe_cwIter = Mesh::FaceEdgeCWIter(mesh_.fe_ccwend(mesh_.face_handle(1)));
267 EXPECT_FALSE(fe_cwIter.is_valid()) << "end iterator is not invalid";
268 EXPECT_TRUE(Mesh::FaceEdgeCCWIter(mesh_.fe_cwend(mesh_.face_handle(1))) == mesh_.fe_ccwend(mesh_.face_handle(1))) << "end iterators are not equal";
269
270 }
271
272
273 /*
274 * Test if the end iterator stays invalid after one lap
275 */
276 //TEST_F(OpenMeshTrimeshCirculatorFaceEdge, FaceEdgeIterCheckInvalidationAtEnds) {
277 //
278 // mesh_.clear();
279 //
280 // // Add some vertices
281 // Mesh::VertexHandle vhandle[5];
282 //
283 // vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
284 // vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
285 // vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
286 // vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
287 // vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
288 //
289 // // Add two faces
290 // std::vector<Mesh::VertexHandle> face_vhandles;
291 //
292 // face_vhandles.push_back(vhandle[0]);
293 // face_vhandles.push_back(vhandle[1]);
294 // face_vhandles.push_back(vhandle[2]);
295 // Mesh::FaceHandle fh0 = mesh_.add_face(face_vhandles);
296 //
297 // face_vhandles.clear();
298 //
299 // face_vhandles.push_back(vhandle[1]);
300 // face_vhandles.push_back(vhandle[3]);
301 // face_vhandles.push_back(vhandle[4]);
302 // mesh_.add_face(face_vhandles);
303 //
304 // face_vhandles.clear();
305 //
306 // face_vhandles.push_back(vhandle[0]);
307 // face_vhandles.push_back(vhandle[3]);
308 // face_vhandles.push_back(vhandle[1]);
309 // mesh_.add_face(face_vhandles);
310 //
311 // face_vhandles.clear();
312 //
313 // face_vhandles.push_back(vhandle[2]);
314 // face_vhandles.push_back(vhandle[1]);
315 // face_vhandles.push_back(vhandle[4]);
316 // mesh_.add_face(face_vhandles);
317 //
318 // /* Test setup:
319 // 0 ==== 2
320 // |\ 0 /|
321 // | \ / |
322 // |2 1 3|
323 // | / \ |
324 // |/ 1 \|
325 // 3 ==== 4 */
326 //
327 //
328 // // Check if the end iterator stays invalid after end
329 // Mesh::FaceEdgeIter endIter = mesh_.fe_end(fh0);
330 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
331 // ++endIter ;
332 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid after increment";
333 //
334 // // Check if the end iterators becomes valid after decrement
335 // endIter = mesh_.fe_end(fh0);
336 // EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
337 // --endIter;
338 // EXPECT_TRUE(endIter.is_valid()) << "EndIter is invalid after decrement";
339 // EXPECT_EQ(1,endIter->idx()) << "EndIter points on the wrong element";
340 //
341 //
342 // // Check if the start iterator decrement is invalid
343 // Mesh::FaceEdgeIter startIter = mesh_.fe_begin(fh0);
344 // EXPECT_TRUE(startIter.is_valid()) << "StartIter is not valid";
345 // --startIter;
346 // EXPECT_FALSE(startIter.is_valid()) << "StartIter decrement is not invalid";
347 //
348 // // Check if the start iterator becomes valid
349 // ++startIter;
350 // EXPECT_TRUE(startIter.is_valid()) << "StartIter is invalid after re-incrementing";
351 // EXPECT_EQ(startIter->idx(), mesh_.fe_begin(fh0)->idx()) << "StartIter points on the wrong element";
352 //
353 //}
354
355
356 /*
357 * Small FaceEdgeIterator Test
358 */
359 /*
360 TEST_F(OpenMeshTrimeshCirculatorFaceEdge, FaceEdgeIterWithoutHolesDecrement) {
361
362 mesh_.clear();
363
364 // Add some vertices
365 Mesh::VertexHandle vhandle[6];
366
367 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
368 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
369 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
370 vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
371 vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
372 vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
373
374 // Add three faces
375 std::vector<Mesh::VertexHandle> face_vhandles;
376
377 face_vhandles.push_back(vhandle[0]);
378 face_vhandles.push_back(vhandle[1]);
379 face_vhandles.push_back(vhandle[2]);
380 mesh_.add_face(face_vhandles);
381
382 face_vhandles.clear();
383
384 face_vhandles.push_back(vhandle[2]);
385 face_vhandles.push_back(vhandle[1]);
386 face_vhandles.push_back(vhandle[3]);
387 mesh_.add_face(face_vhandles);
388
389 face_vhandles.clear();
390
391 face_vhandles.push_back(vhandle[2]);
392 face_vhandles.push_back(vhandle[3]);
393 face_vhandles.push_back(vhandle[4]);
394 mesh_.add_face(face_vhandles);
395
396 face_vhandles.clear();
397
398 face_vhandles.push_back(vhandle[1]);
399 face_vhandles.push_back(vhandle[5]);
400 face_vhandles.push_back(vhandle[3]);
401 mesh_.add_face(face_vhandles);
402 */
403 /* Test setup:
404 *
405 * 0 ------ 2 ------ 4
406 * \ / \ /
407 * \ 0 / \ 2 /
408 * \ / 1 \ /
409 * 1 ------- 3
410 * \ /
411 * \ 3 /
412 * \ /
413 * \ /
414 * 5
415 */
416
417 /*
418 Mesh::FaceEdgeIter fe_it = mesh_.fe_begin(mesh_.face_handle(1));
419 Mesh::FaceEdgeIter fe_end = mesh_.fe_end(mesh_.face_handle(1));
420
421 EXPECT_EQ(4, fe_it->idx() ) << "Index wrong in FaceEdgeIter at initialization";
422 EXPECT_TRUE(fe_it) << "Iterator invalid in FaceEdgeIter at initialization";
423 --fe_it;
424 EXPECT_EQ(1, fe_it->idx() ) << "Index wrong in FaceEdgeIter at step 1";
425 EXPECT_TRUE(fe_it) << "Iterator invalid in FaceEdgeIter at step 1";
426 --fe_it;
427 EXPECT_EQ(3, fe_it->idx() ) << "Index wrong in FaceEdgeIter at step 2";
428 EXPECT_TRUE(fe_it) << "Iterator invalid in FaceEdgeIter at step 2";
429 --fe_it;
430 EXPECT_EQ(4, fe_it->idx() ) << "Index wrong in FaceEdgeIter at end";
431 EXPECT_FALSE(fe_it) << "Iterator invalid in FaceEdgeIter at end";
432 EXPECT_TRUE( fe_it == fe_end ) << "End iterator for FaceEdgeIter not matching";
433
434 Mesh::ConstFaceEdgeIter cfe_it = mesh_.cfe_begin(mesh_.face_handle(1));
435 Mesh::ConstFaceEdgeIter cfe_end = mesh_.cfe_end(mesh_.face_handle(1));
436
437 EXPECT_EQ(4, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at initialization";
438 EXPECT_TRUE(cfe_it) << "Iterator invalid in ConstFaceEdgeIter at initialization";
439 --cfe_it;
440 EXPECT_EQ(1, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at step 1";
441 EXPECT_TRUE(cfe_it) << "Iterator invalid in ConstFaceEdgeIter at step 1";
442 --cfe_it;
443 EXPECT_EQ(3, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at step 2";
444 EXPECT_TRUE(cfe_it) << "Iterator invalid in ConstFaceEdgeIter at step 2";
445 --cfe_it;
446 EXPECT_EQ(4, cfe_it->idx() ) << "Index wrong in ConstFaceEdgeIter at end";
447 EXPECT_FALSE(cfe_it) << "Iterator invalid in ConstFaceEdgeIter at end";
448 EXPECT_TRUE( cfe_it == cfe_end ) << "End iterator for ConstFaceEdgeIter not matching";
449
450 }
451 */
OpenMesh::PolyMeshT::ConstFaceEdgeIter
Kernel::ConstFaceEdgeIter ConstFaceEdgeIter
Circulator.
Definition: PolyMeshT.hh:182
OpenMesh::PolyMeshT::FaceEdgeIter
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Definition: PolyMeshT.hh:172
OpenMeshBase
Definition: unittests_common.hh:21
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
OpenMesh::PolyMeshT::add_vertex
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139