OpenMesh: OpenMesh/Core/Geometry/VectorT.hh Source File

| OpenMesh

VectorT.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43 /*===========================================================================*\
44 * *
45 * $Revision$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50
51 //=============================================================================
52 //
53 // CLASS VectorT
54 //
55 //=============================================================================
56
57 // Don't parse this header file with doxygen since
58 // for some reason (obviously due to a bug in doxygen,
59 // bugreport: https://bugzilla.gnome.org/show_bug.cgi?id=629182)
60 // macro expansion and preprocessor defines
61 // don't work properly.
62
63 #if ((defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
64 #include "Vector11T.hh"
65 #else
66 #ifndef DOXYGEN
67
68 #ifndef OPENMESH_VECTOR_HH
69 #define OPENMESH_VECTOR_HH
70
71
72 //== INCLUDES =================================================================
73
74 #include <OpenMesh/Core/System/config.h>
75 #include <ostream>
76 #include <cmath>
77 #include <cassert>
78 #include <cstring>
79
80 #if defined(__GNUC__) && defined(__SSE__)
81 #include <xmmintrin.h>
82 #endif
83
84 //== NAMESPACES ===============================================================
85
86
87 namespace OpenMesh {
88
89
90 //== CLASS DEFINITION =========================================================
91
92
102 template<typename Scalar, int N> class VectorDataT {
103 public:
104 Scalar values_[N];
105 };
106
107
108 #if defined(__GNUC__) && defined(__SSE__)
109
111 template<> class VectorDataT<float, 4> {
112 public:
113 union {
114 __m128 m128;
115 float values_[4];
116 };
117 };
118
119 #endif
120
121
122
123
124 //== CLASS DEFINITION =========================================================
125
126
127 #define DIM N
128 #define TEMPLATE_HEADER template <typename Scalar, int N>
129 #define CLASSNAME VectorT
130 #define DERIVED VectorDataT<Scalar,N>
131 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
132
138 #include "VectorT_inc.hh"
139
140 #undef DIM
141 #undef TEMPLATE_HEADER
142 #undef CLASSNAME
143 #undef DERIVED
144 #undef unroll
145
146
147
148
149 //== PARTIAL TEMPLATE SPECIALIZATIONS =========================================
150 #if OM_PARTIAL_SPECIALIZATION
151
152
153 #define TEMPLATE_HEADER template <typename Scalar>
154 #define CLASSNAME VectorT<Scalar,DIM>
155 #define DERIVED VectorDataT<Scalar,DIM>
156
157
158 #define DIM 2
159 #define unroll(expr) expr(0) expr(1)
160 #define unroll_comb(expr, op) expr(0) op expr(1)
161 #define unroll_csv(expr) expr(0), expr(1)
162 #include "VectorT_inc.hh"
163 #undef DIM
164 #undef unroll
165 #undef unroll_comb
166 #undef unroll_csv
167
168
169 #define DIM 3
170 #define unroll(expr) expr(0) expr(1) expr(2)
171 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
172 #define unroll_csv(expr) expr(0), expr(1), expr(2)
173 #include "VectorT_inc.hh"
174 #undef DIM
175 #undef unroll
176 #undef unroll_comb
177 #undef unroll_csv
178
179
180 #define DIM 4
181 #define unroll(expr) expr(0) expr(1) expr(2) expr(3)
182 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
183 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
184 #include "VectorT_inc.hh"
185 #undef DIM
186 #undef unroll
187 #undef unroll_comb
188 #undef unroll_csv
189
190 #define DIM 5
191 #define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4)
192 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4)
193 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4)
194 #include "VectorT_inc.hh"
195 #undef DIM
196 #undef unroll
197 #undef unroll_comb
198 #undef unroll_csv
199
200 #define DIM 6
201 #define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4) expr(5)
202 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4) op expr(5)
203 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4), expr(5)
204 #include "VectorT_inc.hh"
205 #undef DIM
206 #undef unroll
207 #undef unroll_comb
208 #undef unroll_csv
209
210
211 #undef TEMPLATE_HEADER
212 #undef CLASSNAME
213 #undef DERIVED
214
215
216
217
218 //== FULL TEMPLATE SPECIALIZATIONS ============================================
219 #else
220
222 template<>
223 inline VectorT<float,3>
224 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
225 {
226 return
227 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
228 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
229 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
230 }
231
232
234 template<>
235 inline VectorT<double,3>
236 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
237 {
238 return
239 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
240 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
241 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
242 }
243
244 #endif
245
246
247
248 //== GLOBAL FUNCTIONS =========================================================
249
250
253 template<typename Scalar1, typename Scalar2,int N>
254 inline VectorT<Scalar1,N> operator*(Scalar2 _s, const VectorT<Scalar1,N>& _v) {
255 return _v*_s;
256 }
257
258
261 template<typename Scalar, int N>
262 inline Scalar
263 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
264 return (_v1 | _v2);
265 }
266
267
270 template<typename Scalar, int N>
271 inline VectorT<Scalar,N>
272 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
273 return (_v1 % _v2);
274 }
275
276
279 template<typename Scalar, int DIM>
280 Scalar norm(const VectorT<Scalar, DIM>& _v) {
281 return _v.norm();
282 }
283
284
287 template<typename Scalar, int DIM>
288 Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
289 return _v.sqrnorm();
290 }
291
292
295 template<typename Scalar, int DIM, typename OtherScalar>
296 VectorT<Scalar, DIM>& vectorize(VectorT<Scalar, DIM>& _v, OtherScalar const& _val) {
297 return _v.vectorize(_val);
298 }
299
300
303 template<typename Scalar, int DIM>
304 VectorT<Scalar, DIM>& normalize(VectorT<Scalar, DIM>& _v) {
305 return _v.normalize();
306 }
307
308
311 template<typename Scalar, int DIM>
312 VectorT<Scalar, DIM>& maximize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
313 return _v1.maximize(_v2);
314 }
315
316
319 template<typename Scalar, int DIM>
320 VectorT<Scalar, DIM>& minimize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
321 return _v1.minimize(_v2);
322 }
323
324
325 //== TYPEDEFS =================================================================
326
328 typedef VectorT<signed char,1> Vec1c;
330 typedef VectorT<unsigned char,1> Vec1uc;
332 typedef VectorT<signed short int,1> Vec1s;
334 typedef VectorT<unsigned short int,1> Vec1us;
336 typedef VectorT<signed int,1> Vec1i;
338 typedef VectorT<unsigned int,1> Vec1ui;
340 typedef VectorT<float,1> Vec1f;
342 typedef VectorT<double,1> Vec1d;
343
345 typedef VectorT<signed char,2> Vec2c;
347 typedef VectorT<unsigned char,2> Vec2uc;
349 typedef VectorT<signed short int,2> Vec2s;
351 typedef VectorT<unsigned short int,2> Vec2us;
353 typedef VectorT<signed int,2> Vec2i;
355 typedef VectorT<unsigned int,2> Vec2ui;
357 typedef VectorT<float,2> Vec2f;
359 typedef VectorT<double,2> Vec2d;
360
362 typedef VectorT<signed char,3> Vec3c;
364 typedef VectorT<unsigned char,3> Vec3uc;
366 typedef VectorT<signed short int,3> Vec3s;
368 typedef VectorT<unsigned short int,3> Vec3us;
370 typedef VectorT<signed int,3> Vec3i;
372 typedef VectorT<unsigned int,3> Vec3ui;
374 typedef VectorT<float,3> Vec3f;
376 typedef VectorT<double,3> Vec3d;
378 typedef VectorT<bool,3> Vec3b;
379
381 typedef VectorT<signed char,4> Vec4c;
383 typedef VectorT<unsigned char,4> Vec4uc;
385 typedef VectorT<signed short int,4> Vec4s;
387 typedef VectorT<unsigned short int,4> Vec4us;
389 typedef VectorT<signed int,4> Vec4i;
391 typedef VectorT<unsigned int,4> Vec4ui;
393 typedef VectorT<float,4> Vec4f;
395 typedef VectorT<double,4> Vec4d;
396
398 typedef VectorT<signed char, 5> Vec5c;
400 typedef VectorT<unsigned char, 5> Vec5uc;
402 typedef VectorT<signed short int, 5> Vec5s;
404 typedef VectorT<unsigned short int, 5> Vec5us;
406 typedef VectorT<signed int, 5> Vec5i;
408 typedef VectorT<unsigned int, 5> Vec5ui;
410 typedef VectorT<float, 5> Vec5f;
412 typedef VectorT<double, 5> Vec5d;
413
415 typedef VectorT<signed char,6> Vec6c;
417 typedef VectorT<unsigned char,6> Vec6uc;
419 typedef VectorT<signed short int,6> Vec6s;
421 typedef VectorT<unsigned short int,6> Vec6us;
423 typedef VectorT<signed int,6> Vec6i;
425 typedef VectorT<unsigned int,6> Vec6ui;
427 typedef VectorT<float,6> Vec6f;
429 typedef VectorT<double,6> Vec6d;
430
431
432 //=============================================================================
433 } // namespace OpenMesh
434 //=============================================================================
435
436
437 #endif // OPENMESH_VECTOR_HH defined
438 //=============================================================================
439 #endif // DOXYGEN
440 #endif // C++11
VectorT::normalize
vector_type & normalize()
normalize vector, return normalized vector
Definition: VectorT_inc.hh:437
OpenMesh::Vec3s
VectorT< signed short int, 3 > Vec3s
3-short signed vector
Definition: Vector11T.hh:803
OpenMesh::Vec4us
VectorT< unsigned short int, 4 > Vec4us
4-short unsigned vector
Definition: Vector11T.hh:824
OpenMesh::Vec5d
VectorT< double, 5 > Vec5d
5-double vector
Definition: Vector11T.hh:849
OpenMesh::Vec6uc
VectorT< unsigned char, 6 > Vec6uc
6-byte unsigned vector
Definition: Vector11T.hh:854
OpenMesh::Vec5uc
VectorT< unsigned char, 5 > Vec5uc
5-byte unsigned vector
Definition: Vector11T.hh:837
OpenMesh::Vec4uc
VectorT< unsigned char, 4 > Vec4uc
4-byte unsigned vector
Definition: Vector11T.hh:820
OpenMesh::Vec3f
VectorT< float, 3 > Vec3f
3-float vector
Definition: Vector11T.hh:811
OpenMesh::Vec1s
VectorT< signed short int, 1 > Vec1s
1-short signed vector
Definition: Vector11T.hh:769
OpenMesh::Vec2uc
VectorT< unsigned char, 2 > Vec2uc
2-byte unsigned vector
Definition: Vector11T.hh:784
OpenMesh::Vec5us
VectorT< unsigned short int, 5 > Vec5us
5-short unsigned vector
Definition: Vector11T.hh:841
OpenMesh::Vec5i
VectorT< signed int, 5 > Vec5i
5-int signed vector
Definition: Vector11T.hh:843
OpenMesh::Vec1c
VectorT< signed char, 1 > Vec1c
1-byte signed vector
Definition: Vector11T.hh:765
OpenMesh::Vec5ui
VectorT< unsigned int, 5 > Vec5ui
5-int unsigned vector
Definition: Vector11T.hh:845
OpenMesh::Vec1f
VectorT< float, 1 > Vec1f
1-float vector
Definition: Vector11T.hh:777
OpenMesh::VectorT::operator%
auto operator%(const VectorT< OtherScalar, DIM > &_rhs) const -> typename std::enable_if< DIM==3, VectorT< decltype((*this)[0] *_rhs[0] -(*this)[0] *_rhs[0]), DIM >>::type
cross product: only defined for Vec3* as specialization
Definition: Vector11T.hh:369
OpenMesh::Vec3uc
VectorT< unsigned char, 3 > Vec3uc
3-byte unsigned vector
Definition: Vector11T.hh:801
VectorT::norm
Scalar norm() const
compute euclidean norm
Definition: VectorT_inc.hh:415
OpenMesh::Vec5s
VectorT< signed short int, 5 > Vec5s
5-short signed vector
Definition: Vector11T.hh:839
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: VectorT_inc.hh:552
OpenMesh::Vec4ui
VectorT< unsigned int, 4 > Vec4ui
4-int unsigned vector
Definition: Vector11T.hh:828
OpenMesh::Vec1ui
VectorT< unsigned int, 1 > Vec1ui
1-int unsigned vector
Definition: Vector11T.hh:775
OpenMesh::Vec4d
VectorT< double, 4 > Vec4d
4-double vector
Definition: Vector11T.hh:832
OpenMesh::Vec2ui
VectorT< unsigned int, 2 > Vec2ui
2-int unsigned vector
Definition: Vector11T.hh:792
OpenMesh::Vec3i
VectorT< signed int, 3 > Vec3i
3-int signed vector
Definition: Vector11T.hh:807
OpenMesh::Vec3ui
VectorT< unsigned int, 3 > Vec3ui
3-int unsigned vector
Definition: Vector11T.hh:809
OpenMesh::Vec2s
VectorT< signed short int, 2 > Vec2s
2-short signed vector
Definition: Vector11T.hh:786
OpenMesh::Vec1d
VectorT< double, 1 > Vec1d
1-double vector
Definition: Vector11T.hh:779
VectorT::sqrnorm
Scalar sqrnorm() const
compute squared euclidean norm
Definition: VectorT_inc.hh:419
OpenMesh::Vec2us
VectorT< unsigned short int, 2 > Vec2us
2-short unsigned vector
Definition: Vector11T.hh:788
VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: VectorT_inc.hh:569
OpenMesh::Vec2i
VectorT< signed int, 2 > Vec2i
2-int signed vector
Definition: Vector11T.hh:790
OpenMesh::Vec6c
VectorT< signed char, 6 > Vec6c
6-byte signed vector
Definition: Vector11T.hh:852
OpenMesh::Vec4c
VectorT< signed char, 4 > Vec4c
4-byte signed vector
Definition: Vector11T.hh:818
OpenMesh::dot
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:181
OpenMesh::Vec3d
VectorT< double, 3 > Vec3d
3-double vector
Definition: Vector11T.hh:813
OpenMesh::Vec4f
VectorT< float, 4 > Vec4f
4-float vector
Definition: Vector11T.hh:830
OpenMesh::Vec1uc
VectorT< unsigned char, 1 > Vec1uc
1-byte unsigned vector
Definition: Vector11T.hh:767
OpenMesh::Vec5c
VectorT< signed char, 5 > Vec5c
5-byte signed vector
Definition: Vector11T.hh:835
OpenMesh::Vec1us
VectorT< unsigned short int, 1 > Vec1us
1-short unsigned vector
Definition: Vector11T.hh:771
OpenMesh::Vec4i
VectorT< signed int, 4 > Vec4i
4-int signed vector
Definition: Vector11T.hh:826
OpenMesh::Vec3c
VectorT< signed char, 3 > Vec3c
3-byte signed vector
Definition: Vector11T.hh:799
OpenMesh::Vec6s
VectorT< signed short int, 6 > Vec6s
6-short signed vector
Definition: Vector11T.hh:856
OpenMesh::Vec5f
VectorT< float, 5 > Vec5f
5-float vector
Definition: Vector11T.hh:847
OpenMesh::Vec6d
VectorT< double, 6 > Vec6d
6-double vector
Definition: Vector11T.hh:866
OpenMesh::Vec3b
VectorT< bool, 3 > Vec3b
3-bool vector
Definition: Vector11T.hh:815
VectorT
Definition: VectorT_inc.hh:72
OpenMesh::Vec2d
VectorT< double, 2 > Vec2d
2-double vector
Definition: Vector11T.hh:796
OpenMesh::Vec6f
VectorT< float, 6 > Vec6f
6-float vector
Definition: Vector11T.hh:864
OpenMesh::Vec3us
VectorT< unsigned short int, 3 > Vec3us
3-short unsigned vector
Definition: Vector11T.hh:805
OpenMesh::operator*
auto operator*(const OtherScalar &_s, const VectorT< Scalar, DIM > &rhs) -> decltype(rhs.operator*(_s))
Component wise multiplication from the left.
Definition: Vector11T.hh:668
OpenMesh::Vec2f
VectorT< float, 2 > Vec2f
2-float vector
Definition: Vector11T.hh:794
OpenMesh::Vec2c
VectorT< signed char, 2 > Vec2c
2-byte signed vector
Definition: Vector11T.hh:782
VectorT::vectorize
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
Definition: VectorT_inc.hh:610
OpenMesh::Vec6ui
VectorT< unsigned int, 6 > Vec6ui
6-int unsigned vector
Definition: Vector11T.hh:862
OpenMesh::Vec4s
VectorT< signed short int, 4 > Vec4s
4-short signed vector
Definition: Vector11T.hh:822
OpenMesh::cross
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:196
OpenMesh::Vec6i
VectorT< signed int, 6 > Vec6i
6-int signed vector
Definition: Vector11T.hh:860
OpenMesh::Vec1i
VectorT< signed int, 1 > Vec1i
1-int signed vector
Definition: Vector11T.hh:773
OpenMesh::Vec6us
VectorT< unsigned short int, 6 > Vec6us
6-short unsigned vector
Definition: Vector11T.hh:858