OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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: 837 $ *
38 * $Date: 2013-06-12 15:14:36 +0200 (Mi, 12. Jun 2013) $ *
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
183 #undef TEMPLATE_HEADER
184 #undef CLASSNAME
185 #undef DERIVED
186
187
188
189
190 //== FULL TEMPLATE SPECIALIZATIONS ============================================
191 #else
192
194 template<>
195 inline VectorT<float,3>
196 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
197 {
198 return
199 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
200 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
201 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
202 }
203
204
206 template<>
207 inline VectorT<double,3>
208 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
209 {
210 return
211 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
212 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
213 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
214 }
215
216 #endif
217
218
219
220 //== GLOBAL FUNCTIONS =========================================================
221
222
225 template<typename Scalar,int N>
226 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
227 return VectorT<Scalar,N>(_v) *= _s;
228 }
229
230
233 template<typename Scalar, int N>
234 inline Scalar
235 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
236 return (_v1 | _v2);
237 }
238
239
242 template<typename Scalar, int N>
243 inline VectorT<Scalar,N>
244 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
245 return (_v1 % _v2);
246 }
247
248
249
250
251 //== TYPEDEFS =================================================================
252
254 typedef VectorT<signed char,1> Vec1c;
256 typedef VectorT<unsigned char,1> Vec1uc;
258 typedef VectorT<signed short int,1> Vec1s;
260 typedef VectorT<unsigned short int,1> Vec1us;
262 typedef VectorT<signed int,1> Vec1i;
264 typedef VectorT<unsigned int,1> Vec1ui;
266 typedef VectorT<float,1> Vec1f;
268 typedef VectorT<double,1> Vec1d;
269
271 typedef VectorT<signed char,2> Vec2c;
273 typedef VectorT<unsigned char,2> Vec2uc;
275 typedef VectorT<signed short int,2> Vec2s;
277 typedef VectorT<unsigned short int,2> Vec2us;
279 typedef VectorT<signed int,2> Vec2i;
281 typedef VectorT<unsigned int,2> Vec2ui;
283 typedef VectorT<float,2> Vec2f;
285 typedef VectorT<double,2> Vec2d;
286
288 typedef VectorT<signed char,3> Vec3c;
290 typedef VectorT<unsigned char,3> Vec3uc;
292 typedef VectorT<signed short int,3> Vec3s;
294 typedef VectorT<unsigned short int,3> Vec3us;
296 typedef VectorT<signed int,3> Vec3i;
298 typedef VectorT<unsigned int,3> Vec3ui;
300 typedef VectorT<float,3> Vec3f;
302 typedef VectorT<double,3> Vec3d;
304 typedef VectorT<bool,3> Vec3b;
305
307 typedef VectorT<signed char,4> Vec4c;
309 typedef VectorT<unsigned char,4> Vec4uc;
311 typedef VectorT<signed short int,4> Vec4s;
313 typedef VectorT<unsigned short int,4> Vec4us;
315 typedef VectorT<signed int,4> Vec4i;
317 typedef VectorT<unsigned int,4> Vec4ui;
319 typedef VectorT<float,4> Vec4f;
321 typedef VectorT<double,4> Vec4d;
322
324 typedef VectorT<signed char,6> Vec6c;
326 typedef VectorT<unsigned char,6> Vec6uc;
328 typedef VectorT<signed short int,6> Vec6s;
330 typedef VectorT<unsigned short int,6> Vec6us;
332 typedef VectorT<signed int,6> Vec6i;
334 typedef VectorT<unsigned int,6> Vec6ui;
336 typedef VectorT<float,6> Vec6f;
338 typedef VectorT<double,6> Vec6d;
339
340
341 //=============================================================================
342 } // namespace OpenMesh
343 //=============================================================================
344 #endif // OPENMESH_VECTOR_HH defined
345 //=============================================================================
346 #endif // DOXYGEN