OpenMesh
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 // ----------------------------------------------------------------------------
45 
46 #ifndef OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
47 #define OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
48 
49 
50 //== INCLUDES =================================================================
51 
52 #include <osg/Geometry>
53 #include <OpenMesh/Core/Utils/vector_cast.hh>
54 
55 //== NAMESPACES ===============================================================
56 
57 namespace OpenMesh {
58 
59 //== CLASS DEFINITION =========================================================
60 
61 // ----------------------------------------------------------------- class ----
62 
63 #define OSG_VECTOR_TRAITS( VecType ) \
64  template <> struct vector_traits< VecType > { \
65  typedef VecType vector_type; \
66  typedef vector_type::ValueType value_type; \
67  typedef GenProg::Int2Type< vector_type::_iSize > typed_size; \
68  \
69  static const size_t size_ = vector_type::_iSize; \
70  static size_t size() { return size_; } \
71  }
72 
74 OSG_VECTOR_TRAITS( osg::Pnt4f );
76 OSG_VECTOR_TRAITS( osg::Pnt3f );
78 OSG_VECTOR_TRAITS( osg::Pnt2f );
79 
81 OSG_VECTOR_TRAITS( osg::Vec4f );
83 OSG_VECTOR_TRAITS( osg::Vec3f );
85 OSG_VECTOR_TRAITS( osg::Vec2f );
86 
88 OSG_VECTOR_TRAITS( osg::Pnt4d );
90 OSG_VECTOR_TRAITS( osg::Pnt3d );
92 OSG_VECTOR_TRAITS( osg::Pnt2d );
93 
95 OSG_VECTOR_TRAITS( osg::Vec4d );
97 OSG_VECTOR_TRAITS( osg::Vec3d );
98 
100 OSG_VECTOR_TRAITS( osg::Vec4ub );
101 
102 
103 // ----------------------------------------------------------------------------
104 
105 
106 #define OSG_COLOR_TRAITS( VecType, N ) \
107  template <> struct vector_traits< VecType > { \
108  typedef VecType vector_type; \
109  typedef vector_type::ValueType value_type; \
110  typedef GenProg::Int2Type< N > typed_size; \
111  \
112  static const size_t size_ = N; \
113  static size_t size() { return size_; } \
114  }
115 
116 
118 OSG_COLOR_TRAITS( osg::Color3ub, 3 );
120 OSG_COLOR_TRAITS( osg::Color4ub, 4 );
122 OSG_COLOR_TRAITS( osg::Color3f, 3 );
124 OSG_COLOR_TRAITS( osg::Color4f, 4 );
125 
126 #undef OSG_VECTOR_TRAITS
127 
128 
129 // ----------------------------------------
130 #if 1
131 #define PNT2VEC_CASTER( DST, SRC ) \
132  template <> struct vector_caster< DST, SRC > { \
133  typedef DST dst_t; \
134  typedef SRC src_t; \
135  typedef const dst_t& return_type; \
136  inline static return_type cast( const src_t& _src ) {\
137  return _src.subZero(); \
138  } \
139  }
140 
142 PNT2VEC_CASTER( osg::Vec3f, osg::Pnt3f );
143 
145 PNT2VEC_CASTER( osg::Vec4f, osg::Pnt4f );
146 
148 PNT2VEC_CASTER( osg::Vec3d, osg::Pnt3d );
149 
151 PNT2VEC_CASTER( osg::Vec4d, osg::Pnt4d );
152 
153 #undef PNT2VEC
154 #else
155 
156  template <>
157  struct vector_caster< osg::Vec3f, osg::Pnt3f >
158  {
159  typedef osg::Vec3f dst_t;
160  typedef osg::Pnt3f src_t;
161 
162  typedef const dst_t& return_type;
163  inline static return_type cast( const src_t& _src )
164  {
165  std::cout << "casting Pnt3f to Vec3f\n";
166  return _src.subZero();
167  }
168  };
169 
170 #endif
171 // ----------------------------------------
172 
174 inline
176 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
177 { return _v1.dot(_v2); }
178 
179 
180 inline
181 osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Pnt3f &_v2 )
182 { return _v1.dot(_v2); }
183 
184 
185 inline
186 osg::Vec2f::ValueType dot( const osg::Vec2f &_v1, const osg::Vec2f &_v2 )
187 { return _v1.dot(_v2); }
188 
189 
190 inline
191 osg::Vec3f cross( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
192 { return _v1.cross(_v2); }
194 
195 //=============================================================================
196 } // namespace OpenMesh
197 //=============================================================================
198 #endif // OPENMESH_VECTORADAPTER_HH defined
199 //=============================================================================
200 
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:176

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .