Developer Documentation

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
unittests_mixed_decimater.cc
1
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 #include <OpenMesh/Tools/Decimater/MixedDecimaterT.hh>
5 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
6 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
7
8 namespace {
9
10 class OpenMeshMixedDecimater : 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(OpenMeshMixedDecimater, DecimateMesh80PercentMc) {
39
40 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
41
42 ASSERT_TRUE(ok);
43
44 typedef OpenMesh::Decimater::MixedDecimaterT< 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 size_t removedVertices = 0;
53 removedVertices = decimaterDBG.decimate_to(5000,0.8f);
54 decimaterDBG.mesh().garbage_collection();
55
56 EXPECT_EQ(2526u, 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(OpenMeshMixedDecimater, DecimateMeshToFaceVerticesLimit) {
63
64 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
65
66 ASSERT_TRUE(ok);
67
68 typedef OpenMesh::Decimater::MixedDecimaterT< 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 size_t removedVertices = 0;
77 removedVertices = decimaterDBG.decimate_to_faces(5000, 8000, 0.7f);
78 decimaterDBG.mesh().garbage_collection();
79
80 EXPECT_EQ(2526u, 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(OpenMeshMixedDecimater, DecimateMeshToFaceFaceLimit) {
87
88 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
89
90 ASSERT_TRUE(ok);
91
92 typedef OpenMesh::Decimater::MixedDecimaterT< 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 size_t removedVertices = 0;
101 removedVertices = decimaterDBG.decimate_to_faces(4500, 9996, 0.7f);
102 decimaterDBG.mesh().garbage_collection();
103
104 EXPECT_EQ(2526u, 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 class UnittestObserver : public OpenMesh::Decimater::Observer
111 {
112 size_t notifies_;
113 size_t all_steps_;
114 public:
115 UnittestObserver(size_t _steps) :Observer(_steps), notifies_(0), all_steps_(0) {}
116
117 void notify(size_t _step)
118 {
119 ++notifies_;
120 all_steps_ = _step;
121 }
122 bool abort() const
123 {
124 return all_steps_ >= 2526u;
125 }
126
127 size_t countedNotifies()
128 {
129 return notifies_;
130 }
131 };
132
133 TEST_F(OpenMeshMixedDecimater, DecimateMeshStoppedByObserver) {
134
135 bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
136
137 ASSERT_TRUE(ok);
138
139 typedef OpenMesh::Decimater::MixedDecimaterT< Mesh > Decimater;
140 typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric;
141
142 Decimater decimaterDBG(mesh_);
143 HModQuadric hModQuadricDBG;
144 decimaterDBG.add(hModQuadricDBG);
145
146 decimaterDBG.module(hModQuadricDBG).unset_max_err();
147
148 decimaterDBG.initialize();
149 UnittestObserver obs(2);
150 decimaterDBG.set_observer(&obs);
151 size_t removedVertices = 0;
152 removedVertices = decimaterDBG.decimate_to_faces(0, 0);
153 decimaterDBG.mesh().garbage_collection();
154
155 EXPECT_TRUE(obs.abort()) << "Observer did not abort the decimater!";
156 EXPECT_EQ(obs.countedNotifies(), 2526u / 2u) << "Observer did not get the right amount of notifications!";
157
158 EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
159 EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
160 EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
161 EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
162 }
163 }
OpenMesh::Decimater::Observer
Observer class.
Definition: Observer.hh:82
OpenMesh::IO::read_mesh
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
OpenMeshBase
Definition: unittests_common.hh:21
OpenMesh::Decimater::ModQuadricT
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:83
OpenMesh::Decimater::MixedDecimaterT
Definition: MixedDecimaterT.hh:83
OpenMesh::Decimater::Observer::notify
virtual void notify(size_t _step)=0
callback
ModQuadricT.hh
OpenMesh::Decimater::Observer::abort
virtual bool abort() const
Abort callback.
Definition: Observer.cc:88
OpenMesh::Decimater::ModNormalFlippingT
Definition: ModNormalFlippingT.hh:85
ModNormalFlippingT.hh