ITK  4.6.0
Insight Segmentation and Registration Toolkit
Public Types | Public Member Functions | Private Attributes | List of all members
itk::VariableLengthVector< TValue > Class Template Reference

#include <itkVariableLengthVector.h>

Detailed Description

template<typename TValue>
class itk::VariableLengthVector< TValue >

Represents an array whose length can be defined at run-time.

This class is templated over the data type. This data-type is meant to be a scalar, such as float, double etc...

Note
ITK itself provides several classes that can serve as Arrays.
  • FixedArray - Compile time fixed length arrays that's intended to represent an enumerated collection of n entities.
  • Array - Run time resizeable array that is intended to hold a collection of n entities
  • Vector - Compile time fixed length array that is intended to hold a collection of n data types. A vector usually has a mathematical meaning. It should only be used when mathematical operations such as addition, multiplication by a scalar, product etc make sense.
  • VariableLengthVector - Run time array that is intended to hold a collection of scalar data types. Again, it should be used only when mathematical operations on it are relevant. If not, use an Array.
  • Point - Represents the spatial coordinates of a spatial location. Operators on Point reflect geometrical concepts.
For the reasons listed above, you cannot instantiate
VariableLengthVector< bool >
.
Design Considerations: We do not derive from vnl_vector to avoid being limited by the explicit template instantiations of vnl_vector and other hacks that vnl folks have been forced to use.
Note
This work is part of the National Alliance for Medical Image Computing (NAMIC), funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB005149.
See Also
CovariantVector
SymmetricSecondRankTensor
RGBPixel
DiffusionTensor3D
Wiki Examples:

Definition at line 76 of file itkVariableLengthVector.h.

Public Types

typedef TValue ComponentType
 
typedef unsigned int ElementIdentifier
 
typedef NumericTraits
< ValueType >::RealType 
RealValueType
 
typedef VariableLengthVector Self
 
typedef TValue ValueType
 

Public Member Functions

TValue * AllocateElements (ElementIdentifier size) const
 
void DestroyExistingData ()
 
void Fill (TValue const &v)
 
const TValue * GetDataPointer () const
 
const TValue & GetElement (unsigned int i) const
 
RealValueType GetNorm () const
 
unsigned int GetSize (void) const
 
RealValueType GetSquaredNorm () const
 
bool operator!= (const Self &v) const
 
Selfoperator- ()
 
const Selfoperator= (const Self &v)
 
const Selfoperator= (TValue const &v)
 
bool operator== (const Self &v) const
 
TValue & operator[] (unsigned int i)
 
TValue const & operator[] (unsigned int i) const
 
void Reserve (ElementIdentifier)
 
void SetData (TValue *data, bool LetArrayManageMemory=false)
 
void SetData (TValue *data, unsigned int sz, bool LetArrayManageMemory=false)
 
void SetElement (unsigned int i, const TValue &value)
 
void SetSize (unsigned int sz, bool destroyExistingData=true)
 
 VariableLengthVector ()
 
 VariableLengthVector (unsigned int dimension)
 
 VariableLengthVector (ValueType *data, unsigned int sz, bool LetArrayManageMemory=false)
 
 VariableLengthVector (const ValueType *data, unsigned int sz, bool LetArrayManageMemory=false)
 
 VariableLengthVector (const VariableLengthVector< TValue > &v)
 
 ~VariableLengthVector ()
 
template<typename T >
 VariableLengthVector (const VariableLengthVector< T > &v)
 
template<typename T >
const VariableLengthVector
< TValue > & 
operator= (const VariableLengthVector< T > &v)
 
unsigned int Size (void) const
 
unsigned int GetNumberOfElements (void) const
 
template<typename T >
Self operator+ (const VariableLengthVector< T > &v) const
 
template<typename T >
Self operator- (const VariableLengthVector< T > &v) const
 
template<typename T >
Self operator* (T s) const
 
template<typename T >
Self operator/ (T s) const
 
Self operator+ (TValue s) const
 
Self operator- (TValue s) const
 
Selfoperator-- ()
 
Selfoperator++ ()
 
Self operator-- (int)
 
Self operator++ (int)
 
template<typename T >
Selfoperator-= (const VariableLengthVector< T > &v)
 
Selfoperator-= (TValue s)
 
template<typename T >
Selfoperator+= (const VariableLengthVector< T > &v)
 
