From 9c9ea1584050eafcb91468664ebd93f9fb51616c Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 19 Dec 2019 14:00:05 +0100 Subject: [PATCH 1/4] 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!"; From 52d3ad9332b288197e7d78f3e2f6cde91d4c428b Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 19 Dec 2019 14:04:59 +0100 Subject: [PATCH 2/4] templatize NormalConeT over Vector instead of Scalar to allow for other types of vectors (eg Eigen) --- src/OpenMesh/Core/Geometry/NormalConeT.hh | 6 +++-- .../Core/Geometry/NormalConeT_impl.hh | 22 +++++++++---------- .../Tools/Decimater/ModNormalDeviationT.hh | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/OpenMesh/Core/Geometry/NormalConeT.hh b/src/OpenMesh/Core/Geometry/NormalConeT.hh index 9baaf588..0b1cc6a1 100644 --- a/src/OpenMesh/Core/Geometry/NormalConeT.hh +++ b/src/OpenMesh/Core/Geometry/NormalConeT.hh @@ -60,6 +60,7 @@ #include +#include //== NAMESPACES =============================================================== @@ -77,13 +78,14 @@ namespace OpenMesh { the center normal and the opening angle. **/ -template +template class NormalConeT { public: // typedefs - typedef VectorT Vec3; + typedef typename vector_traits::value_type Scalar; + typedef Vector Vec3; //! default constructor (not initialized) diff --git a/src/OpenMesh/Core/Geometry/NormalConeT_impl.hh b/src/OpenMesh/Core/Geometry/NormalConeT_impl.hh index 487e2490..ed9ce908 100644 --- a/src/OpenMesh/Core/Geometry/NormalConeT_impl.hh +++ b/src/OpenMesh/Core/Geometry/NormalConeT_impl.hh @@ -70,8 +70,8 @@ namespace OpenMesh { //== IMPLEMENTATION ========================================================== -template -NormalConeT:: +template +NormalConeT:: NormalConeT(const Vec3& _center_normal, Scalar _angle) : center_normal_(_center_normal), angle_(_angle) { @@ -81,9 +81,9 @@ NormalConeT(const Vec3& _center_normal, Scalar _angle) //---------------------------------------------------------------------------- -template -Scalar -NormalConeT:: +template +typename NormalConeT::Scalar +NormalConeT:: max_angle(const Vec3& _norm) const { Scalar dotp = (center_normal_ | _norm); @@ -95,9 +95,9 @@ max_angle(const Vec3& _norm) const //---------------------------------------------------------------------------- -template -Scalar -NormalConeT:: +template +typename NormalConeT::Scalar +NormalConeT:: max_angle(const NormalConeT& _cone) const { Scalar dotp = (center_normal_ | _cone.center_normal_); @@ -112,12 +112,12 @@ max_angle(const NormalConeT& _cone) const //---------------------------------------------------------------------------- -template +template void -NormalConeT:: +NormalConeT:: merge(const NormalConeT& _cone) { - Scalar dotp = (center_normal_ | _cone.center_normal_); + Scalar dotp = dot(center_normal_, _cone.center_normal_); if (fabs(dotp) < 0.99999f) { diff --git a/src/OpenMesh/Tools/Decimater/ModNormalDeviationT.hh b/src/OpenMesh/Tools/Decimater/ModNormalDeviationT.hh index 9966d826..b3ea88e7 100644 --- a/src/OpenMesh/Tools/Decimater/ModNormalDeviationT.hh +++ b/src/OpenMesh/Tools/Decimater/ModNormalDeviationT.hh @@ -97,7 +97,7 @@ public: typedef typename Mesh::VertexHandle VertexHandle; typedef typename Mesh::FaceHandle FaceHandle; typedef typename Mesh::EdgeHandle EdgeHandle; - typedef NormalConeT NormalCone; + typedef NormalConeT NormalCone; From a26ee5d3ef9a903df6c675f43d10438b64aaec86 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 19 Dec 2019 14:08:00 +0100 Subject: [PATCH 3/4] add a unittest for the decimater --- src/Unittests/unittests_eigen3_type.cc | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Unittests/unittests_eigen3_type.cc b/src/Unittests/unittests_eigen3_type.cc index 7be54b70..32be1046 100644 --- a/src/Unittests/unittests_eigen3_type.cc +++ b/src/Unittests/unittests_eigen3_type.cc @@ -7,6 +7,9 @@ #include #include +#include +#include +#include #include @@ -232,6 +235,37 @@ TEST_F(OpenMeshEigenTest, LoadSimpleOFFFile) { mesh_.update_normals(); } +// Test decimation with Eigen as vector type +TEST_F(OpenMeshEigenTest, Decimater) { + mesh_.clear(); + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off"); + + 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!"; + + mesh_.update_normals(); + + OpenMesh::Decimater::DecimaterT decimater(mesh_); + OpenMesh::Decimater::ModQuadricT::Handle hModQuadric; // use a quadric module + OpenMesh::Decimater::ModNormalDeviationT::Handle hModNormalDeviation; // also use normal deviation module as binary check + decimater.add(hModQuadric); + decimater.add(hModNormalDeviation); + decimater.module(hModQuadric).unset_max_err(); + decimater.module(hModNormalDeviation).set_normal_deviation(15); + decimater.initialize(); + size_t removedVertices = decimater.decimate_to(8); + 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!"; +} + } #endif From f9323290c78e5fdcb175e89ba8b3b4f74ffcfb4e Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Thu, 19 Dec 2019 14:14:31 +0100 Subject: [PATCH 4/4] update changelog --- Doc/changelog.docu | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/changelog.docu b/Doc/changelog.docu index c335c46e..5b291fd1 100644 --- a/Doc/changelog.docu +++ b/Doc/changelog.docu @@ -29,6 +29,7 @@
  • Subdivider: Fixed crash in Loop subdivider
  • Subdivider: Fixed crash in ModifiedButterfly subdivider
  • +
  • Decimater: Fixed ModNormalDeviationT not working for meshes with Eigen Vectors as vector type