OpenMesh
OpenMesh/Tools/Subdivider/Uniform/Composite/CompositeT.hh
Go to the documentation of this file.
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 521 $                                                         *
00038  *   $Date: 2012-01-20 15:43:20 +0100 (Fr, 20 Jan 2012) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00046 //=============================================================================
00047 //
00048 //  CLASS CompositeT
00049 //
00050 //=============================================================================
00051 
00052 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITE_HH
00053 #define OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITE_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 #include <string>
00059 #include <vector>
00060 // --------------------
00061 #include <OpenMesh/Tools/Subdivider/Uniform/SubdividerT.hh>
00062 
00063 //== NAMESPACE ================================================================
00064 
00065 namespace OpenMesh   { // BEGIN_NS_OPENMESH
00066 namespace Subdivider { // BEGIN_NS_DECIMATER
00067 namespace Uniform    { // BEGIN_NS_UNIFORM
00068 
00069 
00070 //== CLASS DEFINITION =========================================================
00071 
00086 template <typename MeshType, typename RealType=float > 
00087 class CompositeT : public SubdividerT< MeshType, RealType >
00088 {
00089 public:
00090 
00091   typedef RealType                                real_t;
00092   typedef MeshType                                mesh_t;
00093   typedef SubdividerT< mesh_t, real_t >           parent_t;
00094 
00095 public:
00096 
00097   CompositeT(void) : parent_t(), p_mesh_(NULL) {}
00098   CompositeT(MeshType& _mesh) : parent_t(_mesh), p_mesh_(NULL) {};
00099   virtual ~CompositeT() { }
00100 
00101 public: // inherited interface
00102 
00103   virtual const char *name( void ) const = 0;
00104 
00105 protected: // inherited interface
00106 
00107   bool prepare( MeshType& _m );
00108 
00109   bool subdivide( MeshType& _m, size_t _n, const bool _update_points = true  )
00110   {
00111     assert( p_mesh_ == &_m );
00112 
00113     while(_n--)
00114     {
00115       apply_rules();
00116       commit(_m);
00117     }
00118    
00119     return true;
00120   }
00121 
00122 #ifdef NDEBUG
00123   bool cleanup( MeshType& ) 
00124 #else
00125   bool cleanup( MeshType& _m ) 
00126 #endif
00127   { 
00128     assert( p_mesh_ == &_m );
00129     p_mesh_=NULL; 
00130     return true; 
00131   }
00132 
00133 protected:
00134 
00137   virtual void apply_rules(void) = 0;
00138 
00139 protected:
00140 
00143   void commit( MeshType &_m)
00144   {
00145     typename MeshType::VertexIter v_it;
00146 
00147     for (v_it=_m.vertices_begin(); v_it != _m.vertices_end(); ++v_it)
00148       _m.set_point(v_it.handle(), _m.data(v_it).position());
00149   }
00150 
00151   
00152 public:
00153 
00155   struct Coeff
00156   {
00157     virtual ~Coeff() { }
00158     virtual double operator() (size_t _valence) = 0;
00159   };
00160 
00161 
00162 protected:
00163 
00164   typedef typename MeshType::Scalar         scalar_t;
00165   typedef typename MeshType::VertexHandle   VertexHandle;
00166   typedef typename MeshType::FaceHandle     FaceHandle;
00167   typedef typename MeshType::EdgeHandle     EdgeHandle;
00168   typedef typename MeshType::HalfedgeHandle HalfedgeHandle;
00169 
00171 
00172 
00173   
00174   void Tvv3(); 
00175   void Tvv4(); 
00176   void Tfv();  
00177 
00178   void FF();                 
00179   void FFc(Coeff& _coeff);   
00180   void FFc(scalar_t _c);     
00181 
00182   void FV();                 
00183   void FVc(Coeff& _coeff);   
00184   void FVc(scalar_t _c);     
00185 
00186   void FE();                 
00187 
00188   void VF();                 
00189   void VFa(Coeff& _coeff);   
00190   void VFa(scalar_t _alpha); 
00191 
00192   void VV();                  
00193   void VVc(Coeff& _coeff);    
00194   void VVc(scalar_t _c);      
00195 
00196   void VE();                  
00197 
00198   
00199   void VdE();             
00200   void VdEc(scalar_t _c); 
00201   
00204   void VdEg(Coeff& _coeff);
00207   void VdEg(scalar_t _gamma);
00208 
00209   void EF();               
00210   
00211   void EV();               
00212   void EVc(Coeff& _coeff); 
00213   void EVc(scalar_t _c);   
00214 
00215   void EdE();              
00216   void EdEc(scalar_t _c);  
00217 
00218 
00220 
00221   void corner_cutting(HalfedgeHandle _heh);
00222 
00223   VertexHandle split_edge(HalfedgeHandle _heh);
00224 
00225 private:
00226 
00227   MeshType* p_mesh_;
00228 
00229 };
00230 
00231 
00232 //=============================================================================
00233 } // END_NS_UNIFORM
00234 } // END_NS_SUBDIVIDER
00235 } // END_NS_OPENMESH
00236 //=============================================================================
00237 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_UNIFORM_COMPOSITE_CC)
00238 #define OPENMESH_SUBDIVIDER_TEMPLATES
00239 #include "CompositeT.cc"
00240 #endif
00241 //=============================================================================
00242 #endif // COMPOSITET_HH defined
00243 //=============================================================================
00244