OpenMesh
Vector11T.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2022, 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#ifndef OPENMESH_SRC_OPENMESH_CORE_GEOMETRY_VECTOR11T_HH_
43#define OPENMESH_SRC_OPENMESH_CORE_GEOMETRY_VECTOR11T_HH_
44
45#include <array>
46#include <utility>
47#include <algorithm>
48#include <numeric>
49#include <type_traits>
50#include <cmath>
51#include <ostream>
52#include <istream>
53#include <cassert>
54#include <cstdlib>
55
56// This header is not needed by this file but expected by others including
57// this file.
58#include <OpenMesh/Core/System/config.h>
59
60
61/*
62 * Helpers for VectorT
63 */
64namespace {
65
66template<typename ... Ts>
67struct are_convertible_to;
68
69template<typename To, typename From, typename ... Froms>
70struct are_convertible_to<To, From, Froms...> {
71 static constexpr bool value = std::is_convertible<From, To>::value
72 && are_convertible_to<To, Froms...>::value;
73};
74
75template<typename To, typename From>
76struct are_convertible_to<To, From> : public std::is_convertible<From, To> {
77};
78}
79
80namespace OpenMesh {
81
82template<typename Scalar, int DIM>
83class VectorT {
84
85 static_assert(DIM >= 1, "VectorT requires positive dimensionality.");
86
87 private:
88 using container = std::array<Scalar, DIM>;
89 container values_;
90
91 public:
92
93 //---------------------------------------------------------------- class info
94
96 typedef Scalar value_type;
97
100
102 static constexpr int dim() {
103 return DIM;
104 }
105
107 static constexpr size_t size() {
108 return DIM;
109 }
110
111 static constexpr const size_t size_ = DIM;
112
113 //-------------------------------------------------------------- constructors
114
115 // Converting constructor: Constructs the vector from DIM values (of
116 // potentially heterogenous types) which are all convertible to Scalar.
117 template<typename T, typename ... Ts,
118 typename = typename std::enable_if<sizeof...(Ts)+1 == DIM>::type,
119 typename = typename std::enable_if<
120 are_convertible_to<Scalar, T, Ts...>::value>::type>
121 constexpr VectorT(T v, Ts... vs) : values_ { {static_cast<Scalar>(v), static_cast<Scalar>(vs)...} } {
122 static_assert(sizeof...(Ts)+1 == DIM,
123 "Invalid number of components specified in constructor.");
124 static_assert(are_convertible_to<Scalar, T, Ts...>::value,
125 "Not all components are convertible to Scalar.");
126 }
127
129 constexpr VectorT() {}
130
134 explicit VectorT(const Scalar &v) {
135 vectorize(v);
136 }
137
138 VectorT(const VectorT &rhs) = default;
139 VectorT(VectorT &&rhs) = default;
140 VectorT &operator=(const VectorT &rhs) = default;
141 VectorT &operator=(VectorT &&rhs) = default;
142
147 template<typename S = Scalar, int D = DIM>
148 auto homogenized() const ->
149 typename std::enable_if<D == 4,
150 VectorT<decltype(std::declval<S>()/std::declval<S>()), DIM>>::type {
151 static_assert(D == DIM, "D and DIM need to be identical. (Never "
152 "override the default template arguments.)");
153 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
154 "to be the same type. (Never override the default template "
155 "arguments.)");
156 return VectorT(
157 values_[0]/values_[3],
158 values_[1]/values_[3],
159 values_[2]/values_[3],
160 1);
161 }
162
164 template<typename Iterator,
165 typename = decltype(
166 *std::declval<Iterator&>(), void(),
167 ++std::declval<Iterator&>(), void())>
168 explicit VectorT(Iterator it) {
169 std::copy_n(it, DIM, values_.begin());
170 }
171
173 explicit VectorT(container&& _array) {
174 values_ = _array;
175 }
176
178 template<typename otherScalarType,
179 typename = typename std::enable_if<
180 std::is_convertible<otherScalarType, Scalar>::value>>
182 operator=(_rhs);
183 }
184
185 //--------------------------------------------------------------------- casts
186
188 template<typename OtherScalar,
189 typename = typename std::enable_if<
190 std::is_convertible<OtherScalar, Scalar>::value>>
192 std::transform(_rhs.cbegin(), _rhs.cend(),
193 this->begin(), [](OtherScalar rhs) {
194 return static_cast<Scalar>(std::move(rhs));
195 });
196 return *this;
197 }
198
200 Scalar* data() { return values_.data(); }
201
203 const Scalar* data() const { return values_.data(); }
204
205 //----------------------------------------------------------- element access
206
208 Scalar& operator[](size_t _i) {
209 assert(_i < DIM);
210 return values_[_i];
211 }
212
214 const Scalar& operator[](size_t _i) const {
215 assert(_i < DIM);
216 return values_[_i];
217 }
218
219 //---------------------------------------------------------------- comparsion
220
222 bool operator==(const vector_type& _rhs) const {
223 return std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
224 }
225
227 bool operator!=(const vector_type& _rhs) const {
228 return !std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
229 }
230
231 //---------------------------------------------------------- scalar operators
232
234 template<typename OtherScalar>
235 auto operator*=(const OtherScalar& _s) ->
236 typename std::enable_if<std::is_convertible<
237 decltype(this->values_[0] * _s), Scalar>::value,
238 VectorT<Scalar, DIM>&>::type {
239 for (auto& e : *this) {
240 e *= _s;
241 }
242 return *this;
243 }
244
246 template<typename OtherScalar>
247 auto operator/=(const OtherScalar& _s) ->
248 typename std::enable_if<std::is_convertible<
249 decltype(this->values_[0] / _s), Scalar>::value,
250 VectorT<Scalar, DIM>&>::type {
251 for (auto& e : *this) {
252 e /= _s;
253 }
254 return *this;
255 }
256
258 template<typename OtherScalar>
259 typename std::enable_if<std::is_convertible<
260 decltype(std::declval<Scalar>() * std::declval<OtherScalar>()),
261 Scalar>::value,
263 operator*(const OtherScalar& _s) const {
264 return vector_type(*this) *= _s;
265 }
266
268 template<typename OtherScalar>
269 typename std::enable_if<std::is_convertible<
270 decltype(std::declval<Scalar>() / std::declval<OtherScalar>()),
271 Scalar>::value,
273 operator/(const OtherScalar& _s) const {
274 return vector_type(*this) /= _s;
275 }
276
277 //---------------------------------------------------------- vector operators
278
280 template<typename OtherScalar>
282 typename std::enable_if<
283 sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
284 vector_type&>::type {
285 for (int i = 0; i < DIM; ++i) {
286 data()[i] *= _rhs.data()[i];
287 }
288 return *this;
289 }
290
292 template<typename OtherScalar>
294 typename std::enable_if<
295 sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
296 vector_type&>::type {
297 for (int i = 0; i < DIM; ++i) {
298 data()[i] /= _rhs.data()[i];
299 }
300 return *this;
301 }
302
304 template<typename OtherScalar>
306 typename std::enable_if<
307 sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
308 vector_type&>::type {
309 for (int i = 0; i < DIM; ++i) {
310 data()[i] -= _rhs.data()[i];
311 }
312 return *this;
313 }
314
316 template<typename OtherScalar>
318 typename std::enable_if<
319 sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
320 vector_type&>::type {
321 for (int i = 0; i < DIM; ++i) {
322 data()[i] += _rhs.data()[i];
323 }
324 return *this;
325 }
326
328 template<typename OtherScalar>
329 auto operator*(const VectorT<OtherScalar, DIM>& _rhs) const ->
330 typename std::enable_if<
331 sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
332 vector_type>::type {
333 return vector_type(*this) *= _rhs;
334 }
335
337 template<typename OtherScalar>
338 auto operator/(const VectorT<OtherScalar, DIM>& _rhs) const ->
339 typename std::enable_if<
340 sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
341 vector_type>::type {
342 return vector_type(*this) /= _rhs;
343 }
344
346 template<typename OtherScalar>
347 auto operator+(const VectorT<OtherScalar, DIM>& _rhs) const ->
348 typename std::enable_if<
349 sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
350 vector_type>::type {
351 return vector_type(*this) += _rhs;
352 }
353
355 template<typename OtherScalar>
356 auto operator-(const VectorT<OtherScalar, DIM>& _rhs) const ->
357 typename std::enable_if<
358 sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
359 vector_type>::type {
360 return vector_type(*this) -= _rhs;
361 }
362
364 vector_type operator-(void) const {
365 vector_type v;
366 std::transform(values_.begin(), values_.end(), v.values_.begin(),
367 [](const Scalar &s) { return -s; });
368 return v;
369 }
370
373 template<typename OtherScalar>
374 auto operator% (const VectorT<OtherScalar, DIM> &_rhs) const ->
375 typename std::enable_if<DIM == 3,
376 VectorT<decltype((*this)[0] * _rhs[0] -
377 (*this)[0] * _rhs[0]), DIM>>::type {
378 return {
379 values_[1] * _rhs[2] - values_[2] * _rhs[1],
380 values_[2] * _rhs[0] - values_[0] * _rhs[2],
381 values_[0] * _rhs[1] - values_[1] * _rhs[0]
382 };
383 }
384
387 template<typename OtherScalar>
388 auto cross (const VectorT<OtherScalar, DIM> &_rhs) const ->
389 decltype(*this % _rhs)
390 {
391 return *this % _rhs;
392 }
393
394
397 template<typename OtherScalar>
398 auto operator|(const VectorT<OtherScalar, DIM>& _rhs) const ->
399 decltype(*this->data() * *_rhs.data()) {
400
401 return std::inner_product(begin() + 1, begin() + DIM, _rhs.begin() + 1,
402 *begin() * *_rhs.begin());
403 }
404
407 template<typename OtherScalar>
408 auto dot(const VectorT<OtherScalar, DIM>& _rhs) const ->
409 decltype(*this | _rhs)
410 {
411 return *this | _rhs;
412 }
413
414 //------------------------------------------------------------ euclidean norm
415
417
418
420 template<typename S = Scalar>
421 decltype(std::declval<S>() * std::declval<S>()) sqrnorm() const {
422 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
423 "to be the same type. (Never override the default template "
424 "arguments.)");
425 typedef decltype(values_[0] * values_[0]) RESULT;
426 return std::accumulate(values_.cbegin() + 1, values_.cend(),
427 values_[0] * values_[0],
428 [](const RESULT &l, const Scalar &r) { return l + r * r; });
429 }
430
432 template<typename S = Scalar>
433 auto norm() const ->
434 decltype(std::sqrt(std::declval<VectorT<S, DIM>>().sqrnorm())) {
435 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
436 "to be the same type. (Never override the default template "
437 "arguments.)");
438 return std::sqrt(sqrnorm());
439 }
440
441 template<typename S = Scalar>
442 auto length() const ->
443 decltype(std::declval<VectorT<S, DIM>>().norm()) {
444 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
445 "to be the same type. (Never override the default template "
446 "arguments.)");
447 return norm();
448 }
449
452 template<typename S = Scalar>
453 auto normalize() ->
454 decltype(*this /= std::declval<VectorT<S, DIM>>().norm()) {
455 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
456 "to be the same type. (Never override the default template "
457 "arguments.)");
458 return *this /= norm();
459 }
460
463 template<typename S = Scalar>
464 auto normalized() const ->
465 decltype(*this / std::declval<VectorT<S, DIM>>().norm()) {
466 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
467 "to be the same type. (Never override the default template "
468 "arguments.)");
469 return *this / norm();
470 }
471
474 template<typename S = Scalar>
475 typename std::enable_if<
476 sizeof(decltype(
477 static_cast<S>(0),
478 std::declval<VectorT<S, DIM>>().norm())) >= 0,
479 vector_type&>::type
481 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
482 "to be the same type. (Never override the default template "
483 "arguments.)");
484 auto n = norm();
485 if (n != static_cast<decltype(norm())>(0)) {
486 *this /= n;
487 }
488 return *this;
489 }
490
492
493 //------------------------------------------------------------ euclidean norm
494
496
497
499 Scalar l1_norm() const {
500 return std::accumulate(
501 values_.cbegin() + 1, values_.cend(), values_[0]);
502 }
503
505 Scalar l8_norm() const {
506 return max_abs();
507 }
508
510
511 //------------------------------------------------------------ max, min, mean
512
514
515
517 Scalar max() const {
518 return *std::max_element(values_.cbegin(), values_.cend());
519 }
520
522 Scalar max_abs() const {
523 return std::abs(
524 *std::max_element(values_.cbegin(), values_.cend(),
525 [](const Scalar &a, const Scalar &b) {
526 return std::abs(a) < std::abs(b);
527 }));
528 }
529
531 Scalar min() const {
532 return *std::min_element(values_.cbegin(), values_.cend());
533 }
534
536 Scalar min_abs() const {
537 return std::abs(
538 *std::min_element(values_.cbegin(), values_.cend(),
539 [](const Scalar &a, const Scalar &b) {
540 return std::abs(a) < std::abs(b);
541 }));
542 }
543
545 Scalar mean() const {
546 return l1_norm()/DIM;
547 }
548
550 Scalar mean_abs() const {
551 return std::accumulate(values_.cbegin() + 1, values_.cend(),
552 std::abs(values_[0]),
553 [](const Scalar &l, const Scalar &r) {
554 return l + std::abs(r);
555 }) / DIM;
556 }
557
560 std::transform(values_.cbegin(), values_.cend(),
561 _rhs.values_.cbegin(),
562 values_.begin(),
563 [](const Scalar &l, const Scalar &r) {
564 return std::min(l, r);
565 });
566 return *this;
567 }
568
570 bool minimized(const vector_type& _rhs) {
571 bool result = false;
572 std::transform(values_.cbegin(), values_.cend(),
573 _rhs.values_.cbegin(),
574 values_.begin(),
575 [&result](const Scalar &l, const Scalar &r) {
576 if (l < r) {
577 return l;
578 } else {
579 result = true;
580 return r;
581 }
582 });
583 return result;
584 }
585
588 std::transform(values_.cbegin(), values_.cend(),
589 _rhs.values_.cbegin(),
590 values_.begin(),
591 [](const Scalar &l, const Scalar &r) {
592 return std::max(l, r);
593 });
594 return *this;
595 }
596
598 bool maximized(const vector_type& _rhs) {
599 bool result = false;
600 std::transform(values_.cbegin(), values_.cend(),
601 _rhs.values_.cbegin(),
602 values_.begin(),
603 [&result](const Scalar &l, const Scalar &r) {
604 if (l > r) {
605 return l;
606 } else {
607 result = true;
608 return r;
609 }
610 });
611 return result;
612 }
613
615 inline vector_type min(const vector_type& _rhs) const {
616 return vector_type(*this).minimize(_rhs);
617 }
618
620 inline vector_type max(const vector_type& _rhs) const {
621 return vector_type(*this).maximize(_rhs);
622 }
623
625
626 //------------------------------------------------------------ misc functions
627
629 template<typename Functor>
630 inline vector_type apply(const Functor& _func) const {
631 vector_type result;
632 std::transform(result.values_.cbegin(), result.values_.cend(),
633 result.values_.begin(), _func);
634 return result;
635 }
636
638 vector_type& vectorize(const Scalar& _s) {
639 std::fill(values_.begin(), values_.end(), _s);
640 return *this;
641 }
642
644 static vector_type vectorized(const Scalar& _s) {
645 return vector_type().vectorize(_s);
646 }
647
649 bool operator<(const vector_type& _rhs) const {
650 return std::lexicographical_compare(
651 values_.begin(), values_.end(),
652 _rhs.values_.begin(), _rhs.values_.end());
653 }
654
656 void swap(VectorT& _other)
657 noexcept(noexcept(std::swap(values_, _other.values_))) {
658 std::swap(values_, _other.values_);
659 }
660
661 //------------------------------------------------------------ component iterators
662
664
665
666 using iterator = typename container::iterator;
667 using const_iterator = typename container::const_iterator;
668 using reverse_iterator = typename container::reverse_iterator;
669 using const_reverse_iterator = typename container::const_reverse_iterator;
670
671 iterator begin() noexcept { return values_.begin(); }
672 const_iterator begin() const noexcept { return values_.cbegin(); }
673 const_iterator cbegin() const noexcept { return values_.cbegin(); }
674
675 iterator end() noexcept { return values_.end(); }
676 const_iterator end() const noexcept { return values_.cend(); }
677 const_iterator cend() const noexcept { return values_.cend(); }
678
679 reverse_iterator rbegin() noexcept { return values_.rbegin(); }
680 const_reverse_iterator rbegin() const noexcept { return values_.crbegin(); }
681 const_reverse_iterator crbegin() const noexcept { return values_.crbegin(); }
682
683 reverse_iterator rend() noexcept { return values_.rend(); }
684 const_reverse_iterator rend() const noexcept { return values_.crend(); }
685 const_reverse_iterator crend() const noexcept { return values_.crend(); }
686
688};
689
691template<typename Scalar, int DIM, typename OtherScalar>
692auto operator*(const OtherScalar& _s, const VectorT<Scalar, DIM> &rhs) ->
693 decltype(rhs.operator*(_s)) {
694
695 return rhs * _s;
696}
697
699template<typename Scalar, int DIM>
700auto operator<<(std::ostream& os, const VectorT<Scalar, DIM> &_vec) ->
701 typename std::enable_if<
702 sizeof(decltype(os << _vec[0])) >= 0, std::ostream&>::type {
703
704 os << _vec[0];
705 for (int i = 1; i < DIM; ++i) {
706 os << " " << _vec[i];
707 }
708 return os;
709}
710
712template<typename Scalar, int DIM>
713auto operator>> (std::istream& is, VectorT<Scalar, DIM> &_vec) ->
714 typename std::enable_if<
715 sizeof(decltype(is >> _vec[0])) >= 0, std::istream &>::type {
716 for (int i = 0; i < DIM; ++i)
717 is >> _vec[i];
718 return is;
719}
720
723template<typename Scalar, int DIM>
724Scalar dot(const VectorT<Scalar, DIM>& _v1, const VectorT<Scalar, DIM>& _v2) {
725 return (_v1 | _v2);
726}
727
730template<typename LScalar, typename RScalar, int DIM>
731auto
733 decltype(_v1 % _v2) {
734 return (_v1 % _v2);
735}
736
739template<typename Scalar, int DIM>
741noexcept(noexcept(_v1.swap(_v2))) {
742 _v1.swap(_v2);
743}
744
747template<typename Scalar, int DIM>
748Scalar norm(const VectorT<Scalar, DIM>& _v) {
749 return _v.norm();
750}
751
754template<typename Scalar, int DIM>
755Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
756 return _v.sqrnorm();
757}
760template<typename Scalar, int DIM, typename OtherScalar>
762 return _v.vectorize(_val);
763}
764
767template<typename Scalar, int DIM>
769 return _v.normalize();
770}
771
774template<typename Scalar, int DIM>
776 return _v1.maximize(_v2);
777}
778
781template<typename Scalar, int DIM>
783 return _v1.minimize(_v2);
784}
785
788template<typename Scalar, int DIM>
790 return _v1.max(_v2);
791}
792
795template<typename Scalar, int DIM>
797 return _v1.min(_v2);
798}
799
800
801//== TYPEDEFS =================================================================
802
819
836
855
872
889
906
907} // namespace OpenMesh
908
917constexpr OpenMesh::Vec4f operator"" _htmlColor(unsigned long long raw_color) {
918 return OpenMesh::Vec4f(
919 ((raw_color >> 24) & 0xFF) / 255.0f,
920 ((raw_color >> 16) & 0xFF) / 255.0f,
921 ((raw_color >> 8) & 0xFF) / 255.0f,
922 ((raw_color >> 0) & 0xFF) / 255.0f);
923}
924
925#endif /* OPENMESH_SRC_OPENMESH_CORE_GEOMETRY_VECTOR11T_HH_ */
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
auto operator*(const OtherScalar &_s, const VectorT< Scalar, DIM > &rhs) -> decltype(rhs.operator*(_s))
Component wise multiplication from the left.
Definition: Vector11T.hh:692
VectorT< float, 4 > Vec4f
4-float vector
Definition: Vector11T.hh:869
Definition: Vector11T.hh:83
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
Definition: Vector11T.hh:638
const Scalar & operator[](size_t _i) const
get i'th element read-only
Definition: Vector11T.hh:214
VectorT< Scalar, DIM > & normalize(VectorT< Scalar, DIM > &_v)
non-member normalize
Definition: Vector11T.hh:768
VectorT(Iterator it)
construct from a value array or any other iterator
Definition: Vector11T.hh:168
auto cross(const VectorT< OtherScalar, DIM > &_rhs) const -> decltype(*this % _rhs)
cross product: only defined for Vec3* as specialization
Definition: Vector11T.hh:388
Scalar dot(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
symmetric version of the dot product
Definition: Vector11T.hh:724
Scalar * data()
access to Scalar array
Definition: Vector11T.hh:200
auto operator*(const VectorT< OtherScalar, DIM > &_rhs) const -> typename std::enable_if< sizeof(decltype(this->values_[0] **_rhs.data())) >=0
component-wise vector multiplication
VectorT< Scalar, DIM > & minimize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
non-member minimize
Definition: Vector11T.hh:782
auto operator+(const VectorT< OtherScalar, DIM > &_rhs) const -> typename std::enable_if< sizeof(decltype(this->values_[0]+ *_rhs.data())) >=0
component-wise vector addition
VectorT< Scalar, DIM > vector_type
type of this vector
Definition: Vector11T.hh:99
static constexpr int dim()
returns dimension of the vector (deprecated)
Definition: Vector11T.hh:102
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
Definition: Vector11T.hh:421
static constexpr size_t size()
returns dimension of the vector
Definition: Vector11T.hh:107
const Scalar * data() const
access to const Scalar array
Definition: Vector11T.hh:203
VectorT< Scalar, DIM > & vectorize(VectorT< Scalar, DIM > &_v, OtherScalar const &_val)
non-member vectorize
Definition: Vector11T.hh:761
void swap(VectorT &_other) noexcept(noexcept(std::swap(values_, _other.values_)))
swap with another vector
Definition: Vector11T.hh:656
Scalar max_abs() const
return the maximal absolute component
Definition: Vector11T.hh:522
vector_type min(const vector_type &_rhs) const
component-wise min
Definition: Vector11T.hh:615
VectorT< Scalar, DIM > min(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
non-member min
Definition: Vector11T.hh:796
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:587
Scalar sqrnorm(const VectorT< Scalar, DIM > &_v)
non-member sqrnorm
Definition: Vector11T.hh:755
auto cross(const VectorT< LScalar, DIM > &_v1, const VectorT< RScalar, DIM > &_v2) -> decltype(_v1 % _v2)
symmetric version of the cross product
Definition: Vector11T.hh:732
auto operator|(const VectorT< OtherScalar, DIM > &_rhs) const -> decltype(*this->data() **_rhs.data())
compute scalar product
Definition: Vector11T.hh:398
auto operator-(const VectorT< OtherScalar, DIM > &_rhs) const -> typename std::enable_if< sizeof(decltype(this->values_[0] - *_rhs.data())) >=0
component-wise vector difference
vector_type &::type normalize_cond()
compute squared euclidean norm
Definition: Vector11T.hh:480
VectorT< Scalar, DIM > & maximize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
non-member maximize
Definition: Vector11T.hh:775
void swap(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2) noexcept(noexcept(_v1.swap(_v2)))
non-member swap
Definition: Vector11T.hh:740
VectorT< Scalar, DIM > max(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
non-member max
Definition: Vector11T.hh:789
auto operator-=(const VectorT< OtherScalar, DIM > &_rhs) -> typename std::enable_if< sizeof(decltype(this->values_[0] - *_rhs.data())) >=0
vector difference from this
auto operator*=(const VectorT< OtherScalar, DIM > &_rhs) -> typename std::enable_if< sizeof(decltype(this->values_[0] **_rhs.data())) >=0
component-wise self-multiplication
auto operator/=(const OtherScalar &_s) -> typename std::enable_if< std::is_convertible< decltype(this->values_[0]/_s), Scalar >::value, VectorT< Scalar, DIM > & >::type
component-wise self-division by scalar
Definition: Vector11T.hh:247
vector_type max(const vector_type &_rhs) const
component-wise max
Definition: Vector11T.hh:620
vector_type & operator=(const VectorT< OtherScalar, DIM > &_rhs)
cast from vector with a different scalar type
Definition: Vector11T.hh:191
auto operator/=(const VectorT< OtherScalar, DIM > &_rhs) -> typename std::enable_if< sizeof(decltype(this->values_[0]/*_rhs.data())) >=0
component-wise self-division
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:559
static vector_type vectorized(const Scalar &_s)
store the same value in each component
Definition: Vector11T.hh:644
Scalar l8_norm() const
compute l8_norm
Definition: Vector11T.hh:505
Scalar min_abs() const
return the minimal absolute component
Definition: Vector11T.hh:536
VectorT(const Scalar &v)
Creates a vector with all components set to v.
Definition: Vector11T.hh:134
auto length() const -> decltype(std::declval< VectorT< S, DIM > >().norm())
compute squared euclidean norm
Definition: Vector11T.hh:442
auto operator/(const VectorT< OtherScalar, DIM > &_rhs) const -> typename std::enable_if< sizeof(decltype(this->values_[0]/*_rhs.data())) >=0
component-wise vector division
vector_type operator-(void) const
unary minus
Definition: Vector11T.hh:364
bool operator<(const vector_type &_rhs) const
lexicographical comparison
Definition: Vector11T.hh:649
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Definition: Vector11T.hh:570
auto homogenized() const -> typename std::enable_if< D==4, VectorT< decltype(std::declval< S >()/std::declval< S >()), DIM > >::type
Only for 4-component vectors with division operator on their Scalar: Dehomogenization.
Definition: Vector11T.hh:148
Scalar mean_abs() const
return absolute arithmetic mean
Definition: Vector11T.hh:550
Scalar l1_norm() const
compute L1 (Manhattan) norm
Definition: Vector11T.hh:499
Scalar value_type
the type of the scalar used in this template
Definition: Vector11T.hh:96
auto dot(const VectorT< OtherScalar, DIM > &_rhs) const -> decltype(*this|_rhs)
compute scalar product
Definition: Vector11T.hh:408
VectorT(const VectorT< otherScalarType, DIM > &_rhs)
copy & cast constructor (explicit)
Definition: Vector11T.hh:181
Scalar mean() const
return arithmetic mean
Definition: Vector11T.hh:545
auto operator*=(const OtherScalar &_s) -> typename std::enable_if< std::is_convertible< decltype(this->values_[0] *_s), Scalar >::value, VectorT< Scalar, DIM > & >::type
component-wise self-multiplication with scalar
Definition: Vector11T.hh:235
auto operator+=(const VectorT< OtherScalar, DIM > &_rhs) -> typename std::enable_if< sizeof(decltype(this->values_[0]+ *_rhs.data())) >=0
vector self-addition
constexpr VectorT()
default constructor creates uninitialized values.
Definition: Vector11T.hh:129
vector_type apply(const Functor &_func) const
component-wise apply function object with Scalar operator()(Scalar).
Definition: Vector11T.hh:630
bool operator==(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:222
bool operator!=(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:227
Scalar max() const
return the maximal component
Definition: Vector11T.hh:517
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
Definition: Vector11T.hh:598
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM > >().norm())
normalize vector, return normalized vector
Definition: Vector11T.hh:453
Scalar & operator[](size_t _i)
get i'th element read-write
Definition: Vector11T.hh:208
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM > >().sqrnorm()))
compute euclidean norm
Definition: Vector11T.hh:433
Scalar min() const
return the minimal component
Definition: Vector11T.hh:531
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM > >().norm())
return normalized vector
Definition: Vector11T.hh:464
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:374
Scalar norm(const VectorT< Scalar, DIM > &_v)
non-member norm
Definition: Vector11T.hh:748
VectorT(container &&_array)
construct from an array
Definition: Vector11T.hh:173
Definition: VectorT_inc.hh:68
std::ostream & operator<<(std::ostream &_o, const Timer &_t)
Write seconds to output stream.
Definition: Timer.hh:199

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .