OpenMesh
OpenMesh/Tools/Kernel_OSG/PropertyKernel.hh
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 
00042 #ifndef OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH
00043 #define OPENMESH_KENREL_OSG_PROPERTYKERNEL_HH
00044 
00045 
00046 //== INCLUDES =================================================================
00047 
00048 #include <OpenMesh/Core/Utils/Property.hh>
00049 #include <OpenMesh/Core/Mesh/BaseKernel.hh>
00050 // --------------------
00051 #include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh>
00052 
00053 //== NAMESPACES ===============================================================
00054 
00055 namespace OpenMesh {
00056 namespace Kernel_OSG {
00057 
00058 //== CLASS DEFINITION =========================================================
00059 
00065 template < typename IsTriMesh >
00066 class PropertyKernel : public OpenMesh::BaseKernel
00067 {
00068 public:
00069 
00070   // --------------------------------------------------------------- item types
00071 
00072   typedef FPropHandleT<osg::UInt8>      FPTypesHandle;
00073   typedef FPropHandleT<osg::UInt32>     FPLengthsHandle;
00074   typedef FPropHandleT<osg::UInt32>     FIndicesHandle;
00075 
00076   typedef FP::GeoPTypesUI8              GeoPTypes;
00077   typedef FP::GeoPLengthsUI32           GeoPLengths;
00078   typedef FP::GeoIndicesUI32<IsTriMesh> GeoIndices;
00079 
00080   // ------------------------------------------------- constructor / destructor
00081 
00082   PropertyKernel() {}
00083   virtual ~PropertyKernel() { }
00084 
00085 
00086 protected: // ---------------------------------------------- add osg properties
00087 
00088   // -------------------- vertex properties
00089 
00090   template < typename T >
00091   VPropHandleT<T> add_vpositions( const T& _t, const std::string& _n )
00092   { return VPropHandleT<T>(_add_vprop( new typename _t2vp<T>::prop(_n))); }
00093 
00094   template < typename T >
00095   VPropHandleT<T> add_vnormals( const T& _t, const std::string& _n )
00096   { return VPropHandleT<T>(_add_vprop( new typename _t2vn<T>::prop(_n) )); }
00097 
00098   template < typename T >
00099   VPropHandleT<T> add_vcolors( const T& _t, const std::string& _n )
00100   { return VPropHandleT<T>(_add_vprop( new typename _t2vc<T>::prop(_n) )); }
00101 
00102   template < typename T >
00103   VPropHandleT<T> add_vtexcoords( const T& _t, const std::string& _n )
00104   { return VPropHandleT<T>(_add_vprop( new typename _t2vtc<T>::prop(_n) )); }
00105 
00106 
00107   // -------------------- face properties
00108 
00109   FPTypesHandle add_fptypes( )
00110   { return FPTypesHandle(_add_fprop(new GeoPTypes)); }
00111 
00112   FPLengthsHandle add_fplengths( )
00113   { return FPLengthsHandle(_add_fprop(new GeoPLengths)); }
00114 
00115   FIndicesHandle add_findices( FPTypesHandle _pht, FPLengthsHandle _phl )
00116   { 
00117     GeoIndices *bp = new GeoIndices( fptypes(_pht), fplengths(_phl ) );
00118     return FIndicesHandle(_add_fprop( bp ) ); 
00119   }
00120 
00121 protected: // ------------------------------------------- access osg properties
00122   
00123   template < typename T >
00124   typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph ) 
00125   { return static_cast<typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
00126 
00127   template < typename T >
00128   const typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph) const
00129   { return static_cast<const typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
00130 
00131 
00132   template < typename T >
00133   typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph ) 
00134   { return static_cast<typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
00135 
00136   template < typename T >
00137   const typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph) const
00138   { return static_cast<const typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
00139 
00140 
00141   template < typename T >
00142   typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph )
00143   { return static_cast<typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
00144 
00145   template < typename T >
00146   const typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph ) const
00147   { return static_cast<const typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
00148 
00149 
00150   template < typename T >
00151   typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph )
00152   { return static_cast<typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
00153 
00154   template < typename T >
00155   const typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph ) const
00156   { return static_cast<const typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
00157 
00158 
00159   //
00160   GeoPTypes& fptypes( FPTypesHandle _ph )
00161   { return static_cast<GeoPTypes&>( _fprop(_ph) ); }
00162 
00163   const GeoPTypes& fptypes( FPTypesHandle _ph ) const
00164   { return static_cast<const GeoPTypes&>( _fprop(_ph) ); }
00165 
00166 
00167   GeoPLengths& fplengths( FPLengthsHandle _ph )
00168   { return static_cast<GeoPLengths&>( _fprop(_ph) ); }
00169 
00170   const GeoPLengths& fplengths( FPLengthsHandle _ph ) const
00171   { return static_cast<const GeoPLengths&>( _fprop(_ph) ); }
00172 
00173 
00174   GeoIndices& findices( FIndicesHandle _ph )
00175   { return static_cast<GeoIndices&>( _fprop(_ph) ); }
00176 
00177   const GeoIndices& findices( FIndicesHandle _ph ) const
00178   { return static_cast<const GeoIndices&>( _fprop(_ph) ); }
00179 
00180     
00181 protected: // ------------------------------------ access osg property elements
00182 
00183   template <typename T> 
00184   T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh ) 
00185   { return vpositions(_ph)[_vh.idx()]; }
00186 
00187   template <class T>
00188   const T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00189   { return vpositions(_ph)[_vh.idx()]; }
00190 
00191 
00192   template < typename T> 
00193   T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh ) 
00194   { return vnormals(_ph)[_vh.idx()]; }
00195 
00196   template <class T>
00197   const T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00198   { return vnormals(_ph)[_vh.idx()]; }
00199 
00200 
00201   template < typename T> 
00202   T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh ) 
00203   { return vcolors(_ph)[_vh.idx()]; }
00204 
00205   template <class T>
00206   const T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00207   { return vcolors(_ph)[_vh.idx()]; }
00208 
00209 
00210   template < typename T> 
00211   T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh ) 
00212   { return vtexcoords(_ph)[_vh.idx()]; }
00213 
00214   template <class T>
00215   const T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh ) const 
00216   { return vtexcoords(_ph)[_vh.idx()]; }
00217 
00218 
00219   // -------------------- access face property elements
00220 
00221   FPTypesHandle::value_type& 
00222   fptypes( FPTypesHandle _ph, FaceHandle _fh )
00223   { return fptypes( _ph )[ _fh.idx()]; }
00224 
00225   const FPTypesHandle::value_type& 
00226   fptypes( FPTypesHandle _ph, FaceHandle _fh ) const
00227   { return fptypes( _ph )[ _fh.idx()]; }
00228 
00229 
00230   FPLengthsHandle::value_type& 
00231   fplengths( FPLengthsHandle _ph, FaceHandle _fh )
00232   { return fplengths( _ph )[ _fh.idx()]; }
00233 
00234   const FPLengthsHandle::value_type& 
00235   fplengths( FPLengthsHandle _ph, FaceHandle _fh ) const
00236   { return fplengths( _ph )[ _fh.idx()]; }
00237 
00238 
00239   FIndicesHandle::value_type& 
00240   findices( FIndicesHandle _ph, FaceHandle _fh )
00241   { return findices( _ph )[ _fh.idx()]; }
00242 
00243   const FIndicesHandle::value_type& 
00244   findices( FIndicesHandle _ph, FaceHandle _fh ) const
00245   { return findices( _ph )[ _fh.idx()]; }
00246 
00247 public:
00248 
00249   void stats(void)
00250   {
00251     std::cout << "#V : "  << n_vertices() << std::endl;
00252     std::cout << "#E : "  << n_edges() << std::endl;
00253     std::cout << "#F : "  << n_faces() << std::endl;
00254     property_stats();
00255   }
00256 };
00257 
00258 
00259 //=============================================================================
00260 } // namespace Kernel_OSG
00261 } // namespace OpenMesh
00262 //=============================================================================
00263 #endif // OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH defined
00264 //=============================================================================
00265 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines