ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
imath::CVarVector Class Reference

Implementation of variable-size mathematical vector with double precision elements. More...

#include <CVarVector.h>

Inheritance diagram for imath::CVarVector:
icmm::CVarColor

Public Types

typedef std::vector< double > Elements
 

Public Member Functions

 CVarVector ()
 Create the vector without components.
 
 CVarVector (int componentsCount, double value=0)
 Create vector and initialize number of components.
 
template<typename Iterator >
 CVarVector (Iterator beginIter, Iterator endIter)
 Creates a vector from a range of values using iterators.
 
 CVarVector (const CVarVector &vector)
 Copy constructor.
 
template<int Size>
 CVarVector (const TVector< Size, double > &vector)
 Creates a variable-size vector from a fixed-size TVector.
 
bool IsEmpty () const
 Get true, if the element ist is empty.
 
int GetElementsCount () const
 Get number of elements.
 
bool SetElementsCount (int count, double value=0)
 Set number of elements.
 
double GetElement (int index) const
 Get element at specified index.
 
double & GetElementRef (int index)
 Get reference to element at specified index.
 
void SetElement (int index, double value)
 Set element at specified index.
 
void SetAllElements (double value)
 Set some value to all elements.
 
void Reset ()
 Set size to zero.
 
void Reset (int elementsCount, double value)
 Set number of elements and set all elements to specified value.
 
void Clear ()
 Set all coordinates to zero.
 
void SetElementsFrom (const CVarVector &vector, double expansionValue=0)
 Set elements from other vector without resizing.
 
const ElementsGetElements () const
 Get read-only access to internal element container.
 
ElementsGetElementsRef ()
 Get access to internal element container.
 
bool EnsureElementsCount (int count, double value=0)
 Ensure, that number of elements is at least the specified value.
 
void Translate (const CVarVector &vector)
 Translate the point.
 
CVarVector GetTranslated (const CVarVector &vector)
 Get translated point.
 
void GetTranslated (const CVarVector &vector, CVarVector &result)
 /overloaded
 
void ScaledCumulate (const CVarVector &vector, double scale)
 Add second vector scaled by specified factor.
 
bool IsNull (double tolerance=I_BIG_EPSILON) const
 Check if this vector is null.
 
double GetDotProduct (const CVarVector &vector) const
 Return dot product of two vectors.
 
double GetLength2 () const
 Return euclidean length square.
 
double GetLength () const
 Return euclidian length.
 
double GetDistance2 (const CVarVector &vector) const
 Return distance square between two vectors.
 
double GetDistance (const CVarVector &vector) const
 Return distance between two vectors.
 
double GetElementsSum () const
 Get simple sum of all elements.
 
bool Normalize (double length=1.0)
 Normalize vector to specified length.
 
bool GetNormalized (CVarVector &result, double length=1.0) const
 Return normalized vector with the same direction and specified length.
 
void GetMinimal (const CVarVector &vector, CVarVector &result) const
 Get vector with minimal elements values.
 
void GetMaximal (const CVarVector &vector, CVarVector &result) const
 Get vector with maximal elements values.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
bool operator== (const CVarVector &vector) const
 
bool operator!= (const CVarVector &vector) const
 
bool operator< (const CVarVector &vector) const
 
bool operator> (const CVarVector &vector) const
 
bool operator<= (const CVarVector &vector) const
 
bool operator>= (const CVarVector &vector) const
 
CVarVector operator- () const
 
CVarVector operator+ (const CVarVector &vector) const
 
CVarVector operator- (const CVarVector &vector) const
 
CVarVector operator* (double scalar) const
 
CVarVector operator/ (double scalar) const
 
CVarVectoroperator+= (const CVarVector &vector)
 
CVarVectoroperator-= (const CVarVector &vector)
 
CVarVectoroperator*= (double scalar)
 
CVarVectoroperator/= (double scalar)
 
CVarVectoroperator= (const CVarVector &vector)
 
double operator[] (int i) const
 
double & operator[] (int i)
 

Detailed Description

Implementation of variable-size mathematical vector with double precision elements.

Purpose

CVarVector is a dynamic-size vector class that provides mathematical vector operations similar to TVector but with runtime-determined size. It's ideal for scenarios where the vector dimension is not known at compile time or needs to change during execution. The vector stores double precision floating-point values and supports common operations like addition, scaling, dot product, normalization, and distance calculations.

CVarVector vs TVector

Use CVarVector when:

Use TVector when:

Usage Examples

