Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

PropertyKernel.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *                                                                           *
00009  *                                License                                    *
00010  *                                                                           *
00011  *  This library is free software; you can redistribute it and/or modify it  *
00012  *  under the terms of the GNU Library General Public License as published   *
00013  *  by the Free Software Foundation, version 2.                              *
00014  *                                                                           *
00015  *  This library is distributed in the hope that it will be useful, but      *
00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
00018  *  Library General Public License for more details.                         *
00019  *                                                                           *
00020  *  You should have received a copy of the GNU Library General Public        *
00021  *  License along with this library; if not, write to the Free Software      *
00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
00023  *                                                                           *
00024 \*===========================================================================*/
00025 
00026 #ifndef OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH
00027 #define OPENMESH_KENREL_OSG_PROPERTYKERNEL_HH
00028 
00029 
00030 //== INCLUDES =================================================================
00031 
00032 #include <OpenMesh/Core/Utils/Property.hh>
00033 #include <OpenMesh/Core/Mesh/Kernels/Common/BaseKernel.hh>
00034 // --------------------
00035 #include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh>
00036 
00037 //== NAMESPACES ===============================================================
00038 
00039 namespace OpenMesh {
00040 namespace Kernel_OSG {
00041 
00042 //== CLASS DEFINITION =========================================================
00043 
00049 template < typename IsTriMesh >
00050 class PropertyKernel : public OpenMesh::BaseKernel
00051 {
00052 public:
00053 
00054   // --------------------------------------------------------------- item types
00055 
00056   typedef FPropHandleT<osg::UInt8>      FPTypesHandle;
00057   typedef FPropHandleT<osg::UInt32>     FPLengthsHandle;
00058   typedef FPropHandleT<osg::UInt32>     FIndicesHandle;
00059 
00060   typedef FP::GeoPTypesUI8              GeoPTypes;
00061   typedef FP::GeoPLengthsUI32           GeoPLengths;
00062   typedef FP::GeoIndicesUI32<IsTriMesh> GeoIndices;
00063 
00064   // ------------------------------------------------- constructor / destructor
00065 
00066   PropertyKernel() {}
00067   virtual ~PropertyKernel() { }
00068 
00069 
00070 protected: // ---------------------------------------------- add osg properties
00071 
00072   // -------------------- vertex properties
00073 
00074   template < typename T >
00075   VPropHandleT<T> add_vpositions( const T& _t, const std::string& _n )
00076   { return VPropHandleT<T>(_add_vprop( new typename _t2vp<T>::prop(_n))); }
00077 
00078   template < typename T >
00079   VPropHandleT<T> add_vnormals( const T& _t, const std::string& _n )
00080   { return VPropHandleT<T>(_add_vprop( new typename _t2vn<T>::prop(_n) )); }
00081 
00082   template < typename T >
00083   VPropHandleT<T> add_vcolors( const T& _t, const std::string& _n )
00084   { return VPropHandleT<T>(_add_vprop( new typename _t2vc<T>::prop(_n) )); }
00085 
00086   template < typename T >
00087   VPropHandleT<T> add_vtexcoords( const T& _t, const std::string& _n )
00088   { return VPropHandleT<T>(_add_vprop( new typename _t2vtc<T>::prop(_n) )); }
00089 
00090 
00091   // -------------------- face properties
00092 
00093   FPTypesHandle add_fptypes( )
00094   { return FPTypesHandle(_add_fprop(new GeoPTypes)); }
00095 
00096   FPLengthsHandle add_fplengths( )
00097   { return FPLengthsHandle(_add_fprop(new GeoPLengths)); }
00098 
00099   FIndicesHandle add_findices( FPTypesHandle _pht, FPLengthsHandle _phl )
00100   { 
00101     GeoIndices *bp = new GeoIndices( fptypes(_pht), fplengths(_phl ) );
00102     return FIndicesHandle(_add_fprop( bp ) ); 
00103   }
00104 
00105 protected: // ------------------------------------------- access osg properties
00106   
00107   template < typename T >
00108   typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph ) 
00109   { return static_cast<typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
00110 
00111   template < typename T >
00112   const typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph) const
00113   { return static_cast<const typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
00114 
00115 
00116   template < typename T >
00117   typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph ) 
00118   { return static_cast<typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
00119 
00120   template < typename T >
00121   const typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph) const
00122   { return static_cast<const typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
00123 
00124 
00125   template < typename T >
00126   typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph )
00127   { return static_cast<typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
00128 
00129   template < typename T >
00130   const typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph ) const
00131   { return static_cast<const typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
00132 
00133 
00134   template < typename T >
00135   typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph )
00136   { return static_cast<typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
00137 
00138   template < typename T >
00139   const typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph ) const
00140   { return static_cast<const typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
00141 
00142 
00143   //
00144   GeoPTypes& fptypes( FPTypesHandle _ph )
00145   { return static_cast<GeoPTypes&>( _fprop(_ph) ); }
00146 
00147   const GeoPTypes& fptypes( FPTypesHandle _ph ) const
00148   { return static_cast<const GeoPTypes&>( _fprop(_ph) ); }
00149 
00150 
00151   GeoPLengths& fplengths( FPLengthsHandle _ph )
00152   { return static_cast<GeoPLengths&>( _fprop(_ph) ); }
00153 
00154   const GeoPLengths& fplengths( FPLengthsHandle _ph ) const
00155   { return static_cast<const GeoPLengths&>( _fprop(_ph) ); }
00156 
00157 
00158   GeoIndices& findices( FIndicesHandle _ph )
00159   { return static_cast<GeoIndices&>( _fprop(_ph) ); }
00160 
00161   const GeoIndices& findices( FIndicesHandle _ph ) const
00162   { return static_cast<const GeoIndices&>( _fprop(_ph) ); }
00163 
00164     
00165 protected: // ------------------------------------ access osg property elements
00166 
00167   template <typename T> 
00168   T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh ) 
00169   { return vpositions(_ph)[_vh.idx()]; }
00170 
00171   template <class T>
00172   const T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00173   { return vpositions(_ph)[_vh.idx()]; }
00174 
00175 
00176   template < typename T> 
00177   T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh ) 
00178   { return vnormals(_ph)[_vh.idx()]; }
00179 
00180   template <class T>
00181   const T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00182   { return vnormals(_ph)[_vh.idx()]; }
00183 
00184 
00185   template < typename T> 
00186   T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh ) 
00187   { return vcolors(_ph)[_vh.idx()]; }
00188 
00189   template <class T>
00190   const T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00191   { return vcolors(_ph)[_vh.idx()]; }
00192 
00193 
00194   template < typename T> 
00195   T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh ) 
00196   { return vtexcoords(_ph)[_vh.idx()]; }
00197 
00198   template <class T>
00199   const T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00200   { return vtexcoords(_ph)[_vh.idx()]; }
00201 
00202 
00203   // -------------------- access face property elements
00204 
00205   FPTypesHandle::value_type& 
00206   fptypes( FPTypesHandle _ph, FaceHandle _fh )
00207   { return fptypes( _ph )[ _fh.idx()]; }
00208 
00209   const FPTypesHandle::value_type& 
00210   fptypes( FPTypesHandle _ph, FaceHandle _fh ) const
00211   { return fptypes( _ph )[ _fh.idx()]; }
00212 
00213 
00214   FPLengthsHandle::value_type& 
00215   fplengths( FPLengthsHandle _ph, FaceHandle _fh )
00216   { return fplengths( _ph )[ _fh.idx()]; }
00217 
00218   const FPLengthsHandle::value_type& 
00219   fplengths( FPLengthsHandle _ph, FaceHandle _fh ) const
00220   { return fplengths( _ph )[ _fh.idx()]; }
00221 
00222 
00223   FIndicesHandle::value_type& 
00224   findices( FIndicesHandle _ph, FaceHandle _fh )
00225   { return findices( _ph )[ _fh.idx()]; }
00226 
00227   const FIndicesHandle::value_type& 
00228   findices( FIndicesHandle _ph, FaceHandle _fh ) const
00229   { return findices( _ph )[ _fh.idx()]; }
00230 
00231 public:
00232 
00233   void stats(void)
00234   {
00235     std::cout << "#V : "  << n_vertices() << std::endl;
00236     std::cout << "#E : "  << n_edges() << std::endl;
00237     std::cout << "#F : "  << n_faces() << std::endl;
00238     property_stats();
00239   }
00240 };
00241 
00242 
00243 //=============================================================================
00244 } // namespace Kernel_OSG
00245 } // namespace OpenMesh
00246 //=============================================================================
00247 #endif // OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH defined
00248 //=============================================================================
00249 

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .