OpenMesh

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unittests_trimesh_circulator_vertex_ihalfedge.hh
1 #pragma once
2
3 #include <gtest/gtest.h>
4 #include <Unittests/unittests_common.hh>
5
6 #include <iostream>
7
8 class OpenMeshTrimeshCirculatorVertexIHalfEdge : 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 * Small VertexFaceIterator Test without holes in it
36 */
37 TEST_F(OpenMeshTrimeshCirculatorVertexIHalfEdge, VertexIncomingHalfedgeWithoutHolesIncrement) {
38
39 mesh_.clear();
40
41 // Add some vertices
42 Mesh::VertexHandle vhandle[5];
43
44 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
45 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
46 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
47 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
48 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
49
50 // Add two faces
51 std::vector<Mesh::VertexHandle> face_vhandles;
52
53 face_vhandles.push_back(vhandle[0]);
54 face_vhandles.push_back(vhandle[1]);
55 face_vhandles.push_back(vhandle[2]);
56 mesh_.add_face(face_vhandles);
57
58 face_vhandles.clear();
59
60 face_vhandles.push_back(vhandle[1]);
61 face_vhandles.push_back(vhandle[3]);
62 face_vhandles.push_back(vhandle[4]);
63 mesh_.add_face(face_vhandles);
64
65 face_vhandles.clear();
66
67 face_vhandles.push_back(vhandle[0]);
68 face_vhandles.push_back(vhandle[3]);
69 face_vhandles.push_back(vhandle[1]);
70 mesh_.add_face(face_vhandles);
71
72 face_vhandles.clear();
73
74 face_vhandles.push_back(vhandle[2]);
75 face_vhandles.push_back(vhandle[1]);
76 face_vhandles.push_back(vhandle[4]);
77 mesh_.add_face(face_vhandles);
78
79 /* Test setup:
80 0 ==== 2
81 |\ 0 /|
82 | \ / |
83 |2 1 3|
84 | / \ |
85 |/ 1 \|
86 3 ==== 4 */
87 // Starting halfedge is 1->4
88
89 // Iterate around vertex 1 at the middle (with holes in between)
90 Mesh::VertexIHalfedgeIter vih_it = mesh_.vih_begin(vhandle[1]);
91 Mesh::VertexIHalfedgeIter vih_end = mesh_.vih_end(vhandle[1]);
92
93 EXPECT_EQ(10, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter begin at initialization";
94 EXPECT_EQ(10, vih_end.handle().idx() ) << "Index wrong in VertexIHalfedgeIter end at initialization";
95 EXPECT_EQ(1, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter begin at initialization";
96 EXPECT_TRUE(vih_it) << "Iterator invalid in VertexIHalfedgeIter at initialization";
97
98 ++vih_it ;
99
100 EXPECT_EQ(7, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter step 1";
101 EXPECT_EQ(2, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter step 1";
102 EXPECT_TRUE(vih_it) << "Iterator invalid in VertexIHalfedgeIter at step 1";
103
104 ++vih_it ;
105
106 EXPECT_EQ(0, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter step 2";
107 EXPECT_EQ(0, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter step 2";
108 EXPECT_TRUE(vih_it) << "Iterator invalid in VertexIHalfedgeIter at step 2";
109
110 ++vih_it ;
111
112 EXPECT_EQ(3, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter step 3";
113 EXPECT_EQ(3, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter step 3";
114 EXPECT_TRUE(vih_it) << "Iterator invalid in VertexIHalfedgeIter at step 3";
115
116 ++vih_it ;
117
118 EXPECT_EQ(10, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter step 4";
119 EXPECT_EQ(1, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter step 4";
120 EXPECT_FALSE(vih_it) << "Iterator still valid in VertexIHalfedgeIter at step 4";
121 EXPECT_TRUE( vih_it == vih_end ) << "Miss matched end iterator";
122
123
124 // Iterate around vertex 1 at the middle (with holes in between)
125 Mesh::ConstVertexIHalfedgeIter cvih_it = mesh_.cvih_begin(vhandle[1]);
126 Mesh::ConstVertexIHalfedgeIter cvoh_end = mesh_.cvih_end(vhandle[1]);
127
128 EXPECT_EQ(10, cvih_it.handle().idx() ) << "Index wrong in ConstVertexIHalfedgeIter begin at initialization";
129 EXPECT_EQ(10, cvoh_end.handle().idx() ) << "Index wrong in ConstVertexIHalfedgeIter end at initialization";
130 EXPECT_EQ(1, mesh_.face_handle(cvih_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexIHalfedgeIter begin at initialization";
131 EXPECT_TRUE(cvih_it) << "Iterator invalid in ConstVertexIHalfedgeIter at initialization";
132
133 ++cvih_it ;
134
135 EXPECT_EQ(7, cvih_it.handle().idx() ) << "Index wrong in ConstVertexIHalfedgeIter step 1";
136 EXPECT_EQ(2, mesh_.face_handle(cvih_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexIHalfedgeIter step 1";
137 EXPECT_TRUE(cvih_it) << "Iterator invalid in ConstVertexIHalfedgeIter at step 1";
138
139 ++cvih_it ;
140
141 EXPECT_EQ(0, cvih_it.handle().idx() ) << "Index wrong in ConstVertexIHalfedgeIter step 2";
142 EXPECT_EQ(0, mesh_.face_handle(cvih_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexIHalfedgeIter step 2";
143 EXPECT_TRUE(cvih_it) << "Iterator invalid in ConstVertexIHalfedgeIter at step 2";
144
145 ++cvih_it ;
146
147 EXPECT_EQ(3, cvih_it.handle().idx() ) << "Index wrong in ConstVertexIHalfedgeIter step 3";
148 EXPECT_EQ(3, mesh_.face_handle(cvih_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexIHalfedgeIter step 3";
149 EXPECT_TRUE(cvih_it) << "Iterator invalid in ConstVertexIHalfedgeIter at step 3";
150
151 ++cvih_it ;
152
153 EXPECT_EQ(10, cvih_it.handle().idx() ) << "Index wrong in ConstVertexIHalfedgeIter step 4";
154 EXPECT_EQ(1, mesh_.face_handle(cvih_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexIHalfedgeIter step 4";
155 EXPECT_FALSE(cvih_it) << "Iterator still valid in ConstVertexIHalfedgeIter at step 4";
156 EXPECT_TRUE( cvih_it == cvoh_end ) << "Miss matched end iterator";
157
158 }
159
160 /*
161 * Small VertexFaceOutgoingHalfedgeIterator Test
162 */
163 TEST_F(OpenMeshTrimeshCirculatorVertexIHalfEdge, VertexOIncomingHalfedgeBoundaryIncrement) {
164
165 mesh_.clear();
166
167 // Add some vertices
168 Mesh::VertexHandle vhandle[5];
169
170 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
171 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
172 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
173 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
174 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
175
176 // Add two faces
177 std::vector<Mesh::VertexHandle> face_vhandles;
178
179 face_vhandles.push_back(vhandle[0]);
180 face_vhandles.push_back(vhandle[1]);
181 face_vhandles.push_back(vhandle[2]);
182 mesh_.add_face(face_vhandles);
183
184 face_vhandles.clear();
185
186 face_vhandles.push_back(vhandle[1]);
187 face_vhandles.push_back(vhandle[3]);
188 face_vhandles.push_back(vhandle[4]);
189 mesh_.add_face(face_vhandles);
190
191 face_vhandles.clear();
192
193 face_vhandles.push_back(vhandle[0]);
194 face_vhandles.push_back(vhandle[3]);
195 face_vhandles.push_back(vhandle[1]);
196 mesh_.add_face(face_vhandles);
197
198 face_vhandles.clear();
199
200 face_vhandles.push_back(vhandle[2]);
201 face_vhandles.push_back(vhandle[1]);
202 face_vhandles.push_back(vhandle[4]);
203 mesh_.add_face(face_vhandles);
204
205 /* Test setup:
206 0 ==== 2
207 |\ 0 /|
208 | \ / |
209 |2 1 3|
210 | / \ |
211 |/ 1 \|
212 3 ==== 4 */
213 // Starting halfedge is 1->4
214
215
216 // Iterate around vertex 1 at the middle (with holes in between)
217 Mesh::VertexIHalfedgeIter vih_it = mesh_.vih_begin(vhandle[2]);
218 Mesh::VertexIHalfedgeIter vih_end = mesh_.vih_end(vhandle[2]);
219
220 EXPECT_EQ(14, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter begin at initialization";
221 EXPECT_EQ(14, vih_end.handle().idx() ) << "Index wrong in VertexIHalfedgeIter end at initialization";
222 EXPECT_EQ(3, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter begin at initialization";
223 EXPECT_TRUE(vih_it) << "Iterator invalid in VertexIHalfedgeIter at initialization";
224
225 ++vih_it ;
226
227 EXPECT_EQ(2, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter step 1";
228 EXPECT_EQ(0, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter step 1";
229 EXPECT_TRUE(vih_it) << "Iterator invalid in VertexIHalfedgeIter at step 1";
230
231 ++vih_it ;
232
233 EXPECT_EQ(5, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter step 2";
234 EXPECT_EQ(-1, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter step 2";
235 EXPECT_TRUE(vih_it) << "Iterator invalid in VertexIHalfedgeIter at step 2";
236
237 ++vih_it ;
238
239 EXPECT_EQ(14, vih_it.handle().idx() ) << "Index wrong in VertexIHalfedgeIter step 3";
240 EXPECT_EQ(3, mesh_.face_handle(vih_it.handle()).idx() ) << "Corresponding face Index wrong in VertexIHalfedgeIter step 3";
241 EXPECT_FALSE(vih_it) << "Iterator still valid in VertexIHalfedgeIter at step 3";
242 EXPECT_TRUE( vih_it == vih_end ) << "Miss matched end iterator";
243
244
245 }
246
247
248 /*
249 * Small Test to check dereferencing the iterator
250 * No real result
251 */
252 TEST_F(OpenMeshTrimeshCirculatorVertexIHalfEdge, VertexIncomingHalfedgeDereferenceIncrement) {
253
254 mesh_.clear();
255
256 // Add some vertices
257 Mesh::VertexHandle vhandle[5];
258
259 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
260 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
261 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
262 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
263 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
264
265 std::vector<Mesh::VertexHandle> face_vhandles;
266
267 face_vhandles.push_back(vhandle[0]);
268 face_vhandles.push_back(vhandle[1]);
269 face_vhandles.push_back(vhandle[2]);
270 mesh_.add_face(face_vhandles);
271
272 face_vhandles.clear();
273
274 face_vhandles.push_back(vhandle[1]);
275 face_vhandles.push_back(vhandle[3]);
276 face_vhandles.push_back(vhandle[4]);
277 mesh_.add_face(face_vhandles);
278
279 face_vhandles.clear();
280
281 face_vhandles.push_back(vhandle[0]);
282 face_vhandles.push_back(vhandle[3]);
283 face_vhandles.push_back(vhandle[1]);
284 mesh_.add_face(face_vhandles);
285
286 face_vhandles.clear();
287
288 face_vhandles.push_back(vhandle[2]);
289 face_vhandles.push_back(vhandle[1]);
290 face_vhandles.push_back(vhandle[4]);
291 mesh_.add_face(face_vhandles);
292
293 /* Test setup:
294 0 ==== 2
295 |\ 0 /|
296 | \ / |
297 |2 1 3|
298 | / \ |
299 |/ 1 \|
300 3 ==== 4 */
301
302 // Iterate around vertex 1 at the middle (with holes in between)
303 Mesh::VertexIHalfedgeIter vih_it = mesh_.vih_iter(vhandle[1]);
304
305 // TODO: If called without handle, it won't build
306 Mesh::EdgeHandle eh = mesh_.edge_handle(vih_it.handle());
307 Mesh::HalfedgeHandle heh = mesh_.halfedge_handle(vih_it);
308 Mesh::VertexHandle vh2 = mesh_.to_vertex_handle(vih_it);
309
310 EXPECT_EQ(eh.idx() , 5 ) << "Wrong edge handle after dereferencing";
311 EXPECT_EQ(heh.idx() , 1 ) << "Wrong half edge handle after dereferencing";
312 EXPECT_EQ(vh2.idx() , 1 ) << "Wrong vertex handle after dereferencing";
313
314 }