Commit 580ffdc9 authored by Jan Möbius's avatar Jan Möbius

Missing unit test



git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@642 fdac6126-5c0c-442c-9429-916003d36597
parent 0ebf091e
#ifndef INCLUDE_UNITTESTS_TRIMESH_GARBAGE_COLLECTION_HH
#define INCLUDE_UNITTESTS_TRIMESH_GARBAGE_COLLECTION_HH
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <iostream>
class OpenMeshTriMeshGarbageCollection : public OpenMeshBase {
protected:
// This function is called before each test is run
virtual void SetUp() {
}
// 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
* ====================================================================
*/
/* Adds a cube to a trimesh and deletes vertex 0 and calls garbage collection afterwards
*/
TEST_F(OpenMeshTriMeshGarbageCollection, StandardGarbageCollection) {
mesh_.clear();
mesh_.request_vertex_status();
mesh_.request_edge_status();
mesh_.request_halfedge_status();
mesh_.request_face_status();
// Add some vertices
Mesh::VertexHandle vhandle[8];
vhandle[0] = mesh_.add_vertex(Mesh::Point(-1, -1, 1));
vhandle[1] = mesh_.add_vertex(Mesh::Point( 1, -1, 1));
vhandle[2] = mesh_.add_vertex(Mesh::Point( 1, 1, 1));
vhandle[3] = mesh_.add_vertex(Mesh::Point(-1, 1, 1));
vhandle[4] = mesh_.add_vertex(Mesh::Point(-1, -1, -1));
vhandle[5] = mesh_.add_vertex(Mesh::Point( 1, -1, -1));
vhandle[6] = mesh_.add_vertex(Mesh::Point( 1, 1, -1));
vhandle[7] = mesh_.add_vertex(Mesh::Point(-1, 1, -1));
// Add six faces to form a cube
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
//=======================
face_vhandles.clear();
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[5]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
//=======================
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
mesh_.add_face(face_vhandles);
//=======================
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[5]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
//=======================
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
//=======================
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
// Test setup:
//
//
// 3 ======== 2
// / /|
// / / | z
// 0 ======== 1 | |
// | | | | y
// | 7 | 6 | /
// | | / | /
// | |/ |/
// 4 ======== 5 -------> x
//
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong initial number of vertices";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong initial number of faces";
mesh_.delete_vertex(vhandle[0]);
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after deletion";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces after deletion";
mesh_.garbage_collection();
// Check setup
EXPECT_EQ(7u, mesh_.n_vertices() ) << "Wrong number of vertices after garbage collection";
EXPECT_EQ(8u, mesh_.n_faces() ) << "Wrong number of faces after garbage collection";
}
/* Adds a cube to a trimesh and deletes vertex 0 and calls garbage collection afterwards.
* But this time, we track the vertex handles , halfedge handles, and face handles
*/
TEST_F(OpenMeshTriMeshGarbageCollection, TrackedGarbageCollection) {
mesh_.clear();
mesh_.request_vertex_status();
mesh_.request_edge_status();
mesh_.request_halfedge_status();
mesh_.request_face_status();
// Add some vertices
Mesh::VertexHandle vhandle[8];
vhandle[0] = mesh_.add_vertex(Mesh::Point(-1, -1, 1));
vhandle[1] = mesh_.add_vertex(Mesh::Point( 1, -1, 1));
vhandle[2] = mesh_.add_vertex(Mesh::Point( 1, 1, 1));
vhandle[3] = mesh_.add_vertex(Mesh::Point(-1, 1, 1));
vhandle[4] = mesh_.add_vertex(Mesh::Point(-1, -1, -1));
vhandle[5] = mesh_.add_vertex(Mesh::Point( 1, -1, -1));
vhandle[6] = mesh_.add_vertex(Mesh::Point( 1, 1, -1));
vhandle[7] = mesh_.add_vertex(Mesh::Point(-1, 1, -1));
// Add six faces to form a cube
std::vector<Mesh::VertexHandle> face_vhandles;
// 0
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
// 1
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
mesh_.add_face(face_vhandles);
//=======================
// 2
face_vhandles.clear();
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[5]);
mesh_.add_face(face_vhandles);
// 3
face_vhandles.clear();
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
//=======================
// 4
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
// 5
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[5]);
mesh_.add_face(face_vhandles);
//=======================
// 6
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[5]);
mesh_.add_face(face_vhandles);
// 7
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
//=======================
// 8
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[6]);
mesh_.add_face(face_vhandles);
// 9
face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
//=======================
// 10
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[7]);
mesh_.add_face(face_vhandles);
// 11
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[7]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
// Test setup:
//
//
// 3 ======== 2
// / /|
// / / | z
// 0 ======== 1 | |
// | | | | y
// | 7 | 6 | /
// | | / | /
// | |/ |/
// 4 ======== 5 -------> x
//
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong initial number of vertices";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong initial number of faces";
std::vector<Mesh::VertexHandle> vertexHandles;
for ( Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end(); ++v_it)
vertexHandles.push_back(v_it.handle());
std::vector<Mesh::HalfedgeHandle> halfedgeHandles;
for ( Mesh::HalfedgeIter he_it = mesh_.halfedges_begin(); he_it != mesh_.halfedges_end(); ++he_it)
halfedgeHandles.push_back(he_it.handle());
std::vector<Mesh::FaceHandle> faceHandles;
for ( Mesh::FaceIter f_it = mesh_.faces_begin(); f_it != mesh_.faces_end(); ++f_it)
faceHandles.push_back(f_it.handle());
std::vector<Mesh::VertexHandle*> vertexHandlesP;
for ( unsigned int i = 0 ; i < vertexHandles.size() ; ++i)
vertexHandlesP.push_back(&(vertexHandles[i]));
std::vector<Mesh::HalfedgeHandle*> halfedgeHandlesP;
for ( unsigned int i = 0 ; i < halfedgeHandles.size() ; ++i)
halfedgeHandlesP.push_back(&(halfedgeHandles[i]));
std::vector<Mesh::FaceHandle*> faceHandlesP;
for ( unsigned int i = 0 ; i < faceHandles.size() ; ++i)
faceHandlesP.push_back(&(faceHandles[i]));
// // REMOVE
// std::cerr << "Vertex : ";
// for ( unsigned int i = 0 ; i < vertexHandles.size() ; ++i)
// std::cerr << vertexHandles[i].idx() << " ";
// std::cerr << std::endl;
//
// std::cerr << "Halfedge : ";
// for ( unsigned int i = 0 ; i < halfedgeHandles.size() ; ++i)
// std::cerr << halfedgeHandles[i].idx() << " ";
// std::cerr << std::endl;
//
// std::cerr << "Face : ";
// for ( unsigned int i = 0 ; i < faceHandles.size() ; ++i)
// std::cerr << faceHandles[i].idx() << " ";
// std::cerr << std::endl;
// // REMOVE END
// Deleting vertex 0
// -> deletes vertex 0
// -> deletes faces 0,4,10,11
mesh_.delete_vertex(vhandle[0]);
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after deletion";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces after deletion";
mesh_.garbage_collection(vertexHandlesP,halfedgeHandlesP,faceHandlesP,true,true,true);
// Check setup
EXPECT_EQ(7u, mesh_.n_vertices() ) << "Wrong number of vertices after garbage collection";
EXPECT_EQ(8u, mesh_.n_faces() ) << "Wrong number of faces after garbage collection";
//================================
// Check the updated handles
//================================
// Check setup of vertices
EXPECT_EQ(7 , vertexHandles[0].idx() ) << "Wrong vertex handle after update";
EXPECT_EQ(1 , vertexHandles[1].idx() ) << "Wrong vertex handle after update";
EXPECT_EQ(2 , vertexHandles[2].idx() ) << "Wrong vertex handle after update";
EXPECT_EQ(3 , vertexHandles[3].idx() ) << "Wrong vertex handle after update";
EXPECT_EQ(4 , vertexHandles[4].idx() ) << "Wrong vertex handle after update";
EXPECT_EQ(5 , vertexHandles[5].idx() ) << "Wrong vertex handle after update";
EXPECT_EQ(6 , vertexHandles[6].idx() ) << "Wrong vertex handle after update";
EXPECT_EQ(-1, vertexHandles[7].idx() ) << "Wrong vertex handle after update";
// Check setup of faces
EXPECT_EQ(9 , faceHandles[0 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(1 , faceHandles[1 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(2 , faceHandles[2 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(3 , faceHandles[3 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(8 , faceHandles[4 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(5 , faceHandles[5 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(6 , faceHandles[6 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(7 , faceHandles[7 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(-1 , faceHandles[8 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(-1 , faceHandles[9 ].idx() ) << "Wrong face handle after update";
EXPECT_EQ(-1 , faceHandles[10].idx() ) << "Wrong face handle after update";
EXPECT_EQ(-1 , faceHandles[11].idx() ) << "Wrong face handle after update";
// // REMOVE
// std::cerr << "Vertex : ";
// for ( unsigned int i = 0 ; i < vertexHandles.size() ; ++i)
// std::cerr << vertexHandles[i].idx() << " ";
// std::cerr << std::endl;
//
// std::cerr << "Halfedge : ";
// for ( unsigned int i = 0 ; i < halfedgeHandles.size() ; ++i)
// std::cerr << halfedgeHandles[i].idx() << " ";
// std::cerr << std::endl;
//
// std::cerr << "Face : ";
// for ( unsigned int i = 0 ; i < faceHandles.size() ; ++i)
// std::cerr << faceHandles[i].idx() << " ";
// std::cerr << std::endl;
// // REMOVE END
}
#endif // INCLUDE GUARD
Markdown is supported
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