Developer Documentation
Vector11T.hh
1 /* ========================================================================= *
2  * *
3  * OPENVOLUMEMESHMesh *
4  * Copyright (c) 2001-2016, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.OPENVOLUMEMESHmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OPENVOLUMEMESHMesh. *
11  * This file was originally taken from OpenMesh *
12  *---------------------------------------------------------------------------*
13  * *
14  * Redistribution and use in source and binary forms, with or without *
15  * modification, are permitted provided that the following conditions *
16  * are met: *
17  * *
18  * 1. Redistributions of source code must retain the above copyright notice, *
19  * this list of conditions and the following disclaimer. *
20  * *
21  * 2. Redistributions in binary form must reproduce the above copyright *
22  * notice, this list of conditions and the following disclaimer in the *
23  * documentation and/or other materials provided with the distribution. *
24  * *
25  * 3. Neither the name of the copyright holder nor the names of its *
26  * contributors may be used to endorse or promote products derived from *
27  * this software without specific prior written permission. *
28  * *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40  * *
41  * ========================================================================= */
42 
43 #ifndef OPENVOLUMEMESH_SRC_OPENVOLUMEMESH_GEOMETRY_VECTOR11T_HH_
44 #define OPENVOLUMEMESH_SRC_OPENVOLUMEMESH_GEOMETRY_VECTOR11T_HH_
45 
46 #include <array>
47 #include <utility>
48 #include <algorithm>
49 #include <numeric>
50 #include <type_traits>
51 #include <cmath>
52 #include <ostream>
53 #include <istream>
54 #include <cassert>
55 #include <cstdlib>
56 
57 namespace OpenVolumeMesh {
58 
59 namespace Geometry {
60 
61 /*
62  * Helpers for VectorT
63  */
64 template<typename ... Ts>
66 
67 template<typename To, typename From, typename ... Froms>
68 struct are_convertible_to<To, From, Froms...> {
69  static constexpr bool value = std::is_convertible<From, To>::value
70  && are_convertible_to<To, Froms...>::value;
71 };
72 
73 template<typename To, typename From>
74 struct are_convertible_to<To, From> : public std::is_convertible<From, To> {
75 };
76 
77 template<typename Scalar, int DIM>
78 class VectorT {
79 
80  static_assert(DIM >= 1, "VectorT requires positive dimensionality.");
81 
82  private:
83  using container = std::array<Scalar, DIM>;
84  container values_;
85 
86  public:
87 
88  //---------------------------------------------------------------- class info
89 
91  typedef Scalar value_type;
92 
95 
97  static constexpr int dim() {
98  return DIM;
99  }
100 
102  static constexpr size_t size() {
103  return DIM;
104  }
105 
106  static constexpr const size_t size_ = DIM;
107 
108  //-------------------------------------------------------------- constructors
109 
111  constexpr VectorT() {}
112 
116  explicit VectorT(const Scalar &v) {
117  vectorize(v);
118  }
119 
120  template<typename ... T,
121  typename = typename std::enable_if<sizeof...(T) == DIM>::type,
122  typename = typename std::enable_if<
124  // cppcheck-suppress noExplicitConstructor ; only applies to unimportant DIM==1
125  constexpr VectorT(T... vs) : values_ { {static_cast<Scalar>(vs)...} }
126  {
127  static_assert(sizeof...(T) == DIM,
128  "Invalid number of components specified in constructor.");
130  "Not all components are convertible to Scalar.");
131  }
132 
133  VectorT(const VectorT &rhs) = default;
134  VectorT(VectorT &&rhs) = default;
135  VectorT &operator=(const VectorT &rhs) = default;
136  VectorT &operator=(VectorT &&rhs) = default;
137 
142  template<typename S = Scalar, int D = DIM>
143  auto homogenized() const ->
144  typename std::enable_if<D == 4,
145  VectorT<decltype(std::declval<S>()/std::declval<S>()), DIM>>::type {
146  static_assert(D == DIM, "D and DIM need to be identical. (Never "
147  "override the default template arguments.)");
148  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
149  "to be the same type. (Never override the default template "
150  "arguments.)");
151  return VectorT(
152  values_[0]/values_[3],
153  values_[1]/values_[3],
154  values_[2]/values_[3],
155  1);
156  }
157 
159  template<typename Iterator,
160  typename = decltype(
161  *std::declval<Iterator&>(), void(),
162  ++std::declval<Iterator&>(), void())>
163  explicit VectorT(Iterator it) {
164  std::copy_n(it, DIM, values_.begin());
165  }
166 
168  template<typename otherScalarType,
169  typename = typename std::enable_if<
170  std::is_convertible<otherScalarType, Scalar>::value>>
171  explicit VectorT(const VectorT<otherScalarType, DIM>& _rhs) {
172  operator=(_rhs);
173  }
174 
175  //--------------------------------------------------------------------- casts
176 
178  template<typename OtherScalar,
179  typename = typename std::enable_if<
180  std::is_convertible<OtherScalar, Scalar>::value>>
181  // cppcheck-suppress operatorEqRetRefThis ; false positive
182  vector_type& operator=(const VectorT<OtherScalar, DIM>& _rhs)
183  {
184  std::transform(_rhs.data(), _rhs.data() + DIM,
185  data(), [](OtherScalar rhs) {
186  return static_cast<Scalar>(std::move(rhs));
187  });
188  return *this;
189  }
190 
192  Scalar* data() { return values_.data(); }
193 
195  const Scalar *data() const { return values_.data(); }
196 
197  //----------------------------------------------------------- element access
198 
200  Scalar& operator[](size_t _i) {
201  assert(_i < DIM);
202  return values_[_i];
203  }
204 
206  const Scalar& operator[](size_t _i) const {
207  assert(_i < DIM);
208  return values_[_i];
209  }
210 
211  //---------------------------------------------------------------- comparsion
212 
214  bool operator==(const vector_type& _rhs) const {
215  return std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
216  }
217 
219  bool operator!=(const vector_type& _rhs) const {
220  return !std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
221  }
222 
223  //---------------------------------------------------------- scalar operators
224 
226  template<typename OtherScalar>
227  auto operator*=(const OtherScalar& _s) ->
228  typename std::enable_if<std::is_convertible<
229  decltype(this->values_[0] * _s), Scalar>::value,
230  VectorT<Scalar, DIM>&>::type {
231  for (auto& e : *this) {
232  e *= _s;
233  }
234  return *this;
235  }
236 
238  template<typename OtherScalar>
239  auto operator/=(const OtherScalar& _s) ->
240  typename std::enable_if<std::is_convertible<
241  decltype(this->values_[0] / _s), Scalar>::value,
242  VectorT<Scalar, DIM>&>::type {
243  for (auto& e : *this) {
244  e /= _s;
245  }
246  return *this;
247  }
248 
250  template<typename OtherScalar>
251  typename std::enable_if<std::is_convertible<
252  decltype(std::declval<Scalar>() * std::declval<OtherScalar>()),
253  Scalar>::value,
254  VectorT<Scalar, DIM>>::type
255  operator*(const OtherScalar& _s) const {
256  return vector_type(*this) *= _s;
257  }
258 
260  template<typename OtherScalar>
261  typename std::enable_if<std::is_convertible<
262  decltype(std::declval<Scalar>() / std::declval<OtherScalar>()),
263  Scalar>::value,
264  VectorT<Scalar, DIM>>::type
265  operator/(const OtherScalar& _s) const {
266  return vector_type(*this) /= _s;
267  }
268 
269  //---------------------------------------------------------- vector operators
270 
272  template<typename OtherScalar>
273  auto operator*=(const VectorT<OtherScalar, DIM>& _rhs) ->
274  typename std::enable_if<
275  sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
276  vector_type&>::type {
277  for (int i = 0; i < DIM; ++i) {
278  data()[i] *= _rhs.data()[i];
279  }
280  return *this;
281  }
282 
284  template<typename OtherScalar>
285  auto operator/=(const VectorT<OtherScalar, DIM>& _rhs) ->
286  typename std::enable_if<
287  sizeof(decltype(this->values_[0] / *_rhs.data())) >= 0,
288  vector_type&>::type {
289  for (int i = 0; i < DIM; ++i) {
290  data()[i] /= _rhs.data()[i];
291  }
292  return *this;
293  }
294 
296  template<typename OtherScalar>
297  auto operator-=(const VectorT<OtherScalar, DIM>& _rhs) ->
298  typename std::enable_if<
299  sizeof(decltype(this->values_[0] - *_rhs.data())) >= 0,
300  vector_type&>::type {
301  for (int i = 0; i < DIM; ++i) {
302  data()[i] -= _rhs.data()[i];
303  }
304  return *this;
305  }
306 
308  template<typename OtherScalar>
309  auto operator+=(const VectorT<OtherScalar, DIM>& _rhs) ->
310  typename std::enable_if<
311  sizeof(decltype(this->values_[0] + *_rhs.data())) >= 0,
312  vector_type&>::type {
313  for (int i = 0; i < DIM; ++i) {
314  data()[i] += _rhs.data()[i];
315  }
316  return *this;
317  }
318 
320  template<typename OtherScalar>
321  auto operator*(const VectorT<OtherScalar, DIM>& _rhs) const ->
322  typename std::enable_if<
323  sizeof(decltype(this->values_[0] * *_rhs.data())) >= 0,
324  vector_type>::type {
325  return vector_type(*this) *= _rhs;
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  vector_type operator-(void) const {
357  vector_type v;
358  std::transform(values_.begin(), values_.end(), v.values_.begin(),
359  [](const Scalar &s) { return -s; });
360  return v;
361  }
362 
365  template<typename OtherScalar>
366  auto operator% (const VectorT<OtherScalar, DIM> &_rhs) const ->
367  typename std::enable_if<DIM == 3,
368  VectorT<decltype(this->values_[0] * _rhs[0] -
369  this->values_[0] * _rhs[0]),
370  DIM>>::type {
371  return {
372  values_[1] * _rhs[2] - values_[2] * _rhs[1],
373  values_[2] * _rhs[0] - values_[0] * _rhs[2],
374  values_[0] * _rhs[1] - values_[1] * _rhs[0]
375  };
376  }
377 
380  template<typename OtherScalar>
381  auto operator|(const VectorT<OtherScalar, DIM>& _rhs) const ->
382  decltype(*this->data() * *_rhs.data()) {
383 
384  return std::inner_product(data() + 1, data() + DIM, _rhs.data() + 1,
385  *data() * *_rhs.data());
386  }
387 
388  //------------------------------------------------------------ euclidean norm
389 
391 
392 
394  template<typename S = Scalar>
395  decltype(std::declval<S>() * std::declval<S>()) sqrnorm() const {
396  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
397  "to be the same type. (Never override the default template "
398  "arguments.)");
399  typedef decltype(values_[0] * values_[0]) RESULT;
400  return std::accumulate(values_.cbegin() + 1, values_.cend(),
401  values_[0] * values_[0],
402  [](const RESULT &l, const Scalar &r) { return l + r * r; });
403  }
404 
406  template<typename S = Scalar>
407  auto norm() const ->
408  decltype(std::sqrt(std::declval<VectorT<S, DIM>>().sqrnorm())) {
409  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
410  "to be the same type. (Never override the default template "
411  "arguments.)");
412  return std::sqrt(sqrnorm());
413  }
414 
415  template<typename S = Scalar>
416  auto length() const ->
417  decltype(std::declval<VectorT<S, DIM>>().norm()) {
418  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
419  "to be the same type. (Never override the default template "
420  "arguments.)");
421  return norm();
422  }
423 
426  template<typename S = Scalar>
427  auto normalize() ->
428  decltype(*this /= std::declval<VectorT<S, DIM>>().norm()) {
429  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
430  "to be the same type. (Never override the default template "
431  "arguments.)");
432  return *this /= norm();
433  }
434 
437  template<typename S = Scalar>
438  auto normalized() const ->
439  decltype(*this / std::declval<VectorT<S, DIM>>().norm()) {
440  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
441  "to be the same type. (Never override the default template "
442  "arguments.)");
443  return *this / norm();
444  }
445 
448  template<typename S = Scalar>
449  typename std::enable_if<
450  sizeof(decltype(
451  static_cast<S>(0),
452  std::declval<VectorT<S, DIM>>().norm())) >= 0,
453  vector_type&>::type
455  static_assert(std::is_same<S, Scalar>::value, "S and Scalar need "
456  "to be the same type. (Never override the default template "
457  "arguments.)");
458  auto n = norm();
459  if (n != static_cast<decltype(norm())>(0)) {
460  *this /= n;
461  }
462  return *this;
463  }
464 
466 
467  //------------------------------------------------------------ euclidean norm
468 
470 
471 
473  Scalar l1_norm() const {
474  return std::accumulate(
475  values_.cbegin() + 1, values_.cend(), values_[0]);
476  }
477 
479  Scalar l8_norm() const {
480  return max_abs();
481  }
482 
484 
485  //------------------------------------------------------------ max, min, mean
486 
488 
489 
491  Scalar max() const {
492  return *std::max_element(values_.cbegin(), values_.cend());
493  }
494 
496  Scalar max_abs() const {
497  return std::abs(
498  *std::max_element(values_.cbegin(), values_.cend(),
499  [](const Scalar &a, const Scalar &b) {
500  return std::abs(a) < std::abs(b);
501  }));
502  }
503 
505  Scalar min() const {
506  return *std::min_element(values_.cbegin(), values_.cend());
507  }
508 
510  Scalar min_abs() const {
511  return std::abs(
512  *std::min_element(values_.cbegin(), values_.cend(),
513  [](const Scalar &a, const Scalar &b) {
514  return std::abs(a) < std::abs(b);
515  }));
516  }
517 
519  Scalar mean() const {
520  return l1_norm()/DIM;
521  }
522 
524  Scalar mean_abs() const {
525  return std::accumulate(values_.cbegin() + 1, values_.cend(),
526  std::abs(values_[0]),
527  [](const Scalar &l, const Scalar &r) {
528  return l + std::abs(r);
529  }) / DIM;
530  }
531 
533  vector_type& minimize(const vector_type& _rhs) {
534  std::transform(values_.cbegin(), values_.cend(),
535  _rhs.values_.cbegin(),
536  values_.begin(),
537  [](const Scalar &l, const Scalar &r) {
538  return std::min(l, r);
539  });
540  return *this;
541  }
542 
544  bool minimized(const vector_type& _rhs) {
545  bool result = false;
546  std::transform(values_.cbegin(), values_.cend(),
547  _rhs.values_.cbegin(),
548  values_.begin(),
549  [&result](const Scalar &l, const Scalar &r) {
550  if (l < r) {
551  return l;
552  } else {
553  result = true;
554  return r;
555  }
556  });
557  return result;
558  }
559 
561  vector_type& maximize(const vector_type& _rhs) {
562  std::transform(values_.cbegin(), values_.cend(),
563  _rhs.values_.cbegin(),
564  values_.begin(),
565  [](const Scalar &l, const Scalar &r) {
566  return std::max(l, r);
567  });
568  return *this;
569  }
570 
572  bool maximized(const vector_type& _rhs) {
573  bool result = false;
574  std::transform(values_.cbegin(), values_.cend(),
575  _rhs.values_.cbegin(),
576  values_.begin(),
577  [&result](const Scalar &l, const Scalar &r) {
578  if (l > r) {
579  return l;
580  } else {
581  result = true;
582  return r;
583  }
584  });
585  return result;
586  }
587 
589  inline vector_type min(const vector_type& _rhs) const {
590  return vector_type(*this).minimize(_rhs);
591  }
592 
594  inline vector_type max(const vector_type& _rhs) const {
595  return vector_type(*this).maximize(_rhs);
596  }
597 
599 
600  //------------------------------------------------------------ misc functions
601 
603  template<typename Functor>
604  inline vector_type apply(const Functor& _func) const {
605  vector_type result;
606  std::transform(result.values_.begin(), result.values_.end(),
607  result.values_.begin(), _func);
608  return result;
609  }
610 
612  vector_type& vectorize(const Scalar& _s) {
613  std::fill(values_.begin(), values_.end(), _s);
614  return *this;
615  }
616 
618  static vector_type vectorized(const Scalar& _s) {
619  return vector_type().vectorize(_s);
620  }
621 
623  bool operator<(const vector_type& _rhs) const {
624  return std::lexicographical_compare(
625  values_.begin(), values_.end(),
626  _rhs.values_.begin(), _rhs.values_.end());
627  }
628 
630  void swap(VectorT& _other)
631  noexcept(noexcept(std::swap(values_, _other.values_))) {
632  std::swap(values_, _other.values_);
633  }
634 
635  //------------------------------------------------------------ component iterators
636 
638 
639 
640  using iterator = typename container::iterator;
641  using const_iterator = typename container::const_iterator;
642  using reverse_iterator = typename container::reverse_iterator;
643  using const_reverse_iterator = typename container::const_reverse_iterator;
644 
645  iterator begin() noexcept { return values_.begin(); }
646  const_iterator begin() const noexcept { return values_.cbegin(); }
647  const_iterator cbegin() const noexcept { return values_.cbegin(); }
648 
649  iterator end() noexcept { return values_.end(); }
650  const_iterator end() const noexcept { return values_.cend(); }
651  const_iterator cend() const noexcept { return values_.cend(); }
652 
653  reverse_iterator rbegin() noexcept { return values_.rbegin(); }
654  const_reverse_iterator rbegin() const noexcept { return values_.crbegin(); }
655  const_reverse_iterator crbegin() const noexcept { return values_.crbegin(); }
656 
657  reverse_iterator rend() noexcept { return values_.rend(); }
658  const_reverse_iterator rend() const noexcept { return values_.crend(); }
659  const_reverse_iterator crend() const noexcept { return values_.crend(); }
660 
662 };
663 
665 template<typename Scalar, int DIM, typename OtherScalar>
666 auto operator*(const OtherScalar& _s, const VectorT<Scalar, DIM> &rhs) ->
667  decltype(rhs.operator*(_s)) {
668 
669  return rhs * _s;
670 }
671 
673 template<typename Scalar, int DIM>
674 auto operator<<(std::ostream& os, const VectorT<Scalar, DIM> &_vec) ->
675  typename std::enable_if<
676  sizeof(decltype(os << _vec[0])) >= 0, std::ostream&>::type {
677 
678  os << _vec[0];
679  for (int i = 1; i < DIM; ++i) {
680  os << " " << _vec[i];
681  }
682  return os;
683 }
684 
686 template<typename Scalar, int DIM>
687 auto operator>> (std::istream& is, VectorT<Scalar, DIM> &_vec) ->
688  typename std::enable_if<
689  sizeof(decltype(is >> _vec[0])) >= 0, std::istream &>::type {
690  for (int i = 0; i < DIM; ++i)
691  is >> _vec[i];
692  return is;
693 }
694 
697 template<typename Scalar, int DIM>
698 Scalar dot(const VectorT<Scalar, DIM>& _v1, const VectorT<Scalar, DIM>& _v2) {
699  return (_v1 | _v2);
700 }
701 
704 template<typename LScalar, typename RScalar, int DIM>
705 auto
706 cross(const VectorT<LScalar, DIM>& _v1, const VectorT<RScalar, DIM>& _v2) ->
707  decltype(_v1 % _v2) {
708  return (_v1 % _v2);
709 }
710 
713 template<typename Scalar, int DIM>
714 void swap(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2)
715 noexcept(noexcept(_v1.swap(_v2))) {
716  _v1.swap(_v2);
717 }
718 
719 //== TYPEDEFS =================================================================
720 
734 typedef VectorT<float,1> Vec1f;
736 typedef VectorT<double,1> Vec1d;
737 
751 typedef VectorT<float,2> Vec2f;
753 typedef VectorT<double,2> Vec2d;
754 
768 typedef VectorT<float,3> Vec3f;
770 typedef VectorT<double,3> Vec3d;
772 typedef VectorT<bool,3> Vec3b;
773 
787 typedef VectorT<float,4> Vec4f;
789 typedef VectorT<double,4> Vec4d;
790 
804 typedef VectorT<float, 5> Vec5f;
806 typedef VectorT<double, 5> Vec5d;
807 
821 typedef VectorT<float,6> Vec6f;
823 typedef VectorT<double,6> Vec6d;
824 
825 
826 } // namespace Geometry
827 
828 using namespace Geometry;
829 
830 template <class T>
831 const std::string typeName();
832 
833 template <> const std::string typeName<Vec2f>();
834 template <> const std::string typeName<Vec2d>();
835 template <> const std::string typeName<Vec2i>();
836 template <> const std::string typeName<Vec2ui>();
837 
838 template <> const std::string typeName<Vec3f>();
839 template <> const std::string typeName<Vec3d>();
840 template <> const std::string typeName<Vec3i>();
841 template <> const std::string typeName<Vec3ui>();
842 
843 template <> const std::string typeName<Vec4f>();
844 template <> const std::string typeName<Vec4d>();
845 template <> const std::string typeName<Vec4i>();
846 template <> const std::string typeName<Vec4ui>();
847 
848 } // namespace OpenVolumeMesh
849 
850 
851 #endif /* OPENVOLUMEMESH_SRC_OPENVOLUMEMESH_GEOMETRY_VECTOR11T_HH_ */
static constexpr int dim()
returns dimension of the vector (deprecated)
Definition: Vector11T.hh:97
static constexpr size_t size()
returns dimension of the vector
Definition: Vector11T.hh:102
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
Definition: Vector11T.hh:416
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
Definition: Vector11T.hh:612
void swap(VectorT &_other) noexcept(noexcept(std::swap(values_, _other.values_)))
swap with another vector
Definition: Vector11T.hh:630
VectorT(Iterator it)
construct from a value array or any other iterator
Definition: Vector11T.hh:163
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:265
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:227
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:561
STL namespace.
Scalar * data()
access to Scalar array
Definition: Vector11T.hh:192
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:255
vector_type operator-(void) const
unary minus
Definition: Vector11T.hh:356
const Scalar & operator[](size_t _i) const
get i&#39;th element read-only
Definition: Vector11T.hh:206
Scalar max() const
return the maximal component
Definition: Vector11T.hh:491
auto homogenized() const -> typename std::enable_if< D==4, VectorT< decltype(std::declval< S >()/std::declval< S >()), DIM >>::type
Definition: Vector11T.hh:143
vector_type apply(const Functor &_func) const
component-wise apply function object with Scalar operator()(Scalar).
Definition: Vector11T.hh:604
Scalar l1_norm() const
compute L1 (Manhattan) norm
Definition: Vector11T.hh:473
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:533
VectorT< Scalar, DIM > vector_type
type of this vector
Definition: Vector11T.hh:94
Scalar mean_abs() const
return absolute arithmetic mean
Definition: Vector11T.hh:524
bool operator!=(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:219
static vector_type vectorized(const Scalar &_s)
store the same value in each component
Definition: Vector11T.hh:618
Scalar min() const
return the minimal component
Definition: Vector11T.hh:505
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:239
Scalar value_type
the type of the scalar used in this template
Definition: Vector11T.hh:91
Scalar & operator[](size_t _i)
get i&#39;th element read-write
Definition: Vector11T.hh:200
auto operator|(const VectorT< OtherScalar, DIM > &_rhs) const -> decltype(*this->data() **_rhs.data())
Definition: Vector11T.hh:381
bool operator<(const vector_type &_rhs) const
lexicographical comparison
Definition: Vector11T.hh:623
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:438
VectorT(const VectorT< otherScalarType, DIM > &_rhs)
copy & cast constructor (explicit)
Definition: Vector11T.hh:171
vector_type & operator=(const VectorT< OtherScalar, DIM > &_rhs)
cast from vector with a different scalar type
Definition: Vector11T.hh:182
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
Definition: Vector11T.hh:407
const Scalar * data() const
access to const Scalar array
Definition: Vector11T.hh:195
vector_type min(const vector_type &_rhs) const
component-wise min
Definition: Vector11T.hh:589
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition: Types.cc:154
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:427
Scalar l8_norm() const
compute l8_norm
Definition: Vector11T.hh:479
bool operator==(const vector_type &_rhs) const
component-wise comparison
Definition: Vector11T.hh:214
constexpr VectorT()
default constructor creates uninitialized values.
Definition: Vector11T.hh:111
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Definition: Vector11T.hh:544
Scalar min_abs() const
return the minimal absolute component
Definition: Vector11T.hh:510
Scalar mean() const
return arithmetic mean
Definition: Vector11T.hh:519
Scalar max_abs() const
return the maximal absolute component
Definition: Vector11T.hh:496
vector_type max(const vector_type &_rhs) const
component-wise max
Definition: Vector11T.hh:594
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
Definition: Vector11T.hh:572
vector_type &::type normalize_cond()
compute squared euclidean norm
Definition: Vector11T.hh:454