Selfoperator+= (TValue s)
 
template<typename T >
Selfoperator*= (T s)
 
template<typename T >
Selfoperator/= (T s)
 

Private Attributes

TValue * m_Data
 
bool m_LetArrayManageMemory
 
ElementIdentifier m_NumElements
 

Member Typedef Documentation

template<typename TValue>
typedef TValue itk::VariableLengthVector< TValue >::ComponentType

Definition at line 82 of file itkVariableLengthVector.h.

template<typename TValue>
typedef unsigned int itk::VariableLengthVector< TValue >::ElementIdentifier

Typedef used to indicate the number of elements in the vector

Definition at line 87 of file itkVariableLengthVector.h.

template<typename TValue>
typedef NumericTraits< ValueType >::RealType itk::VariableLengthVector< TValue >::RealValueType

Definition at line 83 of file itkVariableLengthVector.h.

template<typename TValue>
typedef VariableLengthVector itk::VariableLengthVector< TValue >::Self

Definition at line 84 of file itkVariableLengthVector.h.

template<typename TValue>
typedef TValue itk::VariableLengthVector< TValue >::ValueType

The element type stored at each location in the Array.

Definition at line 81 of file itkVariableLengthVector.h.

Constructor & Destructor Documentation

template<typename TValue>
itk::VariableLengthVector< TValue >::VariableLengthVector ( )

Default constructor. It is created with an empty array it has to be allocated later by assignment

template<typename TValue>
itk::VariableLengthVector< TValue >::VariableLengthVector ( unsigned int  dimension)
explicit

Constructor with size. Size can only be changed by assignment

template<typename TValue>
itk::VariableLengthVector< TValue >::VariableLengthVector ( ValueType data,
unsigned int  sz,
bool  LetArrayManageMemory = false 
)

Constructor that initializes array with contents from a user supplied buffer. The pointer to the buffer and the length is specified. By default, the array does not manage the memory of the buffer. It merely points to that location and it is the user's responsibility to delete it. If "LetArrayManageMemory" is true, then this class will free the memory when this object is destroyed.

template<typename TValue>
itk::VariableLengthVector< TValue >::VariableLengthVector ( const ValueType data,
unsigned int  sz,
bool  LetArrayManageMemory = false 
)

Constructor that initializes array with contents from a user supplied buffer. The pointer to the buffer and the length is specified. By default, the array does not manage the memory of the buffer. It merely points to that location and it is the user's responsibility to delete it. If "LetArrayManageMemory" is true, then this class will free the memory when this object is destroyed.

template<typename TValue>
template<typename T >
itk::VariableLengthVector< TValue >::VariableLengthVector ( const VariableLengthVector< T > &  v)
inline

Copy constructor. The reason why the copy constructor and the assignment operator are templated is that it will allow implicit casts to be performed. For instance

* VariableLengthVector< int > vI;
* VariableLengthVector< float > vF( vI );
* or for instance vF = static_cast< VariableLengthVector< float > >( vI );
*

Definition at line 124 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::AllocateElements(), itk::VariableLengthVector< TValue >::m_Data, itk::VariableLengthVector< TValue >::m_LetArrayManageMemory, itk::VariableLengthVector< TValue >::m_NumElements, and itk::VariableLengthVector< TValue >::Size().

template<typename TValue>
itk::VariableLengthVector< TValue >::VariableLengthVector ( const VariableLengthVector< TValue > &  v)

Copy constructer.. Override the default non-templated copy constructor that the compiler provides

template<typename TValue>
itk::VariableLengthVector< TValue >::~VariableLengthVector ( )

This destructor is not virtual for performance reasons. However, this means that subclasses cannot allocate memory.

Member Function Documentation

template<typename TValue>
TValue* itk::VariableLengthVector< TValue >::AllocateElements ( ElementIdentifier  size) const

Allocate memory of certain size and return it.

Referenced by itk::VariableLengthVector< TValue >::VariableLengthVector().

template<typename TValue>
void itk::VariableLengthVector< TValue >::DestroyExistingData ( )

Destroy data that is allocated internally, if LetArrayManageMemory is true.

template<typename TValue>
void itk::VariableLengthVector< TValue >::Fill ( TValue const &  v)
template<typename TValue>
const TValue* itk::VariableLengthVector< TValue >::GetDataPointer ( ) const
inline
template<typename TValue>
const TValue& itk::VariableLengthVector< TValue >::GetElement ( unsigned int  i) const
inline

