OpenMesh
OpenMesh/Tools/Subdivider/Uniform/SubdividerT.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: 362 $                                                         *
00038  *   $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00046 //=============================================================================
00047 //
00048 //  CLASS SubdividerT
00049 //
00050 //=============================================================================
00051 
00052 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
00053 #define OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
00054 
00055 //== INCLUDE ==================================================================
00056 
00057 #include <OpenMesh/Core/System/config.hh>
00058 #include <OpenMesh/Core/Utils/Noncopyable.hh>
00059 #if defined(_DEBUG) || defined(DEBUG)
00060 // Makes life lot easier, when playing/messing around with low-level topology
00061 // changing methods of OpenMesh
00062 #  include <OpenMesh/Tools/Utils/MeshCheckerT.hh>
00063 #  define ASSERT_CONSISTENCY( T, m ) \
00064      assert(OpenMesh::Utils::MeshCheckerT<T>(m).check())
00065 #else
00066 #  define ASSERT_CONSISTENCY( T, m )
00067 #endif
00068 
00069 //== NAMESPACE ================================================================
00070 
00071 namespace OpenMesh   {
00072 namespace Subdivider {
00073 namespace Uniform    {
00074 
00075 
00076 //== CLASS DEFINITION =========================================================
00077 
00086 template <typename MeshType, typename RealType=float>
00087 class SubdividerT : private Utils::Noncopyable
00088 {
00089 public:
00090 
00091   typedef MeshType mesh_t;
00092   typedef RealType real_t;
00093 
00094 public:
00095 
00097 
00098 
00099 
00100   SubdividerT(void) : attached_(NULL) { }
00101 
00104   SubdividerT( MeshType &_m ) : attached_(NULL) {  attach(_m); }
00105 
00107 
00109   virtual ~SubdividerT() 
00110   { detach(); }
00111 
00113   virtual const char *name( void ) const = 0;
00114 
00115 
00116 public: 
00117 
00119 
00120 
00121   bool operator () ( MeshType& _m, size_t _n )
00122   {    
00123     return prepare(_m) && subdivide( _m, _n ) && cleanup( _m );
00124   }
00126 
00127 public: 
00128 
00129 
00130 
00131   bool attach( MeshType& _m )
00132   {
00133     if ( attached_ == &_m )
00134       return true;
00135 
00136     detach();
00137     if (prepare( _m ))
00138     {
00139       attached_ = &_m;
00140       return true;
00141     }
00142     return false;
00143   }
00144 
00147   bool operator()( size_t _n )
00148   {
00149     return attached_ ? subdivide( *attached_, _n ) : false;
00150   }
00151 
00154   void detach(void)
00155   {
00156     if ( attached_ )
00157     {
00158       cleanup( *attached_ );
00159       attached_ = NULL;
00160     }
00161   }
00163 
00164 protected: 
00165 
00167 
00168 
00169   virtual bool prepare( MeshType& _m ) = 0;
00170 
00172   virtual bool subdivide( MeshType& _m, size_t _n ) = 0;
00173 
00175   virtual bool cleanup( MeshType& _m ) = 0;
00177 
00178 private:
00179  
00180   MeshType *attached_;
00181 
00182 };
00183 
00184 //=============================================================================
00185 } // namespace Uniform
00186 } // namespace Subdivider
00187 } // namespace OpenMesh
00188 //=============================================================================
00189 #endif // OPENMESH_SUBDIVIDER_UNIFORM_SUBDIVIDERT_HH
00190 //=============================================================================