Developer Documentation
unittests_mixed_decimater.cc
1 
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.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 
46 
47  Decimater decimaterDBG(mesh_);
48  HModQuadric hModQuadricDBG;
49  decimaterDBG.add( hModQuadricDBG );
50  decimaterDBG.initialize();
51  size_t removedVertices = 0;
52  removedVertices = decimaterDBG.decimate_to(5000,0.8f);
53  decimaterDBG.mesh().garbage_collection();
54 
55  EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
56  EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
57  EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
58  EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
59 }
60 
61 TEST_F(OpenMeshMixedDecimater, DecimateMeshToFaceVerticesLimit) {
62 
63  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
64 
65  ASSERT_TRUE(ok);
66 
69 
70  Decimater decimaterDBG(mesh_);
71  HModQuadric hModQuadricDBG;
72  decimaterDBG.add( hModQuadricDBG );
73  decimaterDBG.initialize();
74  size_t removedVertices = 0;
75  removedVertices = decimaterDBG.decimate_to_faces(5000, 8000, 0.7f);
76  decimaterDBG.mesh().garbage_collection();
77 
78  EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
79  EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
80  EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
81  EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
82 }
83 
84 TEST_F(OpenMeshMixedDecimater, DecimateMeshToFaceFaceLimit) {
85 
86  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
87 
88  ASSERT_TRUE(ok);
89 
92 
93  Decimater decimaterDBG(mesh_);
94  HModQuadric hModQuadricDBG;
95  decimaterDBG.add( hModQuadricDBG );
96  decimaterDBG.initialize();
97  size_t removedVertices = 0;
98  removedVertices = decimaterDBG.decimate_to_faces(4500, 9996, 0.7f);
99  decimaterDBG.mesh().garbage_collection();
100 
101  EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
102  EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
103  EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
104  EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
105 }
106 
107 class UnittestObserver : public OpenMesh::Decimater::Observer
108 {
109  size_t notifies_;
110  size_t all_steps_;
111 public:
112  explicit UnittestObserver(size_t _steps) :Observer(_steps), notifies_(0), all_steps_(0) {}
113 
114  void notify(size_t _step)
115  {
116  ++notifies_;
117  all_steps_ = _step;
118  }
119  bool abort() const
120  {
121  return all_steps_ >= 2526u;
122  }
123 
124  size_t countedNotifies()
125  {
126  return notifies_;
127  }
128 };
129 
130 TEST_F(OpenMeshMixedDecimater, DecimateMeshStoppedByObserver) {
131 
132  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
133 
134  ASSERT_TRUE(ok);
135 
138 
139  Decimater decimaterDBG(mesh_);
140  HModQuadric hModQuadricDBG;
141  decimaterDBG.add(hModQuadricDBG);
142 
143  decimaterDBG.module(hModQuadricDBG).unset_max_err();
144 
145  decimaterDBG.initialize();
146  UnittestObserver obs(2);
147  decimaterDBG.set_observer(&obs);
148  size_t removedVertices = 0;
149  removedVertices = decimaterDBG.decimate_to_faces(0, 0);
150  decimaterDBG.mesh().garbage_collection();
151 
152  EXPECT_TRUE(obs.abort()) << "Observer did not abort the decimater!";
153  EXPECT_EQ(obs.countedNotifies(), 2526u / 2u) << "Observer did not get the right amount of notifications!";
154 
155  EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
156  EXPECT_EQ(5000u, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
157  EXPECT_EQ(14994u, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
158  EXPECT_EQ(9996u, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
159 }
160 }
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:112
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:75