Get one element

Definition at line 179 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data.

template<typename TValue>
RealValueType itk::VariableLengthVector< TValue >::GetNorm ( ) const
template<typename TValue>
unsigned int itk::VariableLengthVector< TValue >::GetNumberOfElements ( void  ) const
inline

Return the number of elements in the Array

Definition at line 169 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
unsigned int itk::VariableLengthVector< TValue >::GetSize ( void  ) const
inline
template<typename TValue>
RealValueType itk::VariableLengthVector< TValue >::GetSquaredNorm ( ) const

Returns vector's squared Euclidean Norm

template<typename TValue>
bool itk::VariableLengthVector< TValue >::operator!= ( const Self v) const
template<typename TValue>
template<typename T >
Self itk::VariableLengthVector< TValue >::operator* ( s) const
inline

Multiply vector elements by a scalar 's'. The vector does not have to have the same element type as the scalar type. The scalar is cast to the output vector element type before the multiplication is performed.

Definition at line 295 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
template<typename T >
Self& itk::VariableLengthVector< TValue >::operator*= ( s)
inline

Multiply each element of the vector by a scalar 's'. The scalar value is cast to the current vector element type prior to multiplication.

Definition at line 456 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
template<typename T >
Self itk::VariableLengthVector< TValue >::operator+ ( const VariableLengthVector< T > &  v) const
inline

Element-wise vector addition. The vectors do not have to have the same element type. The input vector elements are cast to the output vector element type before the addition is performed.

Note
For efficiency, the length of the vectors is not checked; they are assumed to have the same length.

Definition at line 244 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::Size().

template<typename TValue>
Self itk::VariableLengthVector< TValue >::operator+ ( TValue  s) const
inline

Add scalar 's' to each element of the vector.

Definition at line 325 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
Self& itk::VariableLengthVector< TValue >::operator++ ( )
inline

Prefix operator that adds 1 to each element of the vector.

Definition at line 361 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
Self itk::VariableLengthVector< TValue >::operator++ ( int  )
inline

Postfix operator that adds 1 to each element of the vector.

Definition at line 383 of file itkVariableLengthVector.h.

template<typename TValue>
template<typename T >
Self& itk::VariableLengthVector< TValue >::operator+= ( const VariableLengthVector< T > &  v)
inline

Element-wise addition of vector 'v' to the current vector. The vectors do not have to have the same element type. The input vector elements are cast to the current vector element type before the addition is performed.

Note
For efficiency, the length of the vectors is not checked; they are assumed to have the same length.

Definition at line 431 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
Self& itk::VariableLengthVector< TValue >::operator+= ( TValue  s)
inline

Add scalar 's' to each element of the vector.

Definition at line 442 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
template<typename T >
Self itk::VariableLengthVector< TValue >::operator- ( const VariableLengthVector< T > &  v) const
inline

Element-wise subtraction of vectors. The vectors do not have to have the same element type. The input vector elements are cast to the output vector element type before the subtraction is performed.

Note
For efficiency, the length of the vectors is not checked; they are assumed to have the same length.

Definition at line 271 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::Size().

template<typename TValue>
Self itk::VariableLengthVector< TValue >::operator- ( TValue  s) const
inline

Subtract scalar 's' from each element of the vector.

Definition at line 337 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
Self& itk::VariableLengthVector< TValue >::operator- ( )

Negates each vector element.

template<typename TValue>
Self& itk::VariableLengthVector< TValue >::operator-- ( )
inline

Prefix operator that subtracts 1 from each element of the vector.

Definition at line 350 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
Self itk::VariableLengthVector< TValue >::operator-- ( int  )
inline

Postfix operator that subtracts 1 from each element of the vector.

Definition at line 373 of file itkVariableLengthVector.h.

template<typename TValue>
template<typename T >
Self& itk::VariableLengthVector< TValue >::operator-= ( const VariableLengthVector< T > &  v)
inline

Element-wise subtraction of vector 'v' from the current vector. The vectors do not have to have the same element type. The input vector elements are cast to the current vector element type before the subtraction is performed.

Note
For efficiency, the length of the vectors is not checked; they are assumed to have the same length.

Definition at line 401 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
Self& itk::VariableLengthVector< TValue >::operator-= ( TValue  s)
inline

Subtract scalar 's' from each element of the current vector.

