Commit bfc96ee8 authored by Mike Kremer's avatar Mike Kremer

Added tutorial on deleting geometry

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@156 fdac6126-5c0c-442c-9429-916003d36597
parent 0103c928
//=============================================================================
//
// 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 <iostream>
// -------------------- OpenMesh
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/Mesh/Status.hh>
// ----------------------------------------------------------------------------
struct MyTraits : public OpenMesh::DefaultTraits
{
VertexAttributes(OpenMesh::Attributes::Status);
FaceAttributes(OpenMesh::Attributes::Status);
EdgeAttributes(OpenMesh::Attributes::Status);
};
typedef OpenMesh::PolyMesh_ArrayKernelT<MyTraits> 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<MyMesh::VertexHandle> 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;
}
/** \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
**/
/** \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
......@@ -35,8 +35,9 @@ repeatedly replacing each vertex' position by the center of gravity
<li> \ref tutorial_05
<li> \ref tutorial_06
<li> \ref tutorial_07
<li> \ref tutorial_07b
<li> \ref tutorial_08
<li> \ref tutorial_09
</ol>
*/
\ No newline at end of file
*/
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