From 0e15808378183b498ddd7d368dc58f2d10619753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=B6ller?= Date: Mon, 10 Sep 2012 13:59:42 +0000 Subject: [PATCH] - readd unittests - fix McDecimater random crash refs #1007 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@666 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Tools/Decimater/McDecimaterT.cc | 4 +- src/Unittests/unittests.cc | 1 + src/Unittests/unittests_decimater.hh | 47 +++++++++++++++++++ src/Unittests/unittests_mc_decimater.hh | 48 ++++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/OpenMesh/Tools/Decimater/McDecimaterT.cc b/src/OpenMesh/Tools/Decimater/McDecimaterT.cc index 6a406ca5..af81220e 100644 --- a/src/OpenMesh/Tools/Decimater/McDecimaterT.cc +++ b/src/OpenMesh/Tools/Decimater/McDecimaterT.cc @@ -113,7 +113,7 @@ size_t McDecimaterT::decimate(size_t _n_collapses) { for ( unsigned int i = 0; i < randomSamples_; ++i) { // Random halfedge handle - typename Mesh::HalfedgeHandle tmpHandle = typename Mesh::HalfedgeHandle(double(rand()) / RAND_MAX * mesh_.n_halfedges() ); + typename Mesh::HalfedgeHandle tmpHandle = typename Mesh::HalfedgeHandle((static_cast(rand()) / RAND_MAX) * (mesh_.n_halfedges()-1) ); // if it is not deleted, we analyse it if ( ! mesh_.status(tmpHandle).deleted() ) { @@ -191,7 +191,7 @@ size_t McDecimaterT::decimate_to_faces(size_t _nv, size_t _nf) { for ( unsigned int i = 0; i < randomSamples_; ++i) { // Random halfedge handle - typename Mesh::HalfedgeHandle tmpHandle = typename Mesh::HalfedgeHandle(double(rand()) / RAND_MAX * mesh_.n_halfedges() ); + typename Mesh::HalfedgeHandle tmpHandle = typename Mesh::HalfedgeHandle((static_cast(rand()) / RAND_MAX) * (mesh_.n_halfedges()-1) ); // if it is not deleted, we analyse it if ( ! mesh_.status(tmpHandle).deleted() ) { diff --git a/src/Unittests/unittests.cc b/src/Unittests/unittests.cc index 7d8a5eee..95a6fcab 100644 --- a/src/Unittests/unittests.cc +++ b/src/Unittests/unittests.cc @@ -8,6 +8,7 @@ #include "unittests_trimesh_circulators.hh" #include "unittests_decimater.hh" #include "unittests_mc_decimater.hh" +#include "unittests_mixed_decimater.hh" #include "unittests_subdivider.hh" #include "unittests_trimesh_normal_calculations.hh" #include "unittests_trimesh_others.hh" diff --git a/src/Unittests/unittests_decimater.hh b/src/Unittests/unittests_decimater.hh index 2bc6ca03..7da994c2 100644 --- a/src/Unittests/unittests_decimater.hh +++ b/src/Unittests/unittests_decimater.hh @@ -59,5 +59,52 @@ TEST_F(OpenMeshDecimater, DecimateMesh) { EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; } +TEST_F(OpenMeshDecimater, DecimateMeshToFaceVerticesLimit) { + + 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::ModNormalFlippingT< Mesh >::Handle HModNormal; + + Decimater decimaterDBG(mesh_); + HModQuadric hModQuadricDBG; + decimaterDBG.add( hModQuadricDBG ); + decimaterDBG.initialize(); + int removedVertices = 0; + removedVertices = decimaterDBG.decimate_to_faces(5000, 8000); + decimaterDBG.mesh().garbage_collection(); + + EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!"; + EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; + EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!"; + EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; +} + +TEST_F(OpenMeshDecimater, DecimateMeshToFaceFaceLimit) { + + 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::ModNormalFlippingT< Mesh >::Handle HModNormal; + + Decimater decimaterDBG(mesh_); + HModQuadric hModQuadricDBG; + decimaterDBG.add( hModQuadricDBG ); + decimaterDBG.initialize(); + int removedVertices = 0; + removedVertices = decimaterDBG.decimate_to_faces(4500, 9996); + decimaterDBG.mesh().garbage_collection(); + + EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!"; + EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; + EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!"; + EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; +} #endif // INCLUDE GUARD diff --git a/src/Unittests/unittests_mc_decimater.hh b/src/Unittests/unittests_mc_decimater.hh index 9cc89e78..3f7e7d06 100644 --- a/src/Unittests/unittests_mc_decimater.hh +++ b/src/Unittests/unittests_mc_decimater.hh @@ -59,4 +59,52 @@ TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMesh) { EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; } +TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMeshToFaceVerticesLimit) { + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off"); + + ASSERT_TRUE(ok); + + typedef OpenMesh::Decimater::McDecimaterT< Mesh > Decimater; + typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric; + typedef OpenMesh::Decimater::ModNormalFlippingT< Mesh >::Handle HModNormal; + + Decimater decimaterDBG(mesh_); + HModQuadric hModQuadricDBG; + decimaterDBG.add( hModQuadricDBG ); + decimaterDBG.initialize(); + int removedVertices = 0; + removedVertices = decimaterDBG.decimate_to_faces(5000, 8000); + decimaterDBG.mesh().garbage_collection(); + + EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!"; + EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; + EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!"; + EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; +} + +TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMeshToFaceFaceLimit) { + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off"); + + ASSERT_TRUE(ok); + + typedef OpenMesh::Decimater::McDecimaterT< Mesh > Decimater; + typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric; + typedef OpenMesh::Decimater::ModNormalFlippingT< Mesh >::Handle HModNormal; + + Decimater decimaterDBG(mesh_); + HModQuadric hModQuadricDBG; + decimaterDBG.add( hModQuadricDBG ); + decimaterDBG.initialize(); + int removedVertices = 0; + removedVertices = decimaterDBG.decimate_to_faces(4500, 9996); + decimaterDBG.mesh().garbage_collection(); + + EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!"; + EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!"; + EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!"; + EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!"; +} + #endif // INCLUDE GUARD