Definition at line 412 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
template<typename T >
Self itk::VariableLengthVector< TValue >::operator/ ( s) const
inline

Divide vector elements by a scalar 's'. The vector does not have to have the same element type as the scalar type. Both the scalar and vector elements are cast to the RealValueType prior to division, and the result is cast to the ValueType.

Definition at line 311 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
template<typename T >
Self& itk::VariableLengthVector< TValue >::operator/= ( s)
inline

Divide vector elements by a scalar 's'. The vector does not have to have the same element type as the scalar type. Both the scalar and vector elements are cast to the RealValueType prior to division, and the result is cast to the ValueType.

Definition at line 471 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data, and itk::VariableLengthVector< TValue >::m_NumElements.

template<typename TValue>
template<typename T >
const VariableLengthVector< TValue >& itk::VariableLengthVector< TValue >::operator= ( const VariableLengthVector< T > &  v)
inline
template<typename TValue>
const Self& itk::VariableLengthVector< TValue >::operator= ( const Self v)

Assignment operators

template<typename TValue>
const Self& itk::VariableLengthVector< TValue >::operator= ( TValue const &  v)
template<typename TValue>
bool itk::VariableLengthVector< TValue >::operator== ( const Self v) const
template<typename TValue>
TValue& itk::VariableLengthVector< TValue >::operator[] ( unsigned int  i)
inline

Return reference to the element at specified index. No range checking.

Definition at line 173 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data.

template<typename TValue>
TValue const& itk::VariableLengthVector< TValue >::operator[] ( unsigned int  i) const
inline

Return reference to the element at specified index. No range checking.

Definition at line 176 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data.

template<typename TValue>
void itk::VariableLengthVector< TValue >::Reserve ( ElementIdentifier  )

Reserves memory of a certain length.

If the array already contains data, the existing data is copied over and new space is allocated, if necessary. If the length to reserve is less than the current number of elements, then an appropriate number of elements are discarded.

template<typename TValue>
void itk::VariableLengthVector< TValue >::SetData ( TValue *  data,
bool  LetArrayManageMemory = false 
)

Set the pointer from which the data is imported. If "LetArrayManageMemory" is false, then the application retains the responsibility of freeing the memory for this data. If "LetArrayManageMemory" is true, then this class will free the memory when this object is destroyed.

Referenced by itk::MetaArrayReader::GetOutput().

template<typename TValue>
void itk::VariableLengthVector< TValue >::SetData ( TValue *  data,
unsigned int  sz,
bool  LetArrayManageMemory = false 
)

Similar to the previous method. In the above method, the size must be separately set prior to using user-supplied data. This introduces an unnecessary allocation step to be performed. This method avoids it and should be used to import data wherever possible to avoid this. Set the pointer from which the data is imported. If "LetArrayManageMemory" is false, then the application retains the responsibility of freeing the memory for this data. If "LetArrayManageMemory" is true, then this class will free the memory when this object is destroyed.

template<typename TValue>
void itk::VariableLengthVector< TValue >::SetElement ( unsigned int  i,
const TValue &  value 
)
inline

Set one element

Definition at line 182 of file itkVariableLengthVector.h.

References itk::VariableLengthVector< TValue >::m_Data.

template<typename TValue>
void itk::VariableLengthVector< TValue >::SetSize ( unsigned int  sz,
bool  destroyExistingData = true 
)

Set the size to that given.

If destroyExistingData is false: If the array already contains data, the existing data is copied over and new space is allocated, if necessary. If the length to reserve is less than the current number of elements, then an appropriate number of elements are discarded. If true, the size is set destructively to the length given. If the length is different from the current length, existing data will be lost. The default is true.

Referenced by itk::LinearInterpolateImageFunction< TInputImage, TCoordRep >::MakeZeroInitializer(), itk::VariableLengthVector< TValue >::operator=(), and itk::NumericTraits< VariableLengthVector< T > >::SetLength().

template<typename TValue>
unsigned int itk::VariableLengthVector< TValue >::Size ( void  ) const
inline

Member Data Documentation

template<typename TValue>
TValue* itk::VariableLengthVector< TValue >::m_Data
private
template<typename TValue>
bool itk::VariableLengthVector< TValue >::m_LetArrayManageMemory
private
template<typename TValue>
ElementIdentifier itk::VariableLengthVector< TValue >::m_NumElements
private

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