From d1ce0efb547a2116e5313489bac895a5136042d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=B6ller?= Date: Thu, 11 Jun 2015 11:15:35 +0000 Subject: [PATCH] add write unittest for binary files refs #2497 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1281 fdac6126-5c0c-442c-9429-916003d36597 --- src/Unittests/unittests_read_write_STL.cc | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/Unittests/unittests_read_write_STL.cc b/src/Unittests/unittests_read_write_STL.cc index c61146b6..b5781b45 100644 --- a/src/Unittests/unittests_read_write_STL.cc +++ b/src/Unittests/unittests_read_write_STL.cc @@ -130,4 +130,79 @@ TEST_F(OpenMeshReadWriteSTL, LoadSimpleSTLBinaryFileWithNormals) { mesh_.release_face_normals(); } +/* + * Read and Write stl binary file + */ +TEST_F(OpenMeshReadWriteSTL, ReadWriteSimpleSTLBinaryFile) { + + mesh_.clear(); + + OpenMesh::IO::Options opt; + opt += OpenMesh::IO::Options::Binary; + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1Binary.stl"); + + EXPECT_TRUE(ok); + + const char* filename = "cube1Binary_openmeshWriteTestFile.stl"; + + ok = OpenMesh::IO::write_mesh(mesh_, filename, opt); + + EXPECT_TRUE(ok); + + ok = OpenMesh::IO::read_mesh(mesh_, filename, opt); + + EXPECT_TRUE(ok); + + EXPECT_EQ(7526u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + EXPECT_EQ(22572u , mesh_.n_edges()) << "The number of loaded edges is not correct!"; + EXPECT_EQ(15048u , mesh_.n_faces()) << "The number of loaded faces is not correct!"; + + remove(filename); +} + +/* + * Just load a simple mesh file in stlb format and count whether + * the right number of entities has been loaded. Also check facet normals. + */ +TEST_F(OpenMeshReadWriteSTL, ReadWriteSimpleSTLBinaryFileWithNormals) { + + mesh_.clear(); + mesh_.request_face_normals(); + + OpenMesh::IO::Options opt; + opt += OpenMesh::IO::Options::FaceNormal; + opt += OpenMesh::IO::Options::Binary; + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1Binary.stl", opt); + + EXPECT_TRUE(ok); + + const char* filename = "cube1BinaryNormal_openmeshWriteTestFile.stl"; + + ok = OpenMesh::IO::write_mesh(mesh_, filename, opt); + + EXPECT_TRUE(ok); + + ok = OpenMesh::IO::read_mesh(mesh_, filename, opt); + + EXPECT_TRUE(ok); + + EXPECT_TRUE(opt.is_binary()); + EXPECT_TRUE(opt.face_has_normal()); + EXPECT_FALSE(opt.vertex_has_normal()); + + EXPECT_NEAR(-0.038545f, mesh_.normal(mesh_.face_handle(0))[0], 0.0001 ) << "Wrong face normal at face 0 component 0"; + EXPECT_NEAR(-0.004330f, mesh_.normal(mesh_.face_handle(0))[1], 0.0001 ) << "Wrong face normal at face 0 component 1"; + EXPECT_NEAR(0.999247f, mesh_.normal(mesh_.face_handle(0))[2], 0.0001 ) << "Wrong face normal at face 0 component 2"; + + EXPECT_EQ(7526u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!"; + EXPECT_EQ(22572u , mesh_.n_edges()) << "The number of loaded edges is not correct!"; + EXPECT_EQ(15048u , mesh_.n_faces()) << "The number of loaded faces is not correct!"; + + mesh_.release_face_normals(); + remove(filename); +} + + }