00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
00045 #define OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
00046
00047
00048
00049
00050 #include <osg/Geometry>
00051 #include <OpenMesh/Core/Utils/vector_cast.hh>
00052
00053
00054
00055 namespace OpenMesh {
00056
00057
00058
00059
00060
00061 #define OSG_VECTOR_TRAITS( VecType ) \
00062 template <> struct vector_traits< VecType > { \
00063 typedef VecType vector_type; \
00064 typedef vector_type::ValueType value_type; \
00065 typedef GenProg::Int2Type< vector_type::_iSize > typed_size; \
00066 \
00067 static const size_t size_ = vector_type::_iSize; \
00068 static size_t size() { return size_; } \
00069 }
00070
00072 OSG_VECTOR_TRAITS( osg::Pnt4f );
00074 OSG_VECTOR_TRAITS( osg::Pnt3f );
00076 OSG_VECTOR_TRAITS( osg::Pnt2f );
00077
00079 OSG_VECTOR_TRAITS( osg::Vec4f );
00081 OSG_VECTOR_TRAITS( osg::Vec3f );
00083 OSG_VECTOR_TRAITS( osg::Vec2f );
00084
00086 OSG_VECTOR_TRAITS( osg::Pnt4d );
00088 OSG_VECTOR_TRAITS( osg::Pnt3d );
00090 OSG_VECTOR_TRAITS( osg::Pnt2d );
00091
00093 OSG_VECTOR_TRAITS( osg::Vec4d );
00095 OSG_VECTOR_TRAITS( osg::Vec3d );
00096
00098 OSG_VECTOR_TRAITS( osg::Vec4ub );
00099
00100
00101
00102
00103
00104 #define OSG_COLOR_TRAITS( VecType, N ) \
00105 template <> struct vector_traits< VecType > { \
00106 typedef VecType vector_type; \
00107 typedef vector_type::ValueType value_type; \
00108 typedef GenProg::Int2Type< N > typed_size; \
00109 \
00110 static const size_t size_ = N; \
00111 static size_t size() { return size_; } \
00112 }
00113
00114
00116 OSG_COLOR_TRAITS( osg::Color3ub, 3 );
00118 OSG_COLOR_TRAITS( osg::Color4ub, 4 );
00120 OSG_COLOR_TRAITS( osg::Color3f, 3 );
00122 OSG_COLOR_TRAITS( osg::Color4f, 4 );
00123
00124 #undef OSG_VECTOR_TRAITS
00125
00126
00127
00128 #if 1
00129 #define PNT2VEC_CASTER( DST, SRC ) \
00130 template <> struct vector_caster< DST, SRC > { \
00131 typedef DST dst_t; \
00132 typedef SRC src_t; \
00133 typedef const dst_t& return_type; \
00134 inline static return_type cast( const src_t& _src ) {\
00135 return _src.subZero(); \
00136 } \
00137 }
00138
00140 PNT2VEC_CASTER( osg::Vec3f, osg::Pnt3f );
00141
00143 PNT2VEC_CASTER( osg::Vec4f, osg::Pnt4f );
00144
00146 PNT2VEC_CASTER( osg::Vec3d, osg::Pnt3d );
00147
00149 PNT2VEC_CASTER( osg::Vec4d, osg::Pnt4d );
00150
00151 #undef PNT2VEC
00152 #else
00153
00154 template <>
00155 struct vector_caster< osg::Vec3f, osg::Pnt3f >
00156 {
00157 typedef osg::Vec3f dst_t;
00158 typedef osg::Pnt3f src_t;
00159
00160 typedef const dst_t& return_type;
00161 inline static return_type cast( const src_t& _src )
00162 {
00163 std::cout << "casting Pnt3f to Vec3f\n";
00164 return _src.subZero();
00165 }
00166 };
00167
00168 #endif
00169
00170
00172
00173 inline
00174 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
00175 { return _v1.dot(_v2); }
00176
00177
00178 inline
00179 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Pnt3f &_v2 )
00180 { return _v1.dot(_v2); }
00181
00182
00183 inline
00184 osg::Vec2f::ValueType dot( const osg::Vec2f &_v1, const osg::Vec2f &_v2 )
00185 { return _v1.dot(_v2); }
00186
00187
00188 inline
00189 osg::Vec3f cross( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
00190 { return _v1.cross(_v2); }
00192
00193
00194 }
00195
00196 #endif // OPENMESH_VECTORADAPTER_HH defined
00197
00198