- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# Tools/Kernel_OSG/VectorAdapter.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 // ----------------------------------------------------------------------------
    00027
    00028 #ifndef OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
    00029 #define OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
    00030
    00031
    00032 //== INCLUDES =================================================================
    00033
    00034 #include <OpenSG/OSGGeometry.h>
    00035 #include <OpenMesh/Core/Utils/vector_cast.hh>
    00036
    00037 //== NAMESPACES ===============================================================
    00038
    00039 namespace OpenMesh {
    00040
    00041 //== CLASS DEFINITION =========================================================
    00042
    00043 // ----------------------------------------------------------------- class ----
    00044
    00045 #define OSG_VECTOR_TRAITS( VecType ) \
    00046   template <> struct vector_traits< VecType > { \
    00047     typedef VecType                vector_type; \
    00048     typedef vector_type::ValueType value_type;  \
    00049     typedef GenProg::Int2Type< vector_type::_iSize > typed_size; \
    00050     \
    00051     static const size_t size_ = vector_type::_iSize; \
    00052     static size_t size() { return size_; } \
    00053   }
    00054
    00056 OSG_VECTOR_TRAITS( osg::Pnt4f );
    00058 OSG_VECTOR_TRAITS( osg::Pnt3f );
    00060 OSG_VECTOR_TRAITS( osg::Pnt2f );
    00061
    00063 OSG_VECTOR_TRAITS( osg::Vec4f );
    00065 OSG_VECTOR_TRAITS( osg::Vec3f );
    00067 OSG_VECTOR_TRAITS( osg::Vec2f );
    00068
    00070 OSG_VECTOR_TRAITS( osg::Pnt4d );
    00072 OSG_VECTOR_TRAITS( osg::Pnt3d );
    00074 OSG_VECTOR_TRAITS( osg::Pnt2d );
    00075
    00077 OSG_VECTOR_TRAITS( osg::Vec4d );
    00079 OSG_VECTOR_TRAITS( osg::Vec3d );
    00080
    00082 OSG_VECTOR_TRAITS( osg::Vec4ub );
    00083
    00084
    00085 // ----------------------------------------------------------------------------
    00086
    00087
    00088 #define OSG_COLOR_TRAITS( VecType, N ) \
    00089   template <> struct vector_traits< VecType > { \
    00090     typedef VecType                vector_type; \
    00091     typedef vector_type::ValueType value_type;  \
    00092     typedef GenProg::Int2Type< N > typed_size; \
    00093     \
    00094     static const size_t size_ = N; \
    00095     static size_t size() { return size_; } \
    00096   }
    00097
    00098
    00100 OSG_COLOR_TRAITS( osg::Color3ub, 3 );
    00102 OSG_COLOR_TRAITS( osg::Color4ub, 4 );
    00104 OSG_COLOR_TRAITS( osg::Color3f,  3 );
    00106 OSG_COLOR_TRAITS( osg::Color4f,  4 );
    00107
    00108 #undef OSG_VECTOR_TRAITS
    00109
    00110
    00111 // ----------------------------------------
    00112 #if 1
    00113 #define PNT2VEC_CASTER( DST, SRC ) \
    00114   template <> struct vector_caster< DST, SRC > { \
    00115     typedef DST   dst_t; \
    00116     typedef SRC   src_t; \
    00117     typedef const dst_t& return_type; \
    00118     inline static return_type cast( const src_t& _src ) {\
    00119       return _src.subZero(); \
    00120     } \
    00121   }
    00122
    00124 PNT2VEC_CASTER( osg::Vec3f, osg::Pnt3f );
    00125
    00127 PNT2VEC_CASTER( osg::Vec4f, osg::Pnt4f );
    00128
    00130 PNT2VEC_CASTER( osg::Vec3d, osg::Pnt3d );
    00131
    00133 PNT2VEC_CASTER( osg::Vec4d, osg::Pnt4d );
    00134
    00135 #undef PNT2VEC
    00136 #else
    00137
    00138   template <>
    00139   struct vector_caster< osg::Vec3f, osg::Pnt3f >
    00140   {
    00141     typedef osg::Vec3f   dst_t;
    00142     typedef osg::Pnt3f   src_t;
    00143
    00144     typedef const dst_t& return_type;
    00145     inline static return_type cast( const src_t& _src )
    00146     {
    00147       std::cout << "casting Pnt3f to Vec3f\n";
    00148       return _src.subZero();
    00149     }
    00150   };
    00151
    00152 #endif
    00153 // ----------------------------------------
    00154
    00156
    00157 inline
    00158 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
    00159 { return _v1.dot(_v2); }
    00160
    00161
    00162 inline
    00163 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Pnt3f &_v2 )
    00164 { return _v1.dot(_v2); }
    00165
    00166
    00167 inline
    00168 osg::Vec2f::ValueType dot( const osg::Vec2f &_v1, const osg::Vec2f &_v2 )
    00169 { return _v1.dot(_v2); }
    00170
    00171
    00172 inline
    00173 osg::Vec3f cross( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
    00174 { return _v1.cross(_v2); }
    00176
    00177 //=============================================================================
    00178 } // namespace OpenMesh
    00179 //=============================================================================
    00180 #endif // OPENMESH_VECTORADAPTER_HH defined
    00181 //=============================================================================
    00182