42#ifndef OPENMESH_SRC_OPENMESH_CORE_GEOMETRY_VECTOR11T_HH_
43#define OPENMESH_SRC_OPENMESH_CORE_GEOMETRY_VECTOR11T_HH_
58#include <OpenMesh/Core/System/config.h>
66template<
typename ... Ts>
67struct are_convertible_to;
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;
75template<
typename To,
typename From>
76struct are_convertible_to<To, From> :
public std::is_convertible<From, To> {
82template<
typename Scalar,
int DIM>
85 static_assert(DIM >= 1,
"VectorT requires positive dimensionality.");
88 using container = std::array<Scalar, DIM>;
102 static constexpr int dim() {
107 static constexpr size_t size() {
111 static constexpr const size_t size_ = DIM;
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.");
147 template<
typename S = Scalar,
int D = DIM>
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 "
157 values_[0]/values_[3],
158 values_[1]/values_[3],
159 values_[2]/values_[3],
164 template<
typename Iterator,
166 *std::declval<Iterator&>(), void(),
167 ++std::declval<Iterator&>(), void())>
169 std::copy_n(it, DIM, values_.begin());
179 template<
typename otherScalarType,
180 typename =
typename std::enable_if<
181 std::is_convertible<otherScalarType, Scalar>::value>>
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));
201 Scalar*
data() {
return values_.data(); }
204 const Scalar*
data()
const {
return values_.data(); }
224 return std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
229 return !std::equal(_rhs.values_.cbegin(), _rhs.values_.cend(), values_.cbegin());
235 template<
typename OtherScalar>
237 typename std::enable_if<std::is_convertible<
238 decltype(this->values_[0] * _s), Scalar>::value,
240 for (
auto& e : *
this) {
247 template<
typename OtherScalar>
249 typename std::enable_if<std::is_convertible<
250 decltype(this->values_[0] / _s), Scalar>::value,
252 for (
auto& e : *
this) {
259 template<
typename OtherScalar>
260 typename std::enable_if<std::is_convertible<
261 decltype(std::declval<Scalar>() * std::declval<OtherScalar>()),
264 operator*(
const OtherScalar& _s)
const {
269 template<
typename OtherScalar>
270 typename std::enable_if<std::is_convertible<
271 decltype(std::declval<Scalar>() / std::declval<OtherScalar>()),
274 operator/(
const OtherScalar& _s)
const {
281 template<
typename OtherScalar>
283 typename std::enable_if<
284 sizeof(
decltype(this->values_[0] * *_rhs.data())) >= 0,
286 for (
int i = 0; i < DIM; ++i) {
287 data()[i] *= _rhs.data()[i];
293 template<
typename OtherScalar>
295 typename std::enable_if<
296 sizeof(
decltype(this->values_[0] / *_rhs.data())) >= 0,
298 for (
int i = 0; i < DIM; ++i) {
299 data()[i] /= _rhs.data()[i];
305 template<
typename OtherScalar>
307 typename std::enable_if<
308 sizeof(
decltype(this->values_[0] - *_rhs.data())) >= 0,
310 for (
int i = 0; i < DIM; ++i) {
311 data()[i] -= _rhs.data()[i];
317 template<
typename OtherScalar>
319 typename std::enable_if<
320 sizeof(
decltype(this->values_[0] + *_rhs.data())) >= 0,
322 for (
int i = 0; i < DIM; ++i) {
323 data()[i] += _rhs.data()[i];
329 template<
typename OtherScalar>
331 typename std::enable_if<
332 sizeof(
decltype(this->values_[0] * *_rhs.data())) >= 0,
338 template<
typename OtherScalar>
340 typename std::enable_if<
341 sizeof(
decltype(this->values_[0] / *_rhs.data())) >= 0,
347 template<
typename OtherScalar>
349 typename std::enable_if<
350 sizeof(
decltype(this->values_[0] + *_rhs.data())) >= 0,
356 template<
typename OtherScalar>
358 typename std::enable_if<
359 sizeof(
decltype(this->values_[0] - *_rhs.data())) >= 0,
367 std::transform(values_.begin(), values_.end(), v.values_.begin(),
368 [](
const Scalar &s) { return -s; });
374 template<
typename OtherScalar>
376 typename std::enable_if<DIM == 3,
377 VectorT<
decltype((*this)[0] * _rhs[0] -
378 (*this)[0] * _rhs[0]), DIM>>::type {
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]
388 template<
typename OtherScalar>
390 decltype(*
this % _rhs)
398 template<
typename OtherScalar>
400 decltype(*this->
data() * *_rhs.data()) {
402 return std::inner_product(begin() + 1, begin() + DIM, _rhs.begin() + 1,
403 *begin() * *_rhs.begin());
408 template<
typename OtherScalar>
410 decltype(*
this | _rhs)
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 "
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; });
433 template<
typename S = Scalar>
436 static_assert(std::is_same<S, Scalar>::value,
"S and Scalar need "
437 "to be the same type. (Never override the default template "
442 template<
typename S = Scalar>
445 static_assert(std::is_same<S, Scalar>::value,
"S and Scalar need "
446 "to be the same type. (Never override the default template "
453 template<
typename S = Scalar>
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 "
459 return *
this /=
norm();
464 template<
typename S = Scalar>
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 "
470 return *
this /
norm();
475 template<
typename S = Scalar>
476 typename std::enable_if<
482 static_assert(std::is_same<S, Scalar>::value,
"S and Scalar need "
483 "to be the same type. (Never override the default template "
486 if (n !=
static_cast<decltype(
norm())
>(0)) {
501 return std::accumulate(
502 values_.cbegin() + 1, values_.cend(), values_[0]);
519 return *std::max_element(values_.cbegin(), values_.cend());
525 *std::max_element(values_.cbegin(), values_.cend(),
526 [](
const Scalar &a,
const Scalar &b) {
527 return std::abs(a) < std::abs(b);
533 return *std::min_element(values_.cbegin(), values_.cend());
539 *std::min_element(values_.cbegin(), values_.cend(),
540 [](
const Scalar &a,
const Scalar &b) {
541 return std::abs(a) < std::abs(b);
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);
561 std::transform(values_.cbegin(), values_.cend(),
562 _rhs.values_.cbegin(),
564 [](
const Scalar &l,
const Scalar &r) {
565 return std::min(l, r);
573 std::transform(values_.cbegin(), values_.cend(),
574 _rhs.values_.cbegin(),
576 [&result](
const Scalar &l,
const Scalar &r) {
589 std::transform(values_.cbegin(), values_.cend(),
590 _rhs.values_.cbegin(),
592 [](
const Scalar &l,
const Scalar &r) {
593 return std::max(l, r);
601 std::transform(values_.cbegin(), values_.cend(),
602 _rhs.values_.cbegin(),
604 [&result](
const Scalar &l,
const Scalar &r) {
630 template<
typename Functor>
633 std::transform(result.values_.cbegin(), result.values_.cend(),
634 result.values_.begin(), _func);
640 std::fill(values_.begin(), values_.end(), _s);
651 return std::lexicographical_compare(
652 values_.begin(), values_.end(),
653 _rhs.values_.begin(), _rhs.values_.end());
658 noexcept(
noexcept(std::swap(values_, _other.values_))) {
659 std::swap(values_, _other.values_);
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;
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(); }
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(); }
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(); }
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(); }
692template<
typename Scalar,
int DIM,
typename OtherScalar>
694 decltype(rhs.operator*(_s)) {
700template<
typename Scalar,
int DIM>
702 typename std::enable_if<
703 sizeof(
decltype(os << _vec[0])) >= 0, std::ostream&>::type {
706 for (
int i = 1; i < DIM; ++i) {
707 os <<
" " << _vec[i];
713template<
typename Scalar,
int DIM>
715 typename std::enable_if<
716 sizeof(
decltype(is >> _vec[0])) >= 0, std::istream &>::type {
717 for (
int i = 0; i < DIM; ++i)
724template<
typename Scalar,
int DIM>
731template<
typename LScalar,
typename RScalar,
int DIM>
734 decltype(_v1 % _v2) {
740template<
typename Scalar,
int DIM>
742noexcept(
noexcept(_v1.swap(_v2))) {
748template<
typename Scalar,
int DIM>
755template<
typename Scalar,
int DIM>
761template<
typename Scalar,
int DIM,
typename OtherScalar>
768template<
typename Scalar,
int DIM>
775template<
typename Scalar,
int DIM>
782template<
typename Scalar,
int DIM>
789template<
typename Scalar,
int DIM>
796template<
typename Scalar,
int DIM>
918constexpr OpenMesh::Vec4f operator"" _htmlColor(
unsigned long long raw_color) {
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);
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