OpenVolumeMesh
Toggle main menu visibility
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
79
namespace
OpenVolumeMesh {
80
81
namespace
Geometry {
82
83
84
//== CLASS DEFINITION =========================================================
85
86
96
template
<
typename
Scalar,
int
N>
class
VectorDataT {
97
public
:
98
Scalar values_[N];
99
};
100
101
102
#if defined(__GNUC__) && defined(__SSE__)
103
105
template
<>
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
209
template
<>
210
inline
VectorT<float,3>
211
VectorT<float,3>::operator%
(
const
VectorT<float,3>
& _rhs)
const
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
221
template
<>
222
inline
VectorT<double,3>
223
VectorT<double,3>::operator%
(
const
VectorT<double,3>
& _rhs)
const
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
238
template
<
typename
Scalar1,
typename
Scalar2,
int
N>
239
inline
VectorT<Scalar1,N>
operator*(Scalar2 _s,
const
VectorT<Scalar1,N>
& _v) {
240
return
_v*_s;
241
}
242
243
246
template
<
typename
Scalar,
int
N>
247
inline
Scalar
248
dot(
const
VectorT<Scalar,N>
& _v1,
const
VectorT<Scalar,N>
& _v2) {
249
return
(_v1 | _v2);
250
}
251
252
255
template
<
typename
Scalar,
int
N>
256
inline
VectorT<Scalar,N>
257
cross(
const
VectorT<Scalar,N>
& _v1,
const
VectorT<Scalar,N>
& _v2) {
258
return
(_v1 % _v2);
259
}
260
261
262
263
264
//== TYPEDEFS =================================================================
265
267
typedef
VectorT<signed char,1>
Vec1c;
269
typedef
VectorT<unsigned char,1>
Vec1uc;
271
typedef
VectorT<signed short int,1>
Vec1s;
273
typedef
VectorT<unsigned short int,1>
Vec1us;
275
typedef
VectorT<signed int,1>
Vec1i;
277
typedef
VectorT<unsigned int,1>
Vec1ui;
279
typedef
VectorT<float,1>
Vec1f;
281
typedef
VectorT<double,1>
Vec1d;
282
284
typedef
VectorT<signed char,2>
Vec2c;
286
typedef
VectorT<unsigned char,2>
Vec2uc;
288
typedef
VectorT<signed short int,2>
Vec2s;
290
typedef
VectorT<unsigned short int,2>
Vec2us;
292
typedef
VectorT<signed int,2>
Vec2i;
294
typedef
VectorT<unsigned int,2>
Vec2ui;
296
typedef
VectorT<float,2>
Vec2f;
298
typedef
VectorT<double,2>
Vec2d;
299
301
typedef
VectorT<signed char,3>
Vec3c;
303
typedef
VectorT<unsigned char,3>
Vec3uc;
305
typedef
VectorT<signed short int,3>
Vec3s;
307
typedef
VectorT<unsigned short int,3>
Vec3us;
309
typedef
VectorT<signed int,3>
Vec3i;
311
typedef
VectorT<unsigned int,3>
Vec3ui;
313
typedef
VectorT<float,3>
Vec3f;
315
typedef
VectorT<double,3>
Vec3d;
317
typedef
VectorT<bool,3>
Vec3b;
318
320
typedef
VectorT<signed char,4>
Vec4c;
322
typedef
VectorT<unsigned char,4>
Vec4uc;
324
typedef
VectorT<signed short int,4>
Vec4s;
326
typedef
VectorT<unsigned short int,4>
Vec4us;
328
typedef
VectorT<signed int,4>
Vec4i;
330
typedef
VectorT<unsigned int,4>
Vec4ui;
332
typedef
VectorT<float,4>
Vec4f;
334
typedef
VectorT<double,4>
Vec4d;
335
337
typedef
VectorT<signed char, 5>
Vec5c;
339
typedef
VectorT<unsigned char, 5>
Vec5uc;
341
typedef
VectorT<signed short int, 5>
Vec5s;
343
typedef
VectorT<unsigned short int, 5>
Vec5us;
345
typedef
VectorT<signed int, 5>
Vec5i;
347
typedef
VectorT<unsigned int, 5>
Vec5ui;
349
typedef
VectorT<float, 5>
Vec5f;
351
typedef
VectorT<double, 5>
Vec5d;
352
354
typedef
VectorT<signed char,6>
Vec6c;
356
typedef
VectorT<unsigned char,6>
Vec6uc;
358
typedef
VectorT<signed short int,6>
Vec6s;
360
typedef
VectorT<unsigned short int,6>
Vec6us;
362
typedef
VectorT<signed int,6>
Vec6i;
364
typedef
VectorT<unsigned int,6>
Vec6ui;
366
typedef
VectorT<float,6>
Vec6f;
368
typedef
VectorT<double,6>
Vec6d;
369
370
//=============================================================================
371
}
// namespace Geometry
372
373
template
<
class
T>
374
const
std::string typeName();
375
376
template
<>
const
std::string typeName<Geometry::Vec2f>();
377
template
<>
const
std::string typeName<Geometry::Vec2d>();
378
template
<>
const
std::string typeName<Geometry::Vec2i>();
379
template
<>
const
std::string typeName<Geometry::Vec2ui>();
380
381
template
<>
const
std::string typeName<Geometry::Vec3f>();
382
template
<>
const
std::string typeName<Geometry::Vec3d>();
383
template
<>
const
std::string typeName<Geometry::Vec3i>();
384
template
<>
const
std::string typeName<Geometry::Vec3ui>();
385
386
template
<>
const
std::string typeName<Geometry::Vec4f>();
387
template
<>
const
std::string typeName<Geometry::Vec4d>();
388
template
<>
const
std::string typeName<Geometry::Vec4i>();
389
template
<>
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
OpenVolumeMesh::Geometry::VectorT
Definition
Vector11T.hh:78
OpenVolumeMesh::Geometry::VectorT::operator%
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
Project
OpenVolumeMesh
, Computer Graphics Group Aachen,
RWTH Aachen