OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unittests_trimesh_iterators.hh
1 #ifndef INCLUDE_UNITTESTS_TRIMESH_ITERATORS_HH
2 #define INCLUDE_UNITTESTS_TRIMESH_ITERATORS_HH
3 
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6 
7 #include <iostream>
8 
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  // Member already defined in OpenMeshBase
24  //Mesh mesh_;
25 };
26 
27 /*
28  * ====================================================================
29  * Define tests below
30  * ====================================================================
31  */
32 
33 /*
34  * Small VertexIterator Test
35  */
36 TEST_F(OpenMeshIterators, VertexIter) {
37 
38  mesh_.clear();
39 
40  // Add some vertices
41  Mesh::VertexHandle vhandle[4];
42 
43  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
44  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
45  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
46  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
47 
48  // Add two faces
49  std::vector<Mesh::VertexHandle> face_vhandles;
50 
51  face_vhandles.push_back(vhandle[2]);
52  face_vhandles.push_back(vhandle[1]);
53  face_vhandles.push_back(vhandle[0]);
54  mesh_.add_face(face_vhandles);
55 
56  face_vhandles.clear();
57 
58  face_vhandles.push_back(vhandle[2]);
59  face_vhandles.push_back(vhandle[0]);
60  face_vhandles.push_back(vhandle[3]);
61  mesh_.add_face(face_vhandles);
62 
63  // Test setup:
64  // 1 === 2
65  // | / |
66  // | / |
67  // | / |
68  // 0 === 3
69 
70  Mesh::VertexIter v_it = mesh_.vertices_begin();
71  Mesh::VertexIter v_end = mesh_.vertices_end();
72 
73  EXPECT_EQ(0, v_it.handle().idx()) << "Index wrong for vertex iterator vertices_begin()";
74  ++v_it;
75  EXPECT_EQ(1, v_it.handle().idx()) << "Index wrong in vertex iterator";
76  ++v_it;
77  EXPECT_EQ(2, v_it.handle().idx()) << "Index wrong in vertex iterator";
78  ++v_it;
79  EXPECT_EQ(3, v_it.handle().idx()) << "Index wrong in vertex iterator";
80  ++v_it;
81  EXPECT_EQ(4, v_it.handle().idx()) << "Index wrong in vertex iterator";
82 
83  // Check end iterator
84  EXPECT_EQ(4, v_end.handle().idx()) << "Index wrong in vertex iterator for vertices_end()";
85 
86 }
87 
88 /*
89  * Small EdgeIterator Test
90  */
91 TEST_F(OpenMeshIterators, EdgeIter) {
92 
93  mesh_.clear();
94 
95  // Add some vertices
96  Mesh::VertexHandle vhandle[4];
97 
98  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
99  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
100  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
101  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
102 
103  // Add two faces
104  std::vector<Mesh::VertexHandle> face_vhandles;
105 
106  face_vhandles.push_back(vhandle[2]);
107  face_vhandles.push_back(vhandle[1]);
108  face_vhandles.push_back(vhandle[0]);
109  mesh_.add_face(face_vhandles);
110 
111  face_vhandles.clear();
112 
113  face_vhandles.push_back(vhandle[2]);
114  face_vhandles.push_back(vhandle[0]);
115  face_vhandles.push_back(vhandle[3]);
116  mesh_.add_face(face_vhandles);
117 
118  // Test setup:
119  // 1 === 2
120  // | / |
121  // | / |
122  // | / |
123  // 0 === 3
124 
125 
126  Mesh::EdgeIter e_it = mesh_.edges_begin();
127  Mesh::EdgeIter e_end = mesh_.edges_end();
128 
129  EXPECT_EQ(0, e_it.handle().idx()) << "Wrong start index in edge iterator";
130  EXPECT_EQ(5, e_end.handle().idx()) << "Wrong end index in edge iterator";
131 
132  EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "1: Wrong to vertex handle of halfedge 0";
133  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "1: Wrong from vertex handle of halfedge 0";
134  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "1: Wrong to vertex handle of halfedge 1";
135  EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "1: Wrong from vertex handle of halfedge 1";
136 
137  ++e_it;
138  EXPECT_EQ(1, e_it.handle().idx()) << "Wrong index in edge iterator";
139 
140  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "2: Wrong to vertex handle of halfedge 0";
141  EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "2: Wrong from vertex handle of halfedge 0";
142  EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "2: Wrong to vertex handle of halfedge 1";
143  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "2: Wrong from vertex handle of halfedge 1";
144 
145 
146  ++e_it;
147  EXPECT_EQ(2, e_it.handle().idx()) << "Wrong index in edge iterator";
148 
149  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "3: Wrong to vertex handle of halfedge 0";
150  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "3: Wrong from vertex handle of halfedge 0";
151  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "3: Wrong to vertex handle of halfedge 1";
152  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "3: Wrong from vertex handle of halfedge 1";
153 
154 
155  ++e_it;
156  EXPECT_EQ(3, e_it.handle().idx()) << "Wrong index in edge iterator";
157 
158  EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "4: Wrong to vertex handle of halfedge 0";
159  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "4: Wrong from vertex handle of halfedge 0";
160  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "4: Wrong to vertex handle of halfedge 1";
161  EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "4: Wrong from vertex handle of halfedge 1";
162 
163 
164  ++e_it;
165  EXPECT_EQ(4, e_it.handle().idx()) << "Wrong index in edge iterator";
166 
167  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "5: Wrong to vertex handle of halfedge 0";
168  EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "5: Wrong from vertex handle of halfedge 0";
169  EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "5: Wrong to vertex handle of halfedge 1";
170  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "5: Wrong from vertex handle of halfedge 1";
171 
172 
173 }
174 
175 /*
176  * Test with a mesh with one deleted face
177  */
178 TEST_F(OpenMeshIterators, FaceIterEmptyMeshOneDeletedFace) {
179 
180  mesh_.clear();
181 
182  // request delete_face capability
183  mesh_.request_vertex_status();
184  mesh_.request_edge_status();
185  mesh_.request_face_status();
186 
187  // Add some vertices
188  Mesh::VertexHandle vhandle[4];
189 
190  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
191  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
192  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
193 
194  // Add two faces
195  std::vector<Mesh::VertexHandle> face_vhandles;
196 
197  face_vhandles.push_back(vhandle[2]);
198  face_vhandles.push_back(vhandle[1]);
199  face_vhandles.push_back(vhandle[0]);
200  Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
201 
202  // Delete face but keep vertices
203  bool const is_delete_isolated_vertex = false;
204  mesh_.delete_face(fh, is_delete_isolated_vertex);
205 
206  // Test setup (Face deleted but vertices kept.
207  // 1 === 2
208  // | /
209  // | /
210  // | /
211  // 0
212 
213  Mesh::FaceIter f_it = mesh_.faces_begin();
214  Mesh::FaceIter f_end = mesh_.faces_end();
215 
216  EXPECT_EQ(0, f_it.handle().idx()) << "Wrong start index in FaceIterator";
217 
218  EXPECT_EQ(1, f_end.handle().idx()) << "Wrong end index in FaceIterator";
219 
220  ++f_it;
221  EXPECT_EQ(1, f_it.handle().idx()) << "Wrong end index in FaceIterator after one step";
222  EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator after one step";
223 
224  Mesh::ConstFaceIter cf_it = mesh_.faces_begin();
225  Mesh::ConstFaceIter cf_end = mesh_.faces_end();
226 
227  EXPECT_EQ(0, cf_it.handle().idx()) << "Wrong start index in ConstFaceIterator";
228 
229  EXPECT_EQ(1, cf_end.handle().idx()) << "Wrong end index in ConstFaceIterator";
230 
231  ++cf_it;
232  EXPECT_EQ(1, cf_it.handle().idx()) << "Wrong end index in ConstFaceIterator after one step";
233  EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator after one step";
234 
235 
236  // Same with skipping iterators:
237  f_it = mesh_.faces_sbegin();
238  f_end = mesh_.faces_end();
239 
240  EXPECT_EQ(1, f_it.handle().idx()) << "Wrong start index in FaceIterator with skipping";
241 
242  EXPECT_EQ(1, f_end.handle().idx()) << "Wrong end index in FaceIterator with skipping";
243 
244  EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator with skipping";
245 
246  // Same with skipping iterators:
247  cf_it = mesh_.faces_sbegin();
248  cf_end = mesh_.faces_end();
249 
250  EXPECT_EQ(1, cf_it.handle().idx()) << "Wrong start index in ConstFaceIterator with skipping";
251 
252  EXPECT_EQ(1, cf_end.handle().idx()) << "Wrong end index in ConstFaceIterator with skipping";
253 
254  EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator with skipping";
255 
256 
257  mesh_.release_vertex_status();
258  mesh_.release_edge_status();
259  mesh_.release_face_status();
260 
261 }
262 
263 #endif // INCLUDE GUARD

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .