diff --git a/Doc/Tutorial/07b-delete_geometry/delete_geometry.cc b/Doc/Tutorial/07b-delete_geometry/delete_geometry.cc new file mode 100644 index 00000000..c19fa7da --- /dev/null +++ b/Doc/Tutorial/07b-delete_geometry/delete_geometry.cc @@ -0,0 +1,169 @@ +//============================================================================= +// +// OpenMesh +// Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen +// www.openmesh.org +// +//----------------------------------------------------------------------------- +// +// License +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Library General Public License as published +// by the Free Software Foundation, version 2. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +//----------------------------------------------------------------------------- +// +// $Revision: 83 $ +// $Date: 2009-02-27 17:31:45 +0100 (Fri, 27 Feb 2009) $ +// +//============================================================================= + + +#include +// -------------------- OpenMesh +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- + +struct MyTraits : public OpenMesh::DefaultTraits +{ + VertexAttributes(OpenMesh::Attributes::Status); + FaceAttributes(OpenMesh::Attributes::Status); + EdgeAttributes(OpenMesh::Attributes::Status); +}; + + +typedef OpenMesh::PolyMesh_ArrayKernelT MyMesh; + + +// ---------------------------------------------------------------------------- +// Build a simple cube and delete it except one face + +int main() +{ + MyMesh mesh; + + // generate vertices + + MyMesh::VertexHandle vhandle[8]; + MyMesh::FaceHandle fhandle[6]; + + vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, -1, 1)); + vhandle[1] = mesh.add_vertex(MyMesh::Point( 1, -1, 1)); + vhandle[2] = mesh.add_vertex(MyMesh::Point( 1, 1, 1)); + vhandle[3] = mesh.add_vertex(MyMesh::Point(-1, 1, 1)); + vhandle[4] = mesh.add_vertex(MyMesh::Point(-1, -1, -1)); + vhandle[5] = mesh.add_vertex(MyMesh::Point( 1, -1, -1)); + vhandle[6] = mesh.add_vertex(MyMesh::Point( 1, 1, -1)); + vhandle[7] = mesh.add_vertex(MyMesh::Point(-1, 1, -1)); + + + // generate (quadrilateral) faces + + std::vector tmp_face_vhandles; + + tmp_face_vhandles.clear(); + tmp_face_vhandles.push_back(vhandle[0]); + tmp_face_vhandles.push_back(vhandle[1]); + tmp_face_vhandles.push_back(vhandle[2]); + tmp_face_vhandles.push_back(vhandle[3]); + fhandle[0] = mesh.add_face(tmp_face_vhandles); + + tmp_face_vhandles.clear(); + tmp_face_vhandles.push_back(vhandle[7]); + tmp_face_vhandles.push_back(vhandle[6]); + tmp_face_vhandles.push_back(vhandle[5]); + tmp_face_vhandles.push_back(vhandle[4]); + fhandle[1] = mesh.add_face(tmp_face_vhandles); + + tmp_face_vhandles.clear(); + tmp_face_vhandles.push_back(vhandle[1]); + tmp_face_vhandles.push_back(vhandle[0]); + tmp_face_vhandles.push_back(vhandle[4]); + tmp_face_vhandles.push_back(vhandle[5]); + fhandle[2] = mesh.add_face(tmp_face_vhandles); + + + tmp_face_vhandles.clear(); + tmp_face_vhandles.push_back(vhandle[2]); + tmp_face_vhandles.push_back(vhandle[1]); + tmp_face_vhandles.push_back(vhandle[5]); + tmp_face_vhandles.push_back(vhandle[6]); + fhandle[3] = mesh.add_face(tmp_face_vhandles); + + + tmp_face_vhandles.clear(); + tmp_face_vhandles.push_back(vhandle[3]); + tmp_face_vhandles.push_back(vhandle[2]); + tmp_face_vhandles.push_back(vhandle[6]); + tmp_face_vhandles.push_back(vhandle[7]); + fhandle[4] = mesh.add_face(tmp_face_vhandles); + + + tmp_face_vhandles.clear(); + tmp_face_vhandles.push_back(vhandle[0]); + tmp_face_vhandles.push_back(vhandle[3]); + tmp_face_vhandles.push_back(vhandle[7]); + tmp_face_vhandles.push_back(vhandle[4]); + fhandle[5] = mesh.add_face(tmp_face_vhandles); + + // And now delete all faces and vertices + // except face (vh[7], vh[6], vh[5], vh[4]) + // whose handle resides in fhandle[1] + + + // Delete face 0 + mesh.delete_face(fhandle[0], false); + // ... face 2 + mesh.delete_face(fhandle[2], false); + // ... face 3 + mesh.delete_face(fhandle[3], false); + // ... face 4 + mesh.delete_face(fhandle[4], false); + // ... face 5 + mesh.delete_face(fhandle[5], false); + + + // If isolated vertices result in a face deletion + // they have to be deleted manually. If you want this + // to happen automatically, change the second parameter + // to true. + + // Now delete the isolated vertices 0, 1, 2 and 3 + mesh.delete_vertex(vhandle[0], false); + mesh.delete_vertex(vhandle[1], false); + mesh.delete_vertex(vhandle[2], false); + mesh.delete_vertex(vhandle[3], false); + + // Delete all elements that are marked as deleted + // from memory. + mesh.garbage_collection(); + + // write mesh to output.obj + try { + if ( !OpenMesh::IO::write_mesh(mesh, "output.off") ) { + std::cerr << "Cannot write mesh to file 'output.off'" << std::endl; + return 1; + } + } + catch( std::exception& x ) + { + std::cerr << x.what() << std::endl; + return 1; + } + + return 0; +} diff --git a/Doc/tutorial_01.docu b/Doc/tutorial_01.docu index 2f119b69..4507b294 100644 --- a/Doc/tutorial_01.docu +++ b/Doc/tutorial_01.docu @@ -1,4 +1,4 @@ -/** \page tutorial_01 First Steps +/** \page tutorial_01 First Steps - Building a cude This small example shows: \li How to declare your type \c MyMesh, @@ -61,4 +61,4 @@ included first. \include build_cube.cc -**/ \ No newline at end of file +**/ diff --git a/Doc/tutorial_07b.docu b/Doc/tutorial_07b.docu new file mode 100644 index 00000000..07fa194a --- /dev/null +++ b/Doc/tutorial_07b.docu @@ -0,0 +1,39 @@ +/** \page tutorial_07b Deleting geometry elements + +This small example shows how to remove faces and vertices from a mesh. + +We basically use the geometry created in \ref tutorial_01. + +If we want our mesh class to be able to remove vertices, faces or (half-) edges +we have to extend the default traits for our mesh class. +Vertices, faces and (half-)edges need the OpenMesh::Attributes::Status attribute +which is used to hold the flag "deleted" if an element is deleted. + +The struct which defines the mesh traits then looks like this: + +\dontinclude delete_geometry.cc +\skipline struct +\until }; + +After having created the geometry of the cube one can delete faces and vertices +by simply calling delete_vertices() (delete_faces() or delete_edges() respectiely). + +In this example we delete all faces excpet one and the corresponding vertices. +The code looks like this + +\dontinclude delete_geometry.cc +\skipline // Delete face 0 +\until mesh.delete_vertex(vhandle[3], false); + +Now the deleted faces and vertices are marked as "deleted" internally. +Call garbage_collection() to definitely remove them from memory. + +\dontinclude delete_geometry.cc +\skipline // Delete all +\until mesh.garbage_collection(); + +The full source code of the example: + +\include delete_geometry.cc + +**/ \ No newline at end of file diff --git a/Doc/tutorial_main.docu b/Doc/tutorial_main.docu index 560d9a48..f0fe1671 100644 --- a/Doc/tutorial_main.docu +++ b/Doc/tutorial_main.docu @@ -35,8 +35,9 @@ repeatedly replacing each vertex' position by the center of gravity
  • \ref tutorial_05
  • \ref tutorial_06
  • \ref tutorial_07 +
  • \ref tutorial_07b
  • \ref tutorial_08
  • \ref tutorial_09 -*/ \ No newline at end of file +*/