Commit d5f25126 authored by Martin Schultz's avatar Martin Schultz
Browse files

* added missing requestsfor polyMesh.

* fixed missing mesh. before to_vertex_handle / to_edge_handle
* fixed minor typo in documentation
* added unitTests for flipping / collapsing code snippets
closes #2420

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1238 fdac6126-5c0c-442c-9429-916003d36597
parent fddf79f1
/** \page mesh_operations Some basic operations: Flipping and collapsing edges /** \page mesh_operations Some basic operations: Flipping and collapsing edges
In this section you will learn about some basic operations on a mes that %OpenMesh In this section you will learn about some basic operations on a mesh that %OpenMesh
already provides. Comprising the flipping of edges in a triangle mesh as well as already provides. Comprising the flipping of edges in a triangle mesh as well as
collapsing edges by joining the two adjacent vertices. collapsing edges by joining the two adjacent vertices.
...@@ -77,62 +77,48 @@ A simple code example related to the illustration might look like this: ...@@ -77,62 +77,48 @@ A simple code example related to the illustration might look like this:
\code \code
PolyMesh mesh; PolyMesh mesh;
mesh.request_vertex_status();
// You need all status attributes to do delete operations mesh.request_edge_status();
mesh.request_edge_status(); // Add some vertices as in the illustration above
mesh.request_vertex_status(); PolyMesh::VertexHandle vhandle[7];
mesh.request_face_status(); vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, 1, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(-1, 3, 0));
// Add some vertices as in the illustration above vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
PolyMesh::VertexHandle vhandle[7]; vhandle[3] = mesh.add_vertex(MyMesh::Point(0, 2, 0));
vhandle[4] = mesh.add_vertex(MyMesh::Point(0, 4, 0));
vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, 1, 0)); vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(-1, 3, 0)); vhandle[6] = mesh.add_vertex(MyMesh::Point(1, 3, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 0, 0)); // Add three quad faces
vhandle[3] = mesh.add_vertex(MyMesh::Point(0, 2, 0)); std::vector<PolyMesh::VertexHandle> face_vhandles;
vhandle[4] = mesh.add_vertex(MyMesh::Point(0, 4, 0)); face_vhandles.push_back(vhandle[1]);
vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 1, 0)); face_vhandles.push_back(vhandle[0]);
vhandle[6] = mesh.add_vertex(MyMesh::Point(1, 3, 0)); face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[3]);
// Add three quad faces mesh.add_face(face_vhandles);
std::vector<PolyMesh::VertexHandle> face_vhandles; face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[1]); face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[0]); face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[2]); face_vhandles.push_back(vhandle[4]);
face_vhandles.push_back(vhandle[3]); mesh.add_face(face_vhandles);
mesh.add_face(face_vhandles); face_vhandles.clear();
face_vhandles.push_back(vhandle[3]);
face_vhandles.clear(); face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[1]); face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[3]); mesh.add_face(face_vhandles);
face_vhandles.push_back(vhandle[5]); // Now find the edge between vertex vhandle[2]
face_vhandles.push_back(vhandle[4]); // and vhandle[3]
mesh.add_face(face_vhandles); for(PolyMesh::HalfedgeIter it = mesh.halfedges_begin(); it != mesh.halfedges_end(); ++it) {
if( mesh.to_vertex_handle(*it) == vhandle[3] &&
face_vhandles.clear(); mesh.from_vertex_handle(*it) == vhandle[2])
{
face_vhandles.push_back(vhandle[3]); // Collapse edge
face_vhandles.push_back(vhandle[2]); mesh.collapse(*it);
face_vhandles.push_back(vhandle[6]); break;
face_vhandles.push_back(vhandle[5]); }
mesh.add_face(face_vhandles); }
// Our mesh now looks like in the illustration above after the collapsing.
// Now find the edge between vertex vhandle[2]
// and vhandle[3]
for(PolyMesh::HalfedgeIter it = mesh.halfedges_begin(); it != mesh.halfedges_end(); ++it) {
if(to_vertex_handle(*it) == vhandle[3] &&
from_vertex_handle(*it) == vhandle[2]) {
// Collapse edge
mesh.collapse(*it);
break;
}
}
// Our mesh now looks like in the illustration above after the collapsing.
\endcode \endcode
......
...@@ -796,4 +796,89 @@ TEST_F(OpenMeshTutorials, storing_custom_properties) { ...@@ -796,4 +796,89 @@ TEST_F(OpenMeshTutorials, storing_custom_properties) {
EXPECT_TRUE(fill_props(mesh, mprop_map, true)) << "property not filled correctly"; EXPECT_TRUE(fill_props(mesh, mprop_map, true)) << "property not filled correctly";
} }
/*Testcase for code snippet from flipping edges in triangle meshes
* */
TEST_F(OpenMeshTutorials, flipping_edges) {
Mesh mesh;
// Add some vertices
Mesh::VertexHandle vhandle[4];
vhandle[0] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(0, 1, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
vhandle[3] = mesh.add_vertex(MyMesh::Point(1, 0, 0));
// Add two faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
mesh.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
mesh.add_face(face_vhandles);
// Now the edge adjacent to the two faces connects
// vertex vhandle[0] and vhandle[2].
// Find this edge and then flip it
for(Mesh::EdgeIter it = mesh.edges_begin(); it != mesh.edges_end(); ++it) {
if(!mesh.is_boundary(*it)) {
// Flip edge
EXPECT_EQ(2, mesh.to_vertex_handle(mesh.halfedge_handle(*it,0)).idx()) << "expected vertex handle 2!" << std::endl;
EXPECT_EQ(0, mesh.to_vertex_handle(mesh.halfedge_handle(*it,1)).idx()) << "expected vertex handle 0!" << std::endl;
mesh.flip(*it);
EXPECT_EQ(1, mesh.to_vertex_handle(mesh.halfedge_handle(*it,0)).idx()) << "expected vertex handle 1 (did the flip work?)!" << std::endl;
EXPECT_EQ(3, mesh.to_vertex_handle(mesh.halfedge_handle(*it,1)).idx()) << "expected vertex handle 3 (did the flip work?)!" << std::endl;
}
}
// The edge now connects vertex vhandle[1] and vhandle[3].
}
/*Testcase for code snippet from collapsing edges in triangle meshes
* */
TEST_F(OpenMeshTutorials, collapsing_edges) {
PolyMesh mesh;
mesh.request_vertex_status();
mesh.request_edge_status();
// Add some vertices as in the illustration above
PolyMesh::VertexHandle vhandle[7];
vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, 1, 0));
vhandle[1] = mesh.add_vertex(MyMesh::Point(-1, 3, 0));
vhandle[2] = mesh.add_vertex(MyMesh::Point(0, 0, 0));
vhandle[3] = mesh.add_vertex(MyMesh::Point(0, 2, 0));
vhandle[4] = mesh.add_vertex(MyMesh::Point(0, 4, 0));
vhandle[5] = mesh.add_vertex(MyMesh::Point(1, 1, 0));
vhandle[6] = mesh.add_vertex(MyMesh::Point(1, 3, 0));
// Add three quad faces
std::vector<PolyMesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[0]);
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[1]);
face_vhandles.push_back(vhandle[3]);
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[3]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[6]);
face_vhandles.push_back(vhandle[5]);
mesh.add_face(face_vhandles);
// Now find the edge between vertex vhandle[2]
// and vhandle[3]
for(PolyMesh::HalfedgeIter it = mesh.halfedges_begin(); it != mesh.halfedges_end(); ++it) {
if( mesh.to_vertex_handle(*it) == vhandle[3] &&
mesh.from_vertex_handle(*it) == vhandle[2])
{
// Collapse edge
mesh.collapse(*it);
break;
}
}
// Our mesh now looks like in the illustration above after the collapsing.
}
} }
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