First checkin for OpenMesh 2.0

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@2 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Jan Möbius
2009-02-06 13:37:46 +00:00
parent c3321ebdd9
commit 97f515985d
417 changed files with 76182 additions and 0 deletions

View File

@@ -0,0 +1,183 @@
//=============================================================================
//
// 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.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1802 $
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
//
//=============================================================================
/** \file JacobiLaplaceSmootherT.cc
*/
//=============================================================================
//
// CLASS JacobiLaplaceSmootherT - IMPLEMENTATION
//
//=============================================================================
#define OPENMESH_JACOBI_LAPLACE_SMOOTHERT_C
//== INCLUDES =================================================================
#include <OpenMesh/Tools/Smoother/JacobiLaplaceSmootherT.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Smoother {
//== IMPLEMENTATION ==========================================================
template <class Mesh>
void
JacobiLaplaceSmootherT<Mesh>::
smooth(unsigned int _n)
{
if (Base::continuity() > Base::C0)
{
Base::mesh_.add_property(umbrellas_);
if (Base::continuity() > Base::C1)
Base::mesh_.add_property(squared_umbrellas_);
}
LaplaceSmootherT<Mesh>::smooth(_n);
if (Base::continuity() > Base::C0)
{
Base::mesh_.remove_property(umbrellas_);
if (Base::continuity() > Base::C1)
Base::mesh_.remove_property(squared_umbrellas_);
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
JacobiLaplaceSmootherT<Mesh>::
compute_new_positions_C0()
{
typename Mesh::VertexIter v_it, v_end(Base::mesh_.vertices_end());
typename Mesh::CVVIter vv_it;
typename Mesh::Normal u, p, zero(0,0,0);
typename Mesh::Scalar w;
for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
{
if (is_active(v_it))
{
// compute umbrella
u = zero;
for (vv_it=Base::mesh_.cvv_iter(v_it); vv_it; ++vv_it)
{
w = weight(Base::mesh_.edge_handle(vv_it.current_halfedge_handle()));
u += vector_cast<typename Mesh::Normal>(Base::mesh_.point(vv_it)) * w;
}
u *= weight(v_it);
u -= vector_cast<typename Mesh::Normal>(Base::mesh_.point(v_it));
// damping
u *= 0.5;
// store new position
p = vector_cast<typename Mesh::Normal>(Base::mesh_.point(v_it));
p += u;
set_new_position(v_it, p);
}
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
JacobiLaplaceSmootherT<Mesh>::
compute_new_positions_C1()
{
typename Mesh::VertexIter v_it, v_end(Base::mesh_.vertices_end());
typename Mesh::CVVIter vv_it;
typename Mesh::Normal u, uu, p, zero(0,0,0);
typename Mesh::Scalar w, diag;
// 1st pass: compute umbrellas
for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
{
u = zero;
for (vv_it=Base::mesh_.cvv_iter(v_it); vv_it; ++vv_it)
{
w = weight(Base::mesh_.edge_handle(vv_it.current_halfedge_handle()));
u -= vector_cast<typename Mesh::Normal>(Base::mesh_.point(vv_it))*w;
}
u *= weight(v_it);
u += vector_cast<typename Mesh::Normal>(Base::mesh_.point(v_it));
Base::mesh_.property(umbrellas_, v_it) = u;
}
// 2nd pass: compute updates
for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
{
if (is_active(v_it))
{
uu = zero;
diag = 0.0;
for (vv_it=Base::mesh_.cvv_iter(v_it); vv_it; ++vv_it)
{
w = weight(Base::mesh_.edge_handle(vv_it.current_halfedge_handle()));
uu -= Base::mesh_.property(umbrellas_, vv_it);
diag += (w * weight(vv_it) + 1.0) * w;
}
uu *= weight(v_it);
diag *= weight(v_it);
uu += Base::mesh_.property(umbrellas_, v_it);
if (diag) uu *= 1.0/diag;
// damping
uu *= 0.25;
// store new position
p = vector_cast<typename Mesh::Normal>(Base::mesh_.point(v_it));
p -= uu;
set_new_position(v_it, p);
}
}
}
//=============================================================================
} // namespace Smoother
} // namespace OpenMesh
//=============================================================================

View File

@@ -0,0 +1,99 @@
//=============================================================================
//
// 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.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1802 $
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
//
//=============================================================================
/** \file JacobiLaplaceSmootherT.hh
*/
//=============================================================================
//
// CLASS JacobiLaplaceSmootherT
//
//=============================================================================
#ifndef OPENMESH_JACOBI_LAPLACE_SMOOTHERT_HH
#define OPENMESH_JACOBI_LAPLACE_SMOOTHERT_HH
//== INCLUDES =================================================================
#include <OpenMesh/Tools/Smoother/LaplaceSmootherT.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Smoother {
//== CLASS DEFINITION =========================================================
/** Laplacian Smoothing.
*
*/
template <class Mesh>
class JacobiLaplaceSmootherT : public LaplaceSmootherT<Mesh>
{
private:
typedef LaplaceSmootherT<Mesh> Base;
public:
JacobiLaplaceSmootherT( Mesh& _mesh ) : LaplaceSmootherT<Mesh>(_mesh) {}
// override: alloc umbrellas
void smooth(unsigned int _n);
protected:
virtual void compute_new_positions_C0();
virtual void compute_new_positions_C1();
private:
OpenMesh::VPropHandleT<typename Mesh::Normal> umbrellas_;
OpenMesh::VPropHandleT<typename Mesh::Normal> squared_umbrellas_;
};
//=============================================================================
} // namespace Smoother
} // namespace OpenMesh
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_JACOBI_LAPLACE_SMOOTHERT_C)
#define OPENMESH_JACOBI_LAPLACE_SMOOTHERT_TEMPLATES
#include "JacobiLaplaceSmootherT.cc"
#endif
//=============================================================================
#endif // OPENMESH_JACOBI_LAPLACE_SMOOTHERT_HH defined
//=============================================================================

