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 
74  EXPECT_EQ(0, v_it.handle().idx()) << "Index wrong for vertex iterator vertices_begin()";
75  ++v_it;
76  EXPECT_EQ(1, v_it.handle().idx()) << "Index wrong in vertex iterator";
77  ++v_it;
78  EXPECT_EQ(2, v_it.handle().idx()) << "Index wrong in vertex iterator";
79  ++v_it;
80  EXPECT_EQ(3, v_it.handle().idx()) << "Index wrong in vertex iterator";
81  ++v_it;
82  EXPECT_EQ(4, v_it.handle().idx()) << "Index wrong in vertex iterator";
83 
84  // Check end iterator
85  EXPECT_EQ(4, v_end.handle().idx()) << "Index wrong in vertex iterator for vertices_end()";
86 
87 }
88 
89 /*
90  * Small EdgeIterator Test
91  */
92 TEST_F(OpenMeshIterators, EdgeIter) {
93 
94  mesh_.clear();
95 
96  // Add some vertices
97  Mesh::VertexHandle vhandle[4];
98 
99  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
100  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
101  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
102  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
103 
104  // Add two faces
105  std::vector<Mesh::VertexHandle> face_vhandles;
106 
107  face_vhandles.push_back(vhandle[2]);
108  face_vhandles.push_back(vhandle[1]);
109  face_vhandles.push_back(vhandle[0]);
110  mesh_.add_face(face_vhandles);
111 
112  face_vhandles.clear();
113 
114  face_vhandles.push_back(vhandle[2]);
115  face_vhandles.push_back(vhandle[0]);
116  face_vhandles.push_back(vhandle[3]);
117  mesh_.add_face(face_vhandles);
118 
119  // Test setup:
120  // 1 === 2
121  // | / |
122  // | / |
123  // | / |
124  // 0 === 3
125 
126 
127  Mesh::EdgeIter e_it = mesh_.edges_begin();
128  Mesh::EdgeIter e_end = mesh_.edges_end();
129 
130  EXPECT_EQ(0, e_it.handle().idx()) << "Wrong start index in edge iterator";
131  EXPECT_EQ(5, e_end.handle().idx()) << "Wrong end index in edge iterator";
132 
133  EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "1: Wrong to vertex handle of halfedge 0";
134  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "1: Wrong from vertex handle of halfedge 0";
135  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "1: Wrong to vertex handle of halfedge 1";
136  EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "1: Wrong from vertex handle of halfedge 1";
137 
138  ++e_it;
139  EXPECT_EQ(1, e_it.handle().idx()) << "Wrong index in edge iterator";
140 
141  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "2: Wrong to vertex handle of halfedge 0";
142  EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "2: Wrong from vertex handle of halfedge 0";
143  EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "2: Wrong to vertex handle of halfedge 1";
144  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "2: Wrong from vertex handle of halfedge 1";
145 
146 
147  ++e_it;
148  EXPECT_EQ(2, e_it.handle().idx()) << "Wrong index in edge iterator";
149 
150  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "3: Wrong to vertex handle of halfedge 0";
151  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "3: Wrong from vertex handle of halfedge 0";
152  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "3: Wrong to vertex handle of halfedge 1";
153  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "3: Wrong from vertex handle of halfedge 1";
154 
155 
156  ++e_it;
157  EXPECT_EQ(3, e_it.handle().idx()) << "Wrong index in edge iterator";
158 
159  EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "4: Wrong to vertex handle of halfedge 0";
160  EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "4: Wrong from vertex handle of halfedge 0";
161  EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "4: Wrong to vertex handle of halfedge 1";
162  EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "4: Wrong from vertex handle of halfedge 1";
163 
164 
165  ++e_it;
166  EXPECT_EQ(4, e_it.handle().idx()) << "Wrong index in edge iterator";
167 
168  EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "5: Wrong to vertex handle of halfedge 0";
169  EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,0)).idx() ) << "5: Wrong from vertex handle of halfedge 0";
170  EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "5: Wrong to vertex handle of halfedge 1";
171  EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(e_it,1)).idx() ) << "5: Wrong from vertex handle of halfedge 1";
172 
173 
174 }
175 
176 /*
177  * Test with a mesh with one deleted face
178  */
179 TEST_F(OpenMeshIterators, FaceIterEmptyMeshOneDeletedFace) {
180 
181  mesh_.clear();
182 
183  // request delete_face capability
184  mesh_.request_vertex_status();
185  mesh_.request_edge_status();
186  mesh_.request_face_status();
187 
188  // Add some vertices
189  Mesh::VertexHandle vhandle[4];
190 
191  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
192  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
193  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
194 
195  // Add two faces
196  std::vector<Mesh::VertexHandle> face_vhandles;
197 
198  face_vhandles.push_back(vhandle[2]);
199  face_vhandles.push_back(vhandle[1]);
200  face_vhandles.push_back(vhandle[0]);
201  Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
202 
203  // Delete face but keep vertices
204  bool const is_delete_isolated_vertex = false;
205  mesh_.delete_face(fh, is_delete_isolated_vertex);
206 
207  // Test setup (Face deleted but vertices kept.
208  // 1 === 2
209  // | /
210  // | /
211  // | /
212  // 0
213 
214  Mesh::FaceIter f_it = mesh_.faces_begin();
215  Mesh::FaceIter f_end = mesh_.faces_end();
216 
217  EXPECT_EQ(0, f_it.handle().idx()) << "Wrong start index in FaceIterator";
218 
219  EXPECT_EQ(1, f_end.handle().idx()) << "Wrong end index in FaceIterator";
220 
221  ++f_it;
222  EXPECT_EQ(1, f_it.handle().idx()) << "Wrong end index in FaceIterator after one step";
223  EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator after one step";
224 
225  Mesh::ConstFaceIter cf_it = mesh_.faces_begin();
226  Mesh::ConstFaceIter cf_end = mesh_.faces_end();
227 
228  EXPECT_EQ(0, cf_it.handle().idx()) << "Wrong start index in ConstFaceIterator";
229 
230  EXPECT_EQ(1, cf_end.handle().idx()) << "Wrong end index in ConstFaceIterator";
231 
232  ++cf_it;
233  EXPECT_EQ(1, cf_it.handle().idx()) << "Wrong end index in ConstFaceIterator after one step";
234  EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator after one step";
235 
236 
237  // Same with skipping iterators:
238  f_it = mesh_.faces_sbegin();
239  f_end = mesh_.faces_end();
240 
241  EXPECT_EQ(1, f_it.handle().idx()) << "Wrong start index in FaceIterator with skipping";
242 
243  EXPECT_EQ(1, f_end.handle().idx()) << "Wrong end index in FaceIterator with skipping";
244 
245  EXPECT_TRUE(f_it == f_end ) << "Iterator not at end for FaceIterator with skipping";
246 
247  // Same with skipping iterators:
248  cf_it = mesh_.faces_sbegin();
249  cf_end = mesh_.faces_end();
250 
251  EXPECT_EQ(1, cf_it.handle().idx()) << "Wrong start index in ConstFaceIterator with skipping";
252 
253  EXPECT_EQ(1, cf_end.handle().idx()) << "Wrong end index in ConstFaceIterator with skipping";
254 
255  EXPECT_TRUE(cf_it == cf_end ) << "Iterator not at end for ConstFaceIterator with skipping";
256 
257 
258  mesh_.release_vertex_status();
259  mesh_.release_edge_status();
260  mesh_.release_face_status();
261 
262 }
263 
264 #endif // INCLUDE GUARD

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