Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_trimesh_circulator_current_halfedge_handle_replacement.cc
1 
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 
5 #include <iostream>
6 
7 namespace {
8 
9 class OpenMeshTrimeshCirculatorCurrentHalfedgeHandleReplacement : public OpenMeshBase {
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 
24  // Member already defined in OpenMeshBase
25  //Mesh mesh_;
26 };
27 
28 /*
29  * ====================================================================
30  * Define tests below
31  * ====================================================================
32  */
33 
34 
35 /*
36  * duplicate dereferencing behaviour
37  */
38 TEST_F(OpenMeshTrimeshCirculatorCurrentHalfedgeHandleReplacement, dereference) {
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(0,-1, 0));
49  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
50 
51  // Add two 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[1]);
62  face_vhandles.push_back(vhandle[3]);
63  face_vhandles.push_back(vhandle[4]);
64  mesh_.add_face(face_vhandles);
65 
66  face_vhandles.clear();
67 
68  face_vhandles.push_back(vhandle[0]);
69  face_vhandles.push_back(vhandle[3]);
70  face_vhandles.push_back(vhandle[1]);
71  mesh_.add_face(face_vhandles);
72 
73  face_vhandles.clear();
74 
75  face_vhandles.push_back(vhandle[2]);
76  face_vhandles.push_back(vhandle[1]);
77  face_vhandles.push_back(vhandle[4]);
78  mesh_.add_face(face_vhandles);
79 
80  /* Test setup:
81  0 ==== 2
82  |\ 0 /|
83  | \ / |
84  |2 1 3|
85  | / \ |
86  |/ 1 \|
87  3 ==== 4 */
88  // Starting vertex is 1->4
89 
90  // output from fh_it.current_halfedge_handle()
91  int current_halfedge_handles[12] = {
92  4,0,2,10,6,8,1,12,7,14,3,11
93  };
94 
95 
96  size_t i(0);
97  for (Mesh::FaceIter f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
98  for (Mesh::FaceHalfedgeIter fh_it = mesh_.fh_iter(*f_it); fh_it.is_valid(); ++fh_it, ++i) {
99  EXPECT_EQ(current_halfedge_handles[i], fh_it->idx() ) << "halfedge handles don't match";
100  }
101  }
102 }
103 
104 /*
105  * duplicate vv_iter behaviour
106  */
107 TEST_F(OpenMeshTrimeshCirculatorCurrentHalfedgeHandleReplacement, vv_iter) {
108 
109  mesh_.clear();
110 
111  // Add some vertices
112  Mesh::VertexHandle vhandle[5];
113 
114  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
115  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
116  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
117  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
118  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
119 
120  // Add two faces
121  std::vector<Mesh::VertexHandle> face_vhandles;
122 
123  face_vhandles.push_back(vhandle[0]);
124  face_vhandles.push_back(vhandle[1]);
125  face_vhandles.push_back(vhandle[2]);
126  mesh_.add_face(face_vhandles);
127 
128  face_vhandles.clear();
129 
130  face_vhandles.push_back(vhandle[1]);
131  face_vhandles.push_back(vhandle[3]);
132  face_vhandles.push_back(vhandle[4]);
133  mesh_.add_face(face_vhandles);
134 
135  face_vhandles.clear();
136 
137  face_vhandles.push_back(vhandle[0]);
138  face_vhandles.push_back(vhandle[3]);
139  face_vhandles.push_back(vhandle[1]);
140  mesh_.add_face(face_vhandles);
141 
142  face_vhandles.clear();
143 
144  face_vhandles.push_back(vhandle[2]);
145  face_vhandles.push_back(vhandle[1]);
146  face_vhandles.push_back(vhandle[4]);
147  mesh_.add_face(face_vhandles);
148 
149  /* Test setup:
150  0 ==== 2
151  |\ 0 /|
152  | \ / |
153  |2 1 3|
154  | / \ |
155  |/ 1 \|
156  3 ==== 4 */
157  // Starting vertex is 1->4
158 
159  // output from vv_it.current_halfedge_handle()
160  size_t current_halfedge_handles[16] = {
161  5,
162  0,
163  12,
164  11,
165  6,
166  1,
167  2,
168  15,
169  3,
170  4,
171  13,
172  7,
173  8,
174  9,
175  10,
176  14
177  };
178 
179  std::vector<Mesh::EdgeHandle> eh0;
180  std::vector<Mesh::EdgeHandle> eh1;
181  size_t i(0);
182  for (Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
183  for (Mesh::VertexVertexIter vv_it = mesh_.vv_iter(*v_it); vv_it.is_valid(); ++vv_it, ++i)
184  eh0.push_back(mesh_.edge_handle(Mesh::HalfedgeHandle(int(current_halfedge_handles[i]))));
185  }
186  for (Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
187  for (Mesh::VertexOHalfedgeIter voh_it = mesh_.voh_iter(*v_it); voh_it.is_valid(); ++voh_it)
188  eh1.push_back(mesh_.edge_handle(*voh_it));
189  }
190 
191  EXPECT_EQ(eh0.size(), eh1.size()) << "size of vectors does not match";
192  for (size_t i = 0; i < eh0.size(); ++i)
193  EXPECT_EQ(eh0[i], eh1[i]) << "edge handles do not match";
194 
195 }
196 
197 /*
198  * duplicate fe_iter behaviour
199  */
200 TEST_F(OpenMeshTrimeshCirculatorCurrentHalfedgeHandleReplacement, fe_iter) {
201 
202  mesh_.clear();
203 
204  // Add some vertices
205  Mesh::VertexHandle vhandle[5];
206 
207  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
208  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
209  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
210  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
211  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
212 
213  // Add two faces
214  std::vector<Mesh::VertexHandle> face_vhandles;
215 
216  face_vhandles.push_back(vhandle[0]);
217  face_vhandles.push_back(vhandle[1]);
218  face_vhandles.push_back(vhandle[2]);
219  mesh_.add_face(face_vhandles);
220 
221  face_vhandles.clear();
222 
223  face_vhandles.push_back(vhandle[1]);
224  face_vhandles.push_back(vhandle[3]);
225  face_vhandles.push_back(vhandle[4]);
226  mesh_.add_face(face_vhandles);
227 
228  face_vhandles.clear();
229 
230  face_vhandles.push_back(vhandle[0]);
231  face_vhandles.push_back(vhandle[3]);
232  face_vhandles.push_back(vhandle[1]);
233  mesh_.add_face(face_vhandles);
234 
235  face_vhandles.clear();
236 
237  face_vhandles.push_back(vhandle[2]);
238  face_vhandles.push_back(vhandle[1]);
239  face_vhandles.push_back(vhandle[4]);
240  mesh_.add_face(face_vhandles);
241 
242  /* Test setup:
243  0 ==== 2
244  |\ 0 /|
245  | \ / |
246  |2 1 3|
247  | / \ |
248  |/ 1 \|
249  3 ==== 4 */
250  // Starting vertex is 1->4
251 
252  // output from fe_it.current_halfedge_handle()
253  size_t current_halfedge_handles[12] = {
254  4,0,2,10,6,8,1,12,7,14,3,11
255  };
256 
257  size_t i(0);
258 
259  std::vector<Mesh::HalfedgeHandle> heh0;
260  std::vector<Mesh::HalfedgeHandle> heh1;
261 
262  for (Mesh::FaceIter f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
263  for (Mesh::FaceEdgeIter fe_it = mesh_.fe_iter(*f_it); fe_it.is_valid(); ++fe_it, ++i) {
264  heh0.push_back(Mesh::HalfedgeHandle(int(current_halfedge_handles[i])));
265  }
266  }
267  for (Mesh::FaceIter f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it) {
268  for (Mesh::FaceHalfedgeIter fh_it = mesh_.fh_iter(*f_it); fh_it.is_valid(); ++fh_it) {
269  heh1.push_back(*fh_it);
270  }
271  }
272 
273  EXPECT_EQ(heh0.size(), heh1.size()) << "size of vectors does not match";
274  for (size_t i = 0; i < heh0.size(); ++i)
275  EXPECT_EQ(heh0[i], heh1[i]) << "halfedge handles do not match";
276 
277 }
278 
279 /*
280  * Small BoundaryVertexFaceIterator Test
281  */
282 TEST_F(OpenMeshTrimeshCirculatorCurrentHalfedgeHandleReplacement, vf_iter_boundary) {
283 
284  mesh_.clear();
285 
286  // Add some vertices
287  Mesh::VertexHandle vhandle[6];
288 
289  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
290  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
291  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
292  vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
293  vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
294  vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
295 
296  // Add three faces
297  std::vector<Mesh::VertexHandle> face_vhandles;
298 
299  face_vhandles.push_back(vhandle[0]);
300  face_vhandles.push_back(vhandle[1]);
301  face_vhandles.push_back(vhandle[2]);
302  mesh_.add_face(face_vhandles);
303 
304  face_vhandles.clear();
305 
306  face_vhandles.push_back(vhandle[2]);
307  face_vhandles.push_back(vhandle[3]);
308  face_vhandles.push_back(vhandle[4]);
309  mesh_.add_face(face_vhandles);
310 
311  face_vhandles.clear();
312 
313  face_vhandles.push_back(vhandle[1]);
314  face_vhandles.push_back(vhandle[5]);
315  face_vhandles.push_back(vhandle[3]);
316  mesh_.add_face(face_vhandles);
317 
318  /* Test setup:
319  *
320  * 0 ------ 2 ------ 4
321  * \ / \ /
322  * \ 0 / \ 1 /
323  * \ / \ /
324  * 1 ------- 3
325  * \ /
326  * \ 2 /
327  * \ /
328  * \ /
329  * 5
330  */
331  size_t current_halfedge_handles[9] = {
332  0,2,12,4,6,8,16,10,14
333  };
334  std::vector<Mesh::FaceHandle> fh0;
335  std::vector<Mesh::FaceHandle> fh1;
336  size_t i(0);
337  for (Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
338  for (Mesh::VertexFaceIter vf_it = mesh_.vf_iter(*v_it); vf_it.is_valid(); ++vf_it, ++i)
339  fh0.push_back(mesh_.face_handle(Mesh::HalfedgeHandle(current_halfedge_handles[i])));
340  }
341  for (Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it) {
342  for (Mesh::VertexFaceIter vf_it = mesh_.vf_iter(*v_it); vf_it.is_valid(); ++vf_it)
343  fh1.push_back(*vf_it);
344  }
345 
346  EXPECT_EQ(fh0.size(), fh1.size()) << "size of vectors does not match";
347  for (size_t i = 0; i < fh0.size(); ++i)
348  EXPECT_EQ(fh0[i], fh1[i]) << "face handles do not match";
349 }
350 
351 }
Kernel::FaceEdgeIter FaceEdgeIter
Circulator.
Definition: PolyMeshT.hh:172
Kernel::VertexVertexIter VertexVertexIter
Circulator.
Definition: PolyMeshT.hh:165
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:166
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
Kernel::FaceHalfedgeIter FaceHalfedgeIter
Circulator.
Definition: PolyMeshT.hh:171
Kernel::VertexFaceIter VertexFaceIter
Circulator.
Definition: PolyMeshT.hh:169