// Create empty vector and set size later
vec1.SetElement(0, 1.0);
vec1.SetElement(1, 2.0);
vec1.SetElement(2, 3.0);
// Create vector with initial size and value
imath::CVarVector vec2(5, 0.0); // 5 elements, all initialized to 0
// Create from TVector
imath::TVector<3, double> fixedVec = {1.0, 2.0, 3.0};
imath::CVarVector vec3(fixedVec);
// Vector operations
vec4.SetElement(0, 4.0);
vec4.SetElement(1, 5.0);
vec4.SetElement(2, 6.0);
// Addition
vec1.Translate(vec4); // vec1 += vec4
// Dot product
double dot = vec1.GetDotProduct(vec4); // 1*4 + 2*5 + 3*6 = 32
// Length and normalization
double length = vec1.GetLength();
if (vec1.Normalize()) {
// vec1 is now a unit vector
}
// Dynamic resizing
vec1.EnsureElementsCount(10, 0.0); // Grow to at least 10 elements
Implementation of variable-size mathematical vector with double precision elements.
Definition CVarVector.h:110
double GetLength() const
Return euclidian length.
Definition CVarVector.h:534
bool EnsureElementsCount(int count, double value=0)
Ensure, that number of elements is at least the specified value.
double GetDotProduct(const CVarVector &vector) const
Return dot product of two vectors.
Definition CVarVector.h:513
bool Normalize(double length=1.0)
Normalize vector to specified length.
void SetElement(int index, double value)
Set element at specified index.
Definition CVarVector.h:421
bool SetElementsCount(int count, double value=0)
Set number of elements.
Definition CVarVector.h:393
void Translate(const CVarVector &vector)
Translate the point.
Definition CVarVector.h:473
Implementation of fixed-size mathematical vector with specified type of elements.
Definition TVector.h:95

Common Operations

See also
imath::TVector, imath::TFastVector, imath::CVarMatrix

Definition at line 109 of file CVarVector.h.

Member Typedef Documentation

◆ Elements

typedef std::vector<double> imath::CVarVector::Elements

Definition at line 112 of file CVarVector.h.

Constructor & Destructor Documentation

◆ CVarVector() [1/5]

imath::CVarVector::CVarVector ( )
inline

Create the vector without components.

Definition at line 355 of file CVarVector.h.

◆ CVarVector() [2/5]

imath::CVarVector::CVarVector ( int  componentsCount,
double  value = 0 
)
inlineexplicit

Create vector and initialize number of components.

Definition at line 360 of file CVarVector.h.

◆ CVarVector() [3/5]

template<typename Iterator >
imath::CVarVector::CVarVector ( Iterator  beginIter,
Iterator  endIter 
)
inline

Creates a vector from a range of values using iterators.

This constructor enables creation from any container or sequence that provides iterators (e.g., std::vector, std::list, arrays).

Parameters
beginIterIterator to the first element
endIterIterator past the last element
std::vector<double> values = {1.0, 2.0, 3.0, 4.0};
imath::CVarVector vec(values.begin(), values.end());
// vec now contains {1.0, 2.0, 3.0, 4.0}

Definition at line 373 of file CVarVector.h.

◆ CVarVector() [4/5]

imath::CVarVector::CVarVector ( const CVarVector vector)
inline

Copy constructor.

Definition at line 366 of file CVarVector.h.

◆ CVarVector() [5/5]

template<int Size>
imath::CVarVector::CVarVector ( const TVector< Size, double > &  vector)

Creates a variable-size vector from a fixed-size TVector.

Allows conversion from compile-time sized vectors to runtime-sized vectors. Useful when interfacing between subsystems using different vector types.

Parameters
vectorThe fixed-size TVector to convert from
imath::TVector<3, double> fixedVec = {1.0, 2.0, 3.0};
imath::CVarVector varVec(fixedVec);
// varVec.GetElementsCount() == 3

Definition at line 777 of file CVarVector.h.

Member Function Documentation

◆ Clear()

void imath::CVarVector::Clear ( )
inline

Set all coordinates to zero.

Definition at line 442 of file CVarVector.h.

References GetElementsCount().

◆ EnsureElementsCount()

bool imath::CVarVector::EnsureElementsCount ( int  count,
double  value = 0 
)

Ensure, that number of elements is at least the specified value.

It resize the vector if the new size is bigger than the current one.

Returns
always true, this value is provided for template implementations.

◆ GetDistance()

double imath::CVarVector::GetDistance ( const CVarVector vector) const
inline

Return distance between two vectors.

Definition at line 546 of file CVarVector.h.

References GetDistance2().

Referenced by icmm::CVarColor::IsSimilar().

◆ GetDistance2()

double imath::CVarVector::GetDistance2 ( const CVarVector vector) const
inline

Return distance square between two vectors.

Definition at line 540 of file CVarVector.h.

Referenced by GetDistance().

◆ GetDotProduct()

double imath::CVarVector::GetDotProduct ( const CVarVector vector) const
inline

Return dot product of two vectors.

Definition at line 513 of file CVarVector.h.

References GetElementsCount().

Referenced by GetLength2().

◆ GetElement()

double imath::CVarVector::GetElement ( int  index) const
inline

Get element at specified index.

Definition at line 409 of file CVarVector.h.

References operator[]().

Referenced by icmm::CVarColor::IsNormalized(), icmm::CVarColor::operator*(), and icmm::CVarColor::operator/().

◆ GetElementRef()

double & imath::CVarVector::GetElementRef ( int  index)
inline

Get reference to element at specified index.

Definition at line 415 of file CVarVector.h.

References operator[]().

◆ GetElements()

const CVarVector::Elements & imath::CVarVector::GetElements ( ) const
inline

Get read-only access to internal element container.

Definition at line 461 of file CVarVector.h.

◆ GetElementsCount()

int imath::CVarVector::GetElementsCount ( ) const
inline

◆ GetElementsRef()

CVarVector::Elements & imath::CVarVector::GetElementsRef ( )
inline

Get access to internal element container.

Definition at line 467 of file CVarVector.h.

◆ GetElementsSum()

double imath::CVarVector::GetElementsSum ( ) const

Get simple sum of all elements.

◆ GetLength()

double imath::CVarVector::GetLength ( ) const
inline

Return euclidian length.

Definition at line 534 of file CVarVector.h.

References GetLength2().

◆ GetLength2()

double imath::CVarVector::GetLength2 ( ) const
inline

Return euclidean length square.

Definition at line 528 of file CVarVector.h.

References GetDotProduct().

Referenced by GetLength(), and IsNull().

◆ GetMaximal()

void imath::CVarVector::GetMaximal ( const CVarVector vector,
CVarVector result 
) const

Get vector with maximal elements values.

◆ GetMinimal()

void imath::CVarVector::GetMinimal ( const CVarVector vector,
CVarVector result 
) const

Get vector with minimal elements values.

◆ GetNormalized()

bool imath::CVarVector::GetNormalized ( CVarVector result,
double  length = 1.0 
) const

Return normalized vector with the same direction and specified length.

Parameters
lengthnew vector length.
Returns
true, if normalization succeeded.

◆ GetTranslated() [1/2]

CVarVector imath::CVarVector::GetTranslated ( const CVarVector vector)
inline

Get translated point.

Definition at line 484 of file CVarVector.h.

◆ GetTranslated() [2/2]

void imath::CVarVector::GetTranslated ( const CVarVector vector,
CVarVector result 
)
inline

/overloaded

Definition at line 490 of file CVarVector.h.

◆ IsEmpty()

bool imath::CVarVector::IsEmpty ( ) const
inline

Get true, if the element ist is empty.

Definition at line 381 of file CVarVector.h.

◆ IsNull()

bool imath::CVarVector::IsNull ( double  tolerance = I_BIG_EPSILON) const
inline

Check if this vector is null.

Definition at line 507 of file CVarVector.h.

References GetLength2().

◆ Normalize()

bool imath::CVarVector::Normalize ( double  length = 1.0)

Normalize vector to specified length.

Parameters
lengthnew vector length.
Returns
true, if normalization succeeded.

◆ operator!=()

bool imath::CVarVector::operator!= ( const CVarVector vector) const
inline

Definition at line 571 of file CVarVector.h.

References operator==().

◆ operator*()

CVarVector imath::CVarVector::operator* ( double  scalar) const
inline

Definition at line 736 of file CVarVector.h.

◆ operator*=()

CVarVector & imath::CVarVector::operator*= ( double  scalar)
inline

Definition at line 671 of file CVarVector.h.

References GetElementsCount().

Referenced by icmm::CVarColor::operator*=().

◆ operator+()

CVarVector imath::CVarVector::operator+ ( const CVarVector vector) const
inline

Definition at line 716 of file CVarVector.h.

◆ operator+=()

CVarVector & imath::CVarVector::operator+= ( const CVarVector vector)
inline

