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_face.hh
1 #pragma once
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4
5 #include <iostream>
6
7 class OpenMeshTrimeshCirculatorVertexFace : public OpenMeshBase {
8
9 protected:
10
11 // This function is called before each test is run
12 virtual void SetUp() {
13 }
14
15 // This function is called after all tests are through
16 virtual void TearDown() {
17
18 // Do some final stuff with the member data here...
19 }
20
21
22 // Member already defined in OpenMeshBase
23 //Mesh mesh_;
24 };
25
26 /*
27 * ====================================================================
28 * Define tests below
29 * ====================================================================
30 */
31
32
33 /*
34 * Small VertexFaceIterator Test with holes in it
35 *
36 * WARNING!!! Basically this is an illegal configuration!
37 * But this way we can still detect if it breaks!
38 */
39 TEST_F(OpenMeshTrimeshCirculatorVertexFace, VertexFaceIterWithHolesIncrement) {
40
41 mesh_.clear();
42
43 // Add some vertices
44 Mesh::VertexHandle vhandle[5];
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(0,-1, 0));
50 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
51
52 // Add two faces
53 std::vector<Mesh::VertexHandle> face_vhandles;
54
55 face_vhandles.push_back(vhandle[0]);
56 face_vhandles.push_back(vhandle[1]);
57 face_vhandles.push_back(vhandle[2]);
58 mesh_.add_face(face_vhandles);
59
60 face_vhandles.clear();
61
62 face_vhandles.push_back(vhandle[1]);
63 face_vhandles.push_back(vhandle[3]);
64 face_vhandles.push_back(vhandle[4]);
65 mesh_.add_face(face_vhandles);
66
67 /* Test setup:
68 0 ==== 2
69 \ /
70 \ /
71 1
72 / \
73 / \
74 3 ==== 4 */
75
76 // Iterate around vertex 1 at the middle (with holes in between)
77 Mesh::VertexFaceIter vf_it = mesh_.vf_begin(vhandle[1]);
78 Mesh::VertexFaceIter vf_end = mesh_.vf_end(vhandle[1]);
79 EXPECT_EQ(0, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at initialization";
80 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at initialization";
81 ++vf_it ;
82 EXPECT_EQ(1, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 1";
83 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 1";
84 ++vf_it ;
85 EXPECT_EQ(-1, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at end";
86 EXPECT_FALSE(vf_it) << "Iterator not invalid in VertexFaceIter at end";
87 EXPECT_TRUE( vf_it == vf_end ) << "End iterator for VertexFaceIter not matching";
88
89 // Iterate around vertex 1 at the middle (with holes in between) with const iterator
90 Mesh::ConstVertexFaceIter cvf_it = mesh_.cvf_begin(vhandle[1]);
91 Mesh::ConstVertexFaceIter cvf_end = mesh_.cvf_end(vhandle[1]);
92 EXPECT_EQ(0, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at initialization";
93 EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at initialization";
94 ++cvf_it ;
95 EXPECT_EQ(1, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step one";
96 EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step one";
97 ++cvf_it ;
98 EXPECT_EQ(-1, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at end";
99 EXPECT_FALSE(cvf_it) << "Iterator not invalid in ConstVertexFaceIter at end";
100 EXPECT_TRUE( cvf_it == cvf_end ) << "End iterator for ConstVertexFaceIter not matching";
101
102 }
103
104
105
106 /*
107 * Small VertexFaceIterator Test without holes in it
108 */
109 TEST_F(OpenMeshTrimeshCirculatorVertexFace, VertexFaceIterWithoutHolesIncrement) {
110
111 mesh_.clear();
112
113 // Add some vertices
114 Mesh::VertexHandle vhandle[5];
115
116 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
117 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
118 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
119 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
120 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
121
122 // Add two faces
123 std::vector<Mesh::VertexHandle> face_vhandles;
124
125 face_vhandles.push_back(vhandle[0]);
126 face_vhandles.push_back(vhandle[1]);
127 face_vhandles.push_back(vhandle[2]);
128 mesh_.add_face(face_vhandles);
129
130 face_vhandles.clear();
131
132 face_vhandles.push_back(vhandle[1]);
133 face_vhandles.push_back(vhandle[3]);
134 face_vhandles.push_back(vhandle[4]);
135 mesh_.add_face(face_vhandles);
136
137 face_vhandles.clear();
138
139 face_vhandles.push_back(vhandle[0]);
140 face_vhandles.push_back(vhandle[3]);
141 face_vhandles.push_back(vhandle[1]);
142 mesh_.add_face(face_vhandles);
143
144 face_vhandles.clear();
145
146 face_vhandles.push_back(vhandle[2]);
147 face_vhandles.push_back(vhandle[1]);
148 face_vhandles.push_back(vhandle[4]);
149 mesh_.add_face(face_vhandles);
150
151 /* Test setup:
152 0 ==== 2
153 |\ 0 /|
154 | \ / |
155 |2 1 3|
156 | / \ |
157 |/ 1 \|
158 3 ==== 4 */
159
160 Mesh::VertexFaceIter vfa_it = mesh_.vf_begin(vhandle[1]);
161
162 // Iterate around vertex 1 at the middle (with holes in between)
163 Mesh::VertexFaceIter vf_it = mesh_.vf_begin(vhandle[1]);
164 Mesh::VertexFaceIter vf_end = mesh_.vf_end(vhandle[1]);
165 EXPECT_EQ(3, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at initialization";
166 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at initialization";
167 ++vf_it ;
168 EXPECT_EQ(1, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 1";
169 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 1";
170 ++vf_it ;
171 EXPECT_EQ(2, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 2";
172 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 2";
173 ++vf_it ;
174 EXPECT_EQ(0, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 3";
175 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 3";
176 ++vf_it ;
177 EXPECT_EQ(3, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at end";
178 EXPECT_FALSE(vf_it) << "Iterator not invalid in VertexFaceIter at end";
179 EXPECT_TRUE( vf_it == vf_end ) << "End iterator for VertexFaceIter not matching";
180
181 // Iterate around vertex 1 at the middle (with holes in between) with const iterator
182 Mesh::ConstVertexFaceIter cvf_it = mesh_.cvf_begin(vhandle[1]);
183 Mesh::ConstVertexFaceIter cvf_end = mesh_.cvf_end(vhandle[1]);
184 EXPECT_EQ(3, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at initialization";
185 EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at initialization";
186 ++cvf_it ;
187 EXPECT_EQ(1, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step 1";
188 EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step 1";
189 ++cvf_it ;
190 EXPECT_EQ(2, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step 2";
191 EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step 2";
192 ++cvf_it ;
193 EXPECT_EQ(0, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at step 3";
194 EXPECT_TRUE(cvf_it) << "Iterator invalid in ConstVertexFaceIter at step 3";
195 ++cvf_it ;
196 EXPECT_EQ(3, cvf_it.handle().idx() ) << "Index wrong in ConstVertexFaceIter at end";
197 EXPECT_FALSE(cvf_it) << "Iterator not invalid in VertexFaceIter at end";
198 EXPECT_TRUE( cvf_it == cvf_end ) << "End iterator for ConstVertexFaceIter not matching";
199
200 }
201
202
203 /*
204 * Small VertexFaceIterator Test at a boundary vertex
205 */
206 TEST_F(OpenMeshTrimeshCirculatorVertexFace, VertexFaceIterBoundaryIncrement) {
207
208 mesh_.clear();
209
210 // Add some vertices
211 Mesh::VertexHandle vhandle[5];
212
213 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
214 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
215 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
216 vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
217 vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
218
219 // Add two faces
220 std::vector<Mesh::VertexHandle> face_vhandles;
221
222 face_vhandles.push_back(vhandle[0]);
223 face_vhandles.push_back(vhandle[1]);
224 face_vhandles.push_back(vhandle[2]);
225 mesh_.add_face(face_vhandles);
226
227 face_vhandles.clear();
228
229 face_vhandles.push_back(vhandle[1]);
230 face_vhandles.push_back(vhandle[3]);
231 face_vhandles.push_back(vhandle[4]);
232 mesh_.add_face(face_vhandles);
233
234 face_vhandles.clear();
235
236 face_vhandles.push_back(vhandle[0]);
237 face_vhandles.push_back(vhandle[3]);
238 face_vhandles.push_back(vhandle[1]);
239 mesh_.add_face(face_vhandles);
240
241 face_vhandles.clear();
242
243 face_vhandles.push_back(vhandle[2]);
244 face_vhandles.push_back(vhandle[1]);
245 face_vhandles.push_back(vhandle[4]);
246 mesh_.add_face(face_vhandles);
247
248 /* Test setup:
249 0 ==== 2
250 |\ 0 /|
251 | \ / |
252 |2 1 3|
253 | / \ |
254 |/ 1 \|
255 3 ==== 4 */
256
257 // Iterate around vertex 1 at the middle (with holes in between)
258 Mesh::VertexFaceIter vf_it = mesh_.vf_begin(vhandle[2]);
259 Mesh::VertexFaceIter vf_end = mesh_.vf_end(vhandle[2]);
260 EXPECT_EQ(3, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at initialization";
261 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at initialization";
262 ++vf_it ;
263 EXPECT_EQ(0, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 1";
264 EXPECT_TRUE(vf_it) << "Iterator invalid in VertexFaceIter at step 1";
265 ++vf_it ;
266 EXPECT_EQ(-1, vf_it.handle().idx() ) << "Index wrong in VertexFaceIter at step 2";
267 EXPECT_FALSE(vf_it) << "Iterator invalid in VertexFaceIter at step 2";
268 EXPECT_TRUE( vf_it == vf_end ) << "End iterator for VertexFaceIter not matching";
269 }
270