20 #ifndef MIRTK_VectorND_H 21 #define MIRTK_VectorND_H 23 #include "mirtk/Math.h" 24 #include "mirtk/Point.h" 25 #include "mirtk/Vector3.h" 51 template <
int N,
typename T>
54 typedef T ComponentType;
75 template <
typename T2>
82 static int Rows() {
return N; }
94 operator const T *()
const;
241 template <
typename T2>
bool operator <(const VectorND<N, T2> &)
const;
247 template <
typename T2>
bool operator <=(const VectorND<N, T2> &)
const;
278 template <
int N,
typename T>
281 for (
int i = 0; i < N; ++i) {
287 template <
int N,
typename T>
290 for (
int i = 0; i < N; ++i) {
296 template <
int N,
typename T>
300 Throw(ERR_InvalidArgument, __FUNCTION__,
"Vector must have ", N,
" components");
302 for (
int i = 0; i < N; ++i) {
303 _v[i] =
static_cast<T
>(v(i));
308 template <
int N,
typename T1>
template <
typename T2>
311 for (
int i = 0; i < N; ++i) {
312 _v[i] =
static_cast<T1
>(v.
_v[i]);
321 template <
int N,
typename T>
328 template <
int N,
typename T>
335 template <
int N,
typename T>
342 template <
int N,
typename T>
353 template <
int N,
typename T>
356 for (
int i = 0; i < N; ++i) {
357 _v[i] =
static_cast<T
>(s);
363 template <
int N,
typename T>
366 for (
int i = 0; i < N; ++i) {
367 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) + static_cast<double>(s));
373 template <
int N,
typename T>
376 for (
int i = 0; i < N; ++i) {
377 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) - static_cast<double>(s));
383 template <
int N,
typename T>
386 for (
int i = 0; i < N; ++i) {
387 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) * static_cast<double>(s));
393 template <
int N,
typename T>
396 for (
int i = 0; i < N; ++i) {
397 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) / static_cast<double>(s));
403 template <
int N,
typename T>
412 template <
int N,
typename T>
421 template <
int N,
typename T>
430 template <
int N,
typename T>
439 template <
int N,
typename T>
446 template <
int N,
typename T>
453 template <
int N,
typename T>
464 template <
int N,
typename T>
467 for (
int i = 0; i < N; ++i) {
468 _v[i] =
static_cast<T
>(s);
474 template <
int N,
typename T>
477 for (
int i = 0; i < N; ++i) {
478 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) + s);
484 template <
int N,
typename T>
487 for (
int i = 0; i < N; ++i) {
488 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) - s);
494 template <
int N,
typename T>
497 for (
int i = 0; i < N; ++i) {
498 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) * s);
504 template <
int N,
typename T>
507 for (
int i = 0; i < N; ++i) {
508 _v[i] =
static_cast<T
>(
static_cast<double>(_v[i]) / s);
514 template <
int N,
typename T>
523 template <
int N,
typename T>
532 template <
int N,
typename T>
541 template <
int N,
typename T>
550 template <
int N,
typename T>
557 template <
int N,
typename T>
564 template <
int N,
typename T>
575 template <
int N,
typename T>
579 for (
int i = 0; i < N; ++i) {
586 template <
int N,
typename T1>
template <
typename T2>
589 for (
int i = 0; i < N; ++i) {
590 v.
_v[i] =
static_cast<T1
>(v.
_v[i]);
596 template <
int N,
typename T1>
template <
typename T2>
599 for (
int i = 0; i < N; ++i) {
600 _v[i] =
static_cast<T1
>(
static_cast<double>(_v[i]) + static_cast<double>(v.
_v[i]));
606 template <
int N,
typename T1>
template <
typename T2>
609 for (
int i = 0; i < N; ++i) {
610 _v[i] =
static_cast<T1
>(
static_cast<double>(_v[i]) - static_cast<double>(v.
_v[i]));
616 template <
int N,
typename T1>
template <
typename T2>
619 for (
int i = 0; i < N; ++i) {
620 _v[i] =
static_cast<T1
>(
static_cast<double>(_v[i]) * static_cast<double>(v.
_v[i]));
626 template <
int N,
typename T1>
template <
typename T2>
629 for (
int i = 0; i < N; ++i) {
630 _v[i] =
static_cast<T1
>(
static_cast<double>(_v[i]) / static_cast<double>(v.
_v[i]));
636 template <
int N,
typename T1>
template <
typename T2>
645 template <
int N,
typename T1>
template <
typename T2>
654 template <
int N,
typename T1>
template <
typename T2>
663 template <
int N,
typename T1>
template <
typename T2>
676 template <
int N,
typename T>
679 for (
int i = 0; i < N; ++i) {
680 if (!
AreEqual(static_cast<double>(_v[i]), s))
return false;
685 template <
int N,
typename T>
688 return !(*
this == s);
692 template <
int N,
typename T>
695 for (
int i = 0; i < N; ++i) {
696 if (!(static_cast<double>(_v[i]) < s))
return false;
702 template <
int N,
typename T>
705 for (
int i = 0; i < N; ++i) {
706 if (!(static_cast<double>(_v[i]) > s))
return false;
712 template <
int N,
typename T>
719 template <
int N,
typename T>
730 template <
int N,
typename T>
733 return (*
this == static_cast<double>(s));
737 template <
int N,
typename T>
740 return !(*
this == s);
744 template <
int N,
typename T>
747 return (*
this < static_cast<double>(s));
751 template <
int N,
typename T>
754 return (*
this > static_cast<double>(s));
758 template <
int N,
typename T>
765 template <
int N,
typename T>
776 template <
int N,
typename T1>
template <
typename T2>
779 for (
int i = 0; i < N; ++i) {
780 if (!
AreEqual(static_cast<double>(_v[i]), static_cast<double>(v.
_v[i])))
return false;
786 template <
int N,
typename T1>
template <
typename T2>
789 return !(*
this == v);
793 template <
int N,
typename T1>
template <
typename T2>
796 for (
int i = N - 1; i >= 0; --i) {
797 if (static_cast<double>(_v[i]) < static_cast<double>(v.
_v[i]))
return true;
798 if (!
AreEqual(static_cast<double>(_v[i]), static_cast<double>(v.
_v[i])))
break;
804 template <
int N,
typename T1>
template <
typename T2>
807 return !(*
this == v) && !(*
this < v);
811 template <
int N,
typename T1>
template <
typename T2>
814 return (*
this < v) || (*
this == v);
818 template <
int N,
typename T1>
template <
typename T2>
821 return (*
this > v) || (*
this == v);
829 template <
int N,
typename T>
833 for (
int i = 0; i < N; ++i) {
834 dp +=
static_cast<double>(_v[i]) * static_cast<double>(v.
_v[i]);
840 template <
int N,
typename T>
847 template <
int N,
typename T>
854 template <
int N,
typename T>
857 const double length =
Length();
858 if (!
IsZero(length)) (*this) /= length;
866 template <
int N,
class T>
873 template <
int N,
class T>
884 template <
int N,
typename T>
888 for (
int i = 0; i < N; ++i) {
889 w.
_v[i] = pow(v.
_v[i], e);
895 template <
int N,
typename T>
899 for (
int i = 0; i < N; ++i) {
900 w.
_v[i] = pow(v.
_v[i], e);
906 template <
int N,
typename T>
910 for (
int i = 0; i < N; ++i) {
911 w.
_v[i] = sqrt(v.
_v[i]);
919 #endif // MIRTK_VectorND_H bool operator>=(int) const
Element-wise greater or equal than comparison to inegral-valued scalar.
VectorND & operator+=(int)
Add integral valued scalar.
double SquaredLength() const
Compute squared length of vector.
MIRTKCU_API bool IsZero(double a, double tol=1e-12)
Determine equality of a floating point number with zero.
bool operator==(int) const
Element-wise equality comparison with inegral-valued scalar.
double DotProduct(const VectorND &) const
Dot-product with other vector.
VectorND & operator=(int)
Assign integral valued scalar.
int Rows() const
Returns number of rows.
T _v[N]
Vector components.
VectorND operator*(int) const
Multiply vector by integral valued scalar.
T & operator()(int)
Set/get vector component at index.
VectorND operator-() const
Unary negation operator.
VectorND operator+(int) const
Add integral valued scalar to vector.
bool operator<=(int) const
Element-wise less or equal than comparison to inegral-valued scalar.
VectorND operator/(int) const
Divide vector by integral valued scalar.
bool operator>(int) const
Element-wise greater than comparison to inegral-valued scalar.
VectorND & operator-=(int)
Subtract integral valued scalar.
VectorND & operator/=(int)
Divide by integral valued scalar.
bool operator!=(int) const
Element-wise inequality comparison with inegral-valued scalar.
static int Rows()
Number of vector components.
void Throw(ErrorType err, const char *func, Args... args)
MIRTKCU_API bool AreEqual(double a, double b, double tol=1e-12)
Determine equality of two floating point numbers.
bool operator<(int) const
Element-wise less than comparison to inegral-valued scalar.
double Length() const
Compute length of vector.
void Normalize()
Normalize vector to length one.
VectorND & operator*=(int)
Multiply by integral valued scalar.
VectorND(T=T(0))
Construct from scalar.