1 #include <gtest/gtest.h> 2 #include <Unittests/unittests_common.hh> 12 virtual void SetUp() {
18 virtual void TearDown() {
37 TEST_F(OpenMeshReadWritePLY, LoadSimplePointPLYFileWithBadEncoding) {
43 EXPECT_TRUE(ok) <<
"Unable to load pointCloudBadEncoding.ply";
45 EXPECT_EQ(10u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
46 EXPECT_EQ(0u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
47 EXPECT_EQ(0u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
54 TEST_F(OpenMeshReadWritePLY, LoadSimplePointPLYFileWithGoodEncoding) {
60 EXPECT_TRUE(ok) <<
"Unable to load pointCloudGoodEncoding.ply";
62 EXPECT_EQ(10u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
63 EXPECT_EQ(0u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
64 EXPECT_EQ(0u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
70 TEST_F(OpenMeshReadWritePLY, LoadSimplePLY) {
76 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal.ply";
78 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
79 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
80 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
88 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYNoEndl) {
94 EXPECT_TRUE(ok) <<
"Unable to load sphere840.ply";
96 EXPECT_EQ(422u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
97 EXPECT_EQ(1260u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
98 EXPECT_EQ(840u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
105 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYForceVertexColorsAlthoughNotAvailable) {
109 mesh_.request_vertex_colors();
111 std::string file_name =
"cube-minimal.ply";
118 EXPECT_TRUE(ok) << file_name;
120 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
121 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
122 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
123 EXPECT_EQ(36u , mesh_.n_halfedges()) <<
"The number of loaded halfedges is not correct!";
125 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
126 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
127 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
133 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithVertexColors) {
137 mesh_.request_vertex_colors();
144 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-vertexColors.ply";
146 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
147 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
148 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
150 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
151 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
152 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
154 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
155 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
156 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
158 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
159 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
160 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
162 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
163 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
164 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
166 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
167 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
168 EXPECT_TRUE(options.vertex_has_color()) <<
"Wrong user options are returned!";
170 mesh_.release_vertex_colors();
176 TEST_F(OpenMeshReadWritePLY, LoadPLYFromMeshLabWithVertexColors) {
180 mesh_.request_vertex_colors();
187 EXPECT_TRUE(ok) <<
"Unable to load meshlab.ply";
189 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
190 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
191 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
193 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
194 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
195 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
197 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
198 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
199 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
201 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
202 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
203 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
205 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
206 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
207 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
209 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
210 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
211 EXPECT_TRUE(options.vertex_has_color()) <<
"Wrong user options are returned!";
213 mesh_.release_vertex_colors();
219 TEST_F(OpenMeshReadWritePLY, WriteAndReadBinaryPLYWithVertexColors) {
223 mesh_.request_vertex_colors();
230 EXPECT_TRUE(ok) <<
"Unable to load meshlab.ply";
235 EXPECT_TRUE(ok) <<
"Unable to write meshlab_binary.ply";
239 EXPECT_TRUE(ok) <<
"Unable to load meshlab_binary.ply";
241 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
242 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
243 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
245 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
246 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
247 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
249 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
250 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
251 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
253 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
254 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
255 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
257 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
258 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
259 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
261 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
262 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
263 EXPECT_TRUE(options.vertex_has_color()) <<
"Wrong user options are returned!";
265 mesh_.release_vertex_colors();
271 TEST_F(OpenMeshReadWritePLY, WriteAndReadPLYWithFloatVertexColors) {
275 mesh_.request_vertex_colors();
282 EXPECT_TRUE(ok) <<
"Unable to load meshlab.ply";
287 EXPECT_TRUE(ok) <<
"Unable to write meshlab_float.ply";
291 EXPECT_TRUE(ok) <<
"Unable to load meshlab_float.ply";
293 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
294 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
295 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
297 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
298 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
299 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
301 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
302 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
303 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
305 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
306 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
307 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
309 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
310 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
311 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
313 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
314 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
315 EXPECT_TRUE(options.vertex_has_color()) <<
"Wrong user options are returned!";
316 EXPECT_TRUE(options.color_is_float()) <<
"Wrong user options are returned!";
318 mesh_.release_vertex_colors();
324 TEST_F(OpenMeshReadWritePLY, WriteAndReadBinaryPLYWithFloatVertexColors) {
328 mesh_.request_vertex_colors();
335 EXPECT_TRUE(ok) <<
"Unable to load meshlab.ply";
341 EXPECT_TRUE(ok) <<
"Unable to write meshlab_binary_float.ply";
345 EXPECT_TRUE(ok) <<
"Unable to load meshlab_binary_float.ply";
347 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
348 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
349 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
351 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
352 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
353 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(0))[2] ) <<
"Wrong vertex color at vertex 0 component 2";
355 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[0] ) <<
"Wrong vertex color at vertex 3 component 0";
356 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) <<
"Wrong vertex color at vertex 3 component 1";
357 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[2] ) <<
"Wrong vertex color at vertex 3 component 2";
359 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
360 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
361 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) <<
"Wrong vertex color at vertex 4 component 2";
363 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
364 EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
365 EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) <<
"Wrong vertex color at vertex 7 component 2";
367 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
368 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
369 EXPECT_TRUE(options.vertex_has_color()) <<
"Wrong user options are returned!";
370 EXPECT_TRUE(options.color_is_float()) <<
"Wrong user options are returned!";
371 EXPECT_TRUE(options.is_binary()) <<
"Wrong user options are returned!";
373 mesh_.release_vertex_colors();
379 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithTexCoords) {
383 mesh_.request_vertex_texcoords2D();
390 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-texCoords.ply";
392 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
393 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
394 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
396 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) <<
"Wrong vertex color at vertex 0 component 0";
397 EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) <<
"Wrong vertex color at vertex 0 component 1";
399 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) <<
"Wrong vertex color at vertex 2 component 0";
400 EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) <<
"Wrong vertex color at vertex 2 component 1";
402 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) <<
"Wrong vertex color at vertex 4 component 0";
403 EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) <<
"Wrong vertex color at vertex 4 component 1";
405 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) <<
"Wrong vertex color at vertex 7 component 0";
406 EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) <<
"Wrong vertex color at vertex 7 component 1";
409 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
410 EXPECT_TRUE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
411 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
413 mesh_.release_vertex_texcoords2D();
419 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithNormals) {
423 mesh_.request_vertex_normals();
430 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-normals.ply";
432 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
433 EXPECT_EQ(18u , mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
434 EXPECT_EQ(12u , mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
436 EXPECT_TRUE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
437 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
438 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
441 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) <<
"Wrong normal at vertex 0 component 0";
442 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[1] ) <<
"Wrong normal at vertex 0 component 1";
443 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(0))[2] ) <<
"Wrong normal at vertex 0 component 2";
445 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(3))[0] ) <<
"Wrong normal at vertex 3 component 0";
446 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[1] ) <<
"Wrong normal at vertex 3 component 1";
447 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(3))[2] ) <<
"Wrong normal at vertex 3 component 2";
449 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[0] ) <<
"Wrong normal at vertex 4 component 0";
450 EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(4))[1] ) <<
"Wrong normal at vertex 4 component 1";
451 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(4))[2] ) <<
"Wrong normal at vertex 4 component 2";
453 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[0] ) <<
"Wrong normal at vertex 7 component 0";
454 EXPECT_EQ(1, mesh_.normal(mesh_.vertex_handle(7))[1] ) <<
"Wrong normal at vertex 7 component 1";
455 EXPECT_EQ(2, mesh_.normal(mesh_.vertex_handle(7))[2] ) <<
"Wrong normal at vertex 7 component 2";
457 mesh_.release_vertex_normals();
464 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomProps) {
473 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-custom_props.ply";
475 EXPECT_EQ(8u , mesh.n_vertices()) <<
"The number of loaded vertices is not correct!";
476 EXPECT_EQ(12u , mesh.n_edges()) <<
"The number of loaded edges is not correct!";
477 EXPECT_EQ(6u , mesh.n_faces()) <<
"The number of loaded faces is not correct!";
481 ASSERT_TRUE(mesh.get_property_handle(qualityProp,
"quality")) <<
"Could not access quality property";
482 ASSERT_TRUE(mesh.get_property_handle(indexProp,
"index")) <<
"Could not access index property";
485 for (
unsigned i = 0; i < mesh.n_vertices(); ++i)
486 EXPECT_EQ(i ,mesh.property(indexProp,
OpenMesh::VertexHandle(i))) <<
"Vertex index at vertex " << i <<
" is wrong";
490 EXPECT_EQ(0.5f,mesh.property(qualityProp,
OpenMesh::VertexHandle(1))) <<
"Wrong quality value at Vertex 1";
491 EXPECT_EQ(0.7f,mesh.property(qualityProp,
OpenMesh::VertexHandle(2))) <<
"Wrong quality value at Vertex 2";
493 EXPECT_EQ(0.1f,mesh.property(qualityProp,
OpenMesh::VertexHandle(4))) <<
"Wrong quality value at Vertex 4";
501 ASSERT_TRUE(mesh.get_property_handle(testValues,
"test_values")) <<
"Could not access texcoords per face";
515 ASSERT_TRUE(mesh.get_property_handle(texCoordsPerFace,
"texcoords")) <<
"Could not access texcoords per face";
517 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter)
519 EXPECT_EQ(8u, mesh.property(texCoordsPerFace, *f_iter).size()) <<
"Texcoords per face container has wrong size on face: " << f_iter->
idx();
520 if (!mesh.property(texCoordsPerFace, *f_iter).empty())
522 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[0]) <<
"Texcoords wrong on index 0 with face: " << f_iter->idx();
523 EXPECT_EQ(1.0, mesh.property(texCoordsPerFace, *f_iter)[1]) <<
"Texcoords wrong on index 1 with face: " << f_iter->idx();
524 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[2]) <<
"Texcoords wrong on index 2 with face: " << f_iter->idx();
525 EXPECT_EQ(-1.0f, mesh.property(texCoordsPerFace, *f_iter)[3]) <<
"Texcoords wrong on index 3 with face: " << f_iter->idx();
526 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[4]) <<
"Texcoords wrong on index 4 with face: " << f_iter->idx();
527 EXPECT_EQ(0.0f, mesh.property(texCoordsPerFace, *f_iter)[5]) <<
"Texcoords wrong on index 5 with face: " << f_iter->idx();
528 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[6]) <<
"Texcoords wrong on index 6 with face: " << f_iter->idx();
529 EXPECT_EQ(-0.5f, mesh.property(texCoordsPerFace, *f_iter)[7]) <<
"Texcoords wrong on index 7 with face: " << f_iter->idx();
535 ASSERT_TRUE(mesh.get_property_handle(faceIndex,
"faceIndex")) <<
"Could not access faceIndex per face";
537 EXPECT_EQ(0u,mesh.property(faceIndex,
OpenMesh::FaceHandle(0))) <<
"Wrong index value at FaceHandle 0";
538 EXPECT_EQ(1u,mesh.property(faceIndex,
OpenMesh::FaceHandle(1))) <<
"Wrong index value at FaceHandle 1";
539 EXPECT_EQ(2u,mesh.property(faceIndex,
OpenMesh::FaceHandle(2))) <<
"Wrong index value at FaceHandle 2";
540 EXPECT_EQ(3u,mesh.property(faceIndex,
OpenMesh::FaceHandle(3))) <<
"Wrong index value at FaceHandle 3";
541 EXPECT_EQ(4u,mesh.property(faceIndex,
OpenMesh::FaceHandle(4))) <<
"Wrong index value at FaceHandle 4";
542 EXPECT_EQ(5u,mesh.property(faceIndex,
OpenMesh::FaceHandle(5))) <<
"Wrong index value at FaceHandle 5";
547 TEST_F(OpenMeshReadWritePLY, WriteReadSimplePLYWithCustomProps) {
561 const std::string indexPropName =
"mySuperIndexProperty";
562 const std::string qualityPropName =
"quality";
563 const std::string facePropName =
"anotherPropForFaces";
564 const std::string nonPersistantName =
"nonPersistant";
565 const std::string removedPropName =
"willBeRemoved";
567 mesh.add_property(indexProp,indexPropName);
568 mesh.add_property(qualityProp,qualityPropName);
569 mesh.add_property(removedProp, removedPropName);
570 mesh.add_property(faceProp,facePropName);
571 mesh.add_property(nonPersistant,nonPersistantName);
573 mesh.property(indexProp).set_persistent(
true);
574 mesh.property(qualityProp).set_persistent(
true);
575 mesh.property(faceProp).set_persistent(
true);
576 mesh.remove_property(removedProp);
579 for (Mesh::VertexIter v_iter = mesh.vertices_begin(); v_iter != mesh.vertices_end(); ++v_iter, ++i)
581 mesh.property(indexProp, *v_iter) = i;
582 mesh.property(qualityProp, *v_iter) = 3.5*i;
586 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter, ++i)
588 mesh.property(faceProp, *f_iter) = -i;
591 const char* outFilename =
"cube-minimal-customprops_openmeshOutputTestfile.ply";
598 EXPECT_FALSE(loadedMesh.get_property_handle(indexProp,indexPropName)) <<
"Could access to property which was deleted";
606 ASSERT_TRUE(loadedMesh.get_property_handle(indexProp,indexPropName)) <<
"Could not access index property";
607 ASSERT_TRUE(loadedMesh.get_property_handle(qualityProp,qualityPropName)) <<
"Could not access quality property";
608 ASSERT_TRUE(loadedMesh.get_property_handle(faceProp,facePropName)) <<
"Could not access face property";
609 EXPECT_FALSE(loadedMesh.get_property_handle(nonPersistant,nonPersistantName)) <<
"Could access non persistant property";
612 for (Mesh::VertexIter v_iter = loadedMesh.vertices_begin(); v_iter != loadedMesh.vertices_end(); ++v_iter, ++i)
614 EXPECT_EQ(loadedMesh.property(indexProp, *v_iter),
static_cast<unsigned>(i));
615 EXPECT_EQ(loadedMesh.property(qualityProp, *v_iter),3.5*i);
619 for (Mesh::FaceIter f_iter = loadedMesh.faces_begin(); f_iter != loadedMesh.faces_end(); ++f_iter, ++i)
621 EXPECT_EQ(loadedMesh.property(faceProp, *f_iter),-i);
629 TEST_F(OpenMeshReadWritePLY, WriteReadBinaryPLYWithCustomProps) {
643 const std::string indexPropName =
"mySuperIndexProperty";
644 const std::string qualityPropName =
"quality";
645 const std::string facePropName =
"anotherPropForFaces";
646 const std::string nonPersistantName =
"nonPersistant";
647 const std::string removedPropName =
"willBeRemoved";
649 mesh.add_property(indexProp,indexPropName);
650 mesh.add_property(qualityProp,qualityPropName);
651 mesh.add_property(removedProp, removedPropName);
652 mesh.add_property(faceProp,facePropName);
653 mesh.add_property(nonPersistant,nonPersistantName);
655 mesh.property(indexProp).set_persistent(
true);
656 mesh.property(qualityProp).set_persistent(
true);
657 mesh.property(faceProp).set_persistent(
true);
658 mesh.remove_property(removedProp);
661 for (Mesh::VertexIter v_iter = mesh.vertices_begin(); v_iter != mesh.vertices_end(); ++v_iter, ++i)
663 mesh.property(indexProp, *v_iter) = i;
664 mesh.property(qualityProp, *v_iter) = 3.5*i;
668 for (Mesh::FaceIter f_iter = mesh.faces_begin(); f_iter != mesh.faces_end(); ++f_iter, ++i)
670 mesh.property(faceProp, *f_iter) = -i;
673 const char* outFilename =
"cube-minimal-customprops_openmeshOutputTestfileBinary.ply";
681 EXPECT_FALSE(loadedMesh.get_property_handle(indexProp,indexPropName)) <<
"Could access to property which was deleted";
691 ASSERT_TRUE(loadedMesh.get_property_handle(indexProp,indexPropName)) <<
"Could not access index property";
692 ASSERT_TRUE(loadedMesh.get_property_handle(qualityProp,qualityPropName)) <<
"Could not access quality property";
693 ASSERT_TRUE(loadedMesh.get_property_handle(faceProp,facePropName)) <<
"Could not access face property";
694 EXPECT_FALSE(loadedMesh.get_property_handle(nonPersistant,nonPersistantName)) <<
"Could access non persistant property";
697 for (Mesh::VertexIter v_iter = loadedMesh.vertices_begin(); v_iter != loadedMesh.vertices_end(); ++v_iter, ++i)
699 EXPECT_EQ(loadedMesh.property(indexProp, *v_iter),
static_cast<unsigned>(i));
700 EXPECT_EQ(loadedMesh.property(qualityProp, *v_iter),3.5*i);
704 for (Mesh::FaceIter f_iter = loadedMesh.faces_begin(); f_iter != loadedMesh.faces_end(); ++f_iter, ++i)
706 EXPECT_EQ(loadedMesh.property(faceProp, *f_iter),-i);
717 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithExtraElements) {
723 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-extra-elements.ply";
725 EXPECT_EQ(8u, mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
726 EXPECT_EQ(18u, mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
727 EXPECT_EQ(12u, mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
734 TEST_F(OpenMeshReadWritePLY, LoadSimpleBinaryPLYWithExtraElements) {
742 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-extra-elements-binary.ply";
744 EXPECT_EQ(8u, mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
745 EXPECT_EQ(18u, mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
746 EXPECT_EQ(12u, mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
753 TEST_F(OpenMeshReadWritePLY, IgnoreNonMeshPlyFile) {
757 std::stringstream data;
758 data <<
"ply" <<
"\n";
759 data <<
"format binary_little_endian 1.0" <<
"\n";
760 data <<
"comment Image data" <<
"\n";
761 data <<
"element image 0" <<
"\n";
762 data <<
"property list uint16 uint16 row" <<
"\n";
763 data <<
"end_header" <<
"\n";
769 EXPECT_TRUE(ok) <<
"This empty file should be readable without an error!";
771 EXPECT_EQ(0u, mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
772 EXPECT_EQ(0u, mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
773 EXPECT_EQ(0u, mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
780 TEST_F(OpenMeshReadWritePLY, FailOnUnknownPropertyTypeForLists) {
784 std::stringstream data;
785 data <<
"ply" <<
"\n";
786 data <<
"format binary_little_endian 1.0" <<
"\n";
787 data <<
"comment Image data" <<
"\n";
788 data <<
"element image 0" <<
"\n";
789 data <<
"property list blibb blubb row" <<
"\n";
790 data <<
"end_header" <<
"\n";
796 EXPECT_FALSE(ok) <<
"This file should fail to read!";
798 EXPECT_EQ(0u, mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
799 EXPECT_EQ(0u, mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
800 EXPECT_EQ(0u, mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
806 TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithFaceColors) {
810 mesh_.request_face_colors();
817 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-faceColors.ply";
819 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct!";
820 EXPECT_EQ(18u, mesh_.n_edges()) <<
"The number of loaded edges is not correct!";
821 EXPECT_EQ(12u, mesh_.n_faces()) <<
"The number of loaded faces is not correct!";
823 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(0))[0] ) <<
"Wrong face color at face 0";
824 EXPECT_EQ(117, mesh_.color(mesh_.face_handle(0))[1] ) <<
"Wrong face color at face 0";
825 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(0))[2] ) <<
"Wrong face color at face 0";
827 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(3))[0] ) <<
"Wrong face color at face 3";
828 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(3))[1] ) <<
"Wrong face color at face 3";
829 EXPECT_EQ(135, mesh_.color(mesh_.face_handle(3))[2] ) <<
"Wrong face color at face 3";
831 EXPECT_EQ(163, mesh_.color(mesh_.face_handle(4))[0] ) <<
"Wrong face color at face 4";
832 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(4))[1] ) <<
"Wrong face color at face 4";
833 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(4))[2] ) <<
"Wrong face color at face 4";
835 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(7))[0] ) <<
"Wrong face color at face 7";
836 EXPECT_EQ(140, mesh_.color(mesh_.face_handle(7))[1] ) <<
"Wrong face color at face 7";
837 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(7))[2] ) <<
"Wrong face color at face 7";
839 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned!";
840 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned!";
841 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned!";
842 EXPECT_TRUE(options.face_has_color()) <<
"Wrong user options are returned!";
843 EXPECT_FALSE(options.color_has_alpha()) <<
"Wrong user options are returned!";
844 EXPECT_FALSE(options.is_binary()) <<
"Wrong user options are returned!";
846 mesh_.release_face_colors();
852 TEST_F(OpenMeshReadWritePLY, WriteAndReadPLYWithFaceColors) {
855 _outFileName(outFileName),
858 const char* _outFileName;
863 Format(
"cube-minimal-faceColors_ascii_uchar.ply",
865 Format(
"cube-minimal-faceColors_ascii_float.ply",
867 Format(
"cube-minimal-faceColors_binary_uchar.ply",
869 Format(
"cube-minimal-faceColors_binary_float.ply",
873 Format(
"cube-minimal-faceColors_alpha_ascii_uchar.ply",
875 Format(
"cube-minimal-faceColors_alpha_ascii_float.ply",
877 Format(
"cube-minimal-faceColors_alpha_binary_uchar.ply",
879 Format(
"cube-minimal-faceColors_alpha_binary_float.ply",
883 for (
size_t i = 0; i <
sizeof(formats) /
sizeof(Format); ++i)
885 const char* outFileName = formats[i]._outFileName;
889 mesh_.request_face_colors();
896 EXPECT_TRUE(ok) <<
"Unable to load cube-minimal-faceColors.ply";
898 options = formats[i]._options;
901 EXPECT_TRUE(ok) <<
"Unable to write " << outFileName;
907 EXPECT_TRUE(ok) <<
"Unable to load " << outFileName;
909 EXPECT_EQ(8u , mesh_.n_vertices()) <<
"The number of loaded vertices is not correct: " << outFileName;
910 EXPECT_EQ(18u, mesh_.n_edges()) <<
"The number of loaded edges is not correct: " << outFileName;
911 EXPECT_EQ(12u, mesh_.n_faces()) <<
"The number of loaded faces is not correct: " << outFileName;
913 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(0))[0] ) <<
"Wrong face color at face 0: " << outFileName;
914 EXPECT_EQ(117, mesh_.color(mesh_.face_handle(0))[1] ) <<
"Wrong face color at face 0: " << outFileName;
915 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(0))[2] ) <<
"Wrong face color at face 0: " << outFileName;
917 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(3))[0] ) <<
"Wrong face color at face 3: " << outFileName;
918 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(3))[1] ) <<
"Wrong face color at face 3: " << outFileName;
919 EXPECT_EQ(135, mesh_.color(mesh_.face_handle(3))[2] ) <<
"Wrong face color at face 3: " << outFileName;
921 EXPECT_EQ(163, mesh_.color(mesh_.face_handle(4))[0] ) <<
"Wrong face color at face 4: " << outFileName;
922 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(4))[1] ) <<
"Wrong face color at face 4: " << outFileName;
923 EXPECT_EQ(177, mesh_.color(mesh_.face_handle(4))[2] ) <<
"Wrong face color at face 4: " << outFileName;
925 EXPECT_EQ(255, mesh_.color(mesh_.face_handle(7))[0] ) <<
"Wrong face color at face 7: " << outFileName;
926 EXPECT_EQ(140, mesh_.color(mesh_.face_handle(7))[1] ) <<
"Wrong face color at face 7: " << outFileName;
927 EXPECT_EQ(107, mesh_.color(mesh_.face_handle(7))[2] ) <<
"Wrong face color at face 7: " << outFileName;
929 EXPECT_FALSE(options.vertex_has_normal()) <<
"Wrong user options are returned: " << outFileName;
930 EXPECT_FALSE(options.vertex_has_texcoord()) <<
"Wrong user options are returned: " << outFileName;
931 EXPECT_FALSE(options.vertex_has_color()) <<
"Wrong user options are returned: " << outFileName;
932 EXPECT_TRUE(options.face_has_color()) <<
"Wrong user options are returned: " << outFileName;
933 EXPECT_EQ(formats[i]._options.color_is_float(), options.color_is_float()) <<
934 "Wrong user options are returned: " << outFileName;
935 EXPECT_EQ(formats[i]._options.is_binary(), options.is_binary()) <<
936 "Wrong user options are returned: " << outFileName;
938 mesh_.release_face_colors();
Has (r) / store (w) vertex colors.
Handle for a vertex entity.
Has (r) / store (w) face colors.
Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ...
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
Has (r) / store (w) texture coordinates.
Handle for a face entity.
void clear(void)
Clear all bits.
Has (r) custom properties (currently only implemented in PLY Reader ASCII version) ...
Set options for reader/writer modules.
Has (r) / store (w) alpha values for colors.
int idx() const
Get the underlying index of this handle.
Has (r) / store (w) vertex normals.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.