OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unittests_loading.hh
1 #ifndef INCLUDE_UNITTESTS_LOADING_HH
2 #define INCLUDE_UNITTESTS_LOADING_HH
3 
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6 
7 
8 class OpenMeshLoader : public OpenMeshBase {
9 
10  protected:
11 
12  // This function is called before each test is run
13  virtual void SetUp() {
14 
15  // Do some initial stuff with the member data here...
16  }
17 
18  // This function is called after all tests are through
19  virtual void TearDown() {
20 
21  // Do some final stuff with the member data here...
22  }
23 
24  // Member already defined in OpenMeshBase
25  //Mesh mesh_;
26 };
27 
28 /*
29  * ====================================================================
30  * Define tests below
31  * ====================================================================
32  */
33 
34 /*
35  * Just load a simple mesh file in obj format and count whether
36  * the right number of entities has been loaded.
37  */
38 TEST_F(OpenMeshLoader, LoadSimpleOFFFile) {
39 
40  mesh_.clear();
41 
42  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
43 
44  EXPECT_TRUE(ok);
45 
46  EXPECT_EQ(7526, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
47  EXPECT_EQ(22572, mesh_.n_edges()) << "The number of loaded edges is not correct!";
48  EXPECT_EQ(15048, mesh_.n_faces()) << "The number of loaded faces is not correct!";
49 }
50 
51 
52 
53 /*
54  * Just load a simple mesh file in stla format and count whether
55  * the right number of entities has been loaded.
56  */
57 TEST_F(OpenMeshLoader, LoadSimpleSTLFile) {
58 
59  mesh_.clear();
60 
61  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.stl");
62 
63  EXPECT_TRUE(ok);
64 
65  EXPECT_EQ(7526, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
66  EXPECT_EQ(22572, mesh_.n_edges()) << "The number of loaded edges is not correct!";
67  EXPECT_EQ(15048, mesh_.n_faces()) << "The number of loaded faces is not correct!";
68 }
69 
70 
71 
72 /*
73  * Just load a simple mesh file in stlb format and count whether
74  * the right number of entities has been loaded.
75  */
76 TEST_F(OpenMeshLoader, LoadSimpleSTLBinaryFile) {
77 
78  mesh_.clear();
79 
80  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1Binary.stl");
81 
82  EXPECT_TRUE(ok);
83 
84  EXPECT_EQ(7526, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
85  EXPECT_EQ(22572, mesh_.n_edges()) << "The number of loaded edges is not correct!";
86  EXPECT_EQ(15048, mesh_.n_faces()) << "The number of loaded faces is not correct!";
87 }
88 
89 
90 
91 /*
92  * Just load a point file in ply format and count whether
93  * the right number of entities has been loaded.
94  */
95 TEST_F(OpenMeshLoader, LoadSimplePointPLYFileWithBadEncoding) {
96 
97  mesh_.clear();
98 
99  bool ok = OpenMesh::IO::read_mesh(mesh_, "pointCloudBadEncoding.ply");
100 
101  EXPECT_TRUE(ok) << "Unable to load pointCloudBadEncoding.ply";
102 
103  EXPECT_EQ(10, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
104  EXPECT_EQ(0, mesh_.n_edges()) << "The number of loaded edges is not correct!";
105  EXPECT_EQ(0, mesh_.n_faces()) << "The number of loaded faces is not correct!";
106 }
107 
108 /*
109  * Just load a point file in ply format and count whether
110  * the right number of entities has been loaded.
111  */
112 TEST_F(OpenMeshLoader, LoadSimplePointPLYFileWithGoodEncoding) {
113 
114  mesh_.clear();
115 
116  bool ok = OpenMesh::IO::read_mesh(mesh_, "pointCloudGoodEncoding.ply");
117 
118  EXPECT_TRUE(ok) << "Unable to load pointCloudGoodEncoding.ply";
119 
120  EXPECT_EQ(10, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
121  EXPECT_EQ(0, mesh_.n_edges()) << "The number of loaded edges is not correct!";
122  EXPECT_EQ(0, mesh_.n_faces()) << "The number of loaded faces is not correct!";
123 }
124 
125 
126 /*
127  * Just load a obj file of a cube
128  */
129 TEST_F(OpenMeshLoader, LoadSimpleOBJ) {
130 
131  mesh_.clear();
132 
133  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.obj");
134 
135  EXPECT_TRUE(ok) << "Unable to load cube-minimal.obj";
136 
137  EXPECT_EQ(8, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
138  EXPECT_EQ(18, mesh_.n_edges()) << "The number of loaded edges is not correct!";
139  EXPECT_EQ(12, mesh_.n_faces()) << "The number of loaded faces is not correct!";
140 }
141 
142 
143 /*
144  * Just load a obj file of a cube with vertex colors defined directly after the vertex definitions
145  */
146 TEST_F(OpenMeshLoader, LoadSimpleOBJWithVertexColorsAfterVertices) {
147 
148  mesh_.clear();
149 
150  mesh_.request_vertex_colors();
151 
152  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertex-colors-after-vertex-definition.obj");
153 
154  EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertex-colors-after-vertex-definition.obj";
155 
156  EXPECT_EQ(8, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
157  EXPECT_EQ(18, mesh_.n_edges()) << "The number of loaded edges is not correct!";
158  EXPECT_EQ(12, mesh_.n_faces()) << "The number of loaded faces is not correct!";
159 
160  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
161  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
162  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
163 
164  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
165  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
166  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
167 
168  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
169  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
170  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
171 
172  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
173  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
174  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
175 
176  mesh_.release_vertex_colors();
177 }
178 
179 /*
180  * Just load a obj file of a cube with vertex colors defined as separate lines
181  */
182 TEST_F(OpenMeshLoader, LoadSimpleOBJWithVertexColorsAsVCLines) {
183 
184  mesh_.clear();
185 
186  mesh_.request_vertex_colors();
187 
188  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertex-colors-as-vc-lines.obj");
189 
190  EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertex-colors-as-vc-lines.obj";
191 
192  EXPECT_EQ(8, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
193  EXPECT_EQ(18, mesh_.n_edges()) << "The number of loaded edges is not correct!";
194  EXPECT_EQ(12, mesh_.n_faces()) << "The number of loaded faces is not correct!";
195 
196  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
197  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
198  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
199 
200  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
201  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
202  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
203 
204  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
205  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
206  EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
207 
208  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
209  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
210  EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
211 
212  mesh_.release_vertex_colors();
213 
214 }
215 
216 /*
217  * Just load a ply
218  */
219 TEST_F(OpenMeshLoader, LoadSimplePLY) {
220 
221  mesh_.clear();
222 
223  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.ply");
224 
225  EXPECT_TRUE(ok) << "Unable to load cube-minimal.ply";
226 
227  EXPECT_EQ(8, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
228  EXPECT_EQ(18, mesh_.n_edges()) << "The number of loaded edges is not correct!";
229  EXPECT_EQ(12, mesh_.n_faces()) << "The number of loaded faces is not correct!";
230 
231 }
232 
233 
234 /*
235  * Just load a ply with normals, ascii mode
236  */
237 TEST_F(OpenMeshLoader, LoadSimplePLYWithNormals) {
238 
239  mesh_.clear();
240 
241  mesh_.request_vertex_normals();
242 
243  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-normals.ply");
244 
245  EXPECT_TRUE(ok) << "Unable to load cube-minimal-normals.ply";
246 
247  EXPECT_EQ(8, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
248  EXPECT_EQ(18, mesh_.n_edges()) << "The number of loaded edges is not correct!";
249  EXPECT_EQ(12, mesh_.n_faces()) << "The number of loaded faces is not correct!";
250 
251 
252  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong normal at vertex 0 component 0";
253  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong normal at vertex 0 component 1";
254  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(0))[2] ) << "Wrong normal at vertex 0 component 2";
255 
256  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[0] ) << "Wrong normal at vertex 3 component 0";
257  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) << "Wrong normal at vertex 3 component 1";
258  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[2] ) << "Wrong normal at vertex 3 component 2";
259 
260  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[0] ) << "Wrong normal at vertex 4 component 0";
261  EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[1] ) << "Wrong normal at vertex 4 component 1";
262  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[2] ) << "Wrong normal at vertex 4 component 2";
263 
264  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[0] ) << "Wrong normal at vertex 7 component 0";
265  EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[1] ) << "Wrong normal at vertex 7 component 1";
266  EXPECT_EQ(2, mesh_.normal(mesh_.vertex_handle(7))[2] ) << "Wrong normal at vertex 7 component 2";
267 
268  mesh_.release_vertex_normals();
269 
270 }
271 
272 
273 
274 #endif // INCLUDE GUARD

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