20 #ifndef MIRTK_Vector3D_H 21 #define MIRTK_Vector3D_H 23 #include "mirtk/Math.h" 24 #include "mirtk/Point.h" 25 #include "mirtk/Vector3.h" 53 typedef T ComponentType;
96 static int Rows() {
return 3; }
108 operator const T *()
const;
255 template <
typename T2>
bool operator <(const Vector3D<T2> &)
const;
261 template <
typename T2>
bool operator <=(const Vector3D<T2> &)
const;
309 template <
typename T>
316 template <
typename T>
323 template <
typename T>
332 template <
typename T>
341 template <
typename T>
344 _x =
static_cast<T
>(v[0]);
345 _y =
static_cast<T
>(v[1]);
346 _z =
static_cast<T
>(v[2]);
350 template <
typename T>
353 _x =
static_cast<T
>(p.
_x);
354 _y =
static_cast<T
>(p.
_y);
355 _z =
static_cast<T
>(p.
_z);
359 template <
typename T1>
template <
typename T2>
362 _x =
static_cast<T1
>(v._x);
363 _y =
static_cast<T1
>(v._y);
364 _z =
static_cast<T1
>(v._z);
368 template <
typename T>
371 _x =
static_cast<T
>(v._x);
372 _y =
static_cast<T
>(v._y);
373 _z =
static_cast<T
>(v._z);
378 template <
typename T>
381 _x =
static_cast<T
>(p.
_x);
382 _y =
static_cast<T
>(p.
_y);
383 _z =
static_cast<T
>(p.
_z);
392 template <
typename T>
400 cerr <<
"Vector3D::operator(): Invalid index " << i << endl;
406 template <
typename T>
409 return const_cast<Vector3D<T> *
>(
this)->
operator()(i);
413 template <
typename T>
420 template <
typename T>
431 template <
typename T>
434 _x =
static_cast<T
>(s);
435 _y =
static_cast<T
>(s);
436 _z =
static_cast<T
>(s);
441 template <
typename T>
444 _x =
static_cast<T
>(
static_cast<double>(
_x) + static_cast<double>(s));
445 _y =
static_cast<T
>(
static_cast<double>(
_y) + static_cast<double>(s));
446 _z =
static_cast<T
>(
static_cast<double>(
_z) + static_cast<double>(s));
451 template <
typename T>
454 _x =
static_cast<T
>(
static_cast<double>(
_x) - static_cast<double>(s));
455 _y =
static_cast<T
>(
static_cast<double>(
_y) - static_cast<double>(s));
456 _z =
static_cast<T
>(
static_cast<double>(
_z) - static_cast<double>(s));
461 template <
typename T>
464 _x =
static_cast<T
>(
static_cast<double>(
_x) * static_cast<double>(s));
465 _y =
static_cast<T
>(
static_cast<double>(
_y) * static_cast<double>(s));
466 _z =
static_cast<T
>(
static_cast<double>(
_z) * static_cast<double>(s));
471 template <
typename T>
474 _x =
static_cast<T
>(
static_cast<double>(
_x) / static_cast<double>(s));
475 _y =
static_cast<T
>(
static_cast<double>(
_y) / static_cast<double>(s));
476 _z =
static_cast<T
>(
static_cast<double>(
_z) / static_cast<double>(s));
481 template <
typename T>
490 template <
typename T>
499 template <
typename T>
508 template <
typename T>
517 template <
typename T>
524 template <
typename T>
531 template <
typename T>
542 template <
typename T>
545 _x =
static_cast<T
>(s);
546 _y =
static_cast<T
>(s);
547 _z =
static_cast<T
>(s);
552 template <
typename T>
555 _x =
static_cast<T
>(
static_cast<double>(
_x) + s);
556 _y =
static_cast<T
>(
static_cast<double>(
_y) + s);
557 _z =
static_cast<T
>(
static_cast<double>(
_z) + s);
562 template <
typename T>
565 _x =
static_cast<T
>(
static_cast<double>(
_x) - s);
566 _y =
static_cast<T
>(
static_cast<double>(
_y) - s);
567 _z =
static_cast<T
>(
static_cast<double>(
_z) - s);
572 template <
typename T>
575 _x =
static_cast<T
>(
static_cast<double>(
_x) * s);
576 _y =
static_cast<T
>(
static_cast<double>(
_y) * s);
577 _z =
static_cast<T
>(
static_cast<double>(
_z) * s);
582 template <
typename T>
585 _x =
static_cast<T
>(
static_cast<double>(
_x) / s);
586 _y =
static_cast<T
>(
static_cast<double>(
_y) / s);
587 _z =
static_cast<T
>(
static_cast<double>(
_z) / s);
592 template <
typename T>
601 template <
typename T>
610 template <
typename T>
619 template <
typename T>
628 template <
typename T>
635 template <
typename T>
642 template <
typename T>
653 template <
typename T>
660 template <
typename T1>
template <
typename T2>
663 _x =
static_cast<T1
>(v._x);
664 _y =
static_cast<T1
>(v._y);
665 _z =
static_cast<T1
>(v._z);
670 template <
typename T1>
template <
typename T2>
673 _x =
static_cast<T1
>(
static_cast<double>(
_x) + static_cast<double>(v._x));
674 _y =
static_cast<T1
>(
static_cast<double>(
_y) + static_cast<double>(v._y));
675 _z =
static_cast<T1
>(
static_cast<double>(
_z) + static_cast<double>(v._z));
680 template <
typename T1>
template <
typename T2>
683 _x =
static_cast<T1
>(
static_cast<double>(
_x) - static_cast<double>(v._x));
684 _y =
static_cast<T1
>(
static_cast<double>(
_y) - static_cast<double>(v._y));
685 _z =
static_cast<T1
>(
static_cast<double>(
_z) - static_cast<double>(v._z));
690 template <
typename T1>
template <
typename T2>
693 _x =
static_cast<T1
>(
static_cast<double>(
_x) * static_cast<double>(v._x));
694 _y =
static_cast<T1
>(
static_cast<double>(
_y) * static_cast<double>(v._y));
695 _z =
static_cast<T1
>(
static_cast<double>(
_z) * static_cast<double>(v._z));
700 template <
typename T1>
template <
typename T2>
703 _x =
static_cast<T1
>(
static_cast<double>(
_x) / static_cast<double>(v._x));
704 _y =
static_cast<T1
>(
static_cast<double>(
_y) / static_cast<double>(v._y));
705 _z =
static_cast<T1
>(
static_cast<double>(
_z) / static_cast<double>(v._z));
710 template <
typename T1>
template <
typename T2>
719 template <
typename T1>
template <
typename T2>
728 template <
typename T1>
template <
typename T2>
737 template <
typename T1>
template <
typename T2>
750 template <
typename T>
753 return (
_x == s &&
_y == s &&
_z == s);
757 template <
typename T>
760 return !(*
this == s);
764 template <
typename T>
767 return (
_x < s &&
_y < s &&
_z < s);
771 template <
typename T>
774 return (
_x > s &&
_y > s &&
_z > s);
778 template <
typename T>
781 return (
_x <= s &&
_y <= s &&
_z <= s);
785 template <
typename T>
788 return (
_x >= s &&
_y >= s &&
_z >= s);
796 template <
typename T>
799 return (
_x == s &&
_y == s &&
_z == s);
803 template <
typename T>
806 return !(*
this == s);
810 template <
typename T>
813 return (
_x < s &&
_y < s &&
_z < s);
817 template <
typename T>
820 return (
_x > s &&
_y > s &&
_z > s);
824 template <
typename T>
827 return (
_x <= s &&
_y <= s &&
_z <= s);
831 template <
typename T>
834 return (
_x >= s &&
_y >= s &&
_z >= s);
842 template <
typename T1>
template <
typename T2>
845 return ((
_z == v._z) && (
_y == v._y) && (
_x == v._x));
849 template <
typename T1>
template <
typename T2>
852 return ((
_z != v._z) || (
_y != v._y) || (
_x != v._x));
856 template <
typename T1>
template <
typename T2>
859 return ((
_z < v._z) ||
860 ((
_z == v._z) && (
_y < v._y)) ||
861 ((
_z == v._z) && (
_y == v._y) && (
_x < v._x)));
865 template <
typename T1>
template <
typename T2>
868 return ((
_z > v._z) ||
869 ((
_z == v._z) && (
_y > v._y)) ||
870 ((
_z == v._z) && (
_y == v._y) && (
_x > v._x)));
874 template <
typename T1>
template <
typename T2>
877 return ((*
this < v) || (*
this == v));
881 template <
typename T1>
template <
typename T2>
884 return ((*
this > v) || (*
this == v));
892 template <
typename T>
899 template <
typename T>
906 template <
typename T>
909 const double length =
Length();
910 if (length != .0) (*this) /= length;
919 (
_z * v._x -
_x * v._z),
920 (
_x * v._y -
_y * v._x));
928 return v1.CrossProduct(v2);
932 template <
typename T>
935 return (
_x * v._x +
_y * v._y +
_z * v._z);
943 return v1.DotProduct(v2);
959 cerr <<
"Invalid 3D vector element index: " << n << endl;
960 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
970 case 0: v.
_x = value;
971 case 1: v.
_y = value;
972 case 2: v.
_z = value;
974 cerr <<
"Invalid 3D vector element index: " << n << endl;
975 cerr <<
"Set breakpoint in " << __FILE__ <<
":" << __LINE__ <<
" to debug." << endl;
985 template <
typename T>
988 return Vector3D<T>(pow(v._x, e), pow(v._y, e), pow(v._z, e));
992 template <
typename T>
995 return Vector3D<T>(pow(v._x, e), pow(v._y, e), pow(v._z, e));
999 template <
typename T>
1002 return Vector3D<T>(sqrt(v._x), sqrt(v._y), sqrt(v._z));
1008 #endif // MIRTK_Vector3D_H double Length() const
Compute length of vector.
double _x
x coordinate of Point
Vector3D operator/(int) const
Divide vector by integral valued scalar.
Vector3D operator-() const
Unary negation operator.
double SquaredLength() const
Compute squared length of vector.
Vector3D & operator+=(int)
Add integral valued scalar.
void Normalize()
Normalize vector to length one.
bool operator>(int) const
Element-wise greater than comparison to inegral-valued scalar.
bool operator<=(int) const
Element-wise less or equal than comparison to inegral-valued scalar.
double DotProduct(const Vector3D &) const
Dot-product with other vector.
bool operator>=(int) const
Element-wise greater or equal than comparison to inegral-valued scalar.
bool operator==(int) const
Element-wise equality comparison with inegral-valued scalar.
static int Rows()
Number of vector components.
Vector3D & operator-=(int)
Subtract integral valued scalar.
T & operator()(int)
Set/get vector component at index 0: _x, 1: _y, or 2: _z.
Vector3D CrossProduct(const Vector3D &) const
Cross-product with other vector.
Vector3D & operator=(const Vector3D &)
Assignment operator.
double _z
z coordinate of Point
double _y
y coordinate of Point
Vector3D & operator*=(int)
Multiply by integral valued scalar.
Vector3D operator+(int) const
Add integral valued scalar to vector.
Vector3D()
Default constructor.
bool operator!=(int) const
Element-wise inequality comparison with inegral-valued scalar.
bool operator<(int) const
Element-wise less than comparison to inegral-valued scalar.
Vector3D operator*(int) const
Multiply vector by integral valued scalar.
Vector3D & operator/=(int)
Divide by integral valued scalar.