OpenMesh

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
VectorAdapter.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
42 // ----------------------------------------------------------------------------
43
44 #ifndef OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
45 #define OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
46
47
48 //== INCLUDES =================================================================
49
50 #include <osg/Geometry>
51 #include <OpenMesh/Core/Utils/vector_cast.hh>
52
53 //== NAMESPACES ===============================================================
54
55 namespace OpenMesh {
56
57 //== CLASS DEFINITION =========================================================
58
59 // ----------------------------------------------------------------- class ----
60
61 #define OSG_VECTOR_TRAITS( VecType ) \
62 template <> struct vector_traits< VecType > { \
63 typedef VecType vector_type; \
64 typedef vector_type::ValueType value_type; \
65 typedef GenProg::Int2Type< vector_type::_iSize > typed_size; \
66 \
67 static const size_t size_ = vector_type::_iSize; \
68 static size_t size() { return size_; } \
69 }
70
72 OSG_VECTOR_TRAITS( osg::Pnt4f );
74 OSG_VECTOR_TRAITS( osg::Pnt3f );
76 OSG_VECTOR_TRAITS( osg::Pnt2f );
77
79 OSG_VECTOR_TRAITS( osg::Vec4f );
81 OSG_VECTOR_TRAITS( osg::Vec3f );
83 OSG_VECTOR_TRAITS( osg::Vec2f );
84
86 OSG_VECTOR_TRAITS( osg::Pnt4d );
88 OSG_VECTOR_TRAITS( osg::Pnt3d );
90 OSG_VECTOR_TRAITS( osg::Pnt2d );
91
93 OSG_VECTOR_TRAITS( osg::Vec4d );
95 OSG_VECTOR_TRAITS( osg::Vec3d );
96
98 OSG_VECTOR_TRAITS( osg::Vec4ub );
99
100
101 // ----------------------------------------------------------------------------
102
103
104 #define OSG_COLOR_TRAITS( VecType, N ) \
105 template <> struct vector_traits< VecType > { \
106 typedef VecType vector_type; \
107 typedef vector_type::ValueType value_type; \
108 typedef GenProg::Int2Type< N > typed_size; \
109 \
110 static const size_t size_ = N; \
111 static size_t size() { return size_; } \
112 }
113
114
116 OSG_COLOR_TRAITS( osg::Color3ub, 3 );
118 OSG_COLOR_TRAITS( osg::Color4ub, 4 );
120 OSG_COLOR_TRAITS( osg::Color3f, 3 );
122 OSG_COLOR_TRAITS( osg::Color4f, 4 );
123
124 #undef OSG_VECTOR_TRAITS
125
126
127 // ----------------------------------------
128 #if 1
129 #define PNT2VEC_CASTER( DST, SRC ) \
130 template <> struct vector_caster< DST, SRC > { \
131 typedef DST dst_t; \
132 typedef SRC src_t; \
133 typedef const dst_t& return_type; \
134 inline static return_type cast( const src_t& _src ) {\
135 return _src.subZero(); \
136 } \
137 }
138
140 PNT2VEC_CASTER( osg::Vec3f, osg::Pnt3f );
141
143 PNT2VEC_CASTER( osg::Vec4f, osg::Pnt4f );
144
146 PNT2VEC_CASTER( osg::Vec3d, osg::Pnt3d );
147
149 PNT2VEC_CASTER( osg::Vec4d, osg::Pnt4d );
150
151 #undef PNT2VEC
152 #else
153
154 template <>
155 struct vector_caster< osg::Vec3f, osg::Pnt3f >
156 {
157 typedef osg::Vec3f dst_t;
158 typedef osg::Pnt3f src_t;
159
160 typedef const dst_t& return_type;
161 inline static return_type cast( const src_t& _src )
162 {
163 std::cout << "casting Pnt3f to Vec3f\n";
164 return _src.subZero();
165 }
166 };
167
168 #endif
169 // ----------------------------------------
170
172
173 inline
174 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
175 { return _v1.dot(_v2); }
176
177
178 inline
179 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Pnt3f &_v2 )
180 { return _v1.dot(_v2); }
181
182
183 inline
184 osg::Vec2f::ValueType dot( const osg::Vec2f &_v1, const osg::Vec2f &_v2 )
185 { return _v1.dot(_v2); }
186
187
188 inline
189 osg::Vec3f cross( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
190 { return _v1.cross(_v2); }
192
193 //=============================================================================
194 } // namespace OpenMesh
195 //=============================================================================
196 #endif // OPENMESH_VECTORADAPTER_HH defined
197 //=============================================================================
198