View File

@@ -0,0 +1,209 @@
//=============================================================================
//
// 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.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1802 $
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
//
//=============================================================================
/** \file LaplaceSmootherT.cc
*/
//=============================================================================
//
// CLASS LaplaceSmootherT - IMPLEMENTATION
//
//=============================================================================
#define OPENMESH_LAPLACE_SMOOTHERT_C
//== INCLUDES =================================================================
#include <OpenMesh/Tools/Smoother/LaplaceSmootherT.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Smoother {
//== IMPLEMENTATION ==========================================================
template <class Mesh>
LaplaceSmootherT<Mesh>::
LaplaceSmootherT(Mesh& _mesh)
: SmootherT<Mesh>(_mesh)
{
// custom properties
Base::mesh_.add_property(vertex_weights_);
Base::mesh_.add_property(edge_weights_);
}
//-----------------------------------------------------------------------------
template <class Mesh>
LaplaceSmootherT<Mesh>::
~LaplaceSmootherT()
{
// free custom properties
Base::mesh_.remove_property(vertex_weights_);
Base::mesh_.remove_property(edge_weights_);
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
LaplaceSmootherT<Mesh>::
initialize(Component _comp, Continuity _cont)
{
SmootherT<Mesh>::initialize(_comp, _cont);
// calculate weights
switch (_comp)
{
case Base::Tangential:
compute_weights(UniformWeighting);
break;
case Base::Normal:
compute_weights(CotWeighting);
break;
case Base::Tangential_and_Normal:
compute_weights(UniformWeighting);
break;
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
LaplaceSmootherT<Mesh>::
compute_weights(LaplaceWeighting _weighting)
{
typename Mesh::VertexIter v_it, v_end(Base::mesh_.vertices_end());
typename Mesh::EdgeIter e_it, e_end(Base::mesh_.edges_end());
typename Mesh::HalfedgeHandle heh0, heh1, heh2;
typename Mesh::VertexHandle v0, v1;
const typename Mesh::Point *p0, *p1, *p2;
typename Mesh::Normal d0, d1;
typename Mesh::Scalar weight, lb(-1.0), ub(1.0);
// init vertex weights
for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
Base::mesh_.property(vertex_weights_, v_it) = 0.0;
switch (_weighting)
{
// Uniform weighting
case UniformWeighting:
{
for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
{
heh0 = Base::mesh_.halfedge_handle(e_it.handle(), 0);
heh1 = Base::mesh_.halfedge_handle(e_it.handle(), 1);
v0 = Base::mesh_.to_vertex_handle(heh0);
v1 = Base::mesh_.to_vertex_handle(heh1);
Base::mesh_.property(edge_weights_, e_it) = 1.0;
Base::mesh_.property(vertex_weights_, v0) += 1.0;
Base::mesh_.property(vertex_weights_, v1) += 1.0;
}
break;
}
// Cotangent weighting
case CotWeighting:
{
for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
{
weight = 0.0;
heh0 = Base::mesh_.halfedge_handle(e_it.handle(), 0);
v0 = Base::mesh_.to_vertex_handle(heh0);
p0 = &Base::mesh_.point(v0);
heh1 = Base::mesh_.halfedge_handle(e_it.handle(), 1);
v1 = Base::mesh_.to_vertex_handle(heh1);
p1 = &Base::mesh_.point(v1);
heh2 = Base::mesh_.next_halfedge_handle(heh0);
p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
d0 = (*p0 - *p2); d0.normalize();
d1 = (*p1 - *p2); d1.normalize();
weight += 1.0 / tan(acos(std::max(lb, std::min(ub, dot(d0,d1) ))));
heh2 = Base::mesh_.next_halfedge_handle(heh1);
p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
d0 = (*p0 - *p2); d0.normalize();
d1 = (*p1 - *p2); d1.normalize();
weight += 1.0 / tan(acos(std::max(lb, std::min(ub, dot(d0,d1) ))));
Base::mesh_.property(edge_weights_, e_it) = weight;
Base::mesh_.property(vertex_weights_, v0) += weight;
Base::mesh_.property(vertex_weights_, v1) += weight;
}
break;
}
}
// invert vertex weights:
// before: sum of edge weights
// after: one over sum of edge weights
for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
{
weight = Base::mesh_.property(vertex_weights_, v_it);
if (weight)
Base::mesh_.property(vertex_weights_, v_it) = 1.0 / weight;
}
}
//=============================================================================
} // namespace Smoother
} // namespace OpenMesh
//=============================================================================

View File

@@ -0,0 +1,113 @@
//=============================================================================
//
// 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.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1802 $
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
//
//=============================================================================
/** \file LaplaceSmootherT.hh
*/
//=============================================================================
//
// CLASS LaplaceSmootherT
//
//=============================================================================
#ifndef OPENMESH_LAPLACE_SMOOTHERT_HH
#define OPENMESH_LAPLACE_SMOOTHERT_HH
//== INCLUDES =================================================================
#include <OpenMesh/Tools/Smoother/SmootherT.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Smoother {
//== CLASS DEFINITION =========================================================
/// Laplacian Smoothing.
template <class Mesh>
class LaplaceSmootherT : public SmootherT<Mesh>
{
private:
typedef SmootherT<Mesh> Base;
public:
typedef typename SmootherT<Mesh>::Component Component;
typedef typename SmootherT<Mesh>::Continuity Continuity;
typedef typename SmootherT<Mesh>::Scalar Scalar;
typedef typename SmootherT<Mesh>::VertexHandle VertexHandle;
typedef typename SmootherT<Mesh>::EdgeHandle EdgeHandle;
LaplaceSmootherT( Mesh& _mesh );
virtual ~LaplaceSmootherT();
void initialize(Component _comp, Continuity _cont);
protected:
// misc helpers
Scalar weight(VertexHandle _vh) const
{ return Base::mesh_.property(vertex_weights_, _vh); }
Scalar weight(EdgeHandle _eh) const
{ return Base::mesh_.property(edge_weights_, _eh); }
private:
enum LaplaceWeighting { UniformWeighting, CotWeighting };
void compute_weights(LaplaceWeighting _mode);
OpenMesh::VPropHandleT<Scalar> vertex_weights_;
OpenMesh::EPropHandleT<Scalar> edge_weights_;
};
//=============================================================================
} // namespace Smoother
} // namespace OpenMesh
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_LAPLACE_SMOOTHERT_C)
#define OPENMESH_LAPLACE_SMOOTHERT_TEMPLATES
#include "LaplaceSmootherT.cc"
#endif
//=============================================================================
#endif // OPENMESH_LAPLACE_SMOOTHERT_HH defined
//=============================================================================

