OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unittests_mc_decimater.hh
1 #ifndef INCLUDE_UNITTESTS_MC_DECIMATER_HH
2 #define INCLUDE_UNITTESTS_MC_DECIMATER_HH
3
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6 #include <OpenMesh/Tools/Decimater/McDecimaterT.hh>
7 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
8 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
9
10 class OpenMeshMultipleChoiceDecimater : public OpenMeshBase {
11
12 protected:
13
14 // This function is called before each test is run
15 virtual void SetUp() {
16
17 // Do some initial stuff with the member data here...
18 }
19
20 // This function is called after all tests are through
21 virtual void TearDown() {
22
23 // Do some final stuff with the member data here...
24 }
25
26 // Member already defined in OpenMeshBase
27 //Mesh mesh_;
28 };
29
30 /*
31 * ====================================================================
32 * Define tests below
33 * ====================================================================
34 */
35
36 /*
37 */
38 TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMesh) {
39
40 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
41
42 ASSERT_TRUE(ok);
43
44 typedef OpenMesh::Decimater::McDecimaterT< Mesh > Decimater;
45 typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric;
46 typedef OpenMesh::Decimater::ModNormalFlippingT< Mesh >::Handle HModNormal;
47
48 Decimater decimaterDBG(mesh_);
49 HModQuadric hModQuadricDBG;
50 decimaterDBG.add( hModQuadricDBG );
51 decimaterDBG.initialize();
52 int removedVertices = 0;
53 removedVertices = decimaterDBG.decimate_to(5000);
54 decimaterDBG.mesh().garbage_collection();
55
56 EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!";
57 EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
58 EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
59 EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
60 }
61
62 TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMeshToFaceVerticesLimit) {
63
64 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
65
66 ASSERT_TRUE(ok);
67
68 typedef OpenMesh::Decimater::McDecimaterT< Mesh > Decimater;
69 typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric;
70 typedef OpenMesh::Decimater::ModNormalFlippingT< Mesh >::Handle HModNormal;
71
72 Decimater decimaterDBG(mesh_);
73 HModQuadric hModQuadricDBG;
74 decimaterDBG.add( hModQuadricDBG );
75 decimaterDBG.initialize();
76 int removedVertices = 0;
77 removedVertices = decimaterDBG.decimate_to_faces(5000, 8000);
78 decimaterDBG.mesh().garbage_collection();
79
80 EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!";
81 EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
82 EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
83 EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
84 }
85
86 TEST_F(OpenMeshMultipleChoiceDecimater, DecimateMeshToFaceFaceLimit) {
87
88 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
89
90 ASSERT_TRUE(ok);
91
92 typedef OpenMesh::Decimater::McDecimaterT< Mesh > Decimater;
93 typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric;
94 typedef OpenMesh::Decimater::ModNormalFlippingT< Mesh >::Handle HModNormal;
95
96 Decimater decimaterDBG(mesh_);
97 HModQuadric hModQuadricDBG;
98 decimaterDBG.add( hModQuadricDBG );
99 decimaterDBG.initialize();
100 int removedVertices = 0;
101 removedVertices = decimaterDBG.decimate_to_faces(4500, 9996);
102 decimaterDBG.mesh().garbage_collection();
103
104 EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!";
105 EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
106 EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
107 EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
108 }
109
110 #endif // INCLUDE GUARD