unittests_decimater.cc 6.18 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4 5

#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <OpenMesh/Tools/Decimater/DecimaterT.hh>
#include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
6
#include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
Jan Möbius's avatar
Jan Möbius committed
7

8 9
namespace {

Jan Möbius's avatar
Jan Möbius committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
class OpenMeshDecimater : public OpenMeshBase {

    protected:

        // This function is called before each test is run
        virtual void SetUp() {
            
            // Do some initial stuff with the member data here...
        }

        // This function is called after all tests are through
        virtual void TearDown() {

            // Do some final stuff with the member data here...
        }

    // Member already defined in OpenMeshBase
    //Mesh mesh_;  
};

/*
 * ====================================================================
 * Define tests below
 * ====================================================================
 */

/*
 */
TEST_F(OpenMeshDecimater, DecimateMesh) {

  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
    
  ASSERT_TRUE(ok);

  typedef OpenMesh::Decimater::DecimaterT< Mesh >  Decimater;
45
  typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric;
Jan Möbius's avatar
Jan Möbius committed
46 47 48 49 50

  Decimater decimaterDBG(mesh_);
  HModQuadric hModQuadricDBG;
  decimaterDBG.add( hModQuadricDBG );
  decimaterDBG.initialize();
Jan Möbius's avatar
Jan Möbius committed
51
  size_t removedVertices = 0;
Jan Möbius's avatar
Jan Möbius committed
52 53 54
  removedVertices = decimaterDBG.decimate_to(5000);
                    decimaterDBG.mesh().garbage_collection();

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!";
Jan Möbius's avatar
Jan Möbius committed
57 58
  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!";
Jan Möbius's avatar
Jan Möbius committed
59 60
}

Matthias Möller's avatar
Matthias Möller committed
61 62 63 64 65 66 67 68 69 70 71 72 73
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;

  Decimater decimaterDBG(mesh_);
  HModQuadric hModQuadricDBG;
  decimaterDBG.add( hModQuadricDBG );
  decimaterDBG.initialize();
Jan Möbius's avatar
Jan Möbius committed
74
  size_t removedVertices = 0;
Matthias Möller's avatar
Matthias Möller committed
75 76 77
  removedVertices = decimaterDBG.decimate_to_faces(5000, 8000);
                    decimaterDBG.mesh().garbage_collection();

78
  EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
Matthias Möller's avatar
Matthias Möller committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  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;

  Decimater decimaterDBG(mesh_);
  HModQuadric hModQuadricDBG;
  decimaterDBG.add( hModQuadricDBG );
  decimaterDBG.initialize();
Jan Möbius's avatar
Jan Möbius committed
97
  size_t removedVertices = 0;
Matthias Möller's avatar
Matthias Möller committed
98 99 100
  removedVertices = decimaterDBG.decimate_to_faces(4500, 9996);
                    decimaterDBG.mesh().garbage_collection();

101
  EXPECT_EQ(2526u, removedVertices) << "The number of remove vertices is not correct!";
Matthias Möller's avatar
Matthias Möller committed
102 103 104 105
  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!";
}
Jan Möbius's avatar
Jan Möbius committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

TEST_F(OpenMeshDecimater, DecimateMeshExampleFromDoc) {

  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;

  Decimater decimaterDBG(mesh_);
  HModQuadric hModQuadricDBG;
  decimaterDBG.add( hModQuadricDBG );

  std::cout << decimaterDBG.module( hModQuadricDBG ).name() << std::endl;

  decimaterDBG.module( hModQuadricDBG ).unset_max_err();

  decimaterDBG.initialize();
  size_t removedVertices = 0;
  removedVertices = decimaterDBG.decimate_to_faces(4500, 9996);
                    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!";
  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!";
}


136
TEST_F(OpenMeshDecimater, DecimateMeshNormalFlipping) {
Jan Möbius's avatar
Jan Möbius committed
137

138
  bool ok = OpenMesh::IO::read_mesh(mesh_, "cube1.off");
Jan Möbius's avatar
Jan Möbius committed
139

140
  ASSERT_TRUE(ok);
Jan Möbius's avatar
Jan Möbius committed
141

142 143 144
  typedef OpenMesh::Decimater::DecimaterT< Mesh >  Decimater;
  typedef OpenMesh::Decimater::ModNormalFlippingT < Mesh >::Handle HModNormalFlipping;
  typedef OpenMesh::Decimater::ModQuadricT< Mesh >::Handle HModQuadric;
Jan Möbius's avatar
Jan Möbius committed
145

146 147 148
  Decimater decimaterDBG(mesh_);
  HModNormalFlipping hModNormalFlippingDGB;
  decimaterDBG.add( hModNormalFlippingDGB );
Jan Möbius's avatar
Jan Möbius committed
149

150 151 152 153
  HModQuadric hModQuadricDBG;
  decimaterDBG.add( hModQuadricDBG );
  std::cout << decimaterDBG.module( hModQuadricDBG ).name() << std::endl;
  decimaterDBG.module( hModQuadricDBG ).unset_max_err();
Jan Möbius's avatar
Jan Möbius committed
154

155 156 157
  std::cout << decimaterDBG.module( hModNormalFlippingDGB ).name() << std::endl;
  decimaterDBG.module( hModNormalFlippingDGB ).set_max_normal_deviation(45.0);
  EXPECT_TRUE(decimaterDBG.module( hModNormalFlippingDGB ).is_binary()) << "Normal Flipping Module is not binary.";
Jan Möbius's avatar
Jan Möbius committed
158

159 160 161 162
  decimaterDBG.initialize();
  size_t removedVertices = 0;
  removedVertices = decimaterDBG.decimate_to_faces(4500, 9996);
                    decimaterDBG.mesh().garbage_collection();
Jan Möbius's avatar
Jan Möbius committed
163

164 165 166 167 168
  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!";
  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!";
}
Jan Möbius's avatar
Jan Möbius committed
169

170
}