Developer Documentation
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.
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 
100 
102  static constexpr int dim() {
103  return DIM;
104  }
105 
107  static constexpr size_t size() {
108  return DIM;
109  }
110 
111  static constexpr const size_t size_ = DIM;
112 
113  //-------------------------------------------------------------- constructors
114 
115  // Converting constructor: Constructs the vector from DIM values (of
116  // potentially heterogenous types) which are all convertible to Scalar.
117  template<typename T, typename ... Ts,
118  typename = typename std::enable_if<sizeof...(Ts)+1 == DIM>::type,
119  typename = typename std::enable_if<
120  are_convertible_to<Scalar, T, Ts...>::value>::type>
121  constexpr VectorT(T v, Ts... vs) : values_ { {static_cast<Scalar>(v), static_cast<Scalar>(vs)...} } {
122  static_assert(sizeof...(Ts)+1 == DIM,
123  "Invalid number of components specified in constructor.");
124  static_assert(are_convertible_to<Scalar, T, Ts...>::value,
125  "Not all components are convertible to Scalar.");
126  }
127 
129  constexpr VectorT() {}
130 
134  explicit VectorT(const Scalar &v) {
135  vectorize(v);
136  }
137 
138  VectorT(const VectorT &rhs) = default;
139  VectorT(VectorT &&rhs) = default;
140  VectorT &operator=(const VectorT &rhs) = default;
141  VectorT &operator=(VectorT &&rhs) = default;
142 
147  template<typename S = Scalar, int D = DIM>
148  auto homogenized() const ->
149  typename std::enable_if<D == 4,
150  VectorT<decltype(std::declval<S>()/std::declval<S>()), DIM>>::type {
151  static_assert(D == DIM, "D and DIM need to be identical. (Never "
152  "override the default template arguments.)");
153  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
154  "to be the same type. (Never override the default template "
155  "arguments.)");
156  return VectorT(
157  values_[0]/values_[3],
158  values_[1]/values_[3],
159  values_[2]/values_[3],
160  1);
161  }
162 
164  template<typename Iterator,
165  typename = decltype(
166  *std::declval<Iterator&>(), void(),
167  ++std::declval<Iterator&>(), void())>
168  explicit VectorT(Iterator it) {
169  std::copy_n(it, DIM, values_.begin());
170  }
171 
173  explicit VectorT(container&& _array) {
174  values_ = _array;
175  }
176 
178  template<typename otherScalarType,
179  typename = typename std::enable_if<
180  std::is_convertible<otherScalarType, Scalar>::value>>
181  explicit VectorT(const VectorT<otherScalarType, DIM>& _rhs) {
182  operator=(_rhs);
183  }
184 
185  //--------------------------------------------------------------------- casts
186 
188  template<typename OtherScalar,
189  typename = typename std::enable_if<
190  std::is_convertible<OtherScalar, Scalar>::value>>
191  vector_type& operator=(const VectorT<OtherScalar, DIM>& _rhs) {
192  std::transform(_rhs.cbegin(), _rhs.cend(),
193  this->begin(), [](OtherScalar rhs) {
194  return static_cast<Scalar>(std::move(rhs));
195  });
196  return *this;
197  }
198 
200  Scalar* data() { return values_.data(); }
201 
203  const Scalar* data() const { return values_.data(); }
204 
205  //----------------------------------------------------------- element access
206 
208  Scalar& operator[](size_t _i) {
209  assert(_i < DIM);
210  return values_[_i];
211  }
212 
214  const Scalar& operator[](size_t _i) const {
215  assert(_i < DIM);
216  return values_[_i];
217  }
218 
219  //---------------------------------------------------------------- comparsion
220 
222  bool operator==(const vector_type& _rhs) const {
223  return std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
224  }
225 
227  bool operator!=(const vector_type& _rhs) const {
228  return !std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
229  }
230 
231  //---------------------------------------------------------- scalar operators
232 
234  template<typename OtherScalar>
235  auto operator*=(const OtherScalar& _s) ->
236  typename std::enable_if<std::is_convertible<
237  decltype(this->values_[0] * _s), Scalar>::value,
238  VectorT<Scalar, DIM>&>::type {
239  for (auto& e : *this) {
240  e *= _s;
241  }
242  return *this;
243  }
244 
246  template<typename OtherScalar>
247  auto operator/=(const OtherScalar& _s) ->
248  typename std::enable_if<std::is_convertible<
249  decltype(this->values_[0] / _s), Scalar>::value,
250  VectorT<Scalar, DIM>&>::type {
251  for (auto& e : *this) {
252  e /= _s;
253  }
254  return *this;
255  }
256 
258  template<typename OtherScalar>
259  typename std::enable_if<std::is_convertible<
260  decltype(std::declval<Scalar>() * std::declval<OtherScalar>()),
261  Scalar>::value,
262  VectorT<Scalar, DIM>>::type
263  operator*(const OtherScalar& _s) const {
264  return vector_type(*this) *= _s;
265  }
266 
268  template<typename OtherScalar>
269  typename std::enable_if<std::is_convertible<
270  decltype(std::declval<Scalar>() / std::declval<OtherScalar>()),
271  Scalar>::value,
272  VectorT<Scalar, DIM>>::type
273  operator/(const OtherScalar& _s) const {
274  return vector_type(*this) /= _s;
275  }
276 
277  //---------------------------------------------------------- vector operators
278 
280  template<typename OtherScalar>
281  auto operator*=(const VectorT<OtherScalar, DIM>& _rhs) ->
282  typename std::enable_if<
283  sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
284  vector_type&>::type {
285  for (int i = 0; i < DIM; ++i) {
286  data()[i] *= _rhs.data()[i];
287  }
288  return *this;
289  }
290 
292  template<typename OtherScalar>
293  auto operator/=(const VectorT<OtherScalar, DIM>& _rhs) ->
294  typename std::enable_if<
295  sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
296  vector_type&>::type {
297  for (int i = 0; i < DIM; ++i) {
298  data()[i] /= _rhs.data()[i];
299  }
300  return *this;
301  }
302 
304  template<typename OtherScalar>
305  auto operator-=(const VectorT<OtherScalar, DIM>& _rhs) ->
306  typename std::enable_if<
307  sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
308  vector_type&>::type {
309  for (int i = 0; i < DIM; ++i) {
310  data()[i] -= _rhs.data()[i];
311  }
312  return *this;
313  }
314 
316  template<typename OtherScalar>
317  auto operator+=(const VectorT<OtherScalar, DIM>& _rhs) ->
318  typename std::enable_if<
319  sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
320  vector_type&>::type {
321  for (int i = 0; i < DIM; ++i) {
322  data()[i] += _rhs.data()[i];
323  }
324  return *this;
325  }
326 
328  template<typename OtherScalar>
329  auto operator*(const VectorT<OtherScalar, DIM>& _rhs) const ->
330  typename std::enable_if<
331  sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
332  vector_type>::type {
333  return vector_type(*this) *= _rhs;
334  }
335 
337  template<typename OtherScalar>
338  auto operator/(const VectorT<OtherScalar, DIM>& _rhs) const ->
339  typename std::enable_if<
340  sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
341  vector_type>::type {
342  return vector_type(*this) /= _rhs;
343  }
344 
346  template<typename OtherScalar>
347  auto operator+(const VectorT<OtherScalar, DIM>& _rhs) const ->
348  typename std::enable_if<
349  sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
350  vector_type>::type {
351  return vector_type(*this) += _rhs;
352  }
353 
355  template<typename OtherScalar>
356  auto operator-(const VectorT<OtherScalar, DIM>& _rhs) const ->
357  typename std::enable_if<
358  sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
359  vector_type>::type {
360  return vector_type(*this) -= _rhs;
361  }
362 
364  vector_type operator-(void) const {
365  vector_type v;
366  std::transform(values_.begin(), values_.end(), v.values_.begin(),
367  [](const Scalar &s) { return -s; });
368  return v;
369  }
370 
373  template<typename OtherScalar>
374  auto operator% (const VectorT<OtherScalar, DIM> &_rhs) const ->
375  typename std::enable_if<DIM == 3,
376  VectorT<decltype((*this)[0] * _rhs[0] -
377  (*this)[0] * _rhs[0]), DIM>>::type {
378  return {
379  values_[1] * _rhs[2] - values_[2] * _rhs[1],
380  values_[2] * _rhs[0] - values_[0] * _rhs[2],
381  values_[0] * _rhs[1] - values_[1] * _rhs[0]
382  };
383  }
384 
387  template<typename OtherScalar>
388  auto operator|(const VectorT<OtherScalar, DIM>& _rhs) const ->
389  decltype(*this->data() * *_rhs.data()) {
390 
391  return std::inner_product(begin() + 1, begin() + DIM, _rhs.begin() + 1,
392  *begin() * *_rhs.begin());
393  }
394 
395  //------------------------------------------------------------ euclidean norm
396 
398 
399 
401  template<typename S = Scalar>
402  decltype(std::declval<S>() * std::declval<S>()) sqrnorm() const {
403  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
404  "to be the same type. (Never override the default template "
405  "arguments.)");
406  typedef decltype(values_[0] * values_[0]) RESULT;
407  return std::accumulate(values_.cbegin() + 1, values_.cend(),
408  values_[0] * values_[0],
409  [](const RESULT &l, const Scalar &r) { return l + r * r; });
410  }
411 
413  template<typename S = Scalar>
414  auto norm() const ->
415  decltype(std::sqrt(std::declval<VectorT<S, DIM>>().sqrnorm())) {
416  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
417  "to be the same type. (Never override the default template "
418  "arguments.)");
419  return std::sqrt(sqrnorm());
420  }
421 
422  template<typename S = Scalar>
423  auto length() const ->
424  decltype(std::declval<VectorT<S, DIM>>().norm()) {
425  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
426  "to be the same type. (Never override the default template "
427  "arguments.)");
428  return norm();
429  }
430 
433  template<typename S = Scalar>
434  auto normalize() ->
435  decltype(*this /= std::declval<VectorT<S, DIM>>().norm()) {
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 *this /= norm();
440  }
441 
444  template<typename S = Scalar>
445  auto normalized() const ->
446  decltype(*this / std::declval<VectorT<S, DIM>>().norm()) {
447  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
448  "to be the same type. (Never override the default template "
449  "arguments.)");
450  return *this / norm();
451  }
452 
455  template<typename S = Scalar>
456  typename std::enable_if<
457  sizeof(decltype(
458  static_cast<S>(0),
459  std::declval<VectorT<S, DIM>>().norm())) >= 0,
460  vector_type&>::type
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  auto n = norm();
466  if (n != static_cast<decltype(norm())>(0)) {
467  *this /= n;
468  }
469  return *this;
470  }
471 
473 
474  //------------------------------------------------------------ euclidean norm
475 
477 
478 
480  Scalar l1_norm() const {
481  return std::accumulate(
482  values_.cbegin() + 1, values_.cend(), values_[0]);
483  }
484 
486  Scalar l8_norm() const {
487  return max_abs();
488  }
489 
491 
492  //------------------------------------------------------------ max, min, mean
493 
495 
496 
498  Scalar max() const {
499  return *std::max_element(values_.cbegin(), values_.cend());
500  }
501 
503  Scalar max_abs() const {
504  return std::abs(
505  *std::max_element(values_.cbegin(), values_.cend(),
506  [](const Scalar &a, const Scalar &b) {
507  return std::abs(a) < std::abs(b);
508  }));
509  }
510 
512  Scalar min() const {
513  return *std::min_element(values_.cbegin(), values_.cend());
514  }
515 
517  Scalar min_abs() const {
518  return std::abs(
519  *std::min_element(values_.cbegin(), values_.cend(),
520  [](const Scalar &a, const Scalar &b) {
521  return std::abs(a) < std::abs(b);
522  }));
523  }
524 
526  Scalar mean() const {
527  return l1_norm()/DIM;
528  }
529 
531  Scalar mean_abs() const {
532  return std::accumulate(values_.cbegin() + 1, values_.cend(),
533  std::abs(values_[0]),
534  [](const Scalar &l, const Scalar &r) {
535  return l + std::abs(r);
536  }) / DIM;
537  }
538 
540  vector_type& minimize(const vector_type& _rhs) {
541  std::transform(values_.cbegin(), values_.cend(),
542  _rhs.values_.cbegin(),
543  values_.begin(),
544  [](const Scalar &l, const Scalar &r) {
545  return std::min(l, r);
546  });
547  return *this;
548  }
549 
551  bool minimized(const vector_type& _rhs) {
552  bool result = false;
553  std::transform(values_.cbegin(), values_.cend(),
554  _rhs.values_.cbegin(),
555  values_.begin(),
556  [&result](const Scalar &l, const Scalar &r) {
557  if (l < r) {
558  return l;
559  } else {
560  result = true;
561  return r;
562  }
563  });
564  return result;
565  }
566 
568  vector_type& maximize(const vector_type& _rhs) {
569  std::transform(values_.cbegin(), values_.cend(),
570  _rhs.values_.cbegin(),
571  values_.begin(),
572  [](const Scalar &l, const Scalar &r) {
573  return std::max(l, r);
574  });
575  return *this;
576  }
577 
579  bool maximized(const vector_type& _rhs) {
580  bool result = false;
581  std::transform(values_.cbegin(), values_.cend(),
582  _rhs.values_.cbegin(),
583  values_.begin(),
584  [&result](const Scalar &l, const Scalar &r) {
585  if (l > r) {
586  return l;
587  } else {
588  result = true;
589  return r;
590  }
591  });
592  return result;
593  }
594 
596  inline vector_type min(const vector_type& _rhs) const {
597  return vector_type(*this).minimize(_rhs);
598  }
599 
601  inline vector_type max(const vector_type& _rhs) const {
602  return vector_type(*this).maximize(_rhs);
603  }
604 
606 
607  //------------------------------------------------------------ misc functions
608 
610  template<typename Functor>
611  inline vector_type apply(const Functor& _func) const {
612  vector_type result;
613  std::transform(result.values_.cbegin(), result.values_.cend(),
614  result.values_.begin(), _func);
615  return result;
616  }
617 
619  vector_type& vectorize(const Scalar& _s) {
620  std::fill(values_.begin(), values_.end(), _s);
621  return *this;
622  }
623 
625  static vector_type vectorized(const Scalar& _s) {
626  return vector_type().vectorize(_s);
627  }
628 
630  bool operator<(const vector_type& _rhs) const {
631  return std::lexicographical_compare(
632  values_.begin(), values_.end(),
633  _rhs.values_.begin(), _rhs.values_.end());
634  }
635 
637  void swap(VectorT& _other)
638  noexcept(noexcept(std::swap(values_, _other.values_))) {
639  std::swap(values_, _other.values_);
640  }
641 
642  //------------------------------------------------------------ component iterators
643 
645 
646 
647  using iterator = typename container::iterator;
648  using const_iterator = typename container::const_iterator;
649  using reverse_iterator = typename container::reverse_iterator;
650  using const_reverse_iterator = typename container::const_reverse_iterator;
651 
652  iterator begin() noexcept { return values_.begin(); }
653  const_iterator begin() const noexcept { return values_.cbegin(); }
654  const_iterator cbegin() const noexcept { return values_.cbegin(); }
655 
656  iterator end() noexcept { return values_.end(); }
657  const_iterator end() const noexcept { return values_.cend(); }
658  const_iterator cend() const noexcept { return values_.cend(); }
659 
660  reverse_iterator rbegin() noexcept { return values_.rbegin(); }
661  const_reverse_iterator rbegin() const noexcept { return values_.crbegin(); }
662  const_reverse_iterator crbegin() const noexcept { return values_.crbegin(); }
663 
664  reverse_iterator rend() noexcept { return values_.rend(); }
665  const_reverse_iterator rend() const noexcept { return values_.crend(); }
666  const_reverse_iterator crend() const noexcept { return values_.crend(); }
667 
669 };
670 
672 template<typename Scalar, int DIM, typename OtherScalar>
673 auto operator*(const OtherScalar& _s, const VectorT<Scalar, DIM> &rhs) ->
674  decltype(rhs.operator*(_s)) {
675 
676  return rhs * _s;
677 }
678 
680 template<typename Scalar, int DIM>
681 auto operator<<(std::ostream& os, const VectorT<Scalar, DIM> &_vec) ->
682  typename std::enable_if<
683  sizeof(decltype(os << _vec[0])) >= 0, std::ostream&>::type {
684 
685  os << _vec[0];
686  for (int i = 1; i < DIM; ++i) {
687  os << " " << _vec[i];
688  }
689  return os;
690 }
691 
693 template<typename Scalar, int DIM>
694 auto operator>> (std::istream& is, VectorT<Scalar, DIM> &_vec) ->
695  typename std::enable_if<
696  sizeof(decltype(is >> _vec[0])) >= 0, std::istream &>::type {
697  for (int i = 0; i < DIM; ++i)
698  is >> _vec[i];
699  return is;
700 }
701 
704 template<typename Scalar, int DIM>
705 Scalar dot(const VectorT<Scalar, DIM>& _v1, const VectorT<Scalar, DIM>& _v2) {
706  return (_v1 | _v2);
707 }
708 
711 template<typename LScalar, typename RScalar, int DIM>
712 auto
714  decltype(_v1 % _v2) {
715  return (_v1 % _v2);
716 }
717 
720 template<typename Scalar, int DIM>
722 noexcept(noexcept(_v1.swap(_v2))) {
723  _v1.swap(_v2);
724 }
725 
728 template<typename Scalar, int DIM>
729 Scalar norm(const VectorT<Scalar, DIM>& _v) {
730  return _v.norm();
731 }
732 
735 template<typename Scalar, int DIM>
736 Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
737  return _v.sqrnorm();
738 }
741 template<typename Scalar, int DIM, typename OtherScalar>
742 VectorT<Scalar, DIM>& vectorize(VectorT<Scalar, DIM>& _v, OtherScalar const& _val) {
743  return _v.vectorize(_val);
744 }
745 
748 template<typename Scalar, int DIM>
750  return _v.normalize();
751 }
752 
755 template<typename Scalar, int DIM>
757  return _v1.maximize(_v2);
758 }
759 
762 template<typename Scalar, int DIM>
764  return _v1.minimize(_v2);
765 }
766 
769 template<typename Scalar, int DIM>
771  return _v1.max(_v2);
772 }
773 
776 template<typename Scalar, int DIM>
778  return _v1.min(_v2);
779 }
780 
781 
782 //== TYPEDEFS =================================================================
783 
800 
817 
836 
853 
870 
887 
888 } // namespace OpenMesh
889 
898 constexpr OpenMesh::Vec4f operator"" _htmlColor(unsigned long long raw_color) {
899  return OpenMesh::Vec4f(
900  ((raw_color >> 24) & 0xFF) / 255.0f,
901  ((raw_color >> 16) & 0xFF) / 255.0f,
902  ((raw_color >> 8) & 0xFF) / 255.0f,
903  ((raw_color >> 0) & 0xFF) / 255.0f);
904 }
905 
906 #endif /* OPENMESH_SRC_OPENMESH_CORE_GEOMETRY_VECTOR11T_HH_ */
vector_type apply(const Functor &_func) const
component-wise apply function object with Scalar operator()(Scalar).
Definition: Vector11T.hh:611
VectorT(container &&_array)
construct from an array
Definition: Vector11T.hh:173
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
Definition: Vector11T.hh:619
constexpr VectorT()
default constructor creates uninitialized values.
Definition: Vector11T.hh:129
VectorT< Scalar, DIM > max(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:770
VectorT< Scalar, DIM > & vectorize(VectorT< Scalar, DIM > &_v, OtherScalar const &_val)
Definition: Vector11T.hh:742
VectorT< Scalar, DIM > min(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:777
STL namespace.
Scalar norm(const VectorT< Scalar, DIM > &_v)
Definition: Vector11T.hh:729
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:445
Scalar max_abs() const
return the maximal absolute component
Definition: Vector11T.hh:503
Scalar mean() const
return arithmetic mean
Definition: Vector11T.hh:526
Scalar min() const
return the minimal component
Definition: Vector11T.hh:512
Scalar sqrnorm(const VectorT< Scalar, DIM > &_v)
Definition: Vector11T.hh:736
Scalar mean_abs() const
return absolute arithmetic mean
Definition: Vector11T.hh:531
vector_type operator-(void) const
unary minus
Definition: Vector11T.hh:364
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Definition: Vector11T.hh:551
Scalar l1_norm() const
compute L1 (Manhattan) norm
Definition: Vector11T.hh:480
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:568
Scalar min_abs() const
return the minimal absolute component
Definition: Vector11T.hh:517
Scalar value_type
the type of the scalar used in this template
Definition: Vector11T.hh:96
Scalar dot(const VectorT< Scalar, DIM > &_v1, const VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:705
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:263
static vector_type vectorized(const Scalar &_s)
store the same value in each component
Definition: Vector11T.hh:625
auto operator/=(const OtherScalar &_s) -> typename std::enable_if< std::is_convertible< decltype(this->values_[0]/_s), Scalar >::value, VectorT< Scalar, DIM > &>::type
component-wise self-division by scalar
Definition: Vector11T.hh:247
Scalar * data()
access to Scalar array
Definition: Vector11T.hh:200
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
const Scalar * data() const
access to const Scalar array
Definition: Vector11T.hh:203
VectorT(const Scalar &v)
Definition: Vector11T.hh:134
vector_type max(const vector_type &_rhs) const
component-wise max
Definition: Vector11T.hh:601
vector_type &::type normalize_cond()
compute squared euclidean norm
Definition: Vector11T.hh:461
Scalar max() const
return the maximal component
Definition: Vector11T.hh:498
static constexpr size_t size()
returns dimension of the vector
Definition: Vector11T.hh:107
Scalar & operator[](size_t _i)
get i&#39;th element read-write
Definition: Vector11T.hh:208
bool operator==(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:222
VectorT< Scalar, DIM > & normalize(VectorT< Scalar, DIM > &_v)
Definition: Vector11T.hh:749
const Scalar & operator[](size_t _i) const
get i&#39;th element read-only
Definition: Vector11T.hh:214
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:540
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
Definition: Vector11T.hh:579
vector_type & operator=(const VectorT< OtherScalar, DIM > &_rhs)
cast from vector with a different scalar type
Definition: Vector11T.hh:191
Scalar l8_norm() const
compute l8_norm
Definition: Vector11T.hh:486
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
Definition: Vector11T.hh:414
VectorT< Scalar, DIM > & maximize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:756
VectorT(const VectorT< otherScalarType, DIM > &_rhs)
copy & cast constructor (explicit)
Definition: Vector11T.hh:181
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
Definition: Vector11T.hh:423
VectorT< float, 4 > Vec4f
Definition: Vector11T.hh:850
auto operator|(const VectorT< OtherScalar, DIM > &_rhs) const -> decltype(*this->data() **_rhs.data())
Definition: Vector11T.hh:388
VectorT< Scalar, DIM > & minimize(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2)
Definition: Vector11T.hh:763
auto operator*(const OtherScalar &_s, const VectorT< Scalar, DIM > &rhs) -> decltype(rhs.operator*(_s))
Component wise multiplication from the left.
Definition: Vector11T.hh:673
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
Definition: Vector11T.hh:402
bool operator<(const vector_type &_rhs) const
lexicographical comparison
Definition: Vector11T.hh:630
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:273
void swap(VectorT &_other) noexcept(noexcept(std::swap(values_, _other.values_)))
swap with another vector
Definition: Vector11T.hh:637
bool operator!=(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:227
VectorT(Iterator it)
construct from a value array or any other iterator
Definition: Vector11T.hh:168
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:434
void swap(VectorT< Scalar, DIM > &_v1, VectorT< Scalar, DIM > &_v2) noexcept(noexcept(_v1.swap(_v2)))
Definition: Vector11T.hh:721
auto homogenized() const -> typename std::enable_if< D==4, VectorT< decltype(std::declval< S >()/std::declval< S >()), DIM >>::type
Definition: Vector11T.hh:148
auto cross(const VectorT< LScalar, DIM > &_v1, const VectorT< RScalar, DIM > &_v2) -> decltype(_v1 % _v2)
Definition: Vector11T.hh:713
vector_type min(const vector_type &_rhs) const
component-wise min
Definition: Vector11T.hh:596
auto operator*=(const OtherScalar &_s) -> typename std::enable_if< std::is_convertible< decltype(this->values_[0] *_s), Scalar >::value, VectorT< Scalar, DIM > &>::type
component-wise self-multiplication with scalar
Definition: Vector11T.hh:235