Definition at line 645 of file CVarVector.h.

References GetElementsCount().

◆ operator-() [1/2]

CVarVector imath::CVarVector::operator- ( ) const
inline

Definition at line 702 of file CVarVector.h.

References GetElementsCount().

◆ operator-() [2/2]

CVarVector imath::CVarVector::operator- ( const CVarVector vector) const
inline

Definition at line 726 of file CVarVector.h.

◆ operator-=()

CVarVector & imath::CVarVector::operator-= ( const CVarVector vector)
inline

Definition at line 658 of file CVarVector.h.

References GetElementsCount().

◆ operator/()

CVarVector imath::CVarVector::operator/ ( double  scalar) const
inline

Definition at line 746 of file CVarVector.h.

◆ operator/=()

CVarVector & imath::CVarVector::operator/= ( double  scalar)
inline

Definition at line 682 of file CVarVector.h.

References GetElementsCount().

Referenced by icmm::CVarColor::operator/=().

◆ operator<()

bool imath::CVarVector::operator< ( const CVarVector vector) const
inline

Definition at line 577 of file CVarVector.h.

◆ operator<=()

bool imath::CVarVector::operator<= ( const CVarVector vector) const
inline

Definition at line 611 of file CVarVector.h.

◆ operator=()

CVarVector & imath::CVarVector::operator= ( const CVarVector vector)
inline

Definition at line 693 of file CVarVector.h.

References GetElementsCount(), SetElementsCount(), and SetElementsFrom().

◆ operator==()

bool imath::CVarVector::operator== ( const CVarVector vector) const
inline

Definition at line 554 of file CVarVector.h.

Referenced by operator!=().

◆ operator>()

bool imath::CVarVector::operator> ( const CVarVector vector) const
inline

Definition at line 594 of file CVarVector.h.

◆ operator>=()

bool imath::CVarVector::operator>= ( const CVarVector vector) const
inline

Definition at line 628 of file CVarVector.h.

◆ operator[]() [1/2]

double & imath::CVarVector::operator[] ( int  i)
inline

Definition at line 765 of file CVarVector.h.

References GetElementsCount().

◆ operator[]() [2/2]

double imath::CVarVector::operator[] ( int  i) const
inline

Definition at line 756 of file CVarVector.h.

References GetElementsCount().

Referenced by GetElement(), GetElementRef(), and SetElement().

◆ Reset() [1/2]

void imath::CVarVector::Reset ( )
inline

Set size to zero.

Definition at line 436 of file CVarVector.h.

◆ Reset() [2/2]

void imath::CVarVector::Reset ( int  elementsCount,
double  value 
)
inline

Set number of elements and set all elements to specified value.

Definition at line 451 of file CVarVector.h.

◆ ScaledCumulate()

void imath::CVarVector::ScaledCumulate ( const CVarVector vector,
double  scale 
)
inline

Add second vector scaled by specified factor.

It is equal of Translate(vector * scale) but can be faster implemented.

Definition at line 496 of file CVarVector.h.

References GetElementsCount().

◆ Serialize()

bool imath::CVarVector::Serialize ( iser::IArchive archive)

Serialize this vector to specified archive.

◆ SetAllElements()

void imath::CVarVector::SetAllElements ( double  value)
inline

Set some value to all elements.

Definition at line 427 of file CVarVector.h.

References GetElementsCount().

◆ SetElement()

void imath::CVarVector::SetElement ( int  index,
double  value 
)
inline

Set element at specified index.

Definition at line 421 of file CVarVector.h.

References operator[]().

Referenced by icmm::CVarColor::operator*(), and icmm::CVarColor::operator/().

◆ SetElementsCount()

bool imath::CVarVector::SetElementsCount ( int  count,
double  value = 0 
)
inline

Set number of elements.

Returns
always true, this value is provided for template implementations.

Definition at line 393 of file CVarVector.h.

Referenced by operator=().

◆ SetElementsFrom()

void imath::CVarVector::SetElementsFrom ( const CVarVector vector,
double  expansionValue = 0 
)

Set elements from other vector without resizing.

Parameters
vectorsource of element values will be copied.
expansionValueif actual vector has more elements than vector, rest will be replaced with this value.

Referenced by operator=().

◆ Translate()

void imath::CVarVector::Translate ( const CVarVector vector)
inline

Translate the point.

Definition at line 473 of file CVarVector.h.

References GetElementsCount().


The documentation for this class was generated from the following file: