Smoother Update, added function to respect feature vertices/lines/edges on the Mesh
Function skip_features() Defaults to false git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@86 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 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 Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//
|
||||
// License
|
||||
//
|
||||
// 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
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// $Revision$
|
||||
// $Date$
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
/** \file SmootherT.cc
|
||||
|
||||
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
@@ -58,7 +58,8 @@ namespace Smoother {
|
||||
template <class Mesh>
|
||||
SmootherT<Mesh>::
|
||||
SmootherT(Mesh& _mesh)
|
||||
: mesh_(_mesh)
|
||||
: mesh_(_mesh),
|
||||
skip_features_(false)
|
||||
{
|
||||
// request properties
|
||||
mesh_.request_vertex_status();
|
||||
@@ -151,9 +152,33 @@ set_active_vertices()
|
||||
bool active;
|
||||
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
|
||||
{
|
||||
active = ((nothing_selected || mesh_.status(v_it).selected())
|
||||
&& !mesh_.is_boundary(v_it)
|
||||
&& !mesh_.status(v_it).locked());
|
||||
active = ((nothing_selected || mesh_.status(v_it).selected())
|
||||
&& !mesh_.is_boundary(v_it)
|
||||
&& !mesh_.status(v_it).locked());
|
||||
|
||||
if ( skip_features_ ) {
|
||||
|
||||
active = active && !mesh_.status(v_it).feature();
|
||||
|
||||
typename Mesh::VertexOHalfedgeIter voh_it(mesh_,v_it);
|
||||
for ( ; voh_it ; ++voh_it ) {
|
||||
|
||||
// If the edge is a feature edge, skip the current vertex while smoothing
|
||||
if ( mesh_.status(mesh_.edge_handle(voh_it.handle())).feature() )
|
||||
active = false;
|
||||
|
||||
typename Mesh::FaceHandle fh1 = mesh_.face_handle(voh_it.handle() );
|
||||
typename Mesh::FaceHandle fh2 = mesh_.face_handle(mesh_.opposite_halfedge_handle(voh_it.handle() ) );
|
||||
|
||||
// If one of the faces is a feature, lock current vertex
|
||||
if ( fh1.is_valid() && mesh_.status( fh1 ).feature() )
|
||||
active = false;
|
||||
if ( fh2.is_valid() && mesh_.status( fh2 ).feature() )
|
||||
active = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mesh_.property(is_active_, v_it) = active;
|
||||
}
|
||||
|
||||
@@ -212,7 +237,7 @@ set_relative_local_error(Scalar _err)
|
||||
{
|
||||
if (!mesh_.vertices_empty())
|
||||
{
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
v_end(mesh_.vertices_end());
|
||||
|
||||
|
||||
@@ -315,14 +340,14 @@ void
|
||||
SmootherT<Mesh>::
|
||||
project_to_tangent_plane()
|
||||
{
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
v_end(mesh_.vertices_end());
|
||||
// Normal should be a vector type. In some environment a vector type
|
||||
// is different from point type, e.g. OpenSG!
|
||||
typename Mesh::Normal translation, normal;
|
||||
|
||||
|
||||
for (; v_it != v_end; ++v_it)
|
||||
for (; v_it != v_end; ++v_it)
|
||||
{
|
||||
if (is_active(v_it))
|
||||
{
|
||||
@@ -345,14 +370,14 @@ void
|
||||
SmootherT<Mesh>::
|
||||
local_error_check()
|
||||
{
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
v_end(mesh_.vertices_end());
|
||||
|
||||
typename Mesh::Normal translation;
|
||||
typename Mesh::Scalar s;
|
||||
|
||||
|
||||
for (; v_it != v_end; ++v_it)
|
||||
for (; v_it != v_end; ++v_it)
|
||||
{
|
||||
if (is_active(v_it))
|
||||
{
|
||||
@@ -379,10 +404,10 @@ void
|
||||
SmootherT<Mesh>::
|
||||
move_points()
|
||||
{
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
|
||||
v_end(mesh_.vertices_end());
|
||||
|
||||
for (; v_it != v_end; ++v_it)
|
||||
for (; v_it != v_end; ++v_it)
|
||||
if (is_active(v_it))
|
||||
mesh_.set_point(v_it, mesh_.property(new_positions_, v_it));
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 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 Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//
|
||||
// License
|
||||
//
|
||||
// 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
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// $Revision$
|
||||
// $Date$
|
||||
//
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
/** \file SmootherT.hh
|
||||
|
||||
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
@@ -58,7 +58,7 @@ namespace Smoother {
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
/** Base class for smoothing algorithms.
|
||||
*/
|
||||
*/
|
||||
template <class Mesh>
|
||||
class SmootherT : private Utils::Noncopyable
|
||||
{
|
||||
@@ -71,30 +71,34 @@ public:
|
||||
typedef typename Mesh::EdgeHandle EdgeHandle;
|
||||
|
||||
// initialize smoother
|
||||
enum Component {
|
||||
enum Component {
|
||||
Tangential, ///< Smooth tangential direction
|
||||
Normal, ///< Smooth normal direction
|
||||
Tangential_and_Normal ///< Smooth tangential and normal direction
|
||||
};
|
||||
|
||||
enum Continuity {
|
||||
C0,
|
||||
C1,
|
||||
C2
|
||||
enum Continuity {
|
||||
C0,
|
||||
C1,
|
||||
C2
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
// constructor & destructor
|
||||
/** \brief constructor & destructor
|
||||
*
|
||||
* @param _mesh Reference to the mesh
|
||||
*/
|
||||
SmootherT( Mesh& _mesh );
|
||||
virtual ~SmootherT();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/// Initialize smoother
|
||||
/// \param _comp Determine component to smooth
|
||||
/// \param _cont
|
||||
/** Initialize smoother
|
||||
* \param _comp Determine component to smooth
|
||||
* \param _cont Determine Continuity
|
||||
*/
|
||||
void initialize(Component _comp, Continuity _cont);
|
||||
|
||||
|
||||
@@ -105,6 +109,12 @@ public:
|
||||
void disable_local_error_check();
|
||||
//@}
|
||||
|
||||
/** \brief enable or disable feature handling
|
||||
*
|
||||
* @param _state true : If features are selected on the mesh, they will be left unmodified\n
|
||||
* false : Features will be ignored
|
||||
*/
|
||||
void skip_features( bool _state ){ skip_features_ = _state; };
|
||||
|
||||
/// Do _n smoothing iterations
|
||||
virtual void smooth(unsigned int _n);
|
||||
@@ -122,7 +132,7 @@ private:
|
||||
void project_to_tangent_plane();
|
||||
void local_error_check();
|
||||
void move_points();
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
@@ -149,7 +159,7 @@ protected:
|
||||
void set_new_position(VertexHandle _vh, const Point& _p)
|
||||
{ mesh_.property(new_positions_, _vh) = _p; }
|
||||
|
||||
bool is_active(VertexHandle _vh) const
|
||||
bool is_active(VertexHandle _vh) const
|
||||
{ return mesh_.property(is_active_, _vh); }
|
||||
|
||||
Component component() const { return component_; }
|
||||
@@ -158,6 +168,7 @@ protected:
|
||||
protected:
|
||||
|
||||
Mesh& mesh_;
|
||||
bool skip_features_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user