49 #define OPENVOLUMEMESH_VECTOR_HH
52 #define TEMPLATE_HEADER template <typename Scalar, int N>
53 #define CLASSNAME VectorT
54 #define DERIVED VectorDataT<Scalar,N>
55 #define unroll(expr) for (int i=0; i<N; ++i) expr(i)
59 #if defined( OPENVOLUMEMESH_VECTOR_HH )
79 static inline int dim() {
return DIM; }
82 static inline size_t size() {
return DIM; }
84 static const size_t size_ = DIM;
93 explicit inline VectorT(
const Scalar& v) {
100 inline VectorT(
const Scalar& v0,
const Scalar& v1) {
102 Base::values_[0] = v0; Base::values_[1] = v1;
106 inline VectorT(
const Scalar& v0,
const Scalar& v1,
const Scalar& v2) {
108 Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2;
112 inline VectorT(
const Scalar& v0,
const Scalar& v1,
113 const Scalar& v2,
const Scalar& v3) {
115 Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2; Base::values_[3]=v3;
119 inline VectorT(
const Scalar& v0,
const Scalar& v1,
const Scalar& v2,
120 const Scalar& v3,
const Scalar& v4) {
122 Base::values_[0]=v0; Base::values_[1]=v1;Base::values_[2]=v2; Base::values_[3]=v3; Base::values_[4]=v4;
126 inline VectorT(
const Scalar& v0,
const Scalar& v1,
const Scalar& v2,
127 const Scalar& v3,
const Scalar& v4,
const Scalar& v5) {
129 Base::values_[0]=v0; Base::values_[1]=v1; Base::values_[2]=v2;
130 Base::values_[3]=v3; Base::values_[4]=v4; Base::values_[5]=v5;
134 explicit inline VectorT(
const Scalar _values[DIM]) {
135 memcpy(Base::values_, _values, DIM*
sizeof(Scalar));
143 memcpy(Base::values_, _rhs.Base::values_, DIM*
sizeof(Scalar));
150 template<
typename otherScalarType>
151 explicit inline VectorT(
const VectorT<otherScalarType,DIM>& _rhs) {
161 template<
typename otherScalarType>
163 #define expr(i) Base::values_[i] = (Scalar)_rhs[i];
176 inline Scalar*
data() {
return Base::values_; }
179 inline const Scalar*
data()
const {
return Base::values_; }
198 assert(_i<DIM);
return Base::values_[_i];
203 assert(_i<DIM);
return Base::values_[_i];
213 #define expr(i) if(Base::values_[i]!=_rhs.Base::values_[i]) return false;
221 return !(*
this == _rhs);
231 #define expr(i) Base::values_[i] *= _s;
240 #define expr(i) Base::values_[i] /= _s;
252 #define expr(i) Base::values_[i] * _s
264 #define expr(i) Base::values_[i] / _s
279 #define expr(i) Base::values_[i] *= _rhs[i];
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];
315 #define expr(i) Base::values_[i] * _v.Base::values_[i]
327 #define expr(i) Base::values_[i] / _v.Base::values_[i]
339 #define expr(i) Base::values_[i] + _v.Base::values_[i]
351 #define expr(i) Base::values_[i] - _v.Base::values_[i]
361 #define expr(i) v.Base::values_[i] = -Base::values_[i];
370 inline VectorT<Scalar,3>
operator%(
const VectorT<Scalar,3>& _rhs)
const
374 VectorT<Scalar,3>(Base::values_[1]*_rhs.Base::values_[2]-Base::values_[2]*_rhs.Base::values_[1],
375 Base::values_[2]*_rhs.Base::values_[0]-Base::values_[0]*_rhs.Base::values_[2],
376 Base::values_[0]*_rhs.Base::values_[1]-Base::values_[1]*_rhs.Base::values_[0]);
387 #define expr(i) p += Base::values_[i] * _rhs.Base::values_[i];
403 inline Scalar length()
const {
return norm(); }
410 #define expr(i) s += Base::values_[i] * Base::values_[i];
415 #define expr(i) Base::values_[i]*Base::values_[i]
416 return (unroll_comb(expr, +));
435 if (n != (Scalar)0.0)
454 #define expr(i) s += abs(Base::values_[i]);
459 #define expr(i) abs(Base::values_[i])
460 return (unroll_comb(expr, +));
481 Scalar m(Base::values_[0]);
482 for(
int i=1; i<DIM; ++i) if(Base::values_[i]>m) m=Base::values_[i];
489 Scalar m(abs(Base::values_[0]));
490 for(
int i=1; i<DIM; ++i)
491 if(abs(Base::values_[i])>m)
492 m=abs(Base::values_[i]);
500 Scalar m(Base::values_[0]);
501 for(
int i=1; i<DIM; ++i)
if(Base::values_[i]<m) m=Base::values_[i];
508 Scalar m(abs(Base::values_[0]));
509 for(
int i=1; i<DIM; ++i)
510 if(abs(Base::values_[i])<m)
511 m=abs(Base::values_[i]);
517 Scalar m(Base::values_[0]);
518 for(
int i=1; i<DIM; ++i) m+=Base::values_[i];
519 return m/Scalar(DIM);
524 Scalar m(abs(Base::values_[0]));
525 for(
int i=1; i<DIM; ++i) m+=abs(Base::values_[i]);
526 return m/Scalar(DIM);
532 #define expr(i) if (_rhs[i] < Base::values_[i]) Base::values_[i] = _rhs[i];
541 #define expr(i) if (_rhs[i] < Base::values_[i]) { Base::values_[i] = _rhs[i]; result = true; }
549 #define expr(i) if (_rhs[i] > Base::values_[i]) Base::values_[i] = _rhs[i];
558 #define expr(i) if (_rhs[i] > Base::values_[i]) { Base::values_[i] =_rhs[i]; result = true; }
579 template<
typename Functor>
582 #define expr(i) result[i] = _func(Base::values_[i]);
590 #define expr(i) Base::values_[i] = _s;
605 #define expr(i) if (Base::values_[i] != _rhs.Base::values_[i]) \
606 return (Base::values_[i] < _rhs.Base::values_[i]);
618 operator>>(std::istream& is, VectorT<Scalar,DIM>& vec)
620 #define expr(i) is >> vec[i];
630 operator<<(std::ostream& os, const VectorT<Scalar,DIM>& vec)
633 for(
int i=0; i<N-1; ++i) os << vec[i] <<
" ";
636 #define expr(i) vec[i]
637 os << unroll_comb(expr, <<
" " <<);
646 #endif // included by VectorT.hh