Developer Documentation

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
46 //=============================================================================
47 //
48 // CLASS VectorT
49 //
50 //=============================================================================
51
52 // Don't parse this header file with doxygen since
53 // for some reason (obviously due to a bug in doxygen,
54 // bugreport: https://bugzilla.gnome.org/show_bug.cgi?id=629182)
55 // macro expansion and preprocessor defines
56 // don't work properly.
57
58 #if ((defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
59 #include "Vector11T.hh"
60 #else
61 #ifndef DOXYGEN
62
63 #ifndef OPENMESH_VECTOR_HH
64 #define OPENMESH_VECTOR_HH
65
66
67 //== INCLUDES =================================================================
68
69 #include <OpenMesh/Core/System/config.h>
70 #include <ostream>
71 #include <cmath>
72 #include <cassert>
73 #include <cstring>
74
75 #if defined(__GNUC__) && defined(__SSE__)
76 #include <xmmintrin.h>
77 #endif
78
79 //== NAMESPACES ===============================================================
80
81
82 namespace OpenMesh {
83
84
85 //== CLASS DEFINITION =========================================================
86
87
97 template<typename Scalar, int N> class VectorDataT {
98 public:
99 Scalar values_[N];
100 };
101
102
103 #if defined(__GNUC__) && defined(__SSE__)
104
106 template<> class VectorDataT<float, 4> {
107 public:
108 union {
109 __m128 m128;
110 float values_[4];
111 };
112 };
113
114 #endif
115
116
117
118
119 //== CLASS DEFINITION =========================================================
120
121
122 #define DIM N
123 #define TEMPLATE_HEADER template <typename Scalar, int N>
124 #define CLASSNAME VectorT
125 #define DERIVED VectorDataT<Scalar,N>
126 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
127
133 #include "VectorT_inc.hh"
134
135 #undef DIM
136 #undef TEMPLATE_HEADER
137 #undef CLASSNAME
138 #undef DERIVED
139 #undef unroll
140
141
142
143
144 //== PARTIAL TEMPLATE SPECIALIZATIONS =========================================
145 #if OM_PARTIAL_SPECIALIZATION
146
147
148 #define TEMPLATE_HEADER template <typename Scalar>
149 #define CLASSNAME VectorT<Scalar,DIM>
150 #define DERIVED VectorDataT<Scalar,DIM>
151
152
153 #define DIM 2
154 #define unroll(expr) expr(0) expr(1)
155 #define unroll_comb(expr, op) expr(0) op expr(1)
156 #define unroll_csv(expr) expr(0), expr(1)
157 #include "VectorT_inc.hh"
158 #undef DIM
159 #undef unroll
160 #undef unroll_comb
161 #undef unroll_csv
162
163
164 #define DIM 3
165 #define unroll(expr) expr(0) expr(1) expr(2)
166 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
167 #define unroll_csv(expr) expr(0), expr(1), expr(2)
168 #include "VectorT_inc.hh"
169 #undef DIM
170 #undef unroll
171 #undef unroll_comb
172 #undef unroll_csv
173
174
175 #define DIM 4
176 #define unroll(expr) expr(0) expr(1) expr(2) expr(3)
177 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
178 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
179 #include "VectorT_inc.hh"
180 #undef DIM
181 #undef unroll
182 #undef unroll_comb
183 #undef unroll_csv
184
185 #define DIM 5
186 #define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4)
187 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4)
188 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4)
189 #include "VectorT_inc.hh"
190 #undef DIM
191 #undef unroll
192 #undef unroll_comb
193 #undef unroll_csv
194
195 #define DIM 6
196 #define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4) expr(5)
197 #define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4) op expr(5)
198 #define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4), expr(5)
199 #include "VectorT_inc.hh"
200 #undef DIM
201 #undef unroll
202 #undef unroll_comb
203 #undef unroll_csv
204
205
206 #undef TEMPLATE_HEADER
207 #undef CLASSNAME
208 #undef DERIVED
209
210
211
212
213 //== FULL TEMPLATE SPECIALIZATIONS ============================================
214 #else
215
217 template<>
218 inline VectorT<float,3>
219 VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
220 {
221 return
222 VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
223 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
224 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
225 }
226
227
229 template<>
230 inline VectorT<double,3>
231 VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
232 {
233 return
234 VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
235 values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
236 values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
237 }
238
239 #endif
240
241
242
243 //== GLOBAL FUNCTIONS =========================================================
244
245
248 template<typename Scalar1, typename Scalar2,int N>
249 inline VectorT<Scalar1,N> operator*(Scalar2 _s, const VectorT<Scalar1,N>& _v) {
250 return _v*_s;
251 }
252
253
256 template<typename Scalar, int N>
257 inline Scalar
258 dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
259 return (_v1 | _v2);
260 }
261
262
265 template<typename Scalar, int N>
266 inline VectorT<Scalar,N>
267 cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
268 return (_v1 % _v2);
269 }
270
271
274 template<typename Scalar, int DIM>
275 Scalar norm(const VectorT<Scalar, DIM>& _v) {
276 return _v.norm();
277 }
278
279
282 template<typename Scalar, int DIM>
283 Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
284 return _v.sqrnorm();
285 }
286
287
290 template<typename Scalar, int DIM, typename OtherScalar>
291 VectorT<Scalar, DIM>& vectorize(VectorT<Scalar, DIM>& _v, OtherScalar const& _val) {
292 return _v.vectorize(_val);
293 }
294
295
298 template<typename Scalar, int DIM>
299 VectorT<Scalar, DIM>& normalize(VectorT<Scalar, DIM>& _v) {
300 return _v.normalize();
301 }
302
303
306 template<typename Scalar, int DIM>
307 VectorT<Scalar, DIM>& maximize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
308 return _v1.maximize(_v2);
309 }
310
311
314 template<typename Scalar, int DIM>
315 VectorT<Scalar, DIM>& minimize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
316 return _v1.minimize(_v2);
317 }
318
319
320 //== TYPEDEFS =================================================================
321
323 typedef VectorT<signed char,1> Vec1c;
325 typedef VectorT<unsigned char,1> Vec1uc;
327 typedef VectorT<signed short int,1> Vec1s;
329 typedef VectorT<unsigned short int,1> Vec1us;
331 typedef VectorT<signed int,1> Vec1i;
333 typedef VectorT<unsigned int,1> Vec1ui;
335 typedef VectorT<float,1> Vec1f;
337 typedef VectorT<double,1> Vec1d;
338
340 typedef VectorT<signed char,2> Vec2c;
342 typedef VectorT<unsigned char,2> Vec2uc;
344 typedef VectorT<signed short int,2> Vec2s;
346 typedef VectorT<unsigned short int,2> Vec2us;
348 typedef VectorT<signed int,2> Vec2i;
350 typedef VectorT<unsigned int,2> Vec2ui;
352 typedef VectorT<float,2> Vec2f;
354 typedef VectorT<double,2> Vec2d;
355
357 typedef VectorT<signed char,3> Vec3c;
359 typedef VectorT<unsigned char,3> Vec3uc;
361 typedef VectorT<signed short int,3> Vec3s;
363 typedef VectorT<unsigned short int,3> Vec3us;
365 typedef VectorT<signed int,3> Vec3i;
367 typedef VectorT<unsigned int,3> Vec3ui;
369 typedef VectorT<float,3> Vec3f;
371 typedef VectorT<double,3> Vec3d;
373 typedef VectorT<bool,3> Vec3b;
374
376 typedef VectorT<signed char,4> Vec4c;
378 typedef VectorT<unsigned char,4> Vec4uc;
380 typedef VectorT<signed short int,4> Vec4s;
382 typedef VectorT<unsigned short int,4> Vec4us;
384 typedef VectorT<signed int,4> Vec4i;
386 typedef VectorT<unsigned int,4> Vec4ui;
388 typedef VectorT<float,4> Vec4f;
390 typedef VectorT<double,4> Vec4d;
391
393 typedef VectorT<signed char, 5> Vec5c;
395 typedef VectorT<unsigned char, 5> Vec5uc;
397 typedef VectorT<signed short int, 5> Vec5s;
399 typedef VectorT<unsigned short int, 5> Vec5us;
401 typedef VectorT<signed int, 5> Vec5i;
403 typedef VectorT<unsigned int, 5> Vec5ui;
405 typedef VectorT<float, 5> Vec5f;
407 typedef VectorT<double, 5> Vec5d;
408
410 typedef VectorT<signed char,6> Vec6c;
412 typedef VectorT<unsigned char,6> Vec6uc;
414 typedef VectorT<signed short int,6> Vec6s;
416 typedef VectorT<unsigned short int,6> Vec6us;
418 typedef VectorT<signed int,6> Vec6i;
420 typedef VectorT<unsigned int,6> Vec6ui;
422 typedef VectorT<float,6> Vec6f;
424 typedef VectorT<double,6> Vec6d;
425
426
427 //=============================================================================
428 } // namespace OpenMesh
429 //=============================================================================
430
431
432 #endif // OPENMESH_VECTOR_HH defined
433 //=============================================================================
434 #endif // DOXYGEN
435 #endif // C++11
OpenMesh::VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:563
OpenMesh::Vec6i
VectorT< signed int, 6 > Vec6i
Definition: Vector11T.hh:860
OpenMesh::Vec5c
VectorT< signed char, 5 > Vec5c
Definition: Vector11T.hh:835
OpenMesh::Vec5us
VectorT< unsigned short int, 5 > Vec5us
Definition: Vector11T.hh:841
OpenMesh::Vec1uc
VectorT< unsigned char, 1 > Vec1uc
Definition: Vector11T.hh:767
OpenMesh::Vec2i
VectorT< signed int, 2 > Vec2i
Definition: Vector11T.hh:790
OpenMesh::Vec1d
VectorT< double, 1 > Vec1d
Definition: Vector11T.hh:779
OpenMesh::Vec1ui
VectorT< unsigned int, 1 > Vec1ui
Definition: Vector11T.hh:775
OpenMesh::VectorT::sqrnorm
Scalar sqrnorm(const VectorT< Scalar, DIM > &_v)
Definition: VectorT.hh:283
OpenMesh::Vec5uc
VectorT< unsigned char, 5 > Vec5uc
Definition: Vector11T.hh:837
OpenMesh::VectorT::vectorize
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
Definition: Vector11T.hh:614
OpenMesh::VectorT::norm
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
Definition: Vector11T.hh:409
OpenMesh::Vec4f
VectorT< float, 4 > Vec4f
Definition: Vector11T.hh:830
OpenMesh::Vec6d
VectorT< double, 6 > Vec6d
Definition: Vector11T.hh:866
OpenMesh::Vec2s
VectorT< signed short int, 2 > Vec2s
Definition: Vector11T.hh:786
OpenMesh::VectorT::sqrnorm
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
Definition: Vector11T.hh:397
OpenMesh::VectorT::norm
Scalar norm(const VectorT< Scalar, DIM > &_v)
Definition: VectorT.hh:275
OpenMesh::Vec3f
VectorT< float, 3 > Vec3f
Definition: Vector11T.hh:811
OpenMesh::VectorT::normalize
VectorT< Scalar, DIM > & normalize(VectorT< Scalar, DIM > &_v)
Definition: VectorT.hh:299
OpenMesh::Vec4d
VectorT< double, 4 > Vec4d
Definition: Vector11T.hh:832
OpenMesh::Vec4us
VectorT< unsigned short int, 4 > Vec4us
Definition: Vector11T.hh:824
OpenMesh::Vec6ui
VectorT< unsigned int, 6 > Vec6ui
Definition: Vector11T.hh:862
OpenMesh::VectorT::normalize
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:429
OpenMesh::Vec2uc
VectorT< unsigned char, 2 > Vec2uc
Definition: Vector11T.hh:784
OpenMesh::Vec3s
VectorT< signed short int, 3 > Vec3s
Definition: Vector11T.hh:803
OpenMesh::Vec3us
VectorT< unsigned short int, 3 > Vec3us
Definition: Vector11T.hh:805
OpenMesh::Vec2f
VectorT< float, 2 > Vec2f
Definition: Vector11T.hh:794
config.h
OpenMesh::Vec3uc
VectorT< unsigned char, 3 > Vec3uc
Definition: Vector11T.hh:801
OpenMesh::Vec5s
VectorT< signed short int, 5 > Vec5s
Definition: Vector11T.hh:839
OpenMesh::Vec4ui
VectorT< unsigned int, 4 > Vec4ui
Definition: Vector11T.hh:828
OpenMesh::Vec6f
VectorT< float, 6 > Vec6f
Definition: Vector11T.hh:864
OpenMesh::Vec2c
VectorT< signed char, 2 > Vec2c
Definition: Vector11T.hh:782
OpenMesh::VectorDataT
Definition: VectorT.hh:97
OpenMesh::VectorT::operator*
VectorT< Scalar1, N > operator*(Scalar2 _s, const VectorT< Scalar1, N > &_v)
Definition: VectorT.hh:249
OpenMesh::Vec1c
VectorT< signed char, 1 > Vec1c
Definition: Vector11T.hh:765
OpenMesh::Vec2ui
VectorT< unsigned int, 2 > Vec2ui
Definition: Vector11T.hh:792
OpenMesh::Vec6c
VectorT< signed char, 6 > Vec6c
Definition: Vector11T.hh:852
VectorT
OpenMesh::Vec5ui
VectorT< unsigned int, 5 > Vec5ui
Definition: Vector11T.hh:845
OpenMesh::Vec5d
VectorT< double, 5 > Vec5d
Definition: Vector11T.hh:849
OpenMesh::VectorT::maximize
VectorT< Scalar, DIM > & maximize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
Definition: VectorT.hh:307
OpenMesh::Vec3i
VectorT< signed int, 3 > Vec3i
Definition: Vector11T.hh:807
OpenMesh::Vec5f
VectorT< float, 5 > Vec5f
Definition: Vector11T.hh:847
OpenMesh::Vec6us
VectorT< unsigned short int, 6 > Vec6us
Definition: Vector11T.hh:858
OpenMesh::VectorT::dot
Scalar dot(const VectorT< Scalar, N > &_v1, const VectorT< Scalar, N > &_v2)
Definition: VectorT.hh:258
OpenMesh::Vec4i
VectorT< signed int, 4 > Vec4i
Definition: Vector11T.hh:826
OpenMesh::Vec1f
VectorT< float, 1 > Vec1f
Definition: Vector11T.hh:777
OpenMesh::Vec4uc
VectorT< unsigned char, 4 > Vec4uc
Definition: Vector11T.hh:820
OpenMesh::Vec2us
VectorT< unsigned short int, 2 > Vec2us
Definition: Vector11T.hh:788
OpenMesh::Vec1us
VectorT< unsigned short int, 1 > Vec1us
Definition: Vector11T.hh:771
OpenMesh::Vec1i
VectorT< signed int, 1 > Vec1i
Definition: Vector11T.hh:773
OpenMesh::VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:535
OpenMesh::Vec3d
VectorT< double, 3 > Vec3d
Definition: Vector11T.hh:813
OpenMesh::Vec3ui
VectorT< unsigned int, 3 > Vec3ui
Definition: Vector11T.hh:809
OpenMesh::VectorT< float, 3 >
OpenMesh::Vec1s
VectorT< signed short int, 1 > Vec1s
Definition: Vector11T.hh:769
OpenMesh::Vec4s
VectorT< signed short int, 4 > Vec4s
Definition: Vector11T.hh:822
OpenMesh::Vec3c
VectorT< signed char, 3 > Vec3c
Definition: Vector11T.hh:799
OpenMesh::Vec6uc
VectorT< unsigned char, 6 > Vec6uc
Definition: Vector11T.hh:854
OpenMesh::Vec6s
VectorT< signed short int, 6 > Vec6s
Definition: Vector11T.hh:856
OpenMesh::Vec5i
VectorT< signed int, 5 > Vec5i
Definition: Vector11T.hh:843
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
Definition: Vector11T.hh:369
OpenMesh::VectorT::cross
VectorT< Scalar, N > cross(const VectorT< Scalar, N > &_v1, const VectorT< Scalar, N > &_v2)
Definition: VectorT.hh:267
OpenMesh::Vec2d
VectorT< double, 2 > Vec2d
Definition: Vector11T.hh:796
OpenMesh::Vec3b
VectorT< bool, 3 > Vec3b
Definition: Vector11T.hh:815
OpenMesh::VectorT::vectorize
VectorT< Scalar, DIM > & vectorize(VectorT< Scalar, DIM > &_v, OtherScalar const &_val)
Definition: VectorT.hh:291
OpenMesh
Definition: MeshItems.hh:59
OpenMesh::Vec4c
VectorT< signed char, 4 > Vec4c
Definition: Vector11T.hh:818
OpenMesh::VectorT::minimize
VectorT< Scalar, DIM > & minimize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
Definition: VectorT.hh:315