OpenVolumeMesh
 All Classes Functions Variables Typedefs Pages
VectorT.hh
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh 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  * OpenVolumeMesh 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 OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 93 $ *
38  * $Date: 2012-02-10 11:56:12 +0100 (Fr, 10 Feb 2012) $ *
39  * $LastChangedBy: kremer $ *
40  * *
41 \*===========================================================================*/
42 
43 //=============================================================================
44 //
45 // CLASS VectorT originally taken from OpenMesh
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 OPENVOLUMEMESH_VECTOR_HH
57 #define OPENVOLUMEMESH_VECTOR_HH
58 
59 
60 //== INCLUDES =================================================================
61 
62 #include <iostream>
63 #include <assert.h>
64 #include <math.h>
65 #include <string.h>
66 
67 #if defined(__GNUC__) && defined(__SSE__)
68 #include <xmmintrin.h>
69 #endif
70 
71 
72 //== NAMESPACES ===============================================================
73 
74 namespace OpenVolumeMesh {
75 
76 namespace Geometry {
77 
78 //== CLASS DEFINITION =========================================================
79 
80 
81 
91 template <typename Scalar,int N> struct VectorDataT
92 {
93  Scalar values_[N];
94 };
95 
96 
97 #if defined(__GNUC__) && defined(__SSE__)
98 
100 template <> struct VectorDataT<float, 4>
101 {
102  union
103  {
104  __m128 m128;
105  float values_[4];
106  };
107 };
108 
109 #endif
110 
111 
112 
113 
114 //== CLASS DEFINITION =========================================================
115 
116 
117 #define DIM N
118 #define TEMPLATE_HEADER template <typename Scalar, int N>
119 #define CLASSNAME VectorT
120 #define DERIVED VectorDataT<Scalar,N>
121 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
122 
128 #include "VectorT_inc.hh"
129 
130 #undef DIM
131 #undef TEMPLATE_HEADER
132 #undef CLASSNAME
133 #undef DERIVED
134 #undef unroll
135 
136 
137 
138 
139 //== PARTIAL TEMPLATE SPECIALIZATIONS =========================================
140 #if OM_PARTIAL_SPECIALIZATION
141 
142 
143 #define TEMPLATE_HEADER template <typename Scalar>
144 #define CLASSNAME VectorT<Scalar,DIM>
145 #define DERIVED VectorDataT<Scalar,DIM>
146 
147 
148 #define DIM 2
149 #define unroll(expr) expr(0) expr(1)
150 #define unroll_comb(expr, op) expr(0) op expr(1)
151 #define unroll_csv(expr) expr(0), expr(1)
152 #include "VectorT_inc.hh"
153 #undef DIM
154 #undef unroll
155 #undef unroll_comb
156 #undef unroll_csv
157 
158 
159 #define DIM 3
160 #define unroll(expr) expr(0) expr(1) expr(2)
161 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
162 #define unroll_csv(expr) expr(0), expr(1), expr(2)
163 #include "VectorT_inc.hh"
164 #undef DIM
165 #undef unroll
166 #undef unroll_comb
167 #undef unroll_csv
168 
169 
170 #define DIM 4
171 #define unroll(expr) expr(0) expr(1) expr(2) expr(3)
172 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
173 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
174 #include "VectorT_inc.hh"
175 #undef DIM
176 #undef unroll
177 #undef unroll_comb
178 #undef unroll_csv
179 
180 
181 #undef TEMPLATE_HEADER
182 #undef CLASSNAME
183 #undef DERIVED
184 
185 
186 
187 
188 //== FULL TEMPLATE SPECIALIZATIONS ============================================
189 #else
190 
192 template<>
193 inline VectorT<float,3>
194 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
195 {
196  return
197  VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
198  values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
199  values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
200 }
201 
202 
204 template<>
205 inline VectorT<double,3>
206 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
207 {
208  return
209  VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
210  values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
211  values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
212 }
213 
214 #endif
215 
216 
217 
218 //== GLOBAL FUNCTIONS =========================================================
219 
220 
223 template<typename Scalar,int N>
224 inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
225  return VectorT<Scalar,N>(_v) *= _s;
226 }
227 
228 
231 template<typename Scalar, int N>
232 inline Scalar
233 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
234  return (_v1 | _v2);
235 }
236 
237 
240 template<typename Scalar, int N>
241 inline VectorT<Scalar,N>
242 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
243  return (_v1 % _v2);
244 }
245 
246 
247 
248 
249 //== TYPEDEFS =================================================================
250 
252 typedef VectorT<signed char,1> Vec1c;
254 typedef VectorT<unsigned char,1> Vec1uc;
256 typedef VectorT<signed short int,1> Vec1s;
258 typedef VectorT<unsigned short int,1> Vec1us;
260 typedef VectorT<signed int,1> Vec1i;
262 typedef VectorT<unsigned int,1> Vec1ui;
264 typedef VectorT<float,1> Vec1f;
266 typedef VectorT<double,1> Vec1d;
267 
269 typedef VectorT<signed char,2> Vec2c;
271 typedef VectorT<unsigned char,2> Vec2uc;
273 typedef VectorT<signed short int,2> Vec2s;
275 typedef VectorT<unsigned short int,2> Vec2us;
277 typedef VectorT<signed int,2> Vec2i;
279 typedef VectorT<unsigned int,2> Vec2ui;
281 typedef VectorT<float,2> Vec2f;
283 typedef VectorT<double,2> Vec2d;
284 
286 typedef VectorT<signed char,3> Vec3c;
288 typedef VectorT<unsigned char,3> Vec3uc;
290 typedef VectorT<signed short int,3> Vec3s;
292 typedef VectorT<unsigned short int,3> Vec3us;
294 typedef VectorT<signed int,3> Vec3i;
296 typedef VectorT<unsigned int,3> Vec3ui;
298 typedef VectorT<float,3> Vec3f;
300 typedef VectorT<double,3> Vec3d;
301 
303 typedef VectorT<signed char,4> Vec4c;
305 typedef VectorT<unsigned char,4> Vec4uc;
307 typedef VectorT<signed short int,4> Vec4s;
309 typedef VectorT<unsigned short int,4> Vec4us;
311 typedef VectorT<signed int,4> Vec4i;
313 typedef VectorT<unsigned int,4> Vec4ui;
315 typedef VectorT<float,4> Vec4f;
317 typedef VectorT<double,4> Vec4d;
318 
320 typedef VectorT<signed char,6> Vec6c;
322 typedef VectorT<unsigned char,6> Vec6uc;
324 typedef VectorT<signed short int,6> Vec6s;
326 typedef VectorT<unsigned short int,6> Vec6us;
328 typedef VectorT<signed int,6> Vec6i;
330 typedef VectorT<unsigned int,6> Vec6ui;
332 typedef VectorT<float,6> Vec6f;
334 typedef VectorT<double,6> Vec6d;
335 
336 //=============================================================================
337 } // namespace Geometry
338 } // namespace OpenVolumeMesh
339 //=============================================================================
340 #endif // OPENVOLUMEMESH_VECTOR_HH defined
341 //=============================================================================
342 #endif // DOXYGEN