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_ohalfedge.hh
1 #pragma once
2
3 #include <gtest/gtest.h>
4 #include <Unittests/unittests_common.hh>
5
6 #include <iostream>
7
8 class OpenMeshTrimeshCirculatorVertexOHalfEdge : 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 VertexFaceOutgoingHalfedgeIterator Test without holes in it
36 */
37 TEST_F(OpenMeshTrimeshCirculatorVertexOHalfEdge, VertexOutgoingHalfedgeWithoutHolesIncrement) {
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
90 // Iterate around vertex 1 at the middle (with holes in between)
91 Mesh::VertexOHalfedgeIter voh_it = mesh_.voh_begin(vhandle[1]);
92 Mesh::VertexOHalfedgeIter voh_end = mesh_.voh_end(vhandle[1]);
93
94 EXPECT_EQ(11, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter begin at initialization";
95 EXPECT_EQ(11, voh_end.handle().idx() ) << "Index wrong in VertexOHalfedgeIter end at initialization";
96 EXPECT_EQ(3, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter begin at initialization";
97 EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at initialization";
98
99 ++voh_it ;
100
101 EXPECT_EQ(6, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 1";
102 EXPECT_EQ(1, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 1";
103 EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 1";
104
105 ++voh_it ;
106
107 EXPECT_EQ(1, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 2";
108 EXPECT_EQ(2, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 2";
109 EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 2";
110
111 ++voh_it ;
112
113 EXPECT_EQ(2, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 3";
114 EXPECT_EQ(0, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 3";
115 EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 3";
116
117 ++voh_it ;
118
119 EXPECT_EQ(11, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 4";
120 EXPECT_EQ(3, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 4";
121 EXPECT_FALSE(voh_it) << "Iterator still valid in VertexOHalfedgeIter at step 4";
122 EXPECT_TRUE( voh_it == voh_end ) << "Miss matched end iterator";
123
124 // Iterate around vertex 1 at the middle (with holes in between)
125 Mesh::ConstVertexOHalfedgeIter cvoh_it = mesh_.cvoh_begin(vhandle[1]);
126 Mesh::ConstVertexOHalfedgeIter cvoh_end = mesh_.cvoh_end(vhandle[1]);
127
128 EXPECT_EQ(11, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter begin at initialization";
129 EXPECT_EQ(11, cvoh_end.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter end at initialization";
130 EXPECT_EQ(3, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter begin at initialization";
131 EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at initialization";
132
133 ++cvoh_it ;
134
135 EXPECT_EQ(6, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 1";
136 EXPECT_EQ(1, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 1";
137 EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at step 1";
138
139 ++cvoh_it ;
140
141 EXPECT_EQ(1, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 2";
142 EXPECT_EQ(2, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 2";
143 EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at step 2";
144
145 ++cvoh_it ;
146
147 EXPECT_EQ(2, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 3";
148 EXPECT_EQ(0, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 3";
149 EXPECT_TRUE(cvoh_it) << "Iterator invalid in ConstVertexOHalfedgeIter at step 3";
150
151 ++cvoh_it ;
152
153 EXPECT_EQ(11, cvoh_it.handle().idx() ) << "Index wrong in ConstVertexOHalfedgeIter step 4";
154 EXPECT_EQ(3, mesh_.face_handle(cvoh_it.handle()).idx() ) << "Corresponding face Index wrong in ConstVertexOHalfedgeIter step 4";
155 EXPECT_FALSE(cvoh_it) << "Iterator still valid in ConstVertexOHalfedgeIter at step 4";
156 EXPECT_TRUE( cvoh_it == cvoh_end ) << "Miss matched end iterator";
157
158 }
159
160 /*
161 * Small VertexFaceOutgoingHalfedgeIterator Test
162 */
163 TEST_F(OpenMeshTrimeshCirculatorVertexOHalfEdge, VertexOutgoingHalfedgeBoundaryIncrement) {
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::VertexOHalfedgeIter voh_it = mesh_.voh_begin(vhandle[2]);
218 Mesh::VertexOHalfedgeIter voh_end = mesh_.voh_end(vhandle[2]);
219
220 EXPECT_EQ(15, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter begin at initialization";
221 EXPECT_EQ(15, voh_end.handle().idx() ) << "Index wrong in VertexOHalfedgeIter end at initialization";
222 EXPECT_EQ(-1, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter begin at initialization";
223 EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at initialization";
224
225 ++voh_it ;
226
227 EXPECT_EQ(3, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 1";
228 EXPECT_EQ(3, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 1";
229 EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 1";
230
231 ++voh_it ;
232
233 EXPECT_EQ(4, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 2";
234 EXPECT_EQ(0, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 2";
235 EXPECT_TRUE(voh_it) << "Iterator invalid in VertexOHalfedgeIter at step 2";
236
237 ++voh_it ;
238
239 EXPECT_EQ(15, voh_it.handle().idx() ) << "Index wrong in VertexOHalfedgeIter step 3";
240 EXPECT_EQ(-1, mesh_.face_handle(voh_it.handle()).idx() ) << "Corresponding face Index wrong in VertexOHalfedgeIter step 3";
241 EXPECT_FALSE(voh_it) << "Iterator still valid in VertexOHalfedgeIter at step 3";
242 EXPECT_TRUE( voh_it == voh_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(OpenMeshTrimeshCirculatorVertexOHalfEdge, VertexOutgoingHalfedgeDereferenceIncrement) {
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::VertexOHalfedgeIter voh_it = mesh_.voh_iter(vhandle[1]);
304
305 // TODO: If called without handle, it won't build
306 Mesh::EdgeHandle eh = mesh_.edge_handle(voh_it.handle());
307 Mesh::HalfedgeHandle heh = mesh_.halfedge_handle(voh_it);
308 Mesh::VertexHandle vh2 = mesh_.to_vertex_handle(voh_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() , 4 ) << "Wrong vertex handle after dereferencing";
313
314 }
315
316