Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 (Wed, 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 
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 
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 
203 #undef TEMPLATE_HEADER
204 #undef CLASSNAME
205 #undef DERIVED
206 
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 }
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 
289 
306 
325 
342 
359 
376 
377 
378 //=============================================================================
379 } // namespace OpenMesh
380 //=============================================================================
381 #endif // OPENMESH_VECTOR_HH defined
382 //=============================================================================
383 #endif // DOXYGEN
VectorT< double, 4 > Vec4d
Definition: VectorT.hh:341
VectorT< unsigned short int, 5 > Vec5us
Definition: VectorT.hh:350
VectorT< signed short int, 4 > Vec4s
Definition: VectorT.hh:331
VectorT< float, 2 > Vec2f
Definition: VectorT.hh:303
VectorT< unsigned char, 6 > Vec6uc
Definition: VectorT.hh:363
VectorT< float, 6 > Vec6f
Definition: VectorT.hh:373
VectorT< signed char, 4 > Vec4c
Definition: VectorT.hh:327
VectorT< float, 5 > Vec5f
Definition: VectorT.hh:356
VectorT< unsigned int, 5 > Vec5ui
Definition: VectorT.hh:354
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:320
VectorT< unsigned short int, 2 > Vec2us
Definition: VectorT.hh:297
VectorT< unsigned int, 2 > Vec2ui
Definition: VectorT.hh:301
VectorT< signed int, 6 > Vec6i
Definition: VectorT.hh:369
VectorT< signed int, 1 > Vec1i
Definition: VectorT.hh:282
VectorT< unsigned char, 1 > Vec1uc
Definition: VectorT.hh:276
VectorT< double, 1 > Vec1d
Definition: VectorT.hh:288
VectorT< unsigned int, 1 > Vec1ui
Definition: VectorT.hh:284
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:322
VectorT< signed short int, 3 > Vec3s
Definition: VectorT.hh:312
VectorT< signed int, 5 > Vec5i
Definition: VectorT.hh:352
VectorT< signed char, 2 > Vec2c
Definition: VectorT.hh:291
VectorT< unsigned int, 6 > Vec6ui
Definition: VectorT.hh:371
VectorT< unsigned char, 4 > Vec4uc
Definition: VectorT.hh:329
VectorT< double, 2 > Vec2d
Definition: VectorT.hh:305
VectorT< signed char, 3 > Vec3c
Definition: VectorT.hh:308
VectorT< signed char, 6 > Vec6c
Definition: VectorT.hh:361
VectorT< signed short int, 2 > Vec2s
Definition: VectorT.hh:295
VectorT< unsigned int, 3 > Vec3ui
Definition: VectorT.hh:318
VectorT< bool, 3 > Vec3b
Definition: VectorT.hh:324
VectorT< unsigned short int, 4 > Vec4us
Definition: VectorT.hh:333
VectorT< unsigned char, 2 > Vec2uc
Definition: VectorT.hh:293
VectorT< signed char, 1 > Vec1c
Definition: VectorT.hh:274
VectorT< signed char, 5 > Vec5c
Definition: VectorT.hh:344
VectorT< unsigned char, 3 > Vec3uc
Definition: VectorT.hh:310
VectorT< unsigned short int, 3 > Vec3us
Definition: VectorT.hh:314
VectorT< signed int, 2 > Vec2i
Definition: VectorT.hh:299
VectorT< unsigned char, 5 > Vec5uc
Definition: VectorT.hh:346
VectorT< unsigned short int, 6 > Vec6us
Definition: VectorT.hh:367
VectorT< signed short int, 5 > Vec5s
Definition: VectorT.hh:348
VectorT< signed int, 4 > Vec4i
Definition: VectorT.hh:335
VectorT< signed int, 3 > Vec3i
Definition: VectorT.hh:316
VectorT< signed short int, 6 > Vec6s
Definition: VectorT.hh:365
VectorT< double, 6 > Vec6d
Definition: VectorT.hh:375
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:339
VectorT< unsigned int, 4 > Vec4ui
Definition: VectorT.hh:337
VectorT< unsigned short int, 1 > Vec1us
Definition: VectorT.hh:280
VectorT< signed short int, 1 > Vec1s
Definition: VectorT.hh:278
VectorT< float, 1 > Vec1f
Definition: VectorT.hh:286
VectorT< double, 5 > Vec5d
Definition: VectorT.hh:358