OpenMesh
Loading...
Searching...
No Matches
VectorAdapter.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42/*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $Date$ *
46 * *
47\*===========================================================================*/
48
49// ----------------------------------------------------------------------------
50
51#ifndef OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
52#define OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
53
54
55//== INCLUDES =================================================================
56
57#include <osg/Geometry>
58#include <OpenMesh/Core/Utils/vector_cast.hh>
59
60//== NAMESPACES ===============================================================
61
62namespace OpenMesh {
63
64//== CLASS DEFINITION =========================================================
65
66// ----------------------------------------------------------------- class ----
67
68#define OSG_VECTOR_TRAITS( VecType ) \
69 template <> struct vector_traits< VecType > { \
70 typedef VecType vector_type; \
71 typedef vector_type::ValueType value_type; \
72 typedef GenProg::Int2Type< vector_type::_iSize > typed_size; \
73 \
74 static const size_t size_ = vector_type::_iSize; \
75 static size_t size() { return size_; } \
76 }
77
79OSG_VECTOR_TRAITS( osg::Pnt4f );
81OSG_VECTOR_TRAITS( osg::Pnt3f );
83OSG_VECTOR_TRAITS( osg::Pnt2f );
84
86OSG_VECTOR_TRAITS( osg::Vec4f );
88OSG_VECTOR_TRAITS( osg::Vec3f );
90OSG_VECTOR_TRAITS( osg::Vec2f );
91
93OSG_VECTOR_TRAITS( osg::Pnt4d );
95OSG_VECTOR_TRAITS( osg::Pnt3d );
97OSG_VECTOR_TRAITS( osg::Pnt2d );
98
100OSG_VECTOR_TRAITS( osg::Vec4d );
102OSG_VECTOR_TRAITS( osg::Vec3d );
103
105OSG_VECTOR_TRAITS( osg::Vec4ub );
106
107
108// ----------------------------------------------------------------------------
109
110
111#define OSG_COLOR_TRAITS( VecType, N ) \
112 template <> struct vector_traits< VecType > { \
113 typedef VecType vector_type; \
114 typedef vector_type::ValueType value_type; \
115 typedef GenProg::Int2Type< N > typed_size; \
116 \
117 static const size_t size_ = N; \
118 static size_t size() { return size_; } \
119 }
120
121
123OSG_COLOR_TRAITS( osg::Color3ub, 3 );
125OSG_COLOR_TRAITS( osg::Color4ub, 4 );
127OSG_COLOR_TRAITS( osg::Color3f, 3 );
129OSG_COLOR_TRAITS( osg::Color4f, 4 );
130
131#undef OSG_VECTOR_TRAITS
132
133
134// ----------------------------------------
135#if 1
136#define PNT2VEC_CASTER( DST, SRC ) \
137 template <> struct vector_caster< DST, SRC > { \
138 typedef DST dst_t; \
139 typedef SRC src_t; \
140 typedef const dst_t& return_type; \
141 inline static return_type cast( const src_t& _src ) {\
142 return _src.subZero(); \
143 } \
144 }
145
147PNT2VEC_CASTER( osg::Vec3f, osg::Pnt3f );
148
150PNT2VEC_CASTER( osg::Vec4f, osg::Pnt4f );
151
153PNT2VEC_CASTER( osg::Vec3d, osg::Pnt3d );
154
156PNT2VEC_CASTER( osg::Vec4d, osg::Pnt4d );
157
158#undef PNT2VEC
159#else
160
161 template <>
162 struct vector_caster< osg::Vec3f, osg::Pnt3f >
163 {
164 typedef osg::Vec3f dst_t;
165 typedef osg::Pnt3f src_t;
166
167 typedef const dst_t& return_type;
168 inline static return_type cast( const src_t& _src )
169 {
170 std::cout << "casting Pnt3f to Vec3f\n";
171 return _src.subZero();
172 }
173 };
174
175#endif
176// ----------------------------------------
177
179
180inline
181osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
182{ return _v1.dot(_v2); }
183
184
185inline
186osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Pnt3f &_v2 )
187{ return _v1.dot(_v2); }
188
189
190inline
191osg::Vec2f::ValueType dot( const osg::Vec2f &_v1, const osg::Vec2f &_v2 )
192{ return _v1.dot(_v2); }
193
194
195inline
196osg::Vec3f cross( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
197{ return _v1.cross(_v2); }
199
200//=============================================================================
201} // namespace OpenMesh
202//=============================================================================
203#endif // OPENMESH_VECTORADAPTER_HH defined
204//=============================================================================
205
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:64
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition VectorAdapter.hh:181
Scalar dot(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
symmetric version of the dot product
Definition Vector11T.hh:699

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