Fixed bad property handling in OpenMesh Stripifier doing create and delete of properties in generator function not in constructor/destructor.

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@102 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Jan Möbius
2009-04-27 12:42:13 +00:00
parent a38f4435fd
commit 12584beb42
2 changed files with 110 additions and 105 deletions

View File

@@ -1,31 +1,31 @@
//============================================================================= //=============================================================================
// //
// OpenMesh // OpenMesh
// Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen // Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen
// www.openmesh.org // www.openmesh.org
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// License // License
// //
// This library is free software; you can redistribute it and/or modify it // This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published // under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, version 2.1. // by the Free Software Foundation, version 2.1.
// //
// This library is distributed in the hope that it will be useful, but // This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of // WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details. // Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public // You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Revision$ // $Revision$
// $Date$ // $Date$
// //
//============================================================================= //=============================================================================
//============================================================================= //=============================================================================
@@ -45,33 +45,39 @@
//== NAMESPACES =============================================================== //== NAMESPACES ===============================================================
namespace OpenMesh { namespace OpenMesh {
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
template <class Mesh>
StripifierT<Mesh>::
StripifierT(Mesh& _mesh) :
mesh_(_mesh)
{
// preprocess: add new properties
mesh_.add_property( processed_ );
mesh_.add_property( used_ );
mesh_.request_face_status();
}
template <class Mesh>
StripifierT<Mesh>::
~StripifierT() {
// postprocess: remove properties
mesh_.remove_property(processed_);
mesh_.remove_property(used_);
mesh_.release_face_status();
}
template <class Mesh> template <class Mesh>
unsigned int unsigned int
StripifierT<Mesh>:: StripifierT<Mesh>::
stripify() stripify()
{ {
// preprocess: add new properties
mesh_.add_property( processed_ );
mesh_.add_property( used_ );
mesh_.request_face_status();
// build strips // build strips
clear(); clear();
build_strips(); build_strips();
// postprocess: remove properties
//mesh_.remove_property(processed_);
//mesh_.remove_property(used_);
//mesh_.release_face_status();
return n_strips(); return n_strips();
} }
@@ -90,9 +96,9 @@ build_strips()
FaceHandles faces[3]; FaceHandles faces[3];
typename FaceHandles::iterator fh_it, fh_end; typename FaceHandles::iterator fh_it, fh_end;
typename Mesh::FaceIter f_it, f_end=mesh_.faces_end(); typename Mesh::FaceIter f_it, f_end=mesh_.faces_end();
// init faces to be un-processed and un-used // init faces to be un-processed and un-used
// deleted or hidden faces are marked processed // deleted or hidden faces are marked processed
if (mesh_.has_face_status()) if (mesh_.has_face_status())
@@ -108,9 +114,9 @@ build_strips()
for (f_it=mesh_.faces_begin(); f_it!=f_end; ++f_it) for (f_it=mesh_.faces_begin(); f_it!=f_end; ++f_it)
processed(f_it) = used(f_it) = false; processed(f_it) = used(f_it) = false;
} }
for (f_it=mesh_.faces_begin(); true; ) for (f_it=mesh_.faces_begin(); true; )
{ {
// find start face // find start face
@@ -118,39 +124,39 @@ build_strips()
if (!processed(f_it)) if (!processed(f_it))
break; break;
if (f_it==f_end) break; // stop if all have been processed if (f_it==f_end) break; // stop if all have been processed
// collect starting halfedges // collect starting halfedges
h[0] = mesh_.halfedge_handle(f_it.handle()); h[0] = mesh_.halfedge_handle(f_it.handle());
h[1] = mesh_.next_halfedge_handle(h[0]); h[1] = mesh_.next_halfedge_handle(h[0]);
h[2] = mesh_.next_halfedge_handle(h[1]); h[2] = mesh_.next_halfedge_handle(h[1]);
// build 3 strips, take best one // build 3 strips, take best one
best_length = best_idx = 0; best_length = best_idx = 0;
for (unsigned int i=0; i<3; ++i) for (unsigned int i=0; i<3; ++i)
{ {
build_strip(h[i], experiments[i], faces[i]); build_strip(h[i], experiments[i], faces[i]);
if ((length = experiments[i].size()) > best_length) if ((length = experiments[i].size()) > best_length)
{ {
best_length = length; best_length = length;
best_idx = i; best_idx = i;
} }
for (fh_it=faces[i].begin(), fh_end=faces[i].end(); for (fh_it=faces[i].begin(), fh_end=faces[i].end();
fh_it!=fh_end; ++fh_it) fh_it!=fh_end; ++fh_it)
used(*fh_it) = false; used(*fh_it) = false;
} }
// update processed status // update processed status
fh_it = faces[best_idx].begin(); fh_it = faces[best_idx].begin();
fh_end = faces[best_idx].end(); fh_end = faces[best_idx].end();
for (; fh_it!=fh_end; ++fh_it) for (; fh_it!=fh_end; ++fh_it)
processed(*fh_it) = true; processed(*fh_it) = true;
// add best strip to strip-list // add best strip to strip-list
strips_.push_back(experiments[best_idx]); strips_.push_back(experiments[best_idx]);
} }
@@ -170,17 +176,17 @@ build_strip(typename Mesh::HalfedgeHandle _start_hh,
std::list<unsigned int> strip; std::list<unsigned int> strip;
typename Mesh::HalfedgeHandle hh; typename Mesh::HalfedgeHandle hh;
typename Mesh::FaceHandle fh; typename Mesh::FaceHandle fh;
// reset face list // reset face list
_faces.clear(); _faces.clear();
// init strip // init strip
strip.push_back(mesh_.from_vertex_handle(_start_hh).idx()); strip.push_back(mesh_.from_vertex_handle(_start_hh).idx());
strip.push_back(mesh_.to_vertex_handle(_start_hh).idx()); strip.push_back(mesh_.to_vertex_handle(_start_hh).idx());
// walk along the strip: 1st direction // walk along the strip: 1st direction
hh = mesh_.prev_halfedge_handle(mesh_.opposite_halfedge_handle(_start_hh)); hh = mesh_.prev_halfedge_handle(mesh_.opposite_halfedge_handle(_start_hh));
while (1) while (1)
@@ -191,23 +197,23 @@ build_strip(typename Mesh::HalfedgeHandle _start_hh,
hh = mesh_.next_halfedge_handle(hh); hh = mesh_.next_halfedge_handle(hh);
if (mesh_.is_boundary(hh)) break; if (mesh_.is_boundary(hh)) break;
fh = mesh_.face_handle(hh); fh = mesh_.face_handle(hh);
if (processed(fh) || used(fh)) break; if (processed(fh) || used(fh)) break;
_faces.push_back(fh); _faces.push_back(fh);
used(fh) = true; used(fh) = true;
strip.push_back(mesh_.to_vertex_handle(hh).idx()); strip.push_back(mesh_.to_vertex_handle(hh).idx());
// go left // go left
hh = mesh_.opposite_halfedge_handle(hh); hh = mesh_.opposite_halfedge_handle(hh);
hh = mesh_.next_halfedge_handle(hh); hh = mesh_.next_halfedge_handle(hh);
if (mesh_.is_boundary(hh)) break; if (mesh_.is_boundary(hh)) break;
fh = mesh_.face_handle(hh); fh = mesh_.face_handle(hh);
if (processed(fh) || used(fh)) break; if (processed(fh) || used(fh)) break;
_faces.push_back(fh); _faces.push_back(fh);
used(fh) = true; used(fh) = true;
strip.push_back(mesh_.to_vertex_handle(hh).idx()); strip.push_back(mesh_.to_vertex_handle(hh).idx());
} }
// walk along the strip: 2nd direction // walk along the strip: 2nd direction
bool flip(false); bool flip(false);
hh = mesh_.prev_halfedge_handle(_start_hh); hh = mesh_.prev_halfedge_handle(_start_hh);
@@ -219,28 +225,28 @@ build_strip(typename Mesh::HalfedgeHandle _start_hh,
hh = mesh_.next_halfedge_handle(hh); hh = mesh_.next_halfedge_handle(hh);
if (mesh_.is_boundary(hh)) break; if (mesh_.is_boundary(hh)) break;
fh = mesh_.face_handle(hh); fh = mesh_.face_handle(hh);
if (processed(fh) || used(fh)) break; if (processed(fh) || used(fh)) break;
_faces.push_back(fh); _faces.push_back(fh);
used(fh) = true; used(fh) = true;
strip.push_front(mesh_.to_vertex_handle(hh).idx()); strip.push_front(mesh_.to_vertex_handle(hh).idx());
flip = true; flip = true;
// go left // go left
hh = mesh_.opposite_halfedge_handle(hh); hh = mesh_.opposite_halfedge_handle(hh);
hh = mesh_.next_halfedge_handle(hh); hh = mesh_.next_halfedge_handle(hh);
if (mesh_.is_boundary(hh)) break; if (mesh_.is_boundary(hh)) break;
fh = mesh_.face_handle(hh); fh = mesh_.face_handle(hh);
if (processed(fh) || used(fh)) break; if (processed(fh) || used(fh)) break;
_faces.push_back(fh); _faces.push_back(fh);
used(fh) = true; used(fh) = true;
strip.push_front(mesh_.to_vertex_handle(hh).idx()); strip.push_front(mesh_.to_vertex_handle(hh).idx());
flip = false; flip = false;
} }
if (flip) strip.push_front(strip.front()); if (flip) strip.push_front(strip.front());
// copy final strip to _strip // copy final strip to _strip
_strip.clear(); _strip.clear();
_strip.reserve(strip.size()); _strip.reserve(strip.size());

