📄 loopt.hh
字号:
//=============================================================================//// 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: 1.2 $// $Date: 2005-12-21 13:58:55 $////=============================================================================/** \file LoopT.hh *///=============================================================================//// CLASS LoopT////=============================================================================#ifndef OPENMESH_SUBDIVIDER_UNIFORM_LOOPT_HH#define OPENMESH_SUBDIVIDER_UNIFORM_LOOPT_HH//== INCLUDES =================================================================#include <OpenMesh/Core/System/config.hh>#include <OpenMesh/Tools/Subdivider/Uniform/SubdividerT.hh>#include <OpenMesh/Core/Utils/vector_cast.hh>// -------------------- STL#include <vector>#if defined(OM_CC_MIPS)# include <math.h>#else# include <cmath>#endif//== NAMESPACE ================================================================namespace OpenMesh { // BEGIN_NS_OPENMESHnamespace Subdivider { // BEGIN_NS_DECIMATERnamespace Uniform { // BEGIN_NS_DECIMATER//== CLASS DEFINITION =========================================================/** %Uniform Loop subdivision algorithm. * * Implementation as described in * * C. T. Loop, "Smooth Subdivision Surfaces Based on Triangles", * M.S. Thesis, Department of Mathematics, University of Utah, August 1987. * */template <typename MeshType, typename RealType = float>class LoopT : public SubdividerT<MeshType, RealType>{public: typedef RealType real_t; typedef MeshType mesh_t; typedef SubdividerT< mesh_t, real_t > parent_t; typedef std::pair< real_t, real_t > weight_t; typedef std::vector< std::pair<real_t,real_t> > weights_t;public: LoopT(void) : parent_t(), _1over8( 1.0/8.0 ), _3over8( 3.0/8.0 ) { init_weights(); } ~LoopT() {}public: const char *name() const { return "Uniform Loop"; } /// Pre-compute weights void init_weights(size_t _max_valence=50) { weights_.resize(_max_valence); std::generate(weights_.begin(), weights_.end(), compute_weight()); }protected: bool prepare( mesh_t& _m ) { _m.add_property( vp_pos_ ); _m.add_property( ep_pos_ ); return true; } bool cleanup( mesh_t& _m ) { _m.remove_property( vp_pos_ ); _m.remove_property( ep_pos_ ); return true; } bool subdivide( mesh_t& _m, size_t _n) { typename mesh_t::FaceIter fit, f_end; typename mesh_t::EdgeIter eit, e_end; typename mesh_t::VertexIter vit; // Do _n subdivisions for (size_t i=0; i < _n; ++i) { // compute new positions for old vertices for ( vit = _m.vertices_begin(); vit != _m.vertices_end(); ++vit) smooth( _m, vit.handle() ); // Compute position for new vertices and store them in the edge property for (eit=_m.edges_begin(); eit != _m.edges_end(); ++eit) compute_midpoint( _m, eit.handle() ); // Split each edge at midpoint and store precomputed positions (stored in // edge property ep_pos_) in the vertex property vp_pos_; // Attention! Creating new edges, hence make sure the loop ends correctly. e_end = _m.edges_end(); for (eit=_m.edges_begin(); eit != e_end; ++eit) split_edge(_m, eit.handle() ); // Commit changes in topology and reconsitute consistency // Attention! Creating new faces, hence make sure the loop ends correctly. f_end = _m.faces_end(); for (fit = _m.faces_begin(); fit != f_end; ++fit) split_face(_m, fit.handle() ); // Commit changes in geometry for ( vit = _m.vertices_begin(); vit != _m.vertices_end(); ++vit) _m.set_point(vit, _m.property( vp_pos_, vit ) );#if defined(_DEBUG) || defined(DEBUG) // Now we have an consistent mesh! assert( OpenMesh::Utils::MeshCheckerT<mesh_t>(_m).check() );#endif } return true; }private: /// Helper functor to compute weights for Loop-subdivision /// \internal struct compute_weight { compute_weight() : valence(-1) { } weight_t operator() (void) {#if !defined(OM_CC_MIPS) using std::cos;#endif // 1 // alpha(n) = ---- * (40 - ( 3 + 2 cos( 2 Pi / n ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -