Commit b025acaa authored by Jan Möbius's avatar Jan Möbius

Make delete_face function work without edge status

Added unittests for delete_face



git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@782 fdac6126-5c0c-442c-9429-916003d36597
parent 5b46d7ff
......@@ -532,13 +532,14 @@ void PolyConnectivity::delete_face(FaceHandle _fh, bool _delete_isolated_vertice
set_next_halfedge_handle(prev0, next1);
set_next_halfedge_handle(prev1, next0);
// mark edge deleted
status(*del_it).set_deleted(true);
// mark edge deleted if the mesh has a edge status
if ( has_edge_status() )
status(*del_it).set_deleted(true);
// mark corresponding halfedges as deleted
// As the deleted edge is boundary,
// all corresponding halfedges will also e deleted.
// all corresponding halfedges will also be deleted.
if ( has_halfedge_status() ) {
status(h0).set_deleted(true);
status(h1).set_deleted(true);
......
......@@ -253,7 +253,7 @@ public:
void delete_edge(EdgeHandle _eh, bool _delete_isolated_vertices=true);
/** Delete face _fh and resulting degenerated empty halfedges as
well. Resultling isolated vertices will be deleted if
well. Resulting isolated vertices will be deleted if
_delete_isolated_vertices is true.
\attention All item will only be marked to be deleted. They will
......
......@@ -14,6 +14,7 @@
#include "unittests_trimesh_normal_calculations.hh"
#include "unittests_trimesh_others.hh"
#include "unittests_add_face.hh"
#include "unittests_delete_face.hh"
#include "unittests_faceless_mesh.hh"
#include "unittests_trimesh_garbage_collection.hh"
#include "unittests_randomNumberGenerator.hh"
......
......@@ -250,8 +250,11 @@ TEST_F(OpenMeshAddFaceTriangleMesh, CreateTriangleMeshCube) {
//
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges";
EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
}
......@@ -419,8 +422,10 @@ TEST_F(OpenMeshAddFacePolyMesh, CreatePolyMeshCube) {
//
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces";
EXPECT_EQ(12u, mesh_.n_edges() ) << "Wrong number of Edges";
EXPECT_EQ(24u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces";
}
......
......@@ -52,8 +52,9 @@ class OpenMeshDeleteFacePolyMesh : public OpenMeshBasePoly {
*/
/* Adds a cube to a trimesh and then deletes half of the faces
* It does not request edge status!
*/
TEST_F(OpenMeshDeleteFaceTriangleMesh, DeleteHalfTriangleMeshCube) {
TEST_F(OpenMeshDeleteFaceTriangleMesh, DeleteHalfTriangleMeshCubeNoEdgeStatus) {
mesh_.clear();
......@@ -170,8 +171,10 @@ TEST_F(OpenMeshDeleteFaceTriangleMesh, DeleteHalfTriangleMeshCube) {
//
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges";
EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
// =====================================================
// Now we delete half of the mesh
......@@ -179,20 +182,321 @@ TEST_F(OpenMeshDeleteFaceTriangleMesh, DeleteHalfTriangleMeshCube) {
mesh_.request_face_status();
mesh_.request_vertex_status();
mesh_.request_halfedge_status();
const unsigned int n_face_to_delete = mesh_->n_faces()/2;
const unsigned int n_face_to_delete = mesh_.n_faces()/2;
// Check the variable
EXPECT_EQ(6u, n_face_to_delete ) << "Wrong number of faces to delete";
for(size_t i = 0; i < n_face_to_delete; i++)
mesh_.delete_face(mesh_.face_handle(i));
// =====================================================
// Check config afterwards
// =====================================================
EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges after marking as deleted";
EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after marking as deleted";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after marking as deleted";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces after marking as deleted";
// =====================================================
// Cleanup and recheck
// =====================================================
mesh_.garbage_collection();
EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges after garbage collection";
EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after garbage collection";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after garbage collection";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces after garbage collection";
}
/* Adds a cube to a trimesh and then deletes half of the faces
*/
TEST_F(OpenMeshDeleteFaceTriangleMesh, DeleteHalfTriangleMeshCubeWithEdgeStatus) {
mesh_.clear();
// 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(18u, mesh_.n_edges() ) << "Wrong number of Edges";
EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces";
// =====================================================
// Now we delete half of the mesh
// =====================================================
mesh_.request_face_status();
mesh_.request_vertex_status();
mesh_.request_edge_status();
mesh_.request_halfedge_status();
const unsigned int n_face_to_delete = mesh_.n_faces()/2;
// Check the variable
EXPECT_EQ(6u, n_face_to_delete ) << "Wrong number of faces to delete";
for(size_t i = 0; i < n_face_to_delete; i++)
mesh_.delete_face(mesh_.face_handle(i));
// =====================================================
// Check config afterwards
// =====================================================
EXPECT_EQ(18u, mesh_.n_edges() ) << "Wrong number of Edges after marking as deleted";
EXPECT_EQ(36u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after marking as deleted";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after marking as deleted";
EXPECT_EQ(12u, mesh_.n_faces() ) << "Wrong number of faces after marking as deleted";
// =====================================================
// Cleanup and recheck
// =====================================================
mesh_.garbage_collection();
EXPECT_EQ(13u, mesh_.n_edges() ) << "Wrong number of Edges after garbage collection";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after garbage collection";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces after garbage collection";
}
/* Adds a cube to a polymesh
* And delete half of it.
* Does not request edge status
*/
TEST_F(OpenMeshDeleteFacePolyMesh, DeleteteHalfPolyMeshCubeWithoutEdgeStatus) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[8];
vhandle[0] = mesh_.add_vertex(PolyMesh::Point(-1, -1, 1));
vhandle[1] = mesh_.add_vertex(PolyMesh::Point( 1, -1, 1));
vhandle[2] = mesh_.add_vertex(PolyMesh::Point( 1, 1, 1));
vhandle[3] = mesh_.add_vertex(PolyMesh::Point(-1, 1, 1));
vhandle[4] = mesh_.add_vertex(PolyMesh::Point(-1, -1, -1));
vhandle[5] = mesh_.add_vertex(PolyMesh::Point( 1, -1, -1));
vhandle[6] = mesh_.add_vertex(PolyMesh::Point( 1, 1, -1));
vhandle[7] = mesh_.add_vertex(PolyMesh::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[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]);
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]);
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]);
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]);
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]);
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(12u, mesh_.n_edges() ) << "Wrong number of Edges";
EXPECT_EQ(24u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces";
// =====================================================
// Now we delete half of the mesh
// =====================================================
mesh_.request_face_status();
mesh_.request_vertex_status();
mesh_.request_halfedge_status();
const unsigned int n_face_to_delete = mesh_.n_faces()/2;
// Check the variable
EXPECT_EQ(3u, n_face_to_delete ) << "Wrong number of faces to delete";
for(size_t i = 0; i < n_face_to_delete; i++)
mesh_.delete_face(mesh_.face_handle(i));
// =====================================================
// Check config afterwards
// =====================================================
EXPECT_EQ(12u, mesh_.n_edges() ) << "Wrong number of Edges after marking as deleted";
EXPECT_EQ(24u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after marking as deleted";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after marking as deleted";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces after marking as deleted";
// =====================================================
// Cleanup and recheck
// =====================================================
mesh_.garbage_collection();
EXPECT_EQ(12u, mesh_.n_edges() ) << "Wrong number of Edges after garbage collection";
EXPECT_EQ(24u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after garbage collection";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after garbage collection";
EXPECT_EQ(3u, mesh_.n_faces() ) << "Wrong number of faces after garbage collection";
}
/* Adds a cube to a polymesh
* And delete half of it.
*/
TEST_F(OpenMeshDeleteFacePolyMesh, DeleteteHalfPolyMeshCube) {
TEST_F(OpenMeshDeleteFacePolyMesh, DeleteteHalfPolyMeshCubeWithEdgeStatus) {
mesh_.clear();
......@@ -268,25 +572,44 @@ TEST_F(OpenMeshDeleteFacePolyMesh, DeleteteHalfPolyMeshCube) {
//
// Check setup
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces";
EXPECT_EQ(12u, mesh_.n_edges() ) << "Wrong number of Edges";
EXPECT_EQ(24u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces";
// =====================================================
// Now we delete half of the mesh
// =====================================================
mesh_.request_face_status();
mesh_.request_vertex_status();
mesh_.request_edge_status();
mesh_.request_halfedge_status();
const unsigned int n_face_to_delete = mesh_->n_faces()/2;
for(size_t i = 0; i < n_face_to_delete; i++)
const unsigned int n_face_to_delete = mesh_.n_faces()/2;
// Check the variable
EXPECT_EQ(3u, n_face_to_delete ) << "Wrong number of faces to delete";
for(size_t i = 0; i < n_face_to_delete; i++)
mesh_.delete_face(mesh_.face_handle(i));
// =====================================================
// Check config afterwards
// =====================================================
EXPECT_EQ(12u, mesh_.n_edges() ) << "Wrong number of Edges after marking as deleted";
EXPECT_EQ(24u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after marking as deleted";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after marking as deleted";
EXPECT_EQ(6u, mesh_.n_faces() ) << "Wrong number of faces after marking as deleted";
// =====================================================
// Cleanup and recheck
// =====================================================
mesh_.garbage_collection();
EXPECT_EQ(10u, mesh_.n_edges() ) << "Wrong number of Edges after garbage collection";
EXPECT_EQ(20u, mesh_.n_halfedges() ) << "Wrong number of HalfEdges after garbage collection";
EXPECT_EQ(8u, mesh_.n_vertices() ) << "Wrong number of vertices after garbage collection";
EXPECT_EQ(3u, mesh_.n_faces() ) << "Wrong number of faces after garbage collection";
}
......
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