|
ACF $AcfVersion:0$
|
Implementation of fixed-size mathematical vector with specified type of elements. More...
#include <TVector.h>
Public Types | |
| typedef Element | ElementType |
| typedef Element | Elements[Size] |
Public Member Functions | |
| TVector () | |
| Creates an uninitialized vector. | |
| TVector (const TVector< Size, Element > &vector) | |
| Creates a copy of another vector. | |
| TVector (std::initializer_list< Element > values) | |
| Creates a vector from an initializer list. | |
| const Element & | GetElement (int i) const |
| Gets the element at the specified index (read-only). | |
| Element & | GetElementRef (int i) |
| Gets a reference to the element at the specified index (read-write). | |
| void | SetElement (int i, const Element &value) |
| Sets the element at the specified index. | |
| void | SetAllElements (const Element &value) |
| Sets all elements to the same value. | |
| void | Reset () |
| Sets all coordinates to zero. | |
| void | Clear () |
| Sets all coordinates to zero. | |
| const TVector< Size, Element >::Elements & | GetElements () const |
| Get read-only access to internal element container. | |
| TVector< Size, Element >::Elements & | GetElementsRef () |
| Get access to internal element container. | |
| void | Translate (const TVector< Size, Element > &vector) |
| Translates (adds) another vector to this vector. | |
| TVector< Size, Element > | GetTranslated (const TVector< Size, Element > &vector) |
| Returns a new vector that is the translation of this vector. | |
| void | GetTranslated (const TVector< Size, Element > &vector, TVector< Size, Element > &result) |
| Computes the translated vector and stores it in the result parameter. | |
| void | ScaledCumulate (const TVector< Size, Element > &vector, Element scale) |
| Adds a scaled vector to this vector. | |
| bool | IsNull (Element tolerance=I_BIG_EPSILON) const |
| Checks if this vector is null (all elements approximately zero). | |
| Element | GetDotProduct (const TVector< Size, Element > &vector) const |
| Calculates the dot product with another vector. | |
| Element | GetLength2 () const |
| Calculates the squared Euclidean length of the vector. | |
| Element | GetLength () const |
| Calculates the Euclidean length (magnitude) of the vector. | |
| Element | GetDistance2 (const TVector< Size, Element > &vector) const |
| Calculates the squared distance to another vector. | |
| Element | GetDistance (const TVector< Size, Element > &vector) const |
| Calculates the Euclidean distance to another vector. | |
| Element | GetElementsSum () const |
| Calculates the sum of all vector elements. | |
| bool | Normalize (Element length=1.0) |
| Normalizes the vector to a specified length. | |
| bool | GetNormalized (TVector< Size, Element > &result, Element length=1.0) const |
| Returns a normalized copy of this vector with specified length. | |
| void | GetMinimal (const TVector< Size, Element > &vector, TVector< Size, Element > &result) const |
| Get vector with minimal elements values. | |
| void | GetMaximal (const TVector< Size, Element > &vector, TVector< Size, Element > &result) const |
| Get vector with maximal elements values. | |
| bool | Serialize (iser::IArchive &archive) |
| Serialize this vector to specified archive. | |
| bool | operator== (const TVector< Size, Element > &vector) const |
| bool | operator!= (const TVector< Size, Element > &vector) const |
| bool | operator< (const TVector< Size, Element > &vector) const |
| bool | operator> (const TVector< Size, Element > &vector) const |
| bool | operator<= (const TVector< Size, Element > &vector) const |
| bool | operator>= (const TVector< Size, Element > &vector) const |
| TVector< Size, Element > & | operator= (const TVector< Size, Element > &vector)=default |
| TVector< Size, Element > | operator- () const |
| TVector< Size, Element > | operator+ (const TVector< Size, Element > &vector) const |
| TVector< Size, Element > | operator- (const TVector< Size, Element > &vector) const |
| TVector< Size, Element > | operator* (Element scalar) const |
| TVector< Size, Element > | operator/ (Element scalar) const |
| TVector< Size, Element > & | operator+= (const TVector< Size, Element > &vector) |
| TVector< Size, Element > & | operator-= (const TVector< Size, Element > &vector) |
| TVector< Size, Element > & | operator*= (Element scalar) |
| TVector< Size, Element > & | operator/= (Element scalar) |
| const Element & | operator[] (int i) const |
| Element & | operator[] (int i) |
Static Public Member Functions | |
| static int | GetElementsCount () |
| Get number of elements. | |
| static bool | SetElementsCount (int count) |
| Set number of elements. | |
| static const TVector< Size, Element > & | GetZero () |
| Get vector with all coordinates set to 0. | |
Protected Attributes | |
| Elements | m_elements |
Implementation of fixed-size mathematical vector with specified type of elements.
TVector is a template class that provides a generic implementation of fixed-size mathematical vectors. It supports common vector operations like addition, scaling, dot product, normalization, and distance calculations. The vector size is determined at compile-time, enabling efficient memory layout and operations.
| typedef Element imath::TVector< Size, Element >::Elements[Size] |
| typedef Element imath::TVector< Size, Element >::ElementType |
|
inline |
Creates an uninitialized vector.
This constructor creates a vector with the specified size but does not initialize the element values. The element values will contain undefined data until explicitly set using SetElement(), SetAllElements(), or other initialization methods.
|
inline |
Creates a copy of another vector.
| vector | The source vector to copy from. All elements will be copied to this new vector. |
Definition at line 519 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
Creates a vector from an initializer list.
Allows convenient initialization using brace syntax. If the initializer list contains fewer elements than Size, remaining elements are default-initialized (typically to zero for numeric types). If the list contains more elements than Size, only the first Size elements are used.
| values | Initializer list of element values |
|
inline |
Sets all coordinates to zero.
Equivalent to SetAllElements(0) and Reset().
|
inline |
Calculates the Euclidean distance to another vector.
| vector | The other vector (point) |
|
inline |
Calculates the squared distance to another vector.
More efficient than GetDistance() when only relative distances need to be compared, as it avoids the square root operation.
| vector | The other vector (point) |
|
inline |
Calculates the dot product with another vector.
The dot product is defined as: sum(this[i] * vector[i]) for all i. It measures the similarity of direction between two vectors.
| vector | The other vector for dot product calculation |
Definition at line 647 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
Referenced by i3d::Geometry::GetAngleBetweenVectors(), i3d::Geometry::GetSignedAngleBetweenVectors(), i3d::CPlane3d::GetSignedDistance(), and i3d::Geometry::ProjectVectorOntoVector().
|
inline |
Gets the element at the specified index (read-only).
| i | Zero-based index of the element to retrieve (0 <= i < Size) |
Definition at line 546 of file TVector.h.
Referenced by icmm::CLab::GetA(), icmm::CLab::GetB(), icmm::CRgb::GetBlue(), icmm::CCmy::GetC(), icmm::CCmyk::GetC(), icmm::CRgb::GetGreen(), icmm::CHsv::GetHue(), icmm::CCmyk::GetK(), icmm::CLab::GetL(), icmm::CCmy::GetM(), icmm::CCmyk::GetM(), imath::TVector< Size, Element >::GetMaximal(), imath::TVector< Size, Element >::GetMinimal(), icmm::CRgb::GetRed(), icmm::CHsv::GetSaturation(), icmm::CHsv::GetValue(), icmm::CCmy::GetY(), icmm::CCmyk::GetY(), imath::CDouble::operator!=(), imath::CDouble::operator*(), imath::CDouble::operator*=(), imath::CDouble::operator+(), imath::CDouble::operator+=(), imath::CDouble::operator-(), imath::CDouble::operator-=(), imath::CDouble::operator/(), imath::CDouble::operator/=(), imath::CDouble::operator<(), imath::CDouble::operator<=(), imath::CDouble::operator=(), imath::CDouble::operator==(), imath::CDouble::operator>(), and imath::CDouble::operator>=().
|
inline |
Gets a reference to the element at the specified index (read-write).
Returns a non-const reference allowing direct modification of the element.
| i | Zero-based index of the element (0 <= i < Size) |
|
inline |
|
inlinestatic |
|
inline |
| Element imath::TVector< Size, Element >::GetElementsSum | ( | ) | const |
Calculates the sum of all vector elements.
|
inline |
Calculates the Euclidean length (magnitude) of the vector.
Returns sqrt(sum(element[i]^2)) for all i.
Definition at line 667 of file TVector.h.
Referenced by i3d::Geometry::GetDistance(), i3d::CLine3d::GetLength(), and i3d::Geometry::GetTriangleArea().
|
inline |
Calculates the squared Euclidean length of the vector.
Returns sum(element[i]^2) for all i. This is more efficient than GetLength() when only relative lengths need to be compared, as it avoids the square root operation.
Definition at line 660 of file TVector.h.
Referenced by i2d::CLine2d::GetAlphaAndCastDistance(), i2d::CLine2d::GetCastAlpha(), and i3d::Geometry::ProjectVectorOntoVector().
| void imath::TVector< Size, Element >::GetMaximal | ( | const TVector< Size, Element > & | vector, |
| TVector< Size, Element > & | result | ||
| ) | const |
Get vector with maximal elements values.
Definition at line 989 of file TVector.h.
References imath::TVector< Size, Element >::GetElement(), and imath::TVector< Size, Element >::SetElement().
| void imath::TVector< Size, Element >::GetMinimal | ( | const TVector< Size, Element > & | vector, |
| TVector< Size, Element > & | result | ||
| ) | const |
Get vector with minimal elements values.
Definition at line 980 of file TVector.h.
References imath::TVector< Size, Element >::GetElement(), and imath::TVector< Size, Element >::SetElement().
| bool imath::TVector< Size, Element >::GetNormalized | ( | TVector< Size, Element > & | result, |
| Element | length = 1.0 |
||
| ) | const |
Returns a normalized copy of this vector with specified length.
Creates a new vector with the same direction as this vector but with the specified length. The original vector is not modified.
| result | Output parameter that receives the normalized vector |
| length | The desired length for the normalized vector (default: 1.0) |
Definition at line 960 of file TVector.h.
References I_BIG_EPSILON, and imath::TVector< Size, Element >::m_elements.
| TVector< Size, Element > imath::TVector< Size, Element >::GetTranslated | ( | const TVector< Size, Element > & | vector | ) |
Returns a new vector that is the translation of this vector.
| vector | The vector to add |
| void imath::TVector< Size, Element >::GetTranslated | ( | const TVector< Size, Element > & | vector, |
| TVector< Size, Element > & | result | ||
| ) |
Computes the translated vector and stores it in the result parameter.
| vector | The vector to add to this vector |
| result | Output parameter that receives the translated vector |
|
inlinestatic |
|
inline |
Checks if this vector is null (all elements approximately zero).
| tolerance | The maximum absolute value for each element to be considered zero. Default is I_BIG_EPSILON (typically 1e-6 for double precision). |
| bool imath::TVector< Size, Element >::Normalize | ( | Element | length = 1.0 | ) |
Normalizes the vector to a specified length.
Scales the vector so that its length becomes the specified value. If the current length is zero (or very close to zero), the operation fails.
| length | The desired length after normalization (default: 1.0 for unit vector) |
Definition at line 940 of file TVector.h.
References I_BIG_EPSILON.
|
inline |
|
inline |
Definition at line 856 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
|
inline |
Definition at line 830 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
Definition at line 773 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
Definition at line 817 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
Definition at line 843 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
Definition at line 784 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
Definition at line 869 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
inline |
| bool imath::TVector< Size, Element >::operator< | ( | const TVector< Size, Element > & | vector | ) | const |
Definition at line 709 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
| bool imath::TVector< Size, Element >::operator<= | ( | const TVector< Size, Element > & | vector | ) | const |
Definition at line 741 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
default |
|
inline |
Definition at line 690 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
| bool imath::TVector< Size, Element >::operator> | ( | const TVector< Size, Element > & | vector | ) | const |
Definition at line 725 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
| bool imath::TVector< Size, Element >::operator>= | ( | const TVector< Size, Element > & | vector | ) | const |
Definition at line 757 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
| Element & imath::TVector< Size, Element >::operator[] | ( | int | i | ) |
| const Element & imath::TVector< Size, Element >::operator[] | ( | int | i | ) | const |
|
inline |
Sets all coordinates to zero.
Equivalent to SetAllElements(0). This method is provided for compatibility with other vector implementations.
|
inline |
Adds a scaled vector to this vector.
Performs the operation: this[i] += vector[i] * scale for all i. This is equivalent to Translate(vector * scale) but may be more efficiently implemented.
| vector | The vector to add (scaled) |
| scale | The scaling factor to apply to the vector before addition |
Definition at line 631 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
| bool imath::TVector< Size, Element >::Serialize | ( | iser::IArchive & | archive | ) |
Serialize this vector to specified archive.
Definition at line 998 of file TVector.h.
References iser::IArchive::Process().
|
inline |
Sets all elements to the same value.
| value | The value to assign to all vector elements |
|
inline |
Sets the element at the specified index.
| i | Zero-based index of the element to set (0 <= i < Size) |
| value | The new value for the element |
Definition at line 560 of file TVector.h.
Referenced by icmm::CCmy::CCmy(), icmm::CCmyk::CCmyk(), icmm::CHsv::CHsv(), icmm::CLab::CLab(), icmm::CRgb::CRgb(), imath::TVector< Size, Element >::GetMaximal(), imath::TVector< Size, Element >::GetMinimal(), icmm::CLab::SetA(), icmm::CLab::SetB(), icmm::CRgb::SetBlue(), icmm::CCmy::SetC(), icmm::CCmyk::SetC(), icmm::CRgb::SetGreen(), icmm::CHsv::SetHue(), icmm::CCmyk::SetK(), icmm::CLab::SetL(), icmm::CCmy::SetM(), icmm::CCmyk::SetM(), icmm::CRgb::SetRed(), icmm::CHsv::SetSaturation(), icmm::CHsv::SetValue(), icmm::CCmy::SetY(), and icmm::CCmyk::SetY().
|
inlinestatic |
|
inline |
Translates (adds) another vector to this vector.
Performs element-wise addition: this[i] += vector[i] for all i.
| vector | The vector to add to this vector |
Definition at line 608 of file TVector.h.
References imath::TVector< Size, Element >::m_elements.
|
protected |
Definition at line 501 of file TVector.h.
Referenced by imath::TVector< Size, Element >::GetDotProduct(), imath::TVector< Size, Element >::GetNormalized(), imath::TVector< Size, Element >::operator*(), imath::TVector< Size, Element >::operator+(), imath::TVector< Size, Element >::operator+=(), imath::TVector< Size, Element >::operator-(), imath::TVector< Size, Element >::operator-(), imath::TVector< Size, Element >::operator-=(), imath::TVector< Size, Element >::operator/(), imath::TVector< Size, Element >::operator<(), imath::TVector< Size, Element >::operator<=(), imath::TVector< Size, Element >::operator==(), imath::TVector< Size, Element >::operator>(), imath::TVector< Size, Element >::operator>=(), imath::TVector< Size, Element >::ScaledCumulate(), imath::TVector< Size, Element >::Translate(), and imath::TVector< Size, Element >::TVector().