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
VectorT.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: 775 $ *
38 * $Date: 2012-12-05 18:59:57 +0100 (Mi, 05 Dez 2012) $ *
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 <assert.h>
67 #include <math.h>
68 #include <string.h>
69
70 #if defined(__GNUC__) && defined(__SSE__)
71 #include <xmmintrin.h>
72 #endif
73
74
75 //== NAMESPACES ===============================================================
76
77
78 namespace OpenMesh {
79
80
81 //== CLASS DEFINITION =========================================================
82
83
84
94 template <typename Scalar,int N> struct VectorDataT
95 {
96 Scalar values_[N];
97 };
98
99
100 #if defined(__GNUC__) && defined(__SSE__)
101
103 template <> struct VectorDataT<float, 4>
104 {
105 union
106 {
107 __m128 m128;
108 float values_[4];
109 };
110 };
111
112 #endif
113
114
115
116
117 //== CLASS DEFINITION =========================================================
118
119
120 #define DIM N
121 #define TEMPLATE_HEADER template <typename Scalar, int N>
122 #define CLASSNAME VectorT
123 #define DERIVED VectorDataT<Scalar,N>
124 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
125
131 #include "VectorT_inc.hh"
132
133 #undef DIM
134 #undef TEMPLATE_HEADER
135 #undef CLASSNAME
136 #undef DERIVED
137 #undef unroll
138
139
140
141
142 //== PARTIAL TEMPLATE SPECIALIZATIONS =========================================
143 #if OM_PARTIAL_SPECIALIZATION
144
145
146 #define TEMPLATE_HEADER template <typename Scalar>
147 #define CLASSNAME VectorT<Scalar,DIM>
148 #define DERIVED VectorDataT<Scalar,DIM>
149
150
151 #define DIM 2
152 #define unroll(expr) expr(0) expr(1)
153 #define unroll_comb(expr, op) expr(0) op expr(1)
154 #define unroll_csv(expr) expr(0), expr(1)
155 #include "VectorT_inc.hh"
156 #undef DIM
157 #undef unroll
158 #undef unroll_comb
159 #undef unroll_csv
160
161
162 #define DIM 3
163 #define unroll(expr) expr(0) expr(1) expr(2)
164 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
165 #define unroll_csv(expr) expr(0), expr(1), expr(2)
166 #include "VectorT_inc.hh"
167 #undef DIM
168 #undef unroll
169 #undef unroll_comb
170 #undef unroll_csv
171
172
173 #define DIM 4
174 #define unroll(expr) expr(0) expr(1) expr(2) expr(3)
175 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
176 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
177 #include "VectorT_inc.hh"
178 #undef DIM
179 #undef unroll
180 #undef unroll_comb
181 #undef unroll_csv
182
183
184 #undef TEMPLATE_HEADER
185 #undef CLASSNAME
186 #undef DERIVED
187
188
189
190
191 //== FULL TEMPLATE SPECIALIZATIONS ============================================
192 #else
193
195 template<>
196 inline VectorT<float,3>
197 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
198 {
199 return
200 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
201 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
202 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
203 }
204
205
207 template<>
208 inline VectorT<double,3>
209 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
210 {
211 return
212 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
213 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
214 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
215 }
216
217 #endif
218
219
220
221 //== GLOBAL FUNCTIONS =========================================================
222
223
226 template<typename Scalar,int N>
227 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
228 return VectorT<Scalar,N>(_v) *= _s;
229 }
230
231
234 template<typename Scalar, int N>
235 inline Scalar
236 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
237 return (_v1 | _v2);
238 }
239
240
243 template<typename Scalar, int N>
244 inline VectorT<Scalar,N>
245 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
246 return (_v1 % _v2);
247 }
248
249
250
251
252 //== TYPEDEFS =================================================================
253
255 typedef VectorT<signed char,1> Vec1c;
257 typedef VectorT<unsigned char,1> Vec1uc;
259 typedef VectorT<signed short int,1> Vec1s;
261 typedef VectorT<unsigned short int,1> Vec1us;
263 typedef VectorT<signed int,1> Vec1i;
265 typedef VectorT<unsigned int,1> Vec1ui;
267 typedef VectorT<float,1> Vec1f;
269 typedef VectorT<double,1> Vec1d;
270
272 typedef VectorT<signed char,2> Vec2c;
274 typedef VectorT<unsigned char,2> Vec2uc;
276 typedef VectorT<signed short int,2> Vec2s;
278 typedef VectorT<unsigned short int,2> Vec2us;
280 typedef VectorT<signed int,2> Vec2i;
282 typedef VectorT<unsigned int,2> Vec2ui;
284 typedef VectorT<float,2> Vec2f;
286 typedef VectorT<double,2> Vec2d;
287
289 typedef VectorT<signed char,3> Vec3c;
291 typedef VectorT<unsigned char,3> Vec3uc;
293 typedef VectorT<signed short int,3> Vec3s;
295 typedef VectorT<unsigned short int,3> Vec3us;
297 typedef VectorT<signed int,3> Vec3i;
299 typedef VectorT<unsigned int,3> Vec3ui;
301 typedef VectorT<float,3> Vec3f;
303 typedef VectorT<double,3> Vec3d;
305 typedef VectorT<bool,3> Vec3b;
306
308 typedef VectorT<signed char,4> Vec4c;
310 typedef VectorT<unsigned char,4> Vec4uc;
312 typedef VectorT<signed short int,4> Vec4s;
314 typedef VectorT<unsigned short int,4> Vec4us;
316 typedef VectorT<signed int,4> Vec4i;
318 typedef VectorT<unsigned int,4> Vec4ui;
320 typedef VectorT<float,4> Vec4f;
322 typedef VectorT<double,4> Vec4d;
323
325 typedef VectorT<signed char,6> Vec6c;
327 typedef VectorT<unsigned char,6> Vec6uc;
329 typedef VectorT<signed short int,6> Vec6s;
331 typedef VectorT<unsigned short int,6> Vec6us;
333 typedef VectorT<signed int,6> Vec6i;
335 typedef VectorT<unsigned int,6> Vec6ui;
337 typedef VectorT<float,6> Vec6f;
339 typedef VectorT<double,6> Vec6d;
340
341
342 //=============================================================================
343 } // namespace OpenMesh
344 //=============================================================================
345 #endif // OPENMESH_VECTOR_HH defined
346 //=============================================================================
347 #endif // DOXYGEN