27 VTK_ABI_NAMESPACE_BEGIN
28 template <
typename T,
int Size>
59 for (
int i = 0; i < Size; ++i)
61 result += this->
Data[i] * this->
Data[i];
79 const double norm(this->
Norm());
84 const double inv(1.0 / norm);
85 for (
int i = 0; i < Size; ++i)
87 this->
Data[i] =
static_cast<T
>(this->
Data[i] * inv);
113 for (
int i = 0; i < Size; ++i)
115 result += this->
Data[i] * other[i];
125 template <
typename TR>
129 for (
int i = 0; i < Size; ++i)
131 result[i] =
static_cast<TR
>(this->
Data[i]);
140 template <
typename T>
166 void Set(
const T& x,
const T& y)
197 bool operator<(const vtkVector2<T>& v)
const
199 return (this->
Data[0] < v.Data[0]) || (this->
Data[0] == v.Data[0] && this->
Data[1] < v.Data[1]);
206 template <
typename T>
233 void Set(
const T& x,
const T& y,
const T& z)
289 bool operator<(const vtkVector3<T>& v)
const
291 return (this->
Data[0] < v.Data[0]) ||
292 (this->
Data[0] == v.Data[0] && this->
Data[1] < v.Data[1]) ||
293 (this->
Data[0] == v.Data[0] && this->Data[1] == v.Data[1] && this->Data[2] < v.Data[2]);
300 template <
typename T>
328 void Set(
const T& x,
const T& y,
const T& z,
const T& w)
381 #define vtkVectorNormalized(vectorType, type, size) \
382 vectorType Normalized() const \
384 return vectorType(vtkVector<type, size>::Normalized().GetData()); \
387 #define vtkVectorDerivedMacro(vectorType, type, size) \
388 vtkVectorNormalized(vectorType, type, size); \
389 explicit vectorType(type s) \
393 explicit vectorType(const type* i) \
397 explicit vectorType(const vtkTuple<type, size>& o) \
398 : Superclass(o.GetData()) \
401 vectorType(const vtkVector<type, size>& o) \
402 : Superclass(o.GetData()) \
447 #define vtkVector3Cross(vectorType, type) \
448 vectorType Cross(const vectorType& other) const \
450 return vectorType(vtkVector3<type>::Cross(other).GetData()); \
524 template <
typename A,
int Size>
528 for (
int i = 0; i < Size; ++i)
538 template <
typename A,
int Size>
542 for (
int i = 0; i < Size; ++i)
544 ret[i] = v1[i] + v2[i];
552 template <
typename T,
int Size>
555 for (
int dim = 0; dim < Size; ++dim)
566 template <
typename T,
int Size,
typename Scalar>
569 for (
int dim = 0; dim < Size; ++dim)
580 template <
typename A,
int Size>
584 for (
int i = 0; i < Size; ++i)
586 ret[i] = v1[i] - v2[i];
594 template <
typename T,
int Size>
597 for (
int dim = 0; dim < Size; ++dim)
608 template <
typename A,
int Size>
612 for (
int i = 0; i < Size; ++i)
614 ret[i] = v1[i] * v2[i];
622 template <
typename A,
typename B,
int Size>
626 for (
int i = 0; i < Size; ++i)
628 ret[i] = v1[i] * scalar;
636 template <
typename A,
int Size>
640 for (
int i = 0; i < Size; ++i)
642 ret[i] = v1[i] / v2[i];
654 #define vtkVectorOperatorNegate(vectorType, type, size) \
655 inline vectorType operator-(const vectorType& v) \
657 return vectorType((-static_cast<vtkVector<type, size>>(v)).GetData()); \
659 #define vtkVectorOperatorPlus(vectorType, type, size) \
660 inline vectorType operator+(const vectorType& v1, const vectorType& v2) \
663 (static_cast<vtkVector<type, size>>(v1) + static_cast<vtkVector<type, size>>(v2)) \
666 #define vtkVectorOperatorMinus(vectorType, type, size) \
667 inline vectorType operator-(const vectorType& v1, const vectorType& v2) \
670 (static_cast<vtkVector<type, size>>(v1) - static_cast<vtkVector<type, size>>(v2)) \
673 #define vtkVectorOperatorMultiply(vectorType, type, size) \
674 inline vectorType operator*(const vectorType& v1, const vectorType& v2) \
677 (static_cast<vtkVector<type, size>>(v1) * static_cast<vtkVector<type, size>>(v2)) \
680 #define vtkVectorOperatorMultiplyScalar(vectorType, type, size) \
681 template <typename B> \
682 inline vectorType operator*(const vectorType& v1, const B& scalar) \
684 return vectorType((static_cast<vtkVector<type, size>>(v1) * scalar).GetData()); \
686 #define vtkVectorOperatorMultiplyScalarPre(vectorType, type, size) \
687 template <typename B> \
688 inline vectorType operator*(const B& scalar, const vectorType& v1) \
690 return vectorType((static_cast<vtkVector<type, size>>(v1) * scalar).GetData()); \
692 #define vtkVectorOperatorDivide(vectorType, type, size) \
693 inline vectorType operator/(const vectorType& v1, const vectorType& v2) \
696 (static_cast<vtkVector<type, size>>(v1) / static_cast<vtkVector<type, size>>(v2)) \
700 #define vtkVectorOperatorMacro(vectorType, type, size) \
701 vtkVectorOperatorNegate(vectorType, type, size); \
702 vtkVectorOperatorPlus(vectorType, type, size); \
703 vtkVectorOperatorMinus(vectorType, type, size); \
704 vtkVectorOperatorMultiply(vectorType, type, size); \
705 vtkVectorOperatorMultiplyScalar(vectorType, type, size); \
706 vtkVectorOperatorMultiplyScalarPre(vectorType, type, size); \
707 vtkVectorOperatorDivide(vectorType, type, size)
719 VTK_ABI_NAMESPACE_END
720 #endif // vtkVector_h
vtkVectorDerivedMacro(vtkVector2i, int, 2)
T Data[Size]
The only thing stored in memory!
void SetZ(const T &z)
Set the z component of the vector, i.e.
vtkVector4< int > Superclass
vtkVector< A, Size > operator+(const vtkVector< A, Size > &v1, const vtkVector< A, Size > &v2)
Performs addition of vectors of the same basic type.
vtkVector2(const T &scalar)
void SetY(const T &y)
Set the y component of the vector, i.e.
double Normalize()
Normalize the vector in place.
vtkVector4(const T &scalar)
vtkVector3< float > Superclass
templated base type for storage of vectors.
vtkVector3< int > Superclass
vtkVector< T, Size > & operator-=(vtkVector< T, Size > &a, const vtkVector< T, Size > &b)
Subtract the vector b to the vector a of the same basic type.
const T & GetZ() const
Get the z component of the vector, i.e.
const T & GetX() const
Get the x component of the vector, i.e.
vtkVector2i(int x, int y)
vtkVector< A, Size > operator*(const vtkVector< A, Size > &v1, const vtkVector< A, Size > &v2)
Performs multiplication of vectors of the same basic type.
vtkVector< T, Size > & operator+=(vtkVector< T, Size > &a, const vtkVector< T, Size > &b)
Add the vector b to the vector a of the same basic type.
vtkVector2(const T *init)
void Set(const T &x, const T &y)
Set the x and y components of the vector.
void SetX(const T &x)
Set the x component of the vector, i.e.
vtkVector< A, Size > operator/(const vtkVector< A, Size > &v1, const vtkVector< A, Size > &v2)
Performs division of vectors of the same type.
vtkVector3Cross(vtkVector3d, double)
vtkVector4d(double x, double y, double z, double w)
vtkVector3d(double x, double y, double z)
vtkVector2< int > Superclass
const T & GetY() const
Get the y component of the vector, i.e.
const T & GetY() const
Get the y component of the vector, i.e.
vtkVector< T, Size > & operator*=(vtkVector< T, Size > &a, Scalar f)
Multiply a vector a by a scalar.
vtkVector< A, Size > operator-(const vtkVector< A, Size > &v)
This following operators enhance the vtkVector classes, allowing various operator overloads one might...
vtkVector3(const T &scalar)
vtkVector3Cross(vtkVector3f, float)
vtkVector3< double > Superclass
T Dot(const vtkVector< T, Size > &other) const
The dot product of this and the supplied vector.
vtkVector3Cross(vtkVector3i, int)
const T & GetZ() const
Get the z component of the vector, i.e.
vtkVectorDerivedMacro(vtkVector4i, int, 4)
vtkVector2f(float x, float y)
vtkVector2< double > Superclass
vtkVector(const T &scalar)
Initialize all of the vector's elements with the supplied scalar.
vtkVector2d(double x, double y)
void SetW(const T &w)
Set the w component of the vector, i.e.
templated base type for containers of constant size.
vtkVector4(const T &x, const T &y, const T &z, const T &w)
vtkVector3i(int x, int y, int z)
vtkVector2(const T &x, const T &y)
double Norm() const
Get the norm of the vector, i.e.
void SetX(const T &x)
Set the x component of the vector, i.e.
vtkVectorDerivedMacro(vtkVector3d, double, 3)
void Set(const T &x, const T &y, const T &z, const T &w)
Set the x, y, z and w components of a 3D vector in homogeneous coordinates.
void Set(const T &x, const T &y, const T &z)
Set the x, y and z components of the vector.
void SetY(const T &y)
Set the y component of the vector, i.e.
vtkVector(const T *init)
Initialize the vector's elements with the elements of the supplied array.
vtkVector2< float > Superclass
vtkVectorDerivedMacro(vtkVector2d, double, 2)
Some derived classes for the different vectors commonly used.
const T & GetX() const
Get the x component of the vector, i.e.
vtkVector< T, Size > Normalized() const
Return the normalized form of this vector.
vtkVector3< T > Cross(const vtkVector3< T > &other) const
Return the cross product of this X other.
const T & GetX() const
Get the x component of the vector, i.e.
vtkVector4i(int x, int y, int z, int w)
vtkVectorDerivedMacro(vtkVector3i, int, 3)
vtkVector< TR, Size > Cast() const
Cast the vector to the specified type, returning the result.
vtkVectorDerivedMacro(vtkVector3f, float, 3)
vtkVector3(const T &x, const T &y, const T &z)
void SetX(const T &x)
Set the x component of the vector, i.e.
vtkVectorDerivedMacro(vtkVector4d, double, 4)
vtkVectorDerivedMacro(vtkVector2f, float, 2)
void SetZ(const T &z)
Set the z component of the vector, i.e.
const T & GetW() const
Get the w component of the vector, i.e.
vtkVector3(const T *init)
#define vtkVectorOperatorMacro(vectorType, type, size)
void SetY(const T &y)
Set the y component of the vector, i.e.
const T & GetY() const
Get the y component of the vector, i.e.
vtkVector4(const T *init)
T SquaredNorm() const
Get the squared norm of the vector.
vtkVector3f(float x, float y, float z)