operations.docu 4.34 KB
 Mike Kremer committed Mar 01, 2010 1 /** \page mesh_operations Some basic operations: Flipping and collapsing edges  Mike Kremer committed Nov 27, 2009 2   Martin Schultz committed Mar 10, 2015 3 In this section you will learn about some basic operations on a mesh that %OpenMesh  Mike Kremer committed Nov 27, 2009 4 5 6 7 8 9 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 45 46 47 48 49 50 51 52 already provides. Comprising the flipping of edges in a triangle mesh as well as collapsing edges by joining the two adjacent vertices. \li \ref op_flip \li \ref op_collapse \section op_flip Flipping edges in triangle meshes Considering two adjacent faces of a triangle mesh, there exist exactly two different configurations of the inner edge. Calling the function OpenMesh::TriConnectivity::flip(EdgeHandle _eh) will flip the specified edge to its opposite orientation as shown in the illustration below. \image html mesh.flip.png "Flipping edges in a triangle mesh" So, the following snippet of code shows how to use this in your applications: \code TriMesh mesh; // Add some vertices TriMesh::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 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(TriMesh::EdgeIter it = mesh.edges_begin(); it != mesh.edges_end(); ++it) {  Jan Möbius committed Aug 07, 2013 53  if(!mesh.is_boundary(*it)) {  Mike Kremer committed Nov 27, 2009 54  // Flip edge  Jan Möbius committed Aug 07, 2013 55  mesh.flip(*it);  Mike Kremer committed Nov 27, 2009 56 57 58 59 60 61 62 63 64 65 66 67 68 69  } } // The edge now connects vertex vhandle[1] and vhandle[3]. \endcode \section op_collapse Collapsing edges In this section you will learn how to collapse edges such that the two adjacent vertices join. %OpenMesh provides the function OpenMesh::PolyConnectivity::collapse(HalfedgeHandle _heh) to perform this operation. This will collapse the from-vertex (remeber that halfedges are directed) to the to-vertex of the halfedge as illustrated below. Note that collapsing edges might cause topological inconsistencies to your mesh. You should verify consistency after  Jan Möbius committed Dec 19, 2013 70 71 72 collapsing edges by calling OpenMesh::PolyConnectivity::is_collapse_ok(). \note You have to request status attributes in order to use the collapse and delete functions!  Mike Kremer committed Nov 27, 2009 73 74 75 76 77 78  \image html mesh.collapse.png "Collapsing will always be performed in the direction the halfedge points to." A simple code example related to the illustration might look like this: \code  Jan Möbius committed Mar 11, 2015 79 80 81  PolyMesh mesh; // Request required status flags  Martin Schultz committed Mar 10, 2015 82 83  mesh.request_vertex_status(); mesh.request_edge_status();  Jan Möbius committed Mar 11, 2015 84 85  mesh.request_face_status();  Martin Schultz committed Mar 10, 2015 86 87 88 89 90 91 92 93 94  // 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));  Jan Möbius committed Mar 11, 2015 95   Martin Schultz committed Mar 10, 2015 96 97 98 99 100 101 102  // Add three quad faces std::vector 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);  Jan Möbius committed Mar 11, 2015 103   Martin Schultz committed Mar 10, 2015 104 105 106 107 108 109  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);  Jan Möbius committed Mar 11, 2015 110   Martin Schultz committed Mar 10, 2015 111 112 113 114 115 116  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);  Jan Möbius committed Mar 11, 2015 117   Martin Schultz committed Mar 10, 2015 118 119 120 121 122 123 124 125 126 127 128  // 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; } }  Jan Möbius committed Mar 11, 2015 129   Martin Schultz committed Mar 10, 2015 130  // Our mesh now looks like in the illustration above after the collapsing.  Mike Kremer committed Nov 27, 2009 131 132 133 134  \endcode */