OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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(7526u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
47 EXPECT_EQ(22572u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
48 EXPECT_EQ(15048u, 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(7526u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
66 EXPECT_EQ(22572u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
67 EXPECT_EQ(15048u , 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(7526u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
85 EXPECT_EQ(22572u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
86 EXPECT_EQ(15048u , 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(10u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
104 EXPECT_EQ(0u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
105 EXPECT_EQ(0u , 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(10u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
121 EXPECT_EQ(0u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
122 EXPECT_EQ(0u , 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(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
138 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
139 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
140 }
141
142 /*
143 * Just load a obj file of a cube and checks the halfedge and vertex normals
144 */
145 TEST_F(OpenMeshLoader, LoadSimpleOBJCheckHalfEdgeAndVertexNormals) {
146
147 mesh_.clear();
148
149 mesh_.request_halfedge_normals();
150 mesh_.request_vertex_normals();
151
152 OpenMesh::IO::Options options;
153 options += OpenMesh::IO::Options::VertexNormal;
154
155 std::string file_name = "cube-minimal.obj";
156
157 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
158
159 EXPECT_TRUE(ok) << file_name;
160
161 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
162 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
163 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
164 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
165
167 //check vertex normals
168 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong vertex normal at vertex 0 component 0";
169 EXPECT_EQ(-1, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong vertex normal at vertex 0 component 1";
170 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[2] ) << "Wrong vertex normal at vertex 0 component 2";
171
172 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[0] ) << "Wrong vertex normal at vertex 3 component 0";
173 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) << "Wrong vertex normal at vertex 3 component 1";
174 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[2] ) << "Wrong vertex normal at vertex 3 component 2";
175
176 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[0] ) << "Wrong vertex normal at vertex 4 component 0";
177 EXPECT_EQ(-1, mesh_.normal(mesh_.vertex_handle(4))[1] ) << "Wrong vertex normal at vertex 4 component 1";
178 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[2] ) << "Wrong vertex normal at vertex 4 component 2";
179
180 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(7))[0] ) << "Wrong vertex normal at vertex 7 component 0";
181 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(7))[1] ) << "Wrong vertex normal at vertex 7 component 1";
182 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[2] ) << "Wrong vertex normal at vertex 7 component 2";
183
185 //check halfedge normals
186 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(0))[0] ) << "Wrong halfedge normal at halfedge 0 component 0";
187 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(0))[1] ) << "Wrong halfedge normal at halfedge 0 component 1";
188 EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(0))[2] ) << "Wrong halfedge normal at halfedge 0 component 2";
189
190 EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(10))[0] ) << "Wrong halfedge normal at halfedge 10 component 0";
191 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(10))[1] ) << "Wrong halfedge normal at halfedge 10 component 1";
192 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(10))[2] ) << "Wrong halfedge normal at halfedge 10 component 2";
193
194 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(19))[0] ) << "Wrong halfedge normal at halfedge 19 component 0";
195 EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(19))[1] ) << "Wrong halfedge normal at halfedge 19 component 1";
196 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(19))[2] ) << "Wrong halfedge normal at halfedge 19 component 2";
197
198 EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(24))[0] ) << "Wrong halfedge normal at halfedge 24 component 0";
199 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(24))[1] ) << "Wrong halfedge normal at halfedge 24 component 1";
200 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(24))[2] ) << "Wrong halfedge normal at halfedge 24 component 2";
201
202 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(30))[0] ) << "Wrong halfedge normal at halfedge 30 component 0";
203 EXPECT_EQ(-1, mesh_.normal(mesh_.halfedge_handle(30))[1] ) << "Wrong halfedge normal at halfedge 30 component 1";
204 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(30))[2] ) << "Wrong halfedge normal at halfedge 30 component 2";
205
206 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(35))[0] ) << "Wrong halfedge normal at halfedge 35 component 0";
207 EXPECT_EQ(0, mesh_.normal(mesh_.halfedge_handle(35))[1] ) << "Wrong halfedge normal at halfedge 35 component 1";
208 EXPECT_EQ(1, mesh_.normal(mesh_.halfedge_handle(35))[2] ) << "Wrong halfedge normal at halfedge 35 component 2";
209
210 mesh_.release_vertex_normals();
211 mesh_.release_halfedge_normals();
212
213 }
214
215 /*
216 * Just load a obj file and set vertex color option before loading
217 */
218 TEST_F(OpenMeshLoader, LoadSimpleOBJForceVertexColorsAlthoughNotAvailable) {
219
220 mesh_.clear();
221
222 mesh_.request_vertex_colors();
223
224 std::string file_name = "cube-minimal.obj";
225
226 OpenMesh::IO::Options options;
227 options += OpenMesh::IO::Options::VertexColor;
228
229 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
230
231 EXPECT_TRUE(ok) << file_name;
232
233 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
234 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
235 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
236 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
237
238 }
239
240
241 /*
242 * Just load a obj file of a cube and checks the halfedge texCoords
243 */
244 TEST_F(OpenMeshLoader, LoadSimpleOBJCheckTexCoords) {
245
246 mesh_.clear();
247
248 mesh_.request_halfedge_texcoords2D();
249
250 OpenMesh::IO::Options options;
251 options += OpenMesh::IO::Options::FaceTexCoord;
252
253 std::string file_name = "cube-minimal-texCoords.obj";
254
255 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
256
257 EXPECT_TRUE(ok) << file_name;
258
259 EXPECT_EQ(1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[0] ) << "Wrong texCoord at halfedge 0 component 0";
260 EXPECT_EQ(1, mesh_.texcoord2D(mesh_.halfedge_handle(0))[1] ) << "Wrong texCoord at halfedge 0 component 1";
261
262 EXPECT_EQ(3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[0] ) << "Wrong texCoord at halfedge 1 component 0";
263 EXPECT_EQ(3, mesh_.texcoord2D(mesh_.halfedge_handle(10))[1] ) << "Wrong texCoord at halfedge 1 component 1";
264
265 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.halfedge_handle(19))[0] ) << "Wrong texCoord at halfedge 4 component 0";
266 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.halfedge_handle(19))[1] ) << "Wrong texCoord at halfedge 4 component 1";
267
268 EXPECT_EQ(7, mesh_.texcoord2D(mesh_.halfedge_handle(24))[0] ) << "Wrong texCoord at halfedge 7 component 0";
269 EXPECT_EQ(7, mesh_.texcoord2D(mesh_.halfedge_handle(24))[1] ) << "Wrong texCoord at halfedge 7 component 1";
270
271 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.halfedge_handle(30))[0] ) << "Wrong texCoord at halfedge 9 component 0";
272 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.halfedge_handle(30))[1] ) << "Wrong texCoord at halfedge 9 component 1";
273
274 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.halfedge_handle(35))[0] ) << "Wrong texCoord at halfedge 11 component 0";
275 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.halfedge_handle(35))[1] ) << "Wrong texCoord at halfedge 11 component 1";
276
277 mesh_.release_halfedge_texcoords2D();
278 }
279
280
281 /*
282 * Just load a obj file of a cube with vertex colors defined directly after the vertex definitions
283 */
284 TEST_F(OpenMeshLoader, LoadSimpleOBJWithVertexColorsAfterVertices) {
285
286 mesh_.clear();
287
288 mesh_.request_vertex_colors();
289
290 OpenMesh::IO::Options options;
291 options += OpenMesh::IO::Options::VertexColor;
292
293 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertex-colors-after-vertex-definition.obj",options);
294
295 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertex-colors-after-vertex-definition.obj";
296
297 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
298 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
299 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
300
301 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
302 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
303 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
304
305 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
306 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
307 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
308
309 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
310 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
311 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
312
313 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
314 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
315 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
316
317 mesh_.release_vertex_colors();
318 }
319
320 /*
321 * Just load a obj file of a cube with vertex colors defined as separate lines
322 */
323 TEST_F(OpenMeshLoader, LoadSimpleOBJWithVertexColorsAsVCLines) {
324
325 mesh_.clear();
326
327 mesh_.request_vertex_colors();
328
329 OpenMesh::IO::Options options;
330 options += OpenMesh::IO::Options::VertexColor;
331
332 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertex-colors-as-vc-lines.obj",options);
333
334 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertex-colors-as-vc-lines.obj";
335
336 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
337 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
338 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
339
340 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
341 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
342 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
343
344 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
345 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
346 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
347
348 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
349 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
350 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
351
352 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
353 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
354 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
355
356 mesh_.release_vertex_colors();
357
358 }
359
360 /*
361 * Just load a ply
362 */
363 TEST_F(OpenMeshLoader, LoadSimplePLY) {
364
365 mesh_.clear();
366
367 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal.ply");
368
369 EXPECT_TRUE(ok) << "Unable to load cube-minimal.ply";
370
371 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
372 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
373 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
374
375 }
376
377 /*
378 * Just load a ply file and set vertex color option before loading
379 */
380 TEST_F(OpenMeshLoader, LoadSimplePLYForceVertexColorsAlthoughNotAvailable) {
381
382 mesh_.clear();
383
384 mesh_.request_vertex_colors();
385
386 std::string file_name = "cube-minimal.ply";
387
388 OpenMesh::IO::Options options;
389 options += OpenMesh::IO::Options::VertexColor;
390
391 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
392
393 EXPECT_TRUE(ok) << file_name;
394
395 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
396 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
397 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
398 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
399
400 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
401 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
402 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
403 }
404
405 /*
406 * Just load a ply file of a cube with vertex colors
407 */
408 TEST_F(OpenMeshLoader, LoadSimplePLYWithVertexColors) {
409
410 mesh_.clear();
411
412 mesh_.request_vertex_colors();
413
414 OpenMesh::IO::Options options;
415 options += OpenMesh::IO::Options::VertexColor;
416
417 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.ply",options);
418
419 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.ply";
420
421 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
422 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
423 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
424
425 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
426 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
427 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
428
429 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
430 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
431 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
432
433 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
434 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
435 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
436
437 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
438 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
439 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
440
441 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
442 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
443 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
444
445 mesh_.release_vertex_colors();
446 }
447
448 /*
449 * Just load a ply file of a cube with vertex texCoords
450 */
451 TEST_F(OpenMeshLoader, LoadSimplePLYWithTexCoords) {
452
453 mesh_.clear();
454
455 mesh_.request_vertex_texcoords2D();
456
457 OpenMesh::IO::Options options;
458 options += OpenMesh::IO::Options::VertexTexCoord;
459
460 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.ply",options);
461
462 EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.ply";
463
464 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
465 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
466 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
467
468 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
469 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
470
471 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0";
472 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1";
473
474 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
475 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
476
477 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
478 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
479
480
481 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
482 EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
483 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
484
485 mesh_.release_vertex_texcoords2D();
486 }
487
488 /*
489 * Just load a ply with normals, ascii mode
490 */
491 TEST_F(OpenMeshLoader, LoadSimplePLYWithNormals) {
492
493 mesh_.clear();
494
495 mesh_.request_vertex_normals();
496
497 OpenMesh::IO::Options options;
498 options += OpenMesh::IO::Options::VertexNormal;
499
500 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-normals.ply", options);
501
502 EXPECT_TRUE(ok) << "Unable to load cube-minimal-normals.ply";
503
504 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
505 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
506 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
507
508 EXPECT_TRUE(options.vertex_has_normal()) << "Wrong user options are returned!";
509 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
510 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
511
512
513 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong normal at vertex 0 component 0";
514 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong normal at vertex 0 component 1";
515 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(0))[2] ) << "Wrong normal at vertex 0 component 2";
516
517 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[0] ) << "Wrong normal at vertex 3 component 0";
518 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) << "Wrong normal at vertex 3 component 1";
519 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[2] ) << "Wrong normal at vertex 3 component 2";
520
521 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[0] ) << "Wrong normal at vertex 4 component 0";
522 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[1] ) << "Wrong normal at vertex 4 component 1";
523 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[2] ) << "Wrong normal at vertex 4 component 2";
524
525 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[0] ) << "Wrong normal at vertex 7 component 0";
526 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[1] ) << "Wrong normal at vertex 7 component 1";
527 EXPECT_EQ(2, mesh_.normal(mesh_.vertex_handle(7))[2] ) << "Wrong normal at vertex 7 component 2";
528
529 mesh_.release_vertex_normals();
530
531 }
532
533 /*
534 * Just load an om file and set vertex color option before loading
535 */
536 TEST_F(OpenMeshLoader, LoadSimpleOMForceVertexColorsAlthoughNotAvailable) {
537
538 mesh_.clear();
539
540 mesh_.request_vertex_colors();
541
542 std::string file_name = "cube-minimal.om";
543
544 OpenMesh::IO::Options options;
545 options += OpenMesh::IO::Options::VertexColor;
546
547 bool ok = OpenMesh::IO::read_mesh(mesh_, file_name,options);
548
549 EXPECT_TRUE(ok) << file_name;
550
551 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
552 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
553 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
554 EXPECT_EQ(36u , mesh_.n_halfedges()) << "The number of loaded halfedges is not correct!";
555
556 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
557 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
558 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
559 }
560
561 /*
562 * Just load an om file of a cube with vertex texCoords
563 */
564 TEST_F(OpenMeshLoader, LoadSimpleOMWithTexCoords) {
565
566 mesh_.clear();
567
568 mesh_.request_vertex_texcoords2D();
569
570 OpenMesh::IO::Options options;
571 options += OpenMesh::IO::Options::VertexTexCoord;
572
573 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.om",options);
574
575 EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.om";
576
577 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
578 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
579 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
580
581 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
582 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
583
584 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0";
585 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1";
586
587 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
588 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
589
590 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
591 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
592
593
594 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
595 EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
596 EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
597
598 mesh_.release_vertex_texcoords2D();
599 }
600
601 /*
602 * Just load an om file of a cube with vertex colors
603 */
604 TEST_F(OpenMeshLoader, LoadSimpleOMWithVertexColors) {
605
606 mesh_.clear();
607
608 mesh_.request_vertex_colors();
609
610 OpenMesh::IO::Options options;
611 options += OpenMesh::IO::Options::VertexColor;
612
613 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.om",options);
614
615 EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.om";
616
617 EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
618 EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
619 EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
620
621 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
622 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
623 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2";
624
625 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
626 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
627 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
628
629 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
630 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
631 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
632
633 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
634 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
635 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
636
637 EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
638 EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
639 EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
640
641 mesh_.release_vertex_colors();
642 }
643
644 #endif // INCLUDE GUARD