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_face_face.hh
1 #pragma once
2
3 #include <gtest/gtest.h>
4 #include <Unittests/unittests_common.hh>
5
6 #include <iostream>
7
8 class OpenMeshTrimeshCirculatorFaceFace : 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 /*
36 * Small FaceFaceIterator Test with holes in it
37 */
38 TEST_F(OpenMeshTrimeshCirculatorFaceFace, FaceFaceIterWithHoles) {
39
40 mesh_.clear();
41
42 // Add some vertices
43 Mesh::VertexHandle vhandle[5];
44
45 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
46 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
47 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
48 vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
49 vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
50
51 // Add three faces
52 std::vector<Mesh::VertexHandle> face_vhandles;
53
54 face_vhandles.push_back(vhandle[0]);
55 face_vhandles.push_back(vhandle[1]);
56 face_vhandles.push_back(vhandle[2]);
57 mesh_.add_face(face_vhandles);
58
59 face_vhandles.clear();
60
61 face_vhandles.push_back(vhandle[2]);
62 face_vhandles.push_back(vhandle[1]);
63 face_vhandles.push_back(vhandle[3]);
64 mesh_.add_face(face_vhandles);
65
66 face_vhandles.clear();
67
68 face_vhandles.push_back(vhandle[2]);
69 face_vhandles.push_back(vhandle[3]);
70 face_vhandles.push_back(vhandle[4]);
71 mesh_.add_face(face_vhandles);
72
73 /* Test setup:
74 *
75 * 0 ------ 2 ------ 4
76 * \ / \ /
77 * \ 0 / \ 2 /
78 * \ / 1 \ /
79 * 1 ------- 3
80 */
81
82
83 Mesh::FaceFaceIter ff_it = mesh_.ff_begin(mesh_.face_handle(1));
84 Mesh::FaceFaceIter ff_end = mesh_.ff_end(mesh_.face_handle(1));
85
86 EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at initialization";
87 EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at initialization";
88 ++ff_it;
89 EXPECT_EQ(0, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at step 1";
90 EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at step 1";
91 ++ff_it;
92 EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at end";
93 EXPECT_FALSE(ff_it) << "Iterator invalid in FaceFaceIter at end";
94 EXPECT_TRUE( ff_it == ff_end ) << "End iterator for FaceFaceIter not matching";
95
96 Mesh::ConstFaceFaceIter cff_it = mesh_.cff_begin(mesh_.face_handle(1));
97 Mesh::ConstFaceFaceIter cff_end = mesh_.cff_end(mesh_.face_handle(1));
98
99 EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at initialization";
100 EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at initialization";
101 ++cff_it;
102 EXPECT_EQ(0, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at step 1";
103 EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at step 1";
104 ++cff_it;
105 EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at end";
106 EXPECT_FALSE(cff_it) << "Iterator invalid in ConstFaceFaceIter at end";
107 EXPECT_TRUE( cff_it == cff_end ) << "End iterator for ConstFaceFaceIter not matching";
108
109 }
110
111
112
113 /*
114 * Small FaceFaceIterator Test with holes in it
115 */
116 TEST_F(OpenMeshTrimeshCirculatorFaceFace, FaceFaceIterWithoutHoles) {
117
118 mesh_.clear();
119
120 // Add some vertices
121 Mesh::VertexHandle vhandle[6];
122
123 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
124 vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
125 vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
126 vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
127 vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
128 vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
129
130 // Add three faces
131 std::vector<Mesh::VertexHandle> face_vhandles;
132
133 face_vhandles.push_back(vhandle[0]);
134 face_vhandles.push_back(vhandle[1]);
135 face_vhandles.push_back(vhandle[2]);
136 mesh_.add_face(face_vhandles);
137
138 face_vhandles.clear();
139
140 face_vhandles.push_back(vhandle[2]);
141 face_vhandles.push_back(vhandle[1]);
142 face_vhandles.push_back(vhandle[3]);
143 mesh_.add_face(face_vhandles);
144
145 face_vhandles.clear();
146
147 face_vhandles.push_back(vhandle[2]);
148 face_vhandles.push_back(vhandle[3]);
149 face_vhandles.push_back(vhandle[4]);
150 mesh_.add_face(face_vhandles);
151
152 face_vhandles.clear();
153
154 face_vhandles.push_back(vhandle[1]);
155 face_vhandles.push_back(vhandle[5]);
156 face_vhandles.push_back(vhandle[3]);
157 mesh_.add_face(face_vhandles);
158
159 /* Test setup:
160 *
161 * 0 ------ 2 ------ 4
162 * \ / \ /
163 * \ 0 / \ 2 /
164 * \ / 1 \ /
165 * 1 ------- 3
166 * \ /
167 * \ 3 /
168 * \ /
169 * \ /
170 * 5
171 */
172
173
174 Mesh::FaceFaceIter ff_it = mesh_.ff_begin(mesh_.face_handle(1));
175 Mesh::FaceFaceIter ff_end = mesh_.ff_end(mesh_.face_handle(1));
176
177 EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at initialization";
178 EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at initialization";
179 ++ff_it;
180 EXPECT_EQ(0, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at step 1";
181 EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at step 1";
182 ++ff_it;
183 EXPECT_EQ(3, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at step 2";
184 EXPECT_TRUE(ff_it) << "Iterator invalid in FaceFaceIter at step 2";
185 ++ff_it;
186 EXPECT_EQ(2, ff_it.handle().idx() ) << "Index wrong in FaceFaceIter at end";
187 EXPECT_FALSE(ff_it) << "Iterator invalid in FaceFaceIter at end";
188 EXPECT_TRUE( ff_it == ff_end ) << "End iterator for FaceFaceIter not matching";
189
190 Mesh::ConstFaceFaceIter cff_it = mesh_.cff_begin(mesh_.face_handle(1));
191 Mesh::ConstFaceFaceIter cff_end = mesh_.cff_end(mesh_.face_handle(1));
192
193 EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at initialization";
194 EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at initialization";
195 ++cff_it;
196 EXPECT_EQ(0, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at step 1";
197 EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at step 1";
198 ++cff_it;
199 EXPECT_EQ(3, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at step 2";
200 EXPECT_TRUE(cff_it) << "Iterator invalid in ConstFaceFaceIter at step 2";
201 ++cff_it;
202 EXPECT_EQ(2, cff_it.handle().idx() ) << "Index wrong in ConstFaceFaceIter at end";
203 EXPECT_FALSE(cff_it) << "Iterator invalid in ConstFaceFaceIter at end";
204 EXPECT_TRUE( cff_it == cff_end ) << "End iterator for ConstFaceFaceIter not matching";
205
206 }
207
208
209
210 /*
211 * Small FaceFaceIterator Test for getting handles and faces from the facefaceiterator
212 */
213 TEST_F(OpenMeshTrimeshCirculatorFaceFace, FaceFaceIteratorHandleConversion) {
214
215 mesh_.clear();
216
217 // Add some vertices
218 Mesh::VertexHandle vhandle[4];
219
220 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
221 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
222 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
223 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
224
225
226 // Add two faces
227 std::vector<Mesh::VertexHandle> face_vhandles;
228
229 face_vhandles.push_back(vhandle[0]);
230 face_vhandles.push_back(vhandle[2]);
231 face_vhandles.push_back(vhandle[1]);
232 Mesh::FaceHandle fh1 = 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[2]);
239 Mesh::FaceHandle fh2 = mesh_.add_face(face_vhandles);
240
241 face_vhandles.clear();
242
243 /* Test setup:
244 *
245 * 1 -------- 2
246 * | f0 / |
247 * | / f1 |
248 * 0 -------- 3
249 */
250
251 // Check setup
252 EXPECT_EQ(4u , mesh_.n_vertices() ) << "Wrong number of vertices";
253 EXPECT_EQ(2u , mesh_.n_faces() ) << "Wrong number of faces";
254
255
256 Mesh::ConstFaceFaceIter face_iter = mesh_.cff_iter(fh1);
257
258
259 // Get the face via the handle
260 Mesh::FaceHandle faceHandle1 = mesh_.handle(*face_iter);
261 const Mesh::Face& face1 = mesh_.face(faceHandle1);
262
263 EXPECT_EQ(1, faceHandle1.idx() ) << "Wrong face handle index when getting from iterator via handle";
264
265 // Get the face via the face itself
266 const Mesh::Face& face = *face_iter;
267 Mesh::FaceHandle fh = mesh_.handle(face);
268
269
270 EXPECT_EQ(1, fh.idx() ) << "Wrong face handle index when getting from iterator via face";
271
272 bool correct = (&face == &face1);
273
274 // Compare the faces
275 EXPECT_TRUE(correct) << "The faces are different although both ways should give the same one";
276
277 }
278
279