OpenMesh
Loading...
Searching...
No Matches
Vector11T.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, 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 }
177
179 template<typename otherScalarType,
180 typename = typename std::enable_if<
181 std::is_convertible<otherScalarType, Scalar>::value>>
183 operator=(_rhs);
184 }
185
186 //--------------------------------------------------------------------- casts
187
189 template<typename OtherScalar,
190 typename = typename std::enable_if<
191 std::is_convertible<OtherScalar, Scalar>::value>>
193 std::transform(_rhs.cbegin(), _rhs.cend(),
194 this->begin(), [](OtherScalar rhs) {
195 return static_cast<Scalar>(std::move(rhs));
196 });
197 return *this;
198 }
199
201 Scalar* data() { return values_.data(); }
202
204 const Scalar* data() const { return values_.data(); }
205
206 //----------------------------------------------------------- element access
207
209 Scalar& operator[](size_t _i) {
210 assert(_i < DIM);
211 return values_[_i];
212 }
213
215 const Scalar& operator[](size_t _i) const {
216 assert(_i < DIM);
217 return values_[_i];
218 }
219
220 //---------------------------------------------------------------- comparsion
221
223 bool operator==(const vector_type& _rhs) const {
224 return std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
225 }
226
228 bool operator!=(const vector_type& _rhs) const {
229 return !std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
230 }
231
232 //---------------------------------------------------------- scalar operators
233
235 template<typename OtherScalar>
236 auto operator*=(const OtherScalar& _s) ->
237 typename std::enable_if<std::is_convertible<
238 decltype(this->values_[0] * _s), Scalar>::value,
239 VectorT<Scalar, DIM>&>::type {
240 for (auto& e : *this) {
241 e *= _s;
242 }
243 return *this;
244 }
245
247 template<typename OtherScalar>
248 auto operator/=(const OtherScalar& _s) ->
249 typename std::enable_if<std::is_convertible<
250 decltype(this->values_[0] / _s), Scalar>::value,
251 VectorT<Scalar, DIM>&>::type {
252 for (auto& e : *this) {
253 e /= _s;
254 }
255 return *this;
256 }
257
259 template<typename OtherScalar>
260 typename std::enable_if<std::is_convertible<
261 decltype(std::declval<Scalar>() * std::declval<OtherScalar>()),
262 Scalar>::value,
264 operator*(const OtherScalar& _s) const {
265 return vector_type(*this) *= _s;
266 }
267
269 template<typename OtherScalar>
270 typename std::enable_if<std::is_convertible<
271 decltype(std::declval<Scalar>() / std::declval<OtherScalar>()),
272 Scalar>::value,
274 operator/(const OtherScalar& _s) const {
275 return vector_type(*this) /= _s;
276 }
277
278 //---------------------------------------------------------- vector operators
279
281 template<typename OtherScalar>
283 typename std::enable_if<
284 sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
285 vector_type&>::type {
286 for (int i = 0; i < DIM; ++i) {
287 data()[i] *= _rhs.data()[i];
288 }
289 return *this;
290 }
291
293 template<typename OtherScalar>
295 typename std::enable_if<
296 sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
297 vector_type&>::type {
298 for (int i = 0; i < DIM; ++i) {
299 data()[i] /= _rhs.data()[i];
300 }
301 return *this;
302 }
303
305 template<typename OtherScalar>
307 typename std::enable_if<
308 sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
309 vector_type&>::type {
310 for (int i = 0; i < DIM; ++i) {
311 data()[i] -= _rhs.data()[i];
312 }
313 return *this;
314 }
315
317 template<typename OtherScalar>
319 typename std::enable_if<
320 sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
321 vector_type&>::type {
322 for (int i = 0; i < DIM; ++i) {
323 data()[i] += _rhs.data()[i];
324 }
325 return *this;
326 }
327
329 template<typename OtherScalar>
330 auto operator*(const VectorT<OtherScalar, DIM>& _rhs) const ->
331 typename std::enable_if<
332 sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
333 vector_type>::type {
334 return vector_type(*this) *= _rhs;
335 }
336
338 template<typename OtherScalar>
339 auto operator/(const VectorT<OtherScalar, DIM>& _rhs) const ->
340 typename std::enable_if<
341 sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
342 vector_type>::type {
343 return vector_type(*this) /= _rhs;
344 }
345
347 template<typename OtherScalar>
348 auto operator+(const VectorT<OtherScalar, DIM>& _rhs) const ->
349 typename std::enable_if<
350 sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
351 vector_type>::type {
352 return vector_type(*this) += _rhs;
353 }
354
356 template<typename OtherScalar>
357 auto operator-(const VectorT<OtherScalar, DIM>& _rhs) const ->
358 typename std::enable_if<
359 sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
360 vector_type>::type {
361 return vector_type(*this) -= _rhs;
362 }
363
365 vector_type operator-(void) const {
366 vector_type v;
367 std::transform(values_.begin(), values_.end(), v.values_.begin(),
368 [](const Scalar &s) { return -s; });
369 return v;
370 }
371
374 template<typename OtherScalar>
375 auto operator% (const VectorT<OtherScalar, DIM> &_rhs) const ->
376 typename std::enable_if<DIM == 3,
377 VectorT<decltype((*this)[0] * _rhs[0] -
378 (*this)[0] * _rhs[0]), DIM>>::type {
379 return {
380 values_[1] * _rhs[2] - values_[2] * _rhs[1],
381 values_[2] * _rhs[0] - values_[0] * _rhs[2],
382 values_[0] * _rhs[1] - values_[1] * _rhs[0]
383 };
384 }
385
388 template<typename OtherScalar>
389 auto cross (const VectorT<OtherScalar, DIM> &_rhs) const ->
390 decltype(*this % _rhs)
391 {
392 return *this % _rhs;
393 }
394
395
398 template<typename OtherScalar>
399 auto operator|(const VectorT<OtherScalar, DIM>& _rhs) const ->
400 decltype(*this->data() * *_rhs.data()) {
401
402 return std::inner_product(begin() + 1, begin() + DIM, _rhs.begin() + 1,
403 *begin() * *_rhs.begin());
404 }
405
408 template<typename OtherScalar>
409 auto dot(const VectorT<OtherScalar, DIM>& _rhs) const ->
410 decltype(*this | _rhs)
411 {
412 return *this | _rhs;
413 }
414
415 //------------------------------------------------------------ Euclidean norm
416
418
419
421 template<typename S = Scalar>
422 decltype(std::declval<S>() * std::declval<S>()) sqrnorm() const {
423 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
424 "to be the same type. (Never override the default template "
425 "arguments.)");
426 typedef decltype(values_[0] * values_[0]) RESULT;
427 return std::accumulate(values_.cbegin() + 1, values_.cend(),
428 values_[0] * values_[0],
429 [](const RESULT &l, const Scalar &r) { return l + r * r; });
430 }
431
433 template<typename S = Scalar>
434 decltype(std::declval<S>() * std::declval<S>()) squaredNorm() const {
435 return sqrnorm<S>();
436 }
437
439 template<typename S = Scalar>
440 auto norm() const ->
441 decltype(std::sqrt(std::declval<VectorT<S, DIM>>().sqrnorm())) {
442 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
443 "to be the same type. (Never override the default template "
444 "arguments.)");
445 return std::sqrt(sqrnorm());
446 }
447
448 template<typename S = Scalar>
449 auto length() const ->
450 decltype(std::declval<VectorT<S, DIM>>().norm()) {
451 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
452 "to be the same type. (Never override the default template "
453 "arguments.)");
454 return norm();
455 }
456
459 template<typename S = Scalar>
460 auto normalize() ->
461 decltype(*this /= std::declval<VectorT<S, DIM>>().norm()) {
462 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
463 "to be the same type. (Never override the default template "
464 "arguments.)");
465 return *this /= norm();
466 }
467
470 template<typename S = Scalar>
471 auto normalized() const ->
472 decltype(*this / std::declval<VectorT<S, DIM>>().norm()) {
473 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
474 "to be the same type. (Never override the default template "
475 "arguments.)");
476 return *this / norm();
477 }
478
481 template<typename S = Scalar>
482 typename std::enable_if<
483 sizeof(decltype(
484 static_cast<S>(0),
485 std::declval<VectorT<S, DIM>>().norm())) >= 0,
486 vector_type&>::type
488 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
489 "to be the same type. (Never override the default template "
490 "arguments.)");
491 auto n = norm();
492 if (n != static_cast<decltype(norm())>(0)) {
493 *this /= n;
494 }
495 return *this;
496 }
497
499
500 //------------------------------------------------------------ non-Euclidean norms
501
503
504
506 Scalar l1_norm() const {
507 return std::accumulate(
508 values_.cbegin() + 1, values_.cend(), values_[0]);
509 }
510
512 Scalar l8_norm() const {
513 return max_abs();
514 }
515
517
518 //------------------------------------------------------------ max, min, mean
519
521
522
524 Scalar max() const {
525 return *std::max_element(values_.cbegin(), values_.cend());
526 }
527
529 Scalar max_abs() const {
530 return std::abs(
531 *std::max_element(values_.cbegin(), values_.cend(),
532 [](const Scalar &a, const Scalar &b) {
533 return std::abs(a) < std::abs(b);
534 }));
535 }
536
538 Scalar min() const {
539 return *std::min_element(values_.cbegin(), values_.cend());
540 }
541
543 Scalar min_abs() const {
544 return std::abs(
545 *std::min_element(values_.cbegin(), values_.cend(),
546 [](const Scalar &a, const Scalar &b) {
547 return std::abs(a) < std::abs(b);
548 }));
549 }
550
552 Scalar mean() const {
553 return l1_norm()/DIM;
554 }
555
557 Scalar mean_abs() const {
558 return std::accumulate(values_.cbegin() + 1, values_.cend(),
559 std::abs(values_[0]),
560 [](const Scalar &l, const Scalar &r) {
561 return l + std::abs(r);
562 }) / DIM;
563 }
564
567 std::transform(values_.cbegin(), values_.cend(),
568 _rhs.values_.cbegin(),
569 values_.begin(),
570 [](const Scalar &l, const Scalar &r) {
571 return std::min(l, r);
572 });
573 return *this;
574 }
575
577 bool minimized(const vector_type& _rhs) {
578 bool result = false;
579 std::transform(values_.cbegin(), values_.cend(),
580 _rhs.values_.cbegin(),
581 values_.begin(),
582 [&result](const Scalar &l, const Scalar &r) {
583 if (l < r) {
584 return l;
585 } else {
586 result = true;
587 return r;
588 }
589 });
590 return result;
591 }
592
595 std::transform(values_.cbegin(), values_.cend(),
596 _rhs.values_.cbegin(),
597 values_.begin(),
598 [](const Scalar &l, const Scalar &r) {
599 return std::max(l, r);
600 });
601 return *this;
602 }
603
605 bool maximized(const vector_type& _rhs) {
606 bool result = false;
607 std::transform(values_.cbegin(), values_.cend(),
608 _rhs.values_.cbegin(),
609 values_.begin(),
610 [&result](const Scalar &l, const Scalar &r) {
611 if (l > r) {
612 return l;
613 } else {
614 result = true;
615 return r;
616 }
617 });
618 return result;
619 }
620
622 inline vector_type min(const vector_type& _rhs) const {
623 return vector_type(*this).minimize(_rhs);
624 }
625
627 inline vector_type max(const vector_type& _rhs) const {
628 return vector_type(*this).maximize(_rhs);
629 }
630
632
633 //------------------------------------------------------------ misc functions
634
636 template<typename Functor>
637 inline vector_type apply(const Functor& _func) const {
638 vector_type result;
639 std::transform(values_.cbegin(), values_.cend(),
640 result.values_.begin(), _func);
641 return result;
642 }
643
645 vector_type& vectorize(const Scalar& _s) {
646 std::fill(values_.begin(), values_.end(), _s);
647 return *this;
648 }
649
651 static vector_type vectorized(const Scalar& _s) {
652 return vector_type().vectorize(_s);
653 }
654
656 bool operator<(const vector_type& _rhs) const {
657 return std::lexicographical_compare(
658 values_.begin(), values_.end(),
659 _rhs.values_.begin(), _rhs.values_.end());
660 }
661
663 void swap(VectorT& _other)
664 noexcept(noexcept(std::swap(values_, _other.values_))) {
665 std::swap(values_, _other.values_);
666 }
667
668 //------------------------------------------------------------ component iterators
669
671
672
673 using iterator = typename container::iterator;
674 using const_iterator = typename container::const_iterator;
675 using reverse_iterator = typename container::reverse_iterator;
676 using const_reverse_iterator = typename container::const_reverse_iterator;
677
678 iterator begin() noexcept { return values_.begin(); }
679 const_iterator begin() const noexcept { return values_.cbegin(); }
680 const_iterator cbegin() const noexcept { return values_.cbegin(); }
681
682 iterator end() noexcept { return values_.end(); }
683 const_iterator end() const noexcept { return values_.cend(); }
684 const_iterator cend() const noexcept { return values_.cend(); }
685
686 reverse_iterator rbegin() noexcept { return values_.rbegin(); }
687 const_reverse_iterator rbegin() const noexcept { return values_.crbegin(); }
688 const_reverse_iterator crbegin() const noexcept { return values_.crbegin(); }
689
690 reverse_iterator rend() noexcept { return values_.rend(); }
691 const_reverse_iterator rend() const noexcept { return values_.crend(); }
692 const_reverse_iterator crend() const noexcept { return values_.crend(); }
693
695};
696
698template<typename Scalar, int DIM, typename OtherScalar>
699auto operator*(const OtherScalar& _s, const VectorT<Scalar, DIM> &rhs) ->
700 decltype(rhs.operator*(_s)) {
701
702 return rhs * _s;
703}
704
706template<typename Scalar, int DIM>
707auto operator<<(std::ostream& os, const VectorT<Scalar, DIM> &_vec) ->
708 typename std::enable_if<
709 sizeof(decltype(os << _vec[0])) >= 0, std::ostream&>::type {
710
711 os << _vec[0];
712 for (int i = 1; i < DIM; ++i) {
713 os << " " << _vec[i];
714 }
715 return os;
716}
717
719template<typename Scalar, int DIM>
720auto operator>> (std::istream& is, VectorT<Scalar, DIM> &_vec) ->
721 typename std::enable_if<
722 sizeof(decltype(is >> _vec[0])) >= 0, std::istream &>::type {
723 for (int i = 0; i < DIM; ++i)
724 is >> _vec[i];
725 return is;
726}
727
730template<typename Scalar, int DIM>
731Scalar dot(const VectorT<Scalar, DIM>& _v1, const VectorT<Scalar, DIM>& _v2) {
732 return (_v1 | _v2);
733}
734
737template<typename LScalar, typename RScalar, int DIM>
738auto
740 decltype(_v1 % _v2) {
741 return (_v1 % _v2);
742}
743
746template<typename Scalar, int DIM>
748noexcept(noexcept(_v1.swap(_v2))) {
749 _v1.swap(_v2);
750}
751
754template<typename Scalar, int DIM>
755Scalar norm(const VectorT<Scalar, DIM>& _v) {
756 return _v.norm();
757}
758
761template<typename Scalar, int DIM>
762Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
763 return _v.sqrnorm();
764}
767template<typename Scalar, int DIM, typename OtherScalar>
769 return _v.vectorize(_val);
770}
771
774template<typename Scalar, int DIM>
778
781template<typename Scalar, int DIM>
785
788template<typename Scalar, int DIM>
792
795template<typename Scalar, int DIM>
797 return _v1.max(_v2);
798}
799
802template<typename Scalar, int DIM>
804 return _v1.min(_v2);
805}
806
807
808//== TYPEDEFS =================================================================
809
826
843
862
879
896
913
914} // namespace OpenMesh
915
924constexpr OpenMesh::Vec4f operator""_htmlColor(unsigned long long raw_color) {
925 return OpenMesh::Vec4f(
926 ((raw_color >> 24) & 0xFF) / 255.0f,
927 ((raw_color >> 16) & 0xFF) / 255.0f,
928 ((raw_color >> 8) & 0xFF) / 255.0f,
929 ((raw_color >> 0) & 0xFF) / 255.0f);
930}
931
932#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:699
VectorT< float, 4 > Vec4f
4-float vector
Definition Vector11T.hh:876
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:645
const Scalar & operator[](size_t _i) const
get i'th element read-only
Definition Vector11T.hh:215
VectorT< Scalar, DIM > & normalize(VectorT< Scalar, DIM > &_v)
non-member normalize
Definition Vector11T.hh:775
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:389
Scalar dot(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
symmetric version of the dot product
Definition Vector11T.hh:731
Scalar * data()
access to Scalar array
Definition Vector11T.hh:201
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:789
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
decltype(std::declval< S >() *std::declval< S >()) squaredNorm() const
compute squared Euclidean norm (interface compatible with Eigen vectors)
Definition Vector11T.hh:434
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:422
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:204
VectorT< Scalar, DIM > & vectorize(VectorT< Scalar, DIM > &_v, OtherScalar const &_val)
non-member vectorize
Definition Vector11T.hh:768
void swap(VectorT &_other) noexcept(noexcept(std::swap(values_, _other.values_)))
swap with another vector
Definition Vector11T.hh:663
Scalar max_abs() const
return the maximal absolute component
Definition Vector11T.hh:529
vector_type min(const vector_type &_rhs) const
component-wise min
Definition Vector11T.hh:622
VectorT< Scalar, DIM > min(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
non-member min
Definition Vector11T.hh:803
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition Vector11T.hh:594
Scalar sqrnorm(const VectorT< Scalar, DIM > &_v)
non-member sqrnorm
Definition Vector11T.hh:762
auto cross(const VectorT< LScalar, DIM > &_v1, const VectorT< RScalar, DIM > &_v2) -> decltype(_v1 % _v2)
symmetric version of the cross product
Definition Vector11T.hh:739
auto operator|(const VectorT< OtherScalar, DIM > &_rhs) const -> decltype(*this->data() **_rhs.data())
compute scalar product
Definition Vector11T.hh:399
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:487
VectorT< Scalar, DIM > & maximize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
non-member maximize
Definition Vector11T.hh:782
void swap(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2) noexcept(noexcept(_v1.swap(_v2)))
non-member swap
Definition Vector11T.hh:747
VectorT< Scalar, DIM > max(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
non-member max
Definition Vector11T.hh:796
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:248
vector_type max(const vector_type &_rhs) const
component-wise max
Definition Vector11T.hh:627
vector_type & operator=(const VectorT< OtherScalar, DIM > &_rhs)
cast from vector with a different scalar type
Definition Vector11T.hh:192
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:566
static vector_type vectorized(const Scalar &_s)
store the same value in each component
Definition Vector11T.hh:651
Scalar l8_norm() const
compute l8_norm
Definition Vector11T.hh:512
Scalar min_abs() const
return the minimal absolute component
Definition Vector11T.hh:543
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:449
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:365
bool operator<(const vector_type &_rhs) const
lexicographical comparison
Definition Vector11T.hh:656
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Definition Vector11T.hh:577
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:557
Scalar l1_norm() const
compute L1 (Manhattan) norm
Definition Vector11T.hh:506
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:409
VectorT(const VectorT< otherScalarType, DIM > &_rhs)
copy & cast constructor (explicit)
Definition Vector11T.hh:182
Scalar mean() const
return arithmetic mean
Definition Vector11T.hh:552
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:236
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:637
bool operator==(const vector_type &_rhs) const
component-wise comparison
Definition Vector11T.hh:223
bool operator!=(const vector_type &_rhs) const
component-wise comparison
Definition Vector11T.hh:228
Scalar max() const
return the maximal component
Definition Vector11T.hh:524
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
Definition Vector11T.hh:605
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM > >().norm())
normalize vector, return normalized vector
Definition Vector11T.hh:460
Scalar & operator[](size_t _i)
get i'th element read-write
Definition Vector11T.hh:209
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM > >().sqrnorm()))
compute Euclidean norm
Definition Vector11T.hh:440
Scalar min() const
return the minimal component
Definition Vector11T.hh:538
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM > >().norm())
return normalized vector
Definition Vector11T.hh:471
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:375
Scalar norm(const VectorT< Scalar, DIM > &_v)
non-member norm
Definition Vector11T.hh:755
VectorT(container &&_array)
construct from an array
Definition Vector11T.hh:173
Definition VectorT_inc.hh:68

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