From 9c9ea1584050eafcb91468664ebd93f9fb51616c Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 19 Dec 2019 14:00:05 +0100 Subject: [PATCH] add unittest for decimater using normal deviation as binary check --- src/Unittests/unittests_decimater.cc | 37 +++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Unittests/unittests_decimater.cc b/src/Unittests/unittests_decimater.cc index e02780a5..2b7d2376 100644 --- a/src/Unittests/unittests_decimater.cc +++ b/src/Unittests/unittests_decimater.cc @@ -3,6 +3,7 @@ #include #include #include +#include namespace { @@ -49,7 +50,7 @@ TEST_F(OpenMeshDecimater, DecimateMesh) { decimaterDBG.initialize(); size_t removedVertices = 0; removedVertices = decimaterDBG.decimate_to(5000); - decimaterDBG.mesh().garbage_collection(); + decimaterDBG.mesh().garbage_collection(); EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!"; EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; @@ -72,7 +73,7 @@ TEST_F(OpenMeshDecimater, DecimateMeshToFaceVerticesLimit) { decimaterDBG.initialize(); size_t removedVertices = 0; removedVertices = decimaterDBG.decimate_to_faces(5000, 8000); - decimaterDBG.mesh().garbage_collection(); + decimaterDBG.mesh().garbage_collection(); EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!"; EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; @@ -95,7 +96,7 @@ TEST_F(OpenMeshDecimater, DecimateMeshToFaceFaceLimit) { decimaterDBG.initialize(); size_t removedVertices = 0; removedVertices = decimaterDBG.decimate_to_faces(4500, 9996); - decimaterDBG.mesh().garbage_collection(); + decimaterDBG.mesh().garbage_collection(); EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!"; EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; @@ -103,6 +104,34 @@ TEST_F(OpenMeshDecimater, DecimateMeshToFaceFaceLimit) { EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; } + +TEST_F(OpenMeshDecimater, DecimateMeshToVertexLimitWithLowNormalDeviation) { + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off"); + + ASSERT_TRUE(ok); + + typedef OpenMesh::Decimater::DecimaterT< Mesh > Decimater; + typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric; + typedef OpenMesh::Decimater::ModNormalDeviationT< Mesh >::Handle HModNormalDeviation; + + Decimater decimaterDBG(mesh_); + HModQuadric hModQuadricDBG; + decimaterDBG.add( hModQuadricDBG ); + HModNormalDeviation hModNormalDeviation; + decimaterDBG.add( hModNormalDeviation ); + decimaterDBG.module(hModNormalDeviation).set_normal_deviation(15.0); + decimaterDBG.initialize(); + size_t removedVertices = 0; + removedVertices = decimaterDBG.decimate_to(8); + decimaterDBG.mesh().garbage_collection(); + + EXPECT_EQ(6998u, removedVertices) << "The number of remove vertices is not correct!"; + EXPECT_EQ( 528u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; + EXPECT_EQ(1578u, mesh_.n_edges()) << "The number of edges after decimation is not correct!"; + EXPECT_EQ(1052u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; +} + TEST_F(OpenMeshDecimater, DecimateMeshExampleFromDoc) { bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off"); @@ -121,7 +150,7 @@ TEST_F(OpenMeshDecimater, DecimateMeshExampleFromDoc) { decimaterDBG.initialize(); size_t removedVertices = 0; removedVertices = decimaterDBG.decimate_to_faces(4500, 9996); - decimaterDBG.mesh().garbage_collection(); + decimaterDBG.mesh().garbage_collection(); EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!"; EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";