OpenVolumeMesh
Loading...
Searching...
No Matches
VectorT.hh
1/* ========================================================================= *
2 * *
3 * OpenVolumeMesh *
4 * Copyright (c) 2001-2016, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openvolumemesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenVolumeMesh. *
11 * This file was originally taken from OpenMesh *
12 *---------------------------------------------------------------------------*
13 * *
14 * Redistribution and use in source and binary forms, with or without *
15 * modification, are permitted provided that the following conditions *
16 * are met: *
17 * *
18 * 1. Redistributions of source code must retain the above copyright notice, *
19 * this list of conditions and the following disclaimer. *
20 * *
21 * 2. Redistributions in binary form must reproduce the above copyright *
22 * notice, this list of conditions and the following disclaimer in the *
23 * documentation and/or other materials provided with the distribution. *
24 * *
25 * 3. Neither the name of the copyright holder nor the names of its *
26 * contributors may be used to endorse or promote products derived from *
27 * this software without specific prior written permission. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
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
55#if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENVOLUMEMESH_VECTOR_LEGACY)
56#include "Vector11T.hh"
57#else
58#ifndef DOXYGEN
59
60
61#ifndef OPENVOLUMEMESH_VECTOR_HH
62#define OPENVOLUMEMESH_VECTOR_HH
63
64
65//== INCLUDES =================================================================
66
67#include <ostream>
68#include <cmath>
69#include <cassert>
70#include <cstring>
71
72#if defined(__GNUC__) && defined(__SSE__)
73#include <xmmintrin.h>
74#endif
75
76//== NAMESPACES ===============================================================
77
78
79namespace OpenVolumeMesh {
80
81namespace Geometry {
82
83
84//== CLASS DEFINITION =========================================================
85
86
96template<typename Scalar, int N> class VectorDataT {
97 public:
98 Scalar values_[N];
99};
100
101
102#if defined(__GNUC__) && defined(__SSE__)
103
105template<> class VectorDataT<float, 4> {
106 public:
107 union {
108 __m128 m128;
109 float values_[4];
110 };
111};
112
113#endif
114
115
116
117
118//== CLASS DEFINITION =========================================================
119
120
121#define DIM N
122#define TEMPLATE_HEADER template <typename Scalar, int N>
123#define CLASSNAME VectorT
124#define DERIVED VectorDataT<Scalar,N>
125#define unroll(expr) for (int i=0; i<N; ++i) expr(i)
126
132#include "VectorT_inc.hh"
133
134#undef DIM
135#undef TEMPLATE_HEADER
136#undef CLASSNAME
137#undef DERIVED
138#undef unroll
139
140
141
142
143//== PARTIAL TEMPLATE SPECIALIZATIONS =========================================
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#define DIM 3
161#define unroll(expr) expr(0) expr(1) expr(2)
162#define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
163#define unroll_csv(expr) expr(0), expr(1), expr(2)
164#include "VectorT_inc.hh"
165#undef DIM
166#undef unroll
167#undef unroll_comb
168#undef unroll_csv
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#define DIM 5
181#define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4)
182#define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4)
183#define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4)
184#include "VectorT_inc.hh"
185#undef DIM
186#undef unroll
187#undef unroll_comb
188#undef unroll_csv
189
190#define DIM 6
191#define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4) expr(5)
192#define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4) op expr(5)
193#define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4), expr(5)
194#include "VectorT_inc.hh"
195#undef DIM
196#undef unroll
197#undef unroll_comb
198#undef unroll_csv
199
200
201#undef TEMPLATE_HEADER
202#undef CLASSNAME
203#undef DERIVED
204
205
206//== FULL TEMPLATE SPECIALIZATIONS ============================================
207
209template<>
210inline VectorT<float,3>
212{
213 return
214 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
215 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
216 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
217}
218
219
221template<>
224{
225 return
226 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
227 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
228 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
229}
230
231
232
233//== GLOBAL FUNCTIONS =========================================================
234
235
238template<typename Scalar1, typename Scalar2,int N>
239inline VectorT<Scalar1,N> operator*(Scalar2 _s, const VectorT<Scalar1,N>& _v) {
240 return _v*_s;
241}
242
243
246template<typename Scalar, int N>
247inline Scalar
248dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
249 return (_v1 | _v2);
250}
251
252
255template<typename Scalar, int N>
256inline VectorT<Scalar,N>
257cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
258 return (_v1 % _v2);
259}
260
261
262
263
264//== TYPEDEFS =================================================================
265
267typedef VectorT<signed char,1> Vec1c;
269typedef VectorT<unsigned char,1> Vec1uc;
271typedef VectorT<signed short int,1> Vec1s;
273typedef VectorT<unsigned short int,1> Vec1us;
275typedef VectorT<signed int,1> Vec1i;
277typedef VectorT<unsigned int,1> Vec1ui;
279typedef VectorT<float,1> Vec1f;
281typedef VectorT<double,1> Vec1d;
282
284typedef VectorT<signed char,2> Vec2c;
286typedef VectorT<unsigned char,2> Vec2uc;
288typedef VectorT<signed short int,2> Vec2s;
290typedef VectorT<unsigned short int,2> Vec2us;
292typedef VectorT<signed int,2> Vec2i;
294typedef VectorT<unsigned int,2> Vec2ui;
296typedef VectorT<float,2> Vec2f;
298typedef VectorT<double,2> Vec2d;
299
301typedef VectorT<signed char,3> Vec3c;
303typedef VectorT<unsigned char,3> Vec3uc;
305typedef VectorT<signed short int,3> Vec3s;
307typedef VectorT<unsigned short int,3> Vec3us;
309typedef VectorT<signed int,3> Vec3i;
311typedef VectorT<unsigned int,3> Vec3ui;
313typedef VectorT<float,3> Vec3f;
315typedef VectorT<double,3> Vec3d;
317typedef VectorT<bool,3> Vec3b;
318
320typedef VectorT<signed char,4> Vec4c;
322typedef VectorT<unsigned char,4> Vec4uc;
324typedef VectorT<signed short int,4> Vec4s;
326typedef VectorT<unsigned short int,4> Vec4us;
328typedef VectorT<signed int,4> Vec4i;
330typedef VectorT<unsigned int,4> Vec4ui;
332typedef VectorT<float,4> Vec4f;
334typedef VectorT<double,4> Vec4d;
335
337typedef VectorT<signed char, 5> Vec5c;
339typedef VectorT<unsigned char, 5> Vec5uc;
341typedef VectorT<signed short int, 5> Vec5s;
343typedef VectorT<unsigned short int, 5> Vec5us;
345typedef VectorT<signed int, 5> Vec5i;
347typedef VectorT<unsigned int, 5> Vec5ui;
349typedef VectorT<float, 5> Vec5f;
351typedef VectorT<double, 5> Vec5d;
352
354typedef VectorT<signed char,6> Vec6c;
356typedef VectorT<unsigned char,6> Vec6uc;
358typedef VectorT<signed short int,6> Vec6s;
360typedef VectorT<unsigned short int,6> Vec6us;
362typedef VectorT<signed int,6> Vec6i;
364typedef VectorT<unsigned int,6> Vec6ui;
366typedef VectorT<float,6> Vec6f;
368typedef VectorT<double,6> Vec6d;
369
370//=============================================================================
371} // namespace Geometry
372
373template <class T>
374const std::string typeName();
375
376template <> const std::string typeName<Geometry::Vec2f>();
377template <> const std::string typeName<Geometry::Vec2d>();
378template <> const std::string typeName<Geometry::Vec2i>();
379template <> const std::string typeName<Geometry::Vec2ui>();
380
381template <> const std::string typeName<Geometry::Vec3f>();
382template <> const std::string typeName<Geometry::Vec3d>();
383template <> const std::string typeName<Geometry::Vec3i>();
384template <> const std::string typeName<Geometry::Vec3ui>();
385
386template <> const std::string typeName<Geometry::Vec4f>();
387template <> const std::string typeName<Geometry::Vec4d>();
388template <> const std::string typeName<Geometry::Vec4i>();
389template <> const std::string typeName<Geometry::Vec4ui>();
390
391} // namespace OpenVolumeMesh
392//=============================================================================
393#endif // OPENVOLUMEMESH_VECTOR_HH defined
394//=============================================================================
395#endif // DOXYGEN
396#endif // C++11
Definition Vector11T.hh:78
auto operator%(const VectorT< OtherScalar, DIM > &_rhs) const -> typename std::enable_if< DIM==3, VectorT< decltype(this->values_[0] *_rhs[0] - this->values_[0] *_rhs[0]), DIM > >::type
Definition Vector11T.hh:362