| OpenMesh

Vector11T.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 #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 */
64 namespace {
65
66 template<typename ... Ts>
67 struct are_convertible_to;
68
69 template<typename To, typename From, typename ... Froms>
70 struct 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
75 template<typename To, typename From>
76 struct are_convertible_to<To, From> : public std::is_convertible<From, To> {
77 };
78 }
79
80 namespace OpenMesh {
81
82 template<typename Scalar, int DIM>
83 class 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
99 typedef VectorT<Scalar, DIM> vector_type;
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 template<typename otherScalarType,
174 typename = typename std::enable_if<
175 std::is_convertible<otherScalarType, Scalar>::value>>
176 explicit VectorT(const VectorT<otherScalarType, DIM>& _rhs) {
177 operator=(_rhs);
178 }
179
180 //--------------------------------------------------------------------- casts
181
183 template<typename OtherScalar,
184 typename = typename std::enable_if<
185 std::is_convertible<OtherScalar, Scalar>::value>>
186 vector_type& operator=(const VectorT<OtherScalar, DIM>& _rhs) {
187 std::transform(_rhs.cbegin(), _rhs.cend(),
188 this->begin(), [](OtherScalar rhs) {
189 return static_cast<Scalar>(std::move(rhs));
190 });
191 return *this;
192 }
193
195 Scalar* data() { return values_.data(); }
196
198 const Scalar* data() const { return values_.data(); }
199
200 //----------------------------------------------------------- element access
201
203 Scalar& operator[](size_t _i) {
204 assert(_i < DIM);
205 return values_[_i];
206 }
207
209 const Scalar& operator[](size_t _i) const {
210 assert(_i < DIM);
211 return values_[_i];
212 }
213
214 //---------------------------------------------------------------- comparsion
215
217 bool operator==(const vector_type& _rhs) const {
218 return std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
219 }
220
222 bool operator!=(const vector_type& _rhs) const {
223 return !std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
224 }
225
226 //---------------------------------------------------------- scalar operators
227
229 template<typename OtherScalar>
230 auto operator*=(const OtherScalar& _s) ->
231 typename std::enable_if<std::is_convertible<
232 decltype(this->values_[0] * _s), Scalar>::value,
233 VectorT<Scalar, DIM>&>::type {
234 for (auto& e : *this) {
235 e *= _s;
236 }
237 return *this;
238 }
239
241 template<typename OtherScalar>
242 auto operator/=(const OtherScalar& _s) ->
243 typename std::enable_if<std::is_convertible<
244 decltype(this->values_[0] / _s), Scalar>::value,
245 VectorT<Scalar, DIM>&>::type {
246 for (auto& e : *this) {
247 e /= _s;
248 }
249 return *this;
250 }
251
253 template<typename OtherScalar>
254 typename std::enable_if<std::is_convertible<
255 decltype(std::declval<Scalar>() * std::declval<OtherScalar>()),
256 Scalar>::value,
257 VectorT<Scalar, DIM>>::type
258 operator*(const OtherScalar& _s) const {
259 return vector_type(*this) *= _s;
260 }
261
263 template<typename OtherScalar>
264 typename std::enable_if<std::is_convertible<
265 decltype(std::declval<Scalar>() / std::declval<OtherScalar>()),
266 Scalar>::value,
267 VectorT<Scalar, DIM>>::type
268 operator/(const OtherScalar& _s) const {
269 return vector_type(*this) /= _s;
270 }
271
272 //---------------------------------------------------------- vector operators
273
275 template<typename OtherScalar>
276 auto operator*=(const VectorT<OtherScalar, DIM>& _rhs) ->
277 typename std::enable_if<
278 sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
279 vector_type&>::type {
280 for (int i = 0; i < DIM; ++i) {
281 data()[i] *= _rhs.data()[i];
282 }
283 return *this;
284 }
285
287 template<typename OtherScalar>
288 auto operator/=(const VectorT<OtherScalar, DIM>& _rhs) ->
289 typename std::enable_if<
290 sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
291 vector_type&>::type {
292 for (int i = 0; i < DIM; ++i) {
293 data()[i] /= _rhs.data()[i];
294 }
295 return *this;
296 }
297
299 template<typename OtherScalar>
300 auto operator-=(const VectorT<OtherScalar, DIM>& _rhs) ->
301 typename std::enable_if<
302 sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
303 vector_type&>::type {
304 for (int i = 0; i < DIM; ++i) {
305 data()[i] -= _rhs.data()[i];
306 }
307 return *this;
308 }
309
311 template<typename OtherScalar>
312 auto operator+=(const VectorT<OtherScalar, DIM>& _rhs) ->
313 typename std::enable_if<
314 sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
315 vector_type&>::type {
316 for (int i = 0; i < DIM; ++i) {
317 data()[i] += _rhs.data()[i];
318 }
319 return *this;
320 }
321
323 template<typename OtherScalar>
324 auto operator*(const VectorT<OtherScalar, DIM>& _rhs) const ->
325 typename std::enable_if<
326 sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
327 vector_type>::type {
328 return vector_type(*this) *= _rhs;
329 }
330
332 template<typename OtherScalar>
333 auto operator/(const VectorT<OtherScalar, DIM>& _rhs) const ->
334 typename std::enable_if<
335 sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
336 vector_type>::type {
337 return vector_type(*this) /= _rhs;
338 }
339
341 template<typename OtherScalar>
342 auto operator+(const VectorT<OtherScalar, DIM>& _rhs) const ->
343 typename std::enable_if<
344 sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
345 vector_type>::type {
346 return vector_type(*this) += _rhs;
347 }
348
350 template<typename OtherScalar>
351 auto operator-(const VectorT<OtherScalar, DIM>& _rhs) const ->
352 typename std::enable_if<
353 sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
354 vector_type>::type {
355 return vector_type(*this) -= _rhs;
356 }
357
359 vector_type operator-(void) const {
360 vector_type v;
361 std::transform(values_.begin(), values_.end(), v.values_.begin(),
362 [](const Scalar &s) { return -s; });
363 return v;
364 }
365
368 template<typename OtherScalar>
369 auto operator% (const VectorT<OtherScalar, DIM> &_rhs) const ->
370 typename std::enable_if<DIM == 3,
371 VectorT<decltype((*this)[0] * _rhs[0] -
372 (*this)[0] * _rhs[0]), DIM>>::type {
373 return {
374 values_[1] * _rhs[2] - values_[2] * _rhs[1],
375 values_[2] * _rhs[0] - values_[0] * _rhs[2],
376 values_[0] * _rhs[1] - values_[1] * _rhs[0]
377 };
378 }
379
382 template<typename OtherScalar>
383 auto operator|(const VectorT<OtherScalar, DIM>& _rhs) const ->
384 decltype(*this->data() * *_rhs.data()) {
385
386 return std::inner_product(begin() + 1, begin() + DIM, _rhs.begin() + 1,
387 *begin() * *_rhs.begin());
388 }
389
390 //------------------------------------------------------------ euclidean norm
391
393
394
396 template<typename S = Scalar>
397 decltype(std::declval<S>() * std::declval<S>()) sqrnorm() const {
398 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
399 "to be the same type. (Never override the default template "
400 "arguments.)");
401 typedef decltype(values_[0] * values_[0]) RESULT;
402 return std::accumulate(values_.cbegin() + 1, values_.cend(),
403 values_[0] * values_[0],
404 [](const RESULT &l, const Scalar &r) { return l + r * r; });
405 }
406
408 template<typename S = Scalar>
409 auto norm() const ->
410 decltype(std::sqrt(std::declval<VectorT<S, DIM>>().sqrnorm())) {
411 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
412 "to be the same type. (Never override the default template "
413 "arguments.)");
414 return std::sqrt(sqrnorm());
415 }
416
417 template<typename S = Scalar>
418 auto length() const ->
419 decltype(std::declval<VectorT<S, DIM>>().norm()) {
420 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
421 "to be the same type. (Never override the default template "
422 "arguments.)");
423 return norm();
424 }
425
428 template<typename S = Scalar>
429 auto normalize() ->
430 decltype(*this /= std::declval<VectorT<S, DIM>>().norm()) {
431 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
432 "to be the same type. (Never override the default template "
433 "arguments.)");
434 return *this /= norm();
435 }
436
439 template<typename S = Scalar>
440 auto normalized() const ->
441 decltype(*this / std::declval<VectorT<S, DIM>>().norm()) {
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 *this / norm();
446 }
447
450 template<typename S = Scalar>
451 typename std::enable_if<
452 sizeof(decltype(
453 static_cast<S>(0),
454 std::declval<VectorT<S, DIM>>().norm())) >= 0,
455 vector_type&>::type
456 normalize_cond() {
457 static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
458 "to be the same type. (Never override the default template "
459 "arguments.)");
460 auto n = norm();
461 if (n != static_cast<decltype(norm())>(0)) {
462 *this /= n;
463 }
464 return *this;
465 }
466
468
469 //------------------------------------------------------------ euclidean norm
470
472
473
475 Scalar l1_norm() const {
476 return std::accumulate(
477 values_.cbegin() + 1, values_.cend(), values_[0]);
478 }
479
481 Scalar l8_norm() const {
482 return max_abs();
483 }
484
486
487 //------------------------------------------------------------ max, min, mean
488
490
491
493 Scalar max() const {
494 return *std::max_element(values_.cbegin(), values_.cend());
495 }
496
498 Scalar max_abs() const {
499 return std::abs(
500 *std::max_element(values_.cbegin(), values_.cend(),
501 [](const Scalar &a, const Scalar &b) {
502 return std::abs(a) < std::abs(b);
503 }));
504 }
505
507 Scalar min() const {
508 return *std::min_element(values_.cbegin(), values_.cend());
509 }
510
512 Scalar min_abs() const {
513 return std::abs(
514 *std::min_element(values_.cbegin(), values_.cend(),
515 [](const Scalar &a, const Scalar &b) {
516 return std::abs(a) < std::abs(b);
517 }));
518 }
519
521 Scalar mean() const {
522 return l1_norm()/DIM;
523 }
524
526 Scalar mean_abs() const {
527 return std::accumulate(values_.cbegin() + 1, values_.cend(),
528 std::abs(values_[0]),
529 [](const Scalar &l, const Scalar &r) {
530 return l + std::abs(r);
531 }) / DIM;
532 }
533
535 vector_type& minimize(const vector_type& _rhs) {
536 std::transform(values_.cbegin(), values_.cend(),
537 _rhs.values_.cbegin(),
538 values_.begin(),
539 [](const Scalar &l, const Scalar &r) {
540 return std::min(l, r);
541 });
542 return *this;
543 }
544
546 bool minimized(const vector_type& _rhs) {
547 bool result = false;
548 std::transform(values_.cbegin(), values_.cend(),
549 _rhs.values_.cbegin(),
550 values_.begin(),
551 [&result](const Scalar &l, const Scalar &r) {
552 if (l < r) {
553 return l;
554 } else {
555 result = true;
556 return r;
557 }
558 });
559 return result;
560 }
561
563 vector_type& maximize(const vector_type& _rhs) {
564 std::transform(values_.cbegin(), values_.cend(),
565 _rhs.values_.cbegin(),
566 values_.begin(),
567 [](const Scalar &l, const Scalar &r) {
568 return std::max(l, r);
569 });
570 return *this;
571 }
572
574 bool maximized(const vector_type& _rhs) {
575 bool result = false;
576 std::transform(values_.cbegin(), values_.cend(),
577 _rhs.values_.cbegin(),
578 values_.begin(),
579 [&result](const Scalar &l, const Scalar &r) {
580 if (l > r) {
581 return l;
582 } else {
583 result = true;
584 return r;
585 }
586 });
587 return result;
588 }
589
591 inline vector_type min(const vector_type& _rhs) const {
592 return vector_type(*this).minimize(_rhs);
593 }
594
596 inline vector_type max(const vector_type& _rhs) const {
597 return vector_type(*this).maximize(_rhs);
598 }
599
601
602 //------------------------------------------------------------ misc functions
603
605 template<typename Functor>
606 inline vector_type apply(const Functor& _func) const {
607 vector_type result;
608 std::transform(result.values_.cbegin(), result.values_.cend(),
609 result.values_.begin(), _func);
610 return result;
611 }
612
614 vector_type& vectorize(const Scalar& _s) {
615 std::fill(values_.begin(), values_.end(), _s);
616 return *this;
617 }
618
620 static vector_type vectorized(const Scalar& _s) {
621 return vector_type().vectorize(_s);
622 }
623
625 bool operator<(const vector_type& _rhs) const {
626 return std::lexicographical_compare(
627 values_.begin(), values_.end(),
628 _rhs.values_.begin(), _rhs.values_.end());
629 }
630
632 void swap(VectorT& _other)
633 noexcept(noexcept(std::swap(values_, _other.values_))) {
634 std::swap(values_, _other.values_);
635 }
636
637 //------------------------------------------------------------ component iterators
638
640
641
642 using iterator = typename container::iterator;
643 using const_iterator = typename container::const_iterator;
644 using reverse_iterator = typename container::reverse_iterator;
645 using const_reverse_iterator = typename container::const_reverse_iterator;
646
647 iterator begin() noexcept { return values_.begin(); }
648 const_iterator begin() const noexcept { return values_.cbegin(); }
649 const_iterator cbegin() const noexcept { return values_.cbegin(); }
650
651 iterator end() noexcept { return values_.end(); }
652 const_iterator end() const noexcept { return values_.cend(); }
653 const_iterator cend() const noexcept { return values_.cend(); }
654
655 reverse_iterator rbegin() noexcept { return values_.rbegin(); }
656 const_reverse_iterator rbegin() const noexcept { return values_.crbegin(); }
657 const_reverse_iterator crbegin() const noexcept { return values_.crbegin(); }
658
659 reverse_iterator rend() noexcept { return values_.rend(); }
660 const_reverse_iterator rend() const noexcept { return values_.crend(); }
661 const_reverse_iterator crend() const noexcept { return values_.crend(); }
662
664 };
665
667 template<typename Scalar, int DIM, typename OtherScalar>
668 auto operator*(const OtherScalar& _s, const VectorT<Scalar, DIM> &rhs) ->
669 decltype(rhs.operator*(_s)) {
670
671 return rhs * _s;
672 }
673
675 template<typename Scalar, int DIM>
676 auto operator<<(std::ostream& os, const VectorT<Scalar, DIM> &_vec) ->
677 typename std::enable_if<
678 sizeof(decltype(os << _vec[0])) >= 0, std::ostream&>::type {
679
680 os << _vec[0];
681 for (int i = 1; i < DIM; ++i) {
682 os << " " << _vec[i];
683 }
684 return os;
685 }
686
688 template<typename Scalar, int DIM>
689 auto operator>> (std::istream& is, VectorT<Scalar, DIM> &_vec) ->
690 typename std::enable_if<
691 sizeof(decltype(is >> _vec[0])) >= 0, std::istream &>::type {
692 for (int i = 0; i < DIM; ++i)
693 is >> _vec[i];
694 return is;
695 }
696
699 template<typename Scalar, int DIM>
700 Scalar dot(const VectorT<Scalar, DIM>& _v1, const VectorT<Scalar, DIM>& _v2) {
701 return (_v1 | _v2);
702 }
703
706 template<typename LScalar, typename RScalar, int DIM>
707 auto
708 cross(const VectorT<LScalar, DIM>& _v1, const VectorT<RScalar, DIM>& _v2) ->
709 decltype(_v1 % _v2) {
710 return (_v1 % _v2);
711 }
712
715 template<typename Scalar, int DIM>
716 void swap(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2)
717 noexcept(noexcept(_v1.swap(_v2))) {
718 _v1.swap(_v2);
719 }
720
723 template<typename Scalar, int DIM>
724 Scalar norm(const VectorT<Scalar, DIM>& _v) {
725 return _v.norm();
726 }
727
730 template<typename Scalar, int DIM>
731 Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
732 return _v.sqrnorm();
733 }
736 template<typename Scalar, int DIM, typename OtherScalar>
737 VectorT<Scalar, DIM>& vectorize(VectorT<Scalar, DIM>& _v, OtherScalar const& _val) {
738 return _v.vectorize(_val);
739 }
740
743 template<typename Scalar, int DIM>
744 VectorT<Scalar, DIM>& normalize(VectorT<Scalar, DIM>& _v) {
745 return _v.normalize();
746 }
747
750 template<typename Scalar, int DIM>
751 VectorT<Scalar, DIM>& maximize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
752 return _v1.maximize(_v2);
753 }
754
757 template<typename Scalar, int DIM>
758 VectorT<Scalar, DIM>& minimize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
759 return _v1.minimize(_v2);
760 }
761
762 //== TYPEDEFS =================================================================
763
765 typedef VectorT<signed char,1> Vec1c;
767 typedef VectorT<unsigned char,1> Vec1uc;
769 typedef VectorT<signed short int,1> Vec1s;
771 typedef VectorT<unsigned short int,1> Vec1us;
773 typedef VectorT<signed int,1> Vec1i;
775 typedef VectorT<unsigned int,1> Vec1ui;
777 typedef VectorT<float,1> Vec1f;
779 typedef VectorT<double,1> Vec1d;
780
782 typedef VectorT<signed char,2> Vec2c;
784 typedef VectorT<unsigned char,2> Vec2uc;
786 typedef VectorT<signed short int,2> Vec2s;
788 typedef VectorT<unsigned short int,2> Vec2us;
790 typedef VectorT<signed int,2> Vec2i;
792 typedef VectorT<unsigned int,2> Vec2ui;
794 typedef VectorT<float,2> Vec2f;
796 typedef VectorT<double,2> Vec2d;
797
799 typedef VectorT<signed char,3> Vec3c;
801 typedef VectorT<unsigned char,3> Vec3uc;
803 typedef VectorT<signed short int,3> Vec3s;
805 typedef VectorT<unsigned short int,3> Vec3us;
807 typedef VectorT<signed int,3> Vec3i;
809 typedef VectorT<unsigned int,3> Vec3ui;
811 typedef VectorT<float,3> Vec3f;
813 typedef VectorT<double,3> Vec3d;
815 typedef VectorT<bool,3> Vec3b;
816
818 typedef VectorT<signed char,4> Vec4c;
820 typedef VectorT<unsigned char,4> Vec4uc;
822 typedef VectorT<signed short int,4> Vec4s;
824 typedef VectorT<unsigned short int,4> Vec4us;
826 typedef VectorT<signed int,4> Vec4i;
828 typedef VectorT<unsigned int,4> Vec4ui;
830 typedef VectorT<float,4> Vec4f;
832 typedef VectorT<double,4> Vec4d;
833
835 typedef VectorT<signed char, 5> Vec5c;
837 typedef VectorT<unsigned char, 5> Vec5uc;
839 typedef VectorT<signed short int, 5> Vec5s;
841 typedef VectorT<unsigned short int, 5> Vec5us;
843 typedef VectorT<signed int, 5> Vec5i;
845 typedef VectorT<unsigned int, 5> Vec5ui;
847 typedef VectorT<float, 5> Vec5f;
849 typedef VectorT<double, 5> Vec5d;
850
852 typedef VectorT<signed char,6> Vec6c;
854 typedef VectorT<unsigned char,6> Vec6uc;
856 typedef VectorT<signed short int,6> Vec6s;
858 typedef VectorT<unsigned short int,6> Vec6us;
860 typedef VectorT<signed int,6> Vec6i;
862 typedef VectorT<unsigned int,6> Vec6ui;
864 typedef VectorT<float,6> Vec6f;
866 typedef VectorT<double,6> Vec6d;
867
868 } // namespace OpenMesh
869
878 constexpr OpenMesh::Vec4f operator"" _htmlColor(unsigned long long raw_color) {
879 return OpenMesh::Vec4f(
880 ((raw_color >> 24) & 0xFF) / 255.0f,
881 ((raw_color >> 16) & 0xFF) / 255.0f,
882 ((raw_color >> 8) & 0xFF) / 255.0f,
883 ((raw_color >> 0) & 0xFF) / 255.0f);
884 }
885
886 #endif /* OPENMESH_SRC_OPENMESH_CORE_GEOMETRY_VECTOR11T_HH_ */
OpenMesh::VectorT
Definition: Vector11T.hh:83
OpenMesh::VectorT::maximized
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
Definition: Vector11T.hh:574
OpenMesh::VectorT::VectorT
VectorT(Iterator it)
construct from a value array or any other iterator
Definition: Vector11T.hh:168
OpenMesh::VectorT::max
Scalar max() const
return the maximal component
Definition: Vector11T.hh:493
OpenMesh::VectorT::cross
auto cross(const VectorT< LScalar, DIM > &_v1, const VectorT< RScalar, DIM > &_v2) -> decltype(_v1 % _v2)
Definition: Vector11T.hh:708
OpenMesh::VectorT::min
vector_type min(const vector_type &_rhs) const
component-wise min
Definition: Vector11T.hh:591
OpenMesh::VectorT::norm
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
Definition: Vector11T.hh:409
OpenMesh::VectorT::operator[]
const Scalar & operator[](size_t _i) const
get i&#39;th element read-only
Definition: Vector11T.hh:209
OpenMesh::VectorT::operator/
std::enable_if< std::is_convertible< decltype(std::declval< Scalar >)/std::declval< OtherScalar >)), Scalar >::value, VectorT< Scalar, DIM > >::type operator/(const OtherScalar &_s) const
component-wise division by with scalar
Definition: Vector11T.hh:268
OpenMesh::VectorT::VectorT
VectorT(const Scalar &v)
Creates a vector with all components set to v.
Definition: Vector11T.hh:134
OpenMesh::operator*
auto operator*(const OtherScalar &_s, const VectorT< Scalar, DIM > &rhs) -> decltype(rhs.operator*(_s))
Component wise multiplication from the left.
Definition: Vector11T.hh:668
OpenMesh::VectorT::swap
void swap(VectorT &_other) noexcept(noexcept(std::swap(values_, _other.values_)))
swap with another vector
Definition: Vector11T.hh:632
OpenMesh::VectorT::mean_abs
Scalar mean_abs() const
return absolute arithmetic mean
Definition: Vector11T.hh:526
OpenMesh::VectorT::data
const Scalar * data() const
access to const Scalar array
Definition: Vector11T.hh:198
OpenMesh::VectorT::dim
static constexpr int dim()
returns dimension of the vector (deprecated)
Definition: Vector11T.hh:102
OpenMesh::VectorT::normalized
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
return normalized vector
Definition: Vector11T.hh:440
OpenMesh::VectorT::operator[]
Scalar & operator[](size_t _i)
get i&#39;th element read-write
Definition: Vector11T.hh:203
OpenMesh::VectorT::length
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
Definition: Vector11T.hh:418
OpenMesh::VectorT::operator*=
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:230
OpenMesh::VectorT::max_abs
Scalar max_abs() const
return the maximal absolute component
Definition: Vector11T.hh:498
OpenMesh::VectorT::apply
vector_type apply(const Functor &_func) const
component-wise apply function object with Scalar operator()(Scalar).
Definition: Vector11T.hh:606
OpenMesh::VectorT::min_abs
Scalar min_abs() const
return the minimal absolute component
Definition: Vector11T.hh:512
OpenMesh::VectorT::l1_norm
Scalar l1_norm() const
compute L1 (Manhattan) norm
Definition: Vector11T.hh:475
OpenMesh::VectorT::operator|
auto operator|(const VectorT< OtherScalar, DIM > &_rhs) const -> decltype(*this->data() **_rhs.data())
compute scalar product
Definition: Vector11T.hh:383
OpenMesh::VectorT::swap
void swap(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2) noexcept(noexcept(_v1.swap(_v2)))
Definition: Vector11T.hh:716
OpenMesh::VectorT::sqrnorm
Scalar sqrnorm(const VectorT< Scalar, DIM > &_v)
Definition: Vector11T.hh:731
OpenMesh::VectorT::maximize
VectorT< Scalar, DIM > & maximize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:751
OpenMesh::VectorT::vectorized
static vector_type vectorized(const Scalar &_s)
store the same value in each component
Definition: Vector11T.hh:620
OpenMesh::VectorT::operator!=
bool operator!=(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:222
OpenMesh::VectorT::normalize_cond
vector_type &::type normalize_cond()
compute squared euclidean norm
Definition: Vector11T.hh:456
std
STL namespace.
OpenMesh::VectorT::min
Scalar min() const
return the minimal component
Definition: Vector11T.hh:507
OpenMesh::VectorT::minimize
VectorT< Scalar, DIM > & minimize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:758
OpenMesh::VectorT::operator-
vector_type operator-(void) const
unary minus
Definition: Vector11T.hh:359
OpenMesh::VectorT::operator*
std::enable_if< std::is_convertible< decltype(std::declval< Scalar >) *std::declval< OtherScalar >)), Scalar >::value, VectorT< Scalar, DIM > >::type operator*(const OtherScalar &_s) const
component-wise multiplication with scalar
Definition: Vector11T.hh:258
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::VectorT::normalize
VectorT< Scalar, DIM > & normalize(VectorT< Scalar, DIM > &_v)
Definition: Vector11T.hh:744
OpenMesh::VectorT::vectorize
VectorT< Scalar, DIM > & vectorize(VectorT< Scalar, DIM > &_v, OtherScalar const &_val)
Definition: Vector11T.hh:737
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
Scalar norm(const VectorT< Scalar, DIM > &_v)
Definition: Vector11T.hh:724
OpenMesh::VectorT::operator==
bool operator==(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:217
OpenMesh::VectorT::size
static constexpr size_t size()
returns dimension of the vector
Definition: Vector11T.hh:107
OpenMesh::VectorT::operator=
vector_type & operator=(const VectorT< OtherScalar, DIM > &_rhs)
cast from vector with a different scalar type
Definition: Vector11T.hh:186
OpenMesh::VectorT::normalize
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
normalize vector, return normalized vector
Definition: Vector11T.hh:429
OpenMesh::VectorT::VectorT
constexpr VectorT()
default constructor creates uninitialized values.
Definition: Vector11T.hh:129
OpenMesh::VectorT::homogenized
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
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::VectorT::value_type
Scalar value_type
the type of the scalar used in this template
Definition: Vector11T.hh:96
OpenMesh::VectorT::mean
Scalar mean() const
return arithmetic mean
Definition: Vector11T.hh:521
OpenMesh::VectorT::VectorT
VectorT(const VectorT< otherScalarType, DIM > &_rhs)
copy & cast constructor (explicit)
Definition: Vector11T.hh:176
OpenMesh::VectorT::l8_norm
Scalar l8_norm() const
compute l8_norm
Definition: Vector11T.hh:481
OpenMesh::VectorT::operator<
bool operator<(const vector_type &_rhs) const
lexicographical comparison
Definition: Vector11T.hh:625
VectorT< float, 4 >
OpenMesh::VectorT::sqrnorm
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
Definition: Vector11T.hh:397
OpenMesh::VectorT::minimized
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Definition: Vector11T.hh:546
OpenMesh::VectorT::data
Scalar * data()
access to Scalar array
Definition: Vector11T.hh:195
OpenMesh::VectorT::operator/=
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:242
OpenMesh::Vec4f
VectorT< float, 4 > Vec4f
4-float vector
Definition: Vector11T.hh:830
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::VectorT::dot
Scalar dot(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:700
OpenMesh::VectorT::max
vector_type max(const vector_type &_rhs) const
component-wise max
Definition: Vector11T.hh:596
OpenMesh::VectorT::vector_type
VectorT< Scalar, DIM > vector_type
type of this vector
Definition: Vector11T.hh:99