Developer Documentation
unittests_subdivider_adaptive.cc
1 
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
6 
7 namespace {
8 
9 class OpenMeshSubdividerAdaptive_Poly : public OpenMeshBasePoly {
10 
11  protected:
12 
13  // This function is called before each test is run
14  virtual void SetUp() {
15 
16  // Do some initial stuff with the member data here...
17  }
18 
19  // This function is called after all tests are through
20  virtual void TearDown() {
21 
22  // Do some final stuff with the member data here...
23  }
24 
25  // Member already defined in OpenMeshBase
26  //Mesh mesh_;
27 };
28 
29 class OpenMeshSubdividerAdaptive_Triangle : public OpenMeshBase {
30 
31  protected:
32 
33  // This function is called before each test is run
34  virtual void SetUp() {
35 
36  // Do some initial stuff with the member data here...
37  }
38 
39  // This function is called after all tests are through
40  virtual void TearDown() {
41 
42  // Do some final stuff with the member data here...
43  }
44 
45  // Member already defined in OpenMeshBase
46  //Mesh mesh_;
47 };
48 
49 /*
50  * ====================================================================
51  * Define tests below
52  * ====================================================================
53  */
54 
55 struct MeshTraits : public OpenMesh::Subdivider::Adaptive::CompositeTraits {
56  typedef OpenMesh::Vec3f Point;
57  typedef OpenMesh::Vec3f Normal;
58 
62 };
63 
65 typedef MyMesh::VertexHandle VHandle;
66 typedef MyMesh::FaceHandle FHandle;
67 
68 TEST_F(OpenMeshSubdividerAdaptive_Triangle, AdaptiveCompositeRefineVertex) {
69 
70  MyMesh mesh;
71  mesh.request_vertex_status();
72  mesh.request_edge_status();
73  mesh.request_face_status();
74  mesh.request_vertex_normals();
75  mesh.request_face_normals();
76 
77  // Add some vertices
78  VHandle vhandle[9];
79 
80  vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
81  vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
82  vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 2, 0));
83  vhandle[3] = mesh.add_vertex(MyMesh::Point(1, 0, 0));
84  vhandle[4] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
85  vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 2, 0));
86  vhandle[6] = mesh.add_vertex(MyMesh::Point(2, 0, 0));
87  vhandle[7] = mesh.add_vertex(MyMesh::Point(2, 1, 0));
88  vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0));
89 
90  // Add eight faces
91  std::vector<VHandle> face_vhandles;
92 
93  face_vhandles.push_back(vhandle[0]);
94  face_vhandles.push_back(vhandle[4]);
95  face_vhandles.push_back(vhandle[3]);
96 
97  mesh.add_face(face_vhandles);
98  face_vhandles.clear();
99 
100  face_vhandles.push_back(vhandle[0]);
101  face_vhandles.push_back(vhandle[1]);
102  face_vhandles.push_back(vhandle[4]);
103 
104  mesh.add_face(face_vhandles);
105  face_vhandles.clear();
106 
107  face_vhandles.push_back(vhandle[1]);
108  face_vhandles.push_back(vhandle[2]);
109  face_vhandles.push_back(vhandle[4]);
110 
111  mesh.add_face(face_vhandles);
112  face_vhandles.clear();
113 
114  face_vhandles.push_back(vhandle[2]);
115  face_vhandles.push_back(vhandle[5]);
116  face_vhandles.push_back(vhandle[4]);
117 
118  mesh.add_face(face_vhandles);
119  face_vhandles.clear();
120 
121  face_vhandles.push_back(vhandle[3]);
122  face_vhandles.push_back(vhandle[7]);
123  face_vhandles.push_back(vhandle[6]);
124 
125  mesh.add_face(face_vhandles);
126  face_vhandles.clear();
127 
128  face_vhandles.push_back(vhandle[3]);
129  face_vhandles.push_back(vhandle[4]);
130  face_vhandles.push_back(vhandle[7]);
131 
132  mesh.add_face(face_vhandles);
133  face_vhandles.clear();
134 
135  face_vhandles.push_back(vhandle[4]);
136  face_vhandles.push_back(vhandle[8]);
137  face_vhandles.push_back(vhandle[7]);
138 
139  mesh.add_face(face_vhandles);
140  face_vhandles.clear();
141 
142  face_vhandles.push_back(vhandle[4]);
143  face_vhandles.push_back(vhandle[5]);
144  face_vhandles.push_back(vhandle[8]);
145 
146  mesh.add_face(face_vhandles);
147 
158 
159  // Initialize subdivider
161 
166 
167  subdivider.initialize();
168 
169  // Check setup
170  EXPECT_EQ(9u, mesh.n_vertices() ) << "Wrong number of vertices";
171  EXPECT_EQ(8u, mesh.n_faces() ) << "Wrong number of faces";
172 
173  // execute adaptive composite subdivision
174  subdivider.refine(vhandle[4]);
175 
176 
177  // Check setup
178  EXPECT_EQ(17u, mesh.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
179  EXPECT_EQ(24u, mesh.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
180 
181 }
182 
183 TEST_F(OpenMeshSubdividerAdaptive_Triangle, AdaptiveCompositeRefineFace) {
184 
185  MyMesh mesh;
186  mesh.request_vertex_status();
187  mesh.request_edge_status();
188  mesh.request_face_status();
189  mesh.request_vertex_normals();
190  mesh.request_face_normals();
191 
192  // Add some vertices
193  VHandle vhandle[9];
194 
195  vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
196  vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
197  vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 2, 0));
198  vhandle[3] = mesh.add_vertex(MyMesh::Point(1, 0, 0));
199  vhandle[4] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
200  vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 2, 0));
201  vhandle[6] = mesh.add_vertex(MyMesh::Point(2, 0, 0));
202  vhandle[7] = mesh.add_vertex(MyMesh::Point(2, 1, 0));
203  vhandle[8] = mesh.add_vertex(MyMesh::Point(2, 2, 0));
204 
205  // Add eight faces
206  std::vector<VHandle> face_vhandles;
207  std::vector<FHandle> face_handles;
208 
209  face_vhandles.push_back(vhandle[0]);
210  face_vhandles.push_back(vhandle[4]);
211  face_vhandles.push_back(vhandle[3]);
212 
213  face_handles.push_back(mesh.add_face(face_vhandles));
214  face_vhandles.clear();
215 
216  face_vhandles.push_back(vhandle[0]);
217  face_vhandles.push_back(vhandle[1]);
218  face_vhandles.push_back(vhandle[4]);
219 
220  face_handles.push_back(mesh.add_face(face_vhandles));
221  face_vhandles.clear();
222 
223  face_vhandles.push_back(vhandle[1]);
224  face_vhandles.push_back(vhandle[2]);
225  face_vhandles.push_back(vhandle[4]);
226 
227  face_handles.push_back(mesh.add_face(face_vhandles));
228  face_vhandles.clear();
229 
230  face_vhandles.push_back(vhandle[2]);
231  face_vhandles.push_back(vhandle[5]);
232  face_vhandles.push_back(vhandle[4]);
233 
234  face_handles.push_back(mesh.add_face(face_vhandles));
235  face_vhandles.clear();
236 
237  face_vhandles.push_back(vhandle[3]);
238  face_vhandles.push_back(vhandle[7]);
239  face_vhandles.push_back(vhandle[6]);
240 
241  face_handles.push_back(mesh.add_face(face_vhandles));
242  face_vhandles.clear();
243 
244  face_vhandles.push_back(vhandle[3]);
245  face_vhandles.push_back(vhandle[4]);
246  face_vhandles.push_back(vhandle[7]);
247 
248  face_handles.push_back(mesh.add_face(face_vhandles));
249  face_vhandles.clear();
250 
251  face_vhandles.push_back(vhandle[4]);
252  face_vhandles.push_back(vhandle[8]);
253  face_vhandles.push_back(vhandle[7]);
254 
255  face_handles.push_back(mesh.add_face(face_vhandles));
256  face_vhandles.clear();
257 
258  face_vhandles.push_back(vhandle[4]);
259  face_vhandles.push_back(vhandle[5]);
260  face_vhandles.push_back(vhandle[8]);
261 
262  face_handles.push_back(mesh.add_face(face_vhandles));
263 
274 
275  // Initialize subdivider
277 
282 
283  subdivider.initialize();
284 
285  // Check setup
286  EXPECT_EQ(9u, mesh.n_vertices() ) << "Wrong number of vertices";
287  EXPECT_EQ(8u, mesh.n_faces() ) << "Wrong number of faces";
288 
289  // execute adaptive composite subdivision
290  std::vector<FHandle>::iterator it, end;
291  it = face_handles.begin();
292  end = face_handles.end();
293  for (; it != end; ++it)
294  subdivider.refine(*it);
295 
296 
297  // Check setup
298  EXPECT_EQ(245u, mesh.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
299  EXPECT_EQ(458u, mesh.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
300 
301 }
302 }
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Definition: Traits.hh:84
Add status to mesh item (all items)
Definition: Attributes.hh:90
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
#define FaceAttributes(_i)
Macro for defining the face attributes. See Specifying your MyMesh.
Definition: Traits.hh:93
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
#define EdgeAttributes(_i)
Macro for defining the edge attributes. See Specifying your MyMesh.
Definition: Traits.hh:90