52#define OPENMESH_VECTOR_HH
55#define TEMPLATE_HEADER template <typename Scalar, int N>
56#define CLASSNAME VectorT
57#define DERIVED VectorDataT<Scalar,N>
58#define unroll(expr) for (int i=0; i<N; ++i) expr(i)
62#if defined( OPENMESH_VECTOR_HH )
67class CLASSNAME :
public DERIVED
82 static inline int dim() {
return DIM; }
85 static inline size_t size() {
return DIM; }
87 static const size_t size_ = DIM;
96 explicit inline VectorT(
const Scalar& v) {
104 inline VectorT(
const Scalar v0,
const Scalar v1) {
105 Base::values_[0] = v0; Base::values_[1] = v1;
111 inline VectorT(
const Scalar v0,
const Scalar v1,
const Scalar v2) {
112 Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2;
118 inline VectorT(
const Scalar v0,
const Scalar v1,
119 const Scalar v2,
const Scalar v3) {
120 Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2; Base::values_[3]=v3;
123 VectorT homogenized()
const {
return VectorT(Base::values_[0]/Base::values_[3], Base::values_[1]/Base::values_[3], Base::values_[2]/Base::values_[3], 1); }
128 inline VectorT(
const Scalar v0,
const Scalar v1,
const Scalar v2,
129 const Scalar v3,
const Scalar v4) {
130 Base::values_[0]=v0; Base::values_[1]=v1;Base::values_[2]=v2; Base::values_[3]=v3; Base::values_[4]=v4;
136 inline VectorT(
const Scalar v0,
const Scalar v1,
const Scalar v2,
137 const Scalar v3,
const Scalar v4,
const Scalar v5) {
138 Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2;
139 Base::values_[3]=v3; Base::values_[4]=v4; Base::values_[5]=v5;
144 explicit inline VectorT(
const Scalar _values[DIM]) {
145 memcpy(data(), _values, DIM*
sizeof(Scalar));
152 inline vector_type& operator=(
const vector_type& _rhs) {
153 memcpy(Base::values_, _rhs.Base::values_, DIM*
sizeof(Scalar));
160 template<
typename otherScalarType>
171 template<
typename otherScalarType>
173#define expr(i) Base::values_[i] = (Scalar)_rhs[i];
186 inline Scalar*
data() {
return Base::values_; }
189 inline const Scalar*
data()
const {
return Base::values_; }
206 assert(_i<DIM);
return Base::values_[_i];
211 assert(_i<DIM);
return Base::values_[_i];
221#define expr(i) if(Base::values_[i]!=_rhs.Base::values_[i]) return false;
229 return !(*
this == _rhs);
239#define expr(i) Base::values_[i] *= _s;
248#define expr(i) Base::values_[i] /= _s;
260#define expr(i) Base::values_[i] * _s
272#define expr(i) Base::values_[i] / _s
287#define expr(i) Base::values_[i] *= _rhs[i];
295#define expr(i) Base::values_[i] /= _rhs[i];
303#define expr(i) Base::values_[i] -= _rhs[i];
311#define expr(i) Base::values_[i] += _rhs[i];
323#define expr(i) Base::values_[i] * _v.Base::values_[i]
335#define expr(i) Base::values_[i] / _v.Base::values_[i]
347#define expr(i) Base::values_[i] + _v.Base::values_[i]
359#define expr(i) Base::values_[i] - _v.Base::values_[i]
369#define expr(i) v.Base::values_[i] = -Base::values_[i];
382 VectorT<Scalar,3>(Base::values_[1]*_rhs.Base::values_[2]-Base::values_[2]*_rhs.Base::values_[1],
383 Base::values_[2]*_rhs.Base::values_[0]-Base::values_[0]*_rhs.Base::values_[2],
384 Base::values_[0]*_rhs.Base::values_[1]-Base::values_[1]*_rhs.Base::values_[0]);
395#define expr(i) p += Base::values_[i] * _rhs.Base::values_[i];
410 inline Scalar
norm()
const {
return (Scalar)sqrt(sqrnorm()); }
411 inline Scalar
length()
const {
return norm(); }
418#define expr(i) s += Base::values_[i] * Base::values_[i];
423#define expr(i) Base::values_[i]*Base::values_[i]
424 return (unroll_comb(expr, +));
443 return *
this / norm();
451 if (n != (Scalar)0.0)
470#define expr(i) s += std::abs(Base::values_[i]);
475#define expr(i) std::abs(Base::values_[i])
476 return (unroll_comb(expr, +));
497 Scalar m(Base::values_[0]);
498 for(
int i=1; i<DIM; ++i)
if(Base::values_[i]>m) m=Base::values_[i];
505 Scalar m(std::abs(Base::values_[0]));
506 for(
int i=1; i<DIM; ++i)
507 if(std::abs(Base::values_[i])>m)
508 m=std::abs(Base::values_[i]);
516 Scalar m(Base::values_[0]);
517 for(
int i=1; i<DIM; ++i)
if(Base::values_[i]<m) m=Base::values_[i];
524 Scalar m(std::abs(Base::values_[0]));
525 for(
int i=1; i<DIM; ++i)
526 if(std::abs(Base::values_[i])<m)
527 m=std::abs(Base::values_[i]);
533 Scalar m(Base::values_[0]);
534 for(
int i=1; i<DIM; ++i) m+=Base::values_[i];
535 return m/Scalar(DIM);
540 Scalar m(std::abs(Base::values_[0]));
541 for(
int i=1; i<DIM; ++i) m+=std::abs(Base::values_[i]);
542 return m/Scalar(DIM);
548#define expr(i) if (_rhs[i] < Base::values_[i]) Base::values_[i] = _rhs[i];
557#define expr(i) if (_rhs[i] < Base::values_[i]) { Base::values_[i] = _rhs[i]; result = true; }
565#define expr(i) if (_rhs[i] > Base::values_[i]) Base::values_[i] = _rhs[i];
574#define expr(i) if (_rhs[i] > Base::values_[i]) { Base::values_[i] =_rhs[i]; result = true; }
595 template<
typename Functor>
598#define expr(i) result[i] = _func(Base::values_[i]);
606#define expr(i) Base::values_[i] = _s;
621#define expr(i) if (Base::values_[i] != _rhs.Base::values_[i]) \
622 return (Base::values_[i] < _rhs.Base::values_[i]);
636#define expr(i) is >> vec[i];
649 for(
int i=0; i<N-1; ++i) os << vec[i] <<
" ";
652#define expr(i) vec[i]
653 os << unroll_comb(expr, <<
" " <<);
Definition: VectorT_inc.hh:68
Scalar mean() const
return arithmetic mean
Definition: VectorT_inc.hh:532
VectorT< Scalar, N > vector_type
type of this vector
Definition: VectorT_inc.hh:79
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
Definition: VectorT_inc.hh:572
Scalar min() const
return the minimal component
Definition: VectorT_inc.hh:514
static int dim()
returns dimension of the vector (deprecated)
Definition: VectorT_inc.hh:82
Scalar length() const
compute euclidean norm
Definition: VectorT_inc.hh:411
vector_type operator-(const vector_type &_v) const
component-wise vector difference
Definition: VectorT_inc.hh:355
vector_type min(const vector_type &_rhs) const
component-wise min
Definition: VectorT_inc.hh:581
vector_type & operator/=(const vector_type &_rhs)
component-wise self-division
Definition: VectorT_inc.hh:294
const Scalar * data() const
access to const Scalar array
Definition: VectorT_inc.hh:189
static size_t size()
returns dimension of the vector
Definition: VectorT_inc.hh:85
Scalar * data()
access to Scalar array
Definition: VectorT_inc.hh:186
vector_type & operator-=(const vector_type &_rhs)
vector difference from this
Definition: VectorT_inc.hh:302
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: VectorT_inc.hh:564
Scalar value_type
the type of the scalar used in this template
Definition: VectorT_inc.hh:76
vector_type operator/(const vector_type &_v) const
component-wise vector division
Definition: VectorT_inc.hh:331
const vector_type normalized() const
return normalized vector
Definition: VectorT_inc.hh:441
vector_type operator+(const vector_type &_v) const
component-wise vector addition
Definition: VectorT_inc.hh:343
Scalar mean_abs() const
return absolute arithmetic mean
Definition: VectorT_inc.hh:539
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Definition: VectorT_inc.hh:555
VectorT(const Scalar &v)
special constructor for 1D vectors
Definition: VectorT_inc.hh:96
Scalar max_abs() const
return the maximal absolute component
Definition: VectorT_inc.hh:503
VectorT< Scalar, 3 > operator%(const VectorT< Scalar, 3 > &_rhs) const
cross product: only defined for Vec3* as specialization
vector_type max(const vector_type &_rhs) const
component-wise max
Definition: VectorT_inc.hh:586
Scalar norm() const
compute euclidean norm
Definition: VectorT_inc.hh:410
vector_type & operator/=(const Scalar &_s)
component-wise self-division by scalar
Definition: VectorT_inc.hh:247
vector_type & operator+=(const vector_type &_rhs)
vector self-addition
Definition: VectorT_inc.hh:310
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
Definition: VectorT_inc.hh:605
Scalar min_abs() const
return the minimal absolute component
Definition: VectorT_inc.hh:522
Scalar sqrnorm() const
compute squared euclidean norm
Definition: VectorT_inc.hh:414
vector_type operator/(const Scalar &_s) const
component-wise division by with scalar
Definition: VectorT_inc.hh:268
VectorT(const Scalar _values[N])
construct from a value array (explicit)
Definition: VectorT_inc.hh:144
Scalar l8_norm() const
compute l8_norm
Definition: VectorT_inc.hh:482
bool operator==(const vector_type &_rhs) const
component-wise comparison
Definition: VectorT_inc.hh:220
static vector_type vectorized(const Scalar &_s)
store the same value in each component
Definition: VectorT_inc.hh:614
bool operator!=(const vector_type &_rhs) const
component-wise comparison
Definition: VectorT_inc.hh:228
VectorT(const VectorT< otherScalarType, N > &_rhs)
copy & cast constructor (explicit)
Definition: VectorT_inc.hh:161
const Scalar & operator[](size_t _i) const
get i'th element read-only
Definition: VectorT_inc.hh:210
bool operator<(const vector_type &_rhs) const
lexicographical comparison
Definition: VectorT_inc.hh:620
vector_type & normalize()
normalize vector, return normalized vector
Definition: VectorT_inc.hh:432
vector_type operator-(void) const
unary minus
Definition: VectorT_inc.hh:367
Scalar operator|(const vector_type &_rhs) const
compute scalar product
Definition: VectorT_inc.hh:393
vector_type & operator=(const VectorT< otherScalarType, N > &_rhs)
cast from vector with a different scalar type
Definition: VectorT_inc.hh:172
vector_type operator*(const Scalar &_s) const
component-wise multiplication with scalar
Definition: VectorT_inc.hh:256
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: VectorT_inc.hh:547
vector_type & operator*=(const Scalar &_s)
component-wise self-multiplication with scalar
Definition: VectorT_inc.hh:238
VectorT()
default constructor creates uninitialized values.
Definition: VectorT_inc.hh:93
vector_type & normalize_cond()
normalize vector, return normalized vector and avoids div by zero
Definition: VectorT_inc.hh:448
vector_type & operator*=(const vector_type &_rhs)
component-wise self-multiplication
Definition: VectorT_inc.hh:286
Scalar l1_norm() const
compute L1 (Manhattan) norm
Definition: VectorT_inc.hh:466
Scalar max() const
return the maximal component
Definition: VectorT_inc.hh:495
Scalar & operator[](size_t _i)
get i'th element read-write
Definition: VectorT_inc.hh:205
vector_type operator*(const vector_type &_v) const
component-wise vector multiplication
Definition: VectorT_inc.hh:319
vector_type apply(const Functor &_func) const
component-wise apply function object with Scalar operator()(Scalar).
Definition: VectorT_inc.hh:596
std::ostream & operator<<(std::ostream &_o, const Timer &_t)
Write seconds to output stream.
Definition: Timer.hh:205