Commit ae5d5a95 authored by Mike Kremer's avatar Mike Kremer
Browse files

Added first unittests

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@24 66977474-1d4b-4f09-8fe9-267525286df2
parent 1cbfc891
#include <gtest/gtest.h>
#include "unittests_common.hh"
#include "unittests_basics.hh"
#include "unittests_iterators.hh"
int main(int _argc, char** _argv) {
......
#ifndef INCLUDE_UNITTESTS_DECIMATER_HH
#define INCLUDE_UNITTESTS_DECIMATER_HH
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
class SimplePolyhedralMesh : public PolyhedralMeshBase {
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...
}
};
/*
* ====================================================================
* Define tests below
* ====================================================================
*/
/*
*/
TEST_F(SimplePolyhedralMesh, CreateSimpleMesh) {
/*
* Add vertices
*/
VertexHandle v0 = mesh_.add_vertex(Vec3d(-1.0, -1.0, -1.0));
VertexHandle v1 = mesh_.add_vertex(Vec3d( 1.0, -1.0, -1.0));
VertexHandle v2 = mesh_.add_vertex(Vec3d( 1.0, 1.0, -1.0));
VertexHandle v3 = mesh_.add_vertex(Vec3d(-1.0, 1.0, -1.0));
VertexHandle v4 = mesh_.add_vertex(Vec3d(-1.0, -1.0, 1.0));
VertexHandle v5 = mesh_.add_vertex(Vec3d( 1.0, -1.0, 1.0));
VertexHandle v6 = mesh_.add_vertex(Vec3d( 1.0, 1.0, 1.0));
VertexHandle v7 = mesh_.add_vertex(Vec3d(-1.0, 1.0, 1.0));
EXPECT_EQ(8u, mesh_.n_vertices()) << "The number of vertices is not correct!";
/*
* Add faces
*/
std::vector<VertexHandle> fvertices;
fvertices.push_back(v3);
fvertices.push_back(v2);
fvertices.push_back(v1);
fvertices.push_back(v0);
FaceHandle fh0 = mesh_.add_face(fvertices);
fvertices.clear();
fvertices.push_back(v4);
fvertices.push_back(v5);
fvertices.push_back(v6);
fvertices.push_back(v7);
FaceHandle fh1 = mesh_.add_face(fvertices);
fvertices.clear();
fvertices.push_back(v0);
fvertices.push_back(v4);
fvertices.push_back(v7);
fvertices.push_back(v3);
FaceHandle fh2 = mesh_.add_face(fvertices);
fvertices.clear();
fvertices.push_back(v1);
fvertices.push_back(v2);
fvertices.push_back(v6);
fvertices.push_back(v5);
FaceHandle fh3 = mesh_.add_face(fvertices);
fvertices.clear();
fvertices.push_back(v7);
fvertices.push_back(v6);
fvertices.push_back(v2);
fvertices.push_back(v3);
FaceHandle fh4 = mesh_.add_face(fvertices);
fvertices.clear();
fvertices.push_back(v0);
fvertices.push_back(v1);
fvertices.push_back(v5);
fvertices.push_back(v4);
FaceHandle fh5 = mesh_.add_face(fvertices);
EXPECT_EQ(12u, mesh_.n_edges()) << "The number of edges is not correct!";
EXPECT_EQ(6u, mesh_.n_faces()) << "The number of faces is not correct!";
/*
* Add cell
*/
std::vector<HalfFaceHandle> chfaces;
chfaces.push_back(mesh_.halfface_handle(fh0, 0));
chfaces.push_back(mesh_.halfface_handle(fh1, 0));
chfaces.push_back(mesh_.halfface_handle(fh2, 0));
chfaces.push_back(mesh_.halfface_handle(fh3, 0));
chfaces.push_back(mesh_.halfface_handle(fh4, 0));
chfaces.push_back(mesh_.halfface_handle(fh5, 0));
mesh_.add_cell(chfaces);
EXPECT_EQ(1u, mesh_.n_cells()) << "The number of cells is not correct!";
}
#endif // INCLUDE GUARD
......@@ -2,37 +2,83 @@
#define INCLUDE_UNITTESTS_COMMON_HH
#include <gtest/gtest.h>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <OpenVolumeMesh/PolyhedralMesh/PolyhedralMesh.hh>
#include <OpenVolumeMesh/HexahedralMesh/HexahedralMesh.hh>
#include <OpenVolumeMesh/Geometry/VectorT.hh>
struct CustomTraits : public OpenMesh::DefaultTraits {
};
// Vector defines
typedef OpenVolumeMesh::Vec3d Vec3d;
typedef OpenVolumeMesh::Vec3f Vec3f;
/*
* Simple test setting for polyhedral meshes
*/
typedef OpenVolumeMesh::PolyhedralMesh<OpenVolumeMesh::Vec3d> PolyhedralMesh;
class PolyhedralMeshBase: public testing::Test {
protected:
typedef PolyhedralMesh::VertexHandle VertexHandle;
typedef PolyhedralMesh::HalfEdgeHandle HalfEdgeHandle;
typedef PolyhedralMesh::EdgeHandle EdgeHandle;
typedef PolyhedralMesh::HalfFaceHandle HalfFaceHandle;
typedef PolyhedralMesh::FaceHandle FaceHandle;
typedef PolyhedralMesh::CellHandle CellHandle;
typedef OpenMesh::TriMesh_ArrayKernelT<CustomTraits> Mesh;
// 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...
}
// This member will be accessible in all tests
PolyhedralMesh mesh_;
};
/*
* Simple test setting.
* Simple test setting for hexahedral meshes
*/
class OpenMeshBase : public testing::Test {
typedef OpenVolumeMesh::HexahedralMesh<OpenVolumeMesh::Vec3d> HexahedralMesh;
class HexahedralMeshBase: public testing::Test {
protected:
typedef HexahedralMesh::VertexHandle VertexHandle;
typedef HexahedralMesh::HalfEdgeHandle HalfEdgeHandle;
typedef HexahedralMesh::EdgeHandle EdgeHandle;
typedef HexahedralMesh::HalfFaceHandle HalfFaceHandle;
typedef HexahedralMesh::FaceHandle FaceHandle;
typedef HexahedralMesh::CellHandle CellHandle;
protected:
// This function is called before each test is run
virtual void SetUp()
{
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
// Do some initial stuff with the member data here...
}
// This function is called after all tests are through
virtual void TearDown() {
// This function is called after all tests are through
virtual void TearDown()
{
// Do some final stuff with the member data here...
}
// Do some final stuff with the member data here...
}
// This member will be accessible in all tests
Mesh mesh_;
// This member will be accessible in all tests
HexahedralMesh mesh_;
};
#endif // INCLUDE GUARD
......@@ -3,60 +3,6 @@
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <OpenMesh/Tools/Decimater/DecimaterT.hh>
#include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
#include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
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;
typedef OpenMesh::Decimater::ModQuadricT< Decimater >::Handle HModQuadric;
typedef OpenMesh::Decimater::ModNormalFlippingT< Decimater >::Handle HModNormal;
Decimater decimaterDBG(mesh_);
HModQuadric hModQuadricDBG;
decimaterDBG.add( hModQuadricDBG );
decimaterDBG.initialize();
int removedVertices = 0;
removedVertices = decimaterDBG.decimate_to(5000);
decimaterDBG.mesh().garbage_collection();
EXPECT_EQ(2526, removedVertices) << "The number of remove vertices is not correct!";
EXPECT_EQ(5000, mesh_.n_vertices()) << "The number of vertices after decimation is not correct!";
EXPECT_EQ(14994, mesh_.n_edges()) << "The number of edges after decimation is not correct!";
EXPECT_EQ(9996, mesh_.n_faces()) << "The number of faces after decimation is not correct!";
}
#endif // INCLUDE GUARD
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment