OpenMesh
Vector11T.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2023, 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 auto norm() const ->
435 decltype(std::sqrt(std::declval<VectorT<S, DIM>>().sqrnorm())) {
436 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
437 "to be the same type. (Never override the default template "
438 "arguments.)");
439 return std::sqrt(sqrnorm());
440 }
441
442 template<typename S = Scalar>
443 auto length() const ->
444 decltype(std::declval<VectorT<S, DIM>>().norm()) {
445 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
446 "to be the same type. (Never override the default template "
447 "arguments.)");
448 return norm();
449 }
450
453 template<typename S = Scalar>
454 auto normalize() ->
455 decltype(*this /= std::declval<VectorT<S, DIM>>().norm()) {
456 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
457 "to be the same type. (Never override the default template "
458 "arguments.)");
459 return *this /= norm();
460 }
461
464 template<typename S = Scalar>
465 auto normalized() const ->
466 decltype(*this / std::declval<VectorT<S, DIM>>().norm()) {
467 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
468 "to be the same type. (Never override the default template "
469 "arguments.)");
470 return *this / norm();
471 }
472
475 template<typename S = Scalar>
476 typename std::enable_if<
477 sizeof(decltype(
478 static_cast<S>(0),
479 std::declval<VectorT<S, DIM>>().norm())) >= 0,
480 vector_type&>::type
482 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
483 "to be the same type. (Never override the default template "
484 "arguments.)");
485 auto n = norm();
486 if (n != static_cast<decltype(norm())>(0)) {
487 *this /= n;
488 }
489 return *this;
490 }
491
493
494 //------------------------------------------------------------ euclidean norm
495
497
498
500 Scalar l1_norm() const {
501 return std::accumulate(
502 values_.cbegin() + 1, values_.cend(), values_[0]);
503 }
504
506 Scalar l8_norm() const {
507 return max_abs();
508 }
509
511
512 //------------------------------------------------------------ max, min, mean
513
515
516
518 Scalar max() const {
519 return *std::max_element(values_.cbegin(), values_.cend());
520 }
521
523 Scalar max_abs() const {
524 return std::abs(
525 *std::max_element(values_.cbegin(), values_.cend(),
526 [](const Scalar &a, const Scalar &b) {
527 return std::abs(a) < std::abs(b);
528 }));
529 }
530
532 Scalar min() const {
533 return *std::min_element(values_.cbegin(), values_.cend());
534 }
535
537 Scalar min_abs() const {
538 return std::abs(
539 *std::min_element(values_.cbegin(), values_.cend(),
540 [](const Scalar &a, const Scalar &b) {
541 return std::abs(a) < std::abs(b);
542 }));
543 }
544
546 Scalar mean() const {
547 return l1_norm()/DIM;
548 }
549
551 Scalar mean_abs() const {
552 return std::accumulate(values_.cbegin() + 1, values_.cend(),
553 std::abs(values_[0]),
554 [](const Scalar &l, const Scalar &r) {
555 return l + std::abs(r);
556 }) / DIM;
557 }
558
561 std::transform(values_.cbegin(), values_.cend(),
562 _rhs.values_.cbegin(),
563 values_.begin(),
564 [](const Scalar &l, const Scalar &r) {
565 return std::min(l, r);
566 });
567 return *this;
568 }
569
571 bool minimized(const vector_type& _rhs) {
572 bool result = false;
573 std::transform(values_.cbegin(), values_.cend(),
574 _rhs.values_.cbegin(),
575 values_.begin(),
576 [&result](const Scalar &l, const Scalar &r) {
577 if (l < r) {
578 return l;
579 } else {
580 result = true;
581 return r;
582 }
583 });
584 return result;
585 }
586
589 std::transform(values_.cbegin(), values_.cend(),
590 _rhs.values_.cbegin(),
591 values_.begin(),
592 [](const Scalar &l, const Scalar &r) {
593 return std::max(l, r);
594 });
595 return *this;
596 }
597
599 bool maximized(const vector_type& _rhs) {
600 bool result = false;
601 std::transform(values_.cbegin(), values_.cend(),
602 _rhs.values_.cbegin(),
603 values_.begin(),
604 [&result](const Scalar &l, const Scalar &r) {
605 if (l > r) {
606 return l;
607 } else {
608 result = true;
609 return r;
610 }
611 });
612 return result;
613 }
614
616 inline vector_type min(const vector_type& _rhs) const {
617 return vector_type(*this).minimize(_rhs);
618 }
619
621 inline vector_type max(const vector_type& _rhs) const {
622 return vector_type(*this).maximize(_rhs);
623 }
624
626
627 //------------------------------------------------------------ misc functions
628
630 template<typename Functor>
631 inline vector_type apply(const Functor& _func) const {
632 vector_type result;
633 std::transform(result.values_.cbegin(), result.values_.cend(),
634 result.values_.begin(), _func);
635 return result;
636 }
637
639 vector_type& vectorize(const Scalar& _s) {
640 std::fill(values_.begin(), values_.end(), _s);
641 return *this;
642 }
643
645 static vector_type vectorized(const Scalar& _s) {
646 return vector_type().vectorize(_s);
647 }
648
650 bool operator<(const vector_type& _rhs) const {
651 return std::lexicographical_compare(
652 values_.begin(), values_.end(),
653 _rhs.values_.begin(), _rhs.values_.end());
654 }
655
657 void swap(VectorT& _other)
658 noexcept(noexcept(std::swap(values_, _other.values_))) {
659 std::swap(values_, _other.values_);
660 }
661
662 //------------------------------------------------------------ component iterators
663
665
666
667 using iterator = typename container::iterator;
668 using const_iterator = typename container::const_iterator;
669 using reverse_iterator = typename container::reverse_iterator;
670 using const_reverse_iterator = typename container::const_reverse_iterator;
671
672 iterator begin() noexcept { return values_.begin(); }
673 const_iterator begin() const noexcept { return values_.cbegin(); }
674 const_iterator cbegin() const noexcept { return values_.cbegin(); }
675
676 iterator end() noexcept { return values_.end(); }
677 const_iterator end() const noexcept { return values_.cend(); }
678 const_iterator cend() const noexcept { return values_.cend(); }
679
680 reverse_iterator rbegin() noexcept { return values_.rbegin(); }
681 const_reverse_iterator rbegin() const noexcept { return values_.crbegin(); }
682 const_reverse_iterator crbegin() const noexcept { return values_.crbegin(); }
683
684 reverse_iterator rend() noexcept { return values_.rend(); }
685 const_reverse_iterator rend() const noexcept { return values_.crend(); }
686 const_reverse_iterator crend() const noexcept { return values_.crend(); }
687
689};
690
692template<typename Scalar, int DIM, typename OtherScalar>
693auto operator*(const OtherScalar& _s, const VectorT<Scalar, DIM> &rhs) ->
694 decltype(rhs.operator*(_s)) {
695
696 return rhs * _s;
697}
698
700template<typename Scalar, int DIM>
701auto operator<<(std::ostream& os, const VectorT<Scalar, DIM> &_vec) ->
702 typename std::enable_if<
703 sizeof(decltype(os << _vec[0])) >= 0, std::ostream&>::type {
704
705 os << _vec[0];
706 for (int i = 1; i < DIM; ++i) {
707 os << " " << _vec[i];
708 }
709 return os;
710}
711
713template<typename Scalar, int DIM>
714auto operator>> (std::istream& is, VectorT<Scalar, DIM> &_vec) ->
715 typename std::enable_if<
716 sizeof(decltype(is >> _vec[0])) >= 0, std::istream &>::type {
717 for (int i = 0; i < DIM; ++i)
718 is >> _vec[i];
719 return is;
720}
721
724template<typename Scalar, int DIM>
725Scalar dot(const VectorT<Scalar, DIM>& _v1, const VectorT<Scalar, DIM>& _v2) {
726 return (_v1 | _v2);
727}
728
731template<typename LScalar, typename RScalar, int DIM>
732auto
734 decltype(_v1 % _v2) {
735 return (_v1 % _v2);
736}
737
740template<typename Scalar, int DIM>
742noexcept(noexcept(_v1.swap(_v2))) {
743 _v1.swap(_v2);
744}
745
748template<typename Scalar, int DIM>
749Scalar norm(const VectorT<Scalar, DIM>& _v) {
750 return _v.norm();
751}
752
755template<typename Scalar, int DIM>
756Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
757 return _v.sqrnorm();
758}
761template<typename Scalar, int DIM, typename OtherScalar>
763 return _v.vectorize(_val);
764}
765
768template<typename Scalar, int DIM>
770 return _v.normalize();
771}
772
775template<typename Scalar, int DIM>
777 return _v1.maximize(_v2);
778}
779
782template<typename Scalar, int DIM>
784 return _v1.minimize(_v2);
785}
786
789template<typename Scalar, int DIM>
791 return _v1.max(_v2);
792}
793
796template<typename Scalar, int DIM>
798 return _v1.min(_v2);
799}
800
801
802//== TYPEDEFS =================================================================
803
820
837
856
873
890
907
908} // namespace OpenMesh
909
918constexpr OpenMesh::Vec4f operator"" _htmlColor(unsigned long long raw_color) {
919 return OpenMesh::Vec4f(
920 ((raw_color >> 24) & 0xFF) / 255.0f,
921 ((raw_color >> 16) & 0xFF) / 255.0f,
922 ((raw_color >> 8) & 0xFF) / 255.0f,
923 ((raw_color >> 0) & 0xFF) / 255.0f);
924}
925
926#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:693
VectorT< float, 4 > Vec4f
4-float vector
Definition: Vector11T.hh:870
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:639
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:769
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:725
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:783
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: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:762
void swap(VectorT &_other) noexcept(noexcept(std::swap(values_, _other.values_)))
swap with another vector
Definition: Vector11T.hh:657
Scalar max_abs() const
return the maximal absolute component
Definition: Vector11T.hh:523
vector_type min(const vector_type &_rhs) const
component-wise min
Definition: Vector11T.hh:616
VectorT< Scalar, DIM > min(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
non-member min
Definition: Vector11T.hh:797
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:588
Scalar sqrnorm(const VectorT< Scalar, DIM > &_v)
non-member sqrnorm
Definition: Vector11T.hh:756
auto cross(const VectorT< LScalar, DIM > &_v1, const VectorT< RScalar, DIM > &_v2) -> decltype(_v1 % _v2)
symmetric version of the cross product
Definition: Vector11T.hh:733
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:481
VectorT< Scalar, DIM > & maximize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
non-member maximize
Definition: Vector11T.hh:776
void swap(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2) noexcept(noexcept(_v1.swap(_v2)))
non-member swap
Definition: Vector11T.hh:741
VectorT< Scalar, DIM > max(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
non-member max
Definition: Vector11T.hh:790
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:621
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:560
static vector_type vectorized(const Scalar &_s)
store the same value in each component
Definition: Vector11T.hh:645
Scalar l8_norm() const
compute l8_norm
Definition: Vector11T.hh:506
Scalar min_abs() const
return the minimal absolute component
Definition: Vector11T.hh:537
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:443
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:650
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Definition: Vector11T.hh:571
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:551
Scalar l1_norm() const
compute L1 (Manhattan) norm
Definition: Vector11T.hh:500
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:546
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:631
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:518
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
Definition: Vector11T.hh:599
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM > >().norm())
normalize vector, return normalized vector
Definition: Vector11T.hh:454
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:434
Scalar min() const
return the minimal component
Definition: Vector11T.hh:532
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM > >().norm())
return normalized vector
Definition: Vector11T.hh:465
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:749
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 .