View File

@@ -1,31 +1,31 @@
//============================================================================= //=============================================================================
// //
// OpenMesh // OpenMesh
// Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen // Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen
// www.openmesh.org // www.openmesh.org
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// License // License
// //
// This library is free software; you can redistribute it and/or modify it // This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published // under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, version 2.1. // by the Free Software Foundation, version 2.1.
// //
// This library is distributed in the hope that it will be useful, but // This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of // WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details. // Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public // You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// $Revision$ // $Revision$
// $Date$ // $Date$
// //
//============================================================================= //=============================================================================
//============================================================================= //=============================================================================
@@ -57,7 +57,7 @@ namespace OpenMesh {
/** \class StripifierT StripifierT.hh <OpenMesh/Tools/Utils/StripifierT.hh> /** \class StripifierT StripifierT.hh <OpenMesh/Tools/Utils/StripifierT.hh>
This class decomposes a triangle mesh into several triangle strips. This class decomposes a triangle mesh into several triangle strips.
*/ */
@@ -66,7 +66,7 @@ template <class Mesh>
class StripifierT class StripifierT
{ {
public: public:
typedef unsigned int Index; typedef unsigned int Index;
typedef std::vector<Index> Strip; typedef std::vector<Index> Strip;
typedef typename Strip::const_iterator IndexIterator; typedef typename Strip::const_iterator IndexIterator;
@@ -75,11 +75,10 @@ public:
/// Default constructor /// Default constructor
StripifierT(Mesh& _mesh) : mesh_(_mesh) {} StripifierT(Mesh& _mesh);
/// Destructor /// Destructor
~StripifierT() {} ~StripifierT();
/// Compute triangle strips, returns number of strips /// Compute triangle strips, returns number of strips
unsigned int stripify(); unsigned int stripify();