394
Tools/Smoother/SmootherT.cc Normal file
View File

@@ -0,0 +1,394 @@
//=============================================================================
//
// 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.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1802 $
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
//
//=============================================================================
/** \file SmootherT.cc
*/
//=============================================================================
//
// CLASS SmootherT - IMPLEMENTATION
//
//=============================================================================
#define OPENMESH_SMOOTHERT_C
//== INCLUDES =================================================================
#include <OpenMesh/Core/Utils/vector_cast.hh>
#include <OpenMesh/Tools/Smoother/SmootherT.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Smoother {
//== IMPLEMENTATION ==========================================================
template <class Mesh>
SmootherT<Mesh>::
SmootherT(Mesh& _mesh)
: mesh_(_mesh)
{
// request properties
mesh_.request_vertex_status();
mesh_.request_face_normals();
mesh_.request_vertex_normals();
// custom properties
mesh_.add_property(original_positions_);
mesh_.add_property(original_normals_);
mesh_.add_property(new_positions_);
mesh_.add_property(is_active_);
// default settings
component_ = Tangential_and_Normal;
continuity_ = C0;
tolerance_ = -1.0;
}
//-----------------------------------------------------------------------------
template <class Mesh>
SmootherT<Mesh>::
~SmootherT()
{
// free properties
mesh_.release_vertex_status();
mesh_.release_face_normals();
mesh_.release_vertex_normals();
// free custom properties
mesh_.remove_property(original_positions_);
mesh_.remove_property(original_normals_);
mesh_.remove_property(new_positions_);
mesh_.remove_property(is_active_);
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
initialize(Component _comp, Continuity _cont)
{
typename Mesh::VertexIter v_it, v_end(mesh_.vertices_end());
// store smoothing settings
component_ = _comp;
continuity_ = _cont;
// update normals
mesh_.update_face_normals();
mesh_.update_vertex_normals();
// store original points & normals
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
{
mesh_.property(original_positions_, v_it) = mesh_.point(v_it);
mesh_.property(original_normals_, v_it) = mesh_.normal(v_it);
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
set_active_vertices()
{
typename Mesh::VertexIter v_it, v_end(mesh_.vertices_end());
// is something selected?
bool nothing_selected(true);
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
if (mesh_.status(v_it).selected())
{ nothing_selected = false; break; }
// tagg all 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());
mesh_.property(is_active_, v_it) = active;
}
// C1: remove one ring of boundary vertices
if (continuity_ == C1)
{
typename Mesh::VVIter vv_it;
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
if (mesh_.is_boundary(v_it))
for (vv_it=mesh_.vv_iter(v_it); vv_it; ++vv_it)
mesh_.property(is_active_, vv_it) = false;
}
// C2: remove two rings of boundary vertices
if (continuity_ == C2)
{
typename Mesh::VVIter vv_it;
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
{
mesh_.status(v_it).set_tagged(false);
mesh_.status(v_it).set_tagged2(false);
}
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
if (mesh_.is_boundary(v_it))
for (vv_it=mesh_.vv_iter(v_it); vv_it; ++vv_it)
mesh_.status(v_it).set_tagged(true);
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
if (mesh_.status(v_it).tagged())
for (vv_it=mesh_.vv_iter(v_it); vv_it; ++vv_it)
mesh_.status(v_it).set_tagged2(true);
for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
{
if (mesh_.status(v_it).tagged2())
mesh_.property(is_active_, vv_it) = false;
mesh_.status(v_it).set_tagged(false);
mesh_.status(v_it).set_tagged2(false);
}
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
set_relative_local_error(Scalar _err)
{
if (!mesh_.vertices_empty())
{
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
v_end(mesh_.vertices_end());
// compute bounding box
Point bb_min, bb_max;
bb_min = bb_max = mesh_.point(v_it);
for (++v_it; v_it!=v_end; ++v_it)
{
bb_min.minimize(mesh_.point(v_it));
bb_max.minimize(mesh_.point(v_it));
}
// abs. error = rel. error * bounding-diagonal
set_absolute_error(_err * (bb_max-bb_min).norm());
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
set_absolute_local_error(Scalar _err)
{
tolerance_ = _err;
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
disable_local_error_check()
{
tolerance_ = -1.0;
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
smooth(unsigned int _n)
{
// mark active vertices
set_active_vertices();
// smooth _n iterations
while (_n--)
{
compute_new_positions();
if (component_ == Tangential)
project_to_tangent_plane();
else if (tolerance_ >= 0.0)
local_error_check();
move_points();
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
compute_new_positions()
{
switch (continuity_)
{
case C0:
compute_new_positions_C0();
break;
case C1:
compute_new_positions_C1();
break;
case C2:
break;
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
project_to_tangent_plane()
{
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)
{
if (is_active(v_it))
{
translation = new_position(v_it)-orig_position(v_it);
normal = orig_normal(v_it);
normal *= dot(translation, normal);
translation -= normal;
translation += vector_cast<typename Mesh::Normal>(orig_position(v_it));
set_new_position(v_it, translation);
}
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
local_error_check()
{
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)
{
if (is_active(v_it))
{
translation = new_position(v_it) - orig_position(v_it);
s = fabs(dot(translation, orig_normal(v_it)));
if (s > tolerance_)
{
translation *= (tolerance_ / s);
translation += vector_cast<NormalType>(orig_position(v_it));
set_new_position(v_it, translation);
}
}
}
}
//-----------------------------------------------------------------------------
template <class Mesh>
void
SmootherT<Mesh>::
move_points()
{
typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
v_end(mesh_.vertices_end());
for (; v_it != v_end; ++v_it)
if (is_active(v_it))
mesh_.set_point(v_it, mesh_.property(new_positions_, v_it));
}
//=============================================================================
} // namespace Smoother
} // namespace OpenMesh
//=============================================================================

188
Tools/Smoother/SmootherT.hh Normal file
View File

@@ -0,0 +1,188 @@
//=============================================================================
//
// 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.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1802 $
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
//
//=============================================================================
/** \file SmootherT.hh
*/
//=============================================================================
//
// CLASS SmootherT
//
//=============================================================================
#ifndef OPENMESH_SMOOTHER_SMOOTHERT_HH
#define OPENMESH_SMOOTHER_SMOOTHERT_HH
//== INCLUDES =================================================================
#include <OpenMesh/Core/System/config.hh>
#include <OpenMesh/Core/Utils/Property.hh>
#include <OpenMesh/Core/Utils/Noncopyable.hh>
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Smoother {
//== CLASS DEFINITION =========================================================
/** Base class for smoothing algorithms.
*/
template <class Mesh>
class SmootherT : private Utils::Noncopyable
{
public:
typedef typename Mesh::Scalar Scalar;
typedef typename Mesh::Point Point;
typedef typename Mesh::Normal NormalType;
typedef typename Mesh::VertexHandle VertexHandle;
typedef typename Mesh::EdgeHandle EdgeHandle;
// initialize smoother
enum Component {
Tangential, ///< Smooth tangential direction
Normal, ///< Smooth normal direction
Tangential_and_Normal ///< Smooth tangential and normal direction
};
enum Continuity {
C0,
C1,
C2
};
public:
// constructor & destructor
SmootherT( Mesh& _mesh );
virtual ~SmootherT();
public:
/// Initialize smoother
/// \param _comp Determine component to smooth
/// \param _cont
void initialize(Component _comp, Continuity _cont);
//@{
/// Set local error
void set_relative_local_error(Scalar _err);
void set_absolute_local_error(Scalar _err);
void disable_local_error_check();
//@}
/// Do _n smoothing iterations
virtual void smooth(unsigned int _n);
/// Find active vertices. Resets tagged status !
void set_active_vertices();
private:
// single steps of smoothing
void compute_new_positions();
void project_to_tangent_plane();
void local_error_check();
void move_points();
protected:
// override these
virtual void compute_new_positions_C0() = 0;
virtual void compute_new_positions_C1() = 0;
protected:
// misc helpers
const Point& orig_position(VertexHandle _vh) const
{ return mesh_.property(original_positions_, _vh); }
const NormalType& orig_normal(VertexHandle _vh) const
{ return mesh_.property(original_normals_, _vh); }
const Point& new_position(VertexHandle _vh) const
{ return mesh_.property(new_positions_, _vh); }
void set_new_position(VertexHandle _vh, const Point& _p)
{ mesh_.property(new_positions_, _vh) = _p; }
bool is_active(VertexHandle _vh) const
{ return mesh_.property(is_active_, _vh); }
Component component() const { return component_; }
Continuity continuity() const { return continuity_; }
protected:
Mesh& mesh_;
private:
Scalar tolerance_;
Scalar normal_deviation_;
Component component_;
Continuity continuity_;
OpenMesh::VPropHandleT<Point> original_positions_;
OpenMesh::VPropHandleT<NormalType> original_normals_;
OpenMesh::VPropHandleT<Point> new_positions_;
OpenMesh::VPropHandleT<bool> is_active_;
};
//=============================================================================
} // namespace Smoother
} // namespace OpenMesh
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SMOOTHERT_C)
#define OPENMESH_SMOOTHERT_TEMPLATES
#include "SmootherT.cc"
#endif
//=============================================================================
#endif // OPENMESH_SMOOTHER_SMOOTHERT_HH defined
//=============================================================================

View File

@@ -0,0 +1,92 @@
//=============================================================================
//
// 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.
//
// 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: 1802 $
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
//
//=============================================================================
#ifndef SMOOTH_MESH_HH
#define SMOOTH_MESH_HH
//== INCLUDES =================================================================
#include <OpenMesh/Core/Utils/Property.hh>
//== NAMESPACE ================================================================
namespace OpenMesh { //BEGIN_NS_OPENMESH
template <class _Mesh, class _PropertyHandle>
void smooth_mesh_property(unsigned int _n_iters, _Mesh& _m, _PropertyHandle _pph)
{
typedef typename _PropertyHandle::Value Value;
std::vector<Value> temp_values(_m.n_vertices());
for (unsigned int i=0; i < _n_iters; ++i)
{
for ( typename _Mesh::ConstVertexIter cv_it = _m.vertices_begin();
cv_it != _m.vertices_end(); ++cv_it)
{
unsigned int valence = 0;
Value& temp_value = temp_values[cv_it.handle().idx()];
temp_value.vectorize(0);
for ( typename _Mesh::ConstVertexVertexIter cvv_it = _m.cvv_iter(cv_it);
cvv_it; ++cvv_it)
{
temp_value += _m.property(_pph,cvv_it);
++valence;
}
if (valence > 0)
{//guard against isolated vertices
temp_value *= (typename Value::value_type)(1.0 / valence);
}
else
{
temp_value = _m.property(_pph, cv_it);
}
}
for ( typename _Mesh::ConstVertexIter cv_it = _m.vertices_begin();
cv_it != _m.vertices_end(); ++cv_it)
{
_m.property(_pph,cv_it) = temp_values[cv_it.handle().idx()];
}
}
}
template <class _Mesh>
void smooth_mesh(_Mesh& _m, uint _n_iters)
{
smooth_mesh_property(_n_iters, _m, _m.points_pph());
}
};//namespace OpenMesh
#endif//SMOOTH_MESH_HH