Developer Documentation
unittests_subdivider_uniform.cc
1 
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
6 
7 namespace {
8 
9 class OpenMeshSubdividerUniform_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 OpenMeshSubdividerUniform_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 /*
56  */
57 TEST_F(OpenMeshSubdividerUniform_Triangle, Subdivider_Loop) {
58 
59  mesh_.clear();
60 
61  // Add some vertices
62  Mesh::VertexHandle vhandle[9];
63 
64  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
65  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
66  vhandle[2] = mesh_.add_vertex(Mesh::Point(0, 2, 0));
67  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
68  vhandle[4] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
69  vhandle[5] = mesh_.add_vertex(Mesh::Point(1, 2, 0));
70  vhandle[6] = mesh_.add_vertex(Mesh::Point(2, 0, 0));
71  vhandle[7] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
72  vhandle[8] = mesh_.add_vertex(Mesh::Point(2, 2, 0));
73 
74  // Add eight faces
75  std::vector<Mesh::VertexHandle> face_vhandles;
76 
77  face_vhandles.push_back(vhandle[0]);
78  face_vhandles.push_back(vhandle[4]);
79  face_vhandles.push_back(vhandle[3]);
80 
81  mesh_.add_face(face_vhandles);
82  face_vhandles.clear();
83 
84  face_vhandles.push_back(vhandle[0]);
85  face_vhandles.push_back(vhandle[1]);
86  face_vhandles.push_back(vhandle[4]);
87 
88  mesh_.add_face(face_vhandles);
89  face_vhandles.clear();
90 
91  face_vhandles.push_back(vhandle[1]);
92  face_vhandles.push_back(vhandle[2]);
93  face_vhandles.push_back(vhandle[4]);
94 
95  mesh_.add_face(face_vhandles);
96  face_vhandles.clear();
97 
98  face_vhandles.push_back(vhandle[2]);
99  face_vhandles.push_back(vhandle[5]);
100  face_vhandles.push_back(vhandle[4]);
101 
102  mesh_.add_face(face_vhandles);
103  face_vhandles.clear();
104 
105  face_vhandles.push_back(vhandle[3]);
106  face_vhandles.push_back(vhandle[7]);
107  face_vhandles.push_back(vhandle[6]);
108 
109  mesh_.add_face(face_vhandles);
110  face_vhandles.clear();
111 
112  face_vhandles.push_back(vhandle[3]);
113  face_vhandles.push_back(vhandle[4]);
114  face_vhandles.push_back(vhandle[7]);
115 
116  mesh_.add_face(face_vhandles);
117  face_vhandles.clear();
118 
119  face_vhandles.push_back(vhandle[4]);
120  face_vhandles.push_back(vhandle[8]);
121  face_vhandles.push_back(vhandle[7]);
122 
123  mesh_.add_face(face_vhandles);
124  face_vhandles.clear();
125 
126  face_vhandles.push_back(vhandle[4]);
127  face_vhandles.push_back(vhandle[5]);
128  face_vhandles.push_back(vhandle[8]);
129 
130  mesh_.add_face(face_vhandles);
131 
132  // Test setup:
133  // 6 === 7 === 8
134  // | / | / |
135  // | / | / |
136  // | / | / |
137  // 3 === 4 === 5
138  // | / | \ |
139  // | / | \ |
140  // | / | \ |
141  // 0 === 1 === 2
142 
143  // Initialize subdivider
145 
146  // Check setup
147  EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
148  EXPECT_EQ(8u, mesh_.n_faces() ) << "Wrong number of faces";
149 
150  // Execute 3 subdivision steps
151  sqrt3.attach(mesh_);
152  sqrt3( 3 );
153  sqrt3.detach();
154 
155  // Check setup
156  EXPECT_EQ(121u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with sqrt3";
157  EXPECT_EQ(216u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with sqrt3";
158 
159 }
160 
161 /*
162  * ====================================================================
163  * Define tests below
164  * ====================================================================
165  */
166 
167 /*
168  */
169 TEST_F(OpenMeshSubdividerUniform_Poly, Subdivider_CatmullClark) {
170 
171  mesh_.clear();
172 
173  // Add some vertices
174  Mesh::VertexHandle vhandle[9];
175 
176  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
177  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
178  vhandle[2] = mesh_.add_vertex(Mesh::Point(0, 2, 0));
179  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
180  vhandle[4] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
181  vhandle[5] = mesh_.add_vertex(Mesh::Point(1, 2, 0));
182  vhandle[6] = mesh_.add_vertex(Mesh::Point(2, 0, 0));
183  vhandle[7] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
184  vhandle[8] = mesh_.add_vertex(Mesh::Point(2, 2, 0));
185 
186  // Add four faces
187  std::vector<Mesh::VertexHandle> face_vhandles;
188 
189  face_vhandles.push_back(vhandle[0]);
190  face_vhandles.push_back(vhandle[1]);
191  face_vhandles.push_back(vhandle[4]);
192  face_vhandles.push_back(vhandle[3]);
193 
194  mesh_.add_face(face_vhandles);
195  face_vhandles.clear();
196 
197  face_vhandles.push_back(vhandle[1]);
198  face_vhandles.push_back(vhandle[2]);
199  face_vhandles.push_back(vhandle[5]);
200  face_vhandles.push_back(vhandle[4]);
201 
202  mesh_.add_face(face_vhandles);
203  face_vhandles.clear();
204 
205  face_vhandles.push_back(vhandle[4]);
206  face_vhandles.push_back(vhandle[5]);
207  face_vhandles.push_back(vhandle[8]);
208  face_vhandles.push_back(vhandle[7]);
209 
210  mesh_.add_face(face_vhandles);
211  face_vhandles.clear();
212 
213  face_vhandles.push_back(vhandle[3]);
214  face_vhandles.push_back(vhandle[4]);
215  face_vhandles.push_back(vhandle[7]);
216  face_vhandles.push_back(vhandle[6]);
217 
218  mesh_.add_face(face_vhandles);
219 
220  // Test setup:
221  // 6 === 7 === 8
222  // | | |
223  // | | |
224  // | | |
225  // 3 === 4 === 5
226  // | | |
227  // | | |
228  // | | |
229  // 0 === 1 === 2
230 
231  // Initialize subdivider
233 
234  // Check setup
235  EXPECT_EQ(9u, mesh_.n_vertices() ) << "Wrong number of vertices";
236  EXPECT_EQ(4u, mesh_.n_faces() ) << "Wrong number of faces";
237 
238  // Execute 3 subdivision steps
239  catmull.attach(mesh_);
240  catmull( 3 );
241  catmull.detach();
242 
243  EXPECT_EQ(289u, mesh_.n_vertices() ) << "Wrong number of vertices after subdivision with catmull clark";
244  EXPECT_EQ(256u, mesh_.n_faces() ) << "Wrong number of faces after subdivision with catmull clark";
245 
246 }
247 }
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
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115