OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VectorT.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2015 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: 1193 $ *
38  * $Date: 2015-01-14 14:11:23 +0100 (Mi, 14 Jan 2015) $ *
39  * *
40 \*===========================================================================*/
41 
42 
43 //=============================================================================
44 //
45 // CLASS VectorT
46 //
47 //=============================================================================
48 
49 // Don't parse this header file with doxygen since
50 // for some reason (obviously due to a bug in doxygen,
51 // bugreport: https://bugzilla.gnome.org/show_bug.cgi?id=629182)
52 // macro expansion and preprocessor defines
53 // don't work properly.
54 #ifndef DOXYGEN
55 
56 #ifndef OPENMESH_VECTOR_HH
57 #define OPENMESH_VECTOR_HH
58 
59 
60 //== INCLUDES =================================================================
61 
62 
63 #include <OpenMesh/Core/System/config.h>
64 #include <iostream>
65 #include <cmath>
66 #include <cassert>
67 #include <cstring>
68 
69 #if defined(__GNUC__) && defined(__SSE__)
70 #include <xmmintrin.h>
71 #endif
72 
73 
74 //== NAMESPACES ===============================================================
75 
76 
77 namespace OpenMesh {
78 
79 
80 //== CLASS DEFINITION =========================================================
81 
82 
83 
93 template <typename Scalar,int N> struct VectorDataT
94 {
95  Scalar values_[N];
96 };
97 
98 
99 #if defined(__GNUC__) && defined(__SSE__)
100 
102 template <> struct VectorDataT<float, 4>
103 {
104  union
105  {
106  __m128 m128;
107  float values_[4];
108  };
109 };
110 
111 #endif
112 
113 
114 
115 
116 //== CLASS DEFINITION =========================================================
117 
118 
119 #define DIM N
120 #define TEMPLATE_HEADER template <typename Scalar, int N>
121 #define CLASSNAME VectorT
122 #define DERIVED VectorDataT<Scalar,N>
123 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
124 
130 #include "VectorT_inc.hh"
131 
132 #undef DIM
133 #undef TEMPLATE_HEADER
134 #undef CLASSNAME
135 #undef DERIVED
136 #undef unroll
137 
138 
139 
140 
141 //== PARTIAL TEMPLATE SPECIALIZATIONS =========================================
142 #if OM_PARTIAL_SPECIALIZATION
143 
144 
145 #define TEMPLATE_HEADER template <typename Scalar>
146 #define CLASSNAME VectorT<Scalar,DIM>
147 #define DERIVED VectorDataT<Scalar,DIM>
148 
149 
150 #define DIM 2
151 #define unroll(expr) expr(0) expr(1)
152 #define unroll_comb(expr, op) expr(0) op expr(1)
153 #define unroll_csv(expr) expr(0), expr(1)
154 #include "VectorT_inc.hh"
155 #undef DIM
156 #undef unroll
157 #undef unroll_comb
158 #undef unroll_csv
159 
160 
161 #define DIM 3
162 #define unroll(expr) expr(0) expr(1) expr(2)
163 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
164 #define unroll_csv(expr) expr(0), expr(1), expr(2)
165 #include "VectorT_inc.hh"
166 #undef DIM
167 #undef unroll
168 #undef unroll_comb
169 #undef unroll_csv
170 
171 
172 #define DIM 4
173 #define unroll(expr) expr(0) expr(1) expr(2) expr(3)
174 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
175 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
176 #include "VectorT_inc.hh"
177 #undef DIM
178 #undef unroll
179 #undef unroll_comb
180 #undef unroll_csv
181 
182 #define DIM 5
183 #define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4)
184 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4)
185 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4)
186 #include "VectorT_inc.hh"
187 #undef DIM
188 #undef unroll
189 #undef unroll_comb
190 #undef unroll_csv
191 
192 #define DIM 6
193 #define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4) expr(5)
194 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4) op expr(5)
195 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4), expr(5)
196 #include "VectorT_inc.hh"
197 #undef DIM
198 #undef unroll
199 #undef unroll_comb
200 #undef unroll_csv
201 
202 
203 #undef TEMPLATE_HEADER
204 #undef CLASSNAME
205 #undef DERIVED
206 
207 
208 
209 
210 //== FULL TEMPLATE SPECIALIZATIONS ============================================
211 #else
212 
214 template<>
215 inline VectorT<float,3>
217 {
218  return
219  VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
220  values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
221  values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
222 }
223 
224 
226 template<>
227 inline VectorT<double,3>
229 {
230  return
231  VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
232  values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
233  values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
234 }
235 
236 #endif
237 
238 
239 
240 //== GLOBAL FUNCTIONS =========================================================
241 
242 
245 template<typename Scalar,int N>
246 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
247  return VectorT<Scalar,N>(_v) *= _s;
248 }
249 
250 
253 template<typename Scalar, int N>
254 inline Scalar
255 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
256  return (_v1 | _v2);
257 }
258 
259 
262 template<typename Scalar, int N>
263 inline VectorT<Scalar,N>
264 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
265  return (_v1 % _v2);
266 }
267 
268 
269 
270 
271 //== TYPEDEFS =================================================================
272 
274 typedef VectorT<signed char,1> Vec1c;
276 typedef VectorT<unsigned char,1> Vec1uc;
278 typedef VectorT<signed short int,1> Vec1s;
280 typedef VectorT<unsigned short int,1> Vec1us;
282 typedef VectorT<signed int,1> Vec1i;
284 typedef VectorT<unsigned int,1> Vec1ui;
286 typedef VectorT<float,1> Vec1f;
288 typedef VectorT<double,1> Vec1d;
289 
291 typedef VectorT<signed char,2> Vec2c;
293 typedef VectorT<unsigned char,2> Vec2uc;
295 typedef VectorT<signed short int,2> Vec2s;
297 typedef VectorT<unsigned short int,2> Vec2us;
299 typedef VectorT<signed int,2> Vec2i;
301 typedef VectorT<unsigned int,2> Vec2ui;
303 typedef VectorT<float,2> Vec2f;
305 typedef VectorT<double,2> Vec2d;
306 
308 typedef VectorT<signed char,3> Vec3c;
310 typedef VectorT<unsigned char,3> Vec3uc;
312 typedef VectorT<signed short int,3> Vec3s;
314 typedef VectorT<unsigned short int,3> Vec3us;
316 typedef VectorT<signed int,3> Vec3i;
318 typedef VectorT<unsigned int,3> Vec3ui;
320 typedef VectorT<float,3> Vec3f;
322 typedef VectorT<double,3> Vec3d;
324 typedef VectorT<bool,3> Vec3b;
325 
327 typedef VectorT<signed char,4> Vec4c;
329 typedef VectorT<unsigned char,4> Vec4uc;
331 typedef VectorT<signed short int,4> Vec4s;
333 typedef VectorT<unsigned short int,4> Vec4us;
335 typedef VectorT<signed int,4> Vec4i;
337 typedef VectorT<unsigned int,4> Vec4ui;
339 typedef VectorT<float,4> Vec4f;
341 typedef VectorT<double,4> Vec4d;
342 
344 typedef VectorT<signed char, 5> Vec5c;
346 typedef VectorT<unsigned char, 5> Vec5uc;
348 typedef VectorT<signed short int, 5> Vec5s;
350 typedef VectorT<unsigned short int, 5> Vec5us;
352 typedef VectorT<signed int, 5> Vec5i;
354 typedef VectorT<unsigned int, 5> Vec5ui;
356 typedef VectorT<float, 5> Vec5f;
358 typedef VectorT<double, 5> Vec5d;
359 
361 typedef VectorT<signed char,6> Vec6c;
363 typedef VectorT<unsigned char,6> Vec6uc;
365 typedef VectorT<signed short int,6> Vec6s;
367 typedef VectorT<unsigned short int,6> Vec6us;
369 typedef VectorT<signed int,6> Vec6i;
371 typedef VectorT<unsigned int,6> Vec6ui;
373 typedef VectorT<float,6> Vec6f;
375 typedef VectorT<double,6> Vec6d;
376 
377 
378 //=============================================================================
379 } // namespace OpenMesh
380 //=============================================================================
381 #endif // OPENMESH_VECTOR_HH defined
382 //=============================================================================
383 #endif // DOXYGEN
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:189
Definition: VectorT_inc.hh:63
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:174
VectorT< Scalar, 3 > operator%(const VectorT< Scalar, 3 > &_rhs) const
cross product: only defined for Vec3* as specialization
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56

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