PolyVox  0.2.1
Open source voxel management library
Public Member Functions
PolyVox::Vector< Size, Type > Class Template Reference

Represents a vector in space. More...

#include <Vector.h>

+ Inheritance diagram for PolyVox::Vector< Size, Type >:

List of all members.

Public Member Functions

 Vector (Type x, Type y)
 Constructor.
 Vector (Type x, Type y, Type z)
 Constructor.
 Vector (Type x, Type y, Type z, Type w)
 Constructor.
 Vector (void)
 Constructor.
 Vector (const Vector< Size, Type > &vector)
 Copy Constructor.
template<typename CastType >
 Vector (const Vector< Size, CastType > &vector)
 Copy Constructor which performs casting.
 ~Vector (void)
 Destructor.
Vector< Size, Type > & operator= (const Vector< Size, Type > &rhs)
 Assignment Operator.
bool operator== (const Vector< Size, Type > &rhs) const
 Equality Operator.
bool operator!= (const Vector< Size, Type > &rhs) const
 Inequality Operator.
bool operator< (const Vector< Size, Type > &rhs) const
 Comparison Operator.
Vector< Size, Type > & operator+= (const Vector< Size, Type > &rhs)
 Addition and Assignment Operator.
Vector< Size, Type > & operator-= (const Vector< Size, Type > &rhs)
 Subtraction and Assignment Operator.
Vector< Size, Type > & operator*= (const Vector< Size, Type > &rhs)
 Multiplication and Assignment Operator.
Vector< Size, Type > & operator/= (const Vector< Size, Type > &rhs)
 Division and Assignment Operator.
Vector< Size, Type > & operator*= (const Type &rhs)
 Multiplication and Assignment Operator.
Vector< Size, Type > & operator/= (const Type &rhs)
 Division and Assignment Operator.
Type getElement (uint32_t index) const
 Element Access.
Type getX (void) const
 Get the x component of the vector.
Type getY (void) const
 Get the y component of the vector.
Type getZ (void) const
 Get the z component of the vector.
Type getW (void) const
 Get the w component of the vector.
void setElement (uint32_t index, Type tValue)
 Element Access.
void setElements (Type x, Type y)
 Element Access.
void setElements (Type x, Type y, Type z)
 Element Access.
void setElements (Type x, Type y, Type z, Type w)
 Element Access.
void setX (Type tX)
 Set the x component of the vector.
void setY (Type tY)
 Set the y component of the vector.
void setZ (Type tZ)
 Set the z component of the vector.
void setW (Type tW)
 Set the w component of the vector.
double length (void) const
 Get the length of the vector.
double lengthSquared (void) const
 Get the squared length of the vector.
double angleTo (const Vector< Size, Type > &vector) const
 Find the angle between this vector and that which is passed as a parameter.
Vector< Size, Type > cross (const Vector< Size, Type > &vector) const
 Find the cross product between this vector and the vector passed as a parameter.
Type dot (const Vector< Size, Type > &rhs) const
 Find the dot product between this vector and the vector passed as a parameter.
void normalise (void)
 Normalise the vector.

Detailed Description

template<uint32_t Size, typename Type>
class PolyVox::Vector< Size, Type >

Represents a vector in space.

This Vector class is templated on both size and data type. It is designed to be generic but so far had only been tested with vectors of size 2 and 3. Also note that some of the operations do not make sense with integer types, for example it does not make conceptual sense to try and normalise an integer Vector.

The elements of the Vector are accessed via the overloaded () operator which takes an index indicating the element to fetch. They are set using the set() function which takes an index indicating the element to set and a new value for that element. For convienience, the functions getX(), setX(), getY(), setY(), getZ(), setZ(), getw() and setW() do the same thing for the first 4 elements of the Vector.

A variety of overloaded operators are also provided for comparison and arithmetic operations. For most of these arithmetic operators only the unary versions are documented below - however often binary versions are also generated by std::operators.

Lastly, note that for convienience a set of typedefs are included for 2 and 3 dimensional vectors with type float, double, int32_t, and uint32_t. They are used as follows:

Vector2DInt4 test(1,2); //Declares a 2 dimensional Vector of type int4.

Definition at line 62 of file Vector.h.


Constructor & Destructor Documentation

template<uint32_t Size, typename Type>
PolyVox::Vector< Size, Type >::Vector ( Type  x,
Type  y 
)

Constructor.

Creates a Vector object and initialises it with given values.

Parameters:
xx component to set.
yy component to set.

Definition at line 33 of file Vector.inl.

template<uint32_t Size, typename Type>
PolyVox::Vector< Size, Type >::Vector ( Type  x,
Type  y,
Type  z 
)

Constructor.

Creates a Vector3D object and initialises it with given values.

Parameters:
xx component to set.
yy component to set.
zz component to set.

Definition at line 47 of file Vector.inl.

template<uint32_t Size, typename Type>
PolyVox::Vector< Size, Type >::Vector ( Type  x,
Type  y,
Type  z,
Type  w 
)

Constructor.

Creates a Vector3D object and initialises it with given values.

Parameters:
xx component to set.
yy component to set.
zz component to set.
ww component to set.

Definition at line 63 of file Vector.inl.

template<uint32_t Size, typename Type>
PolyVox::Vector< Size, Type >::Vector ( void  )

Constructor.

Creates a Vector object but does not initialise it.

Definition at line 75 of file Vector.inl.

template<uint32_t Size, typename Type>
PolyVox::Vector< Size, Type >::Vector ( const Vector< Size, Type > &  vector)

Copy Constructor.

Copy constructor builds object based on object passed as parameter.

Parameters:
vectorA reference to the Vector to be copied.

Definition at line 84 of file Vector.inl.

template<uint32_t Size, typename Type >
template<typename CastType >
PolyVox::Vector< Size, Type >::Vector ( const Vector< Size, CastType > &  vector)
explicit

Copy Constructor which performs casting.

This copy constructor allows casting between vectors with different data types.

It is now possible to use code such as:

Vector3DDouble v3dDouble(1.0,2.0,3.0); Vector3DFloat v3dFloat = static_cast<Vector3DFloat>(v3dDouble); //Casting

Parameters:
vectorA reference to the Vector to be copied.

Definition at line 100 of file Vector.inl.

+ Here is the call graph for this function:

template<uint32_t Size, typename Type >
PolyVox::Vector< Size, Type >::~Vector ( void  )

Destructor.

Destroys the Vector.

Definition at line 112 of file Vector.inl.


Member Function Documentation

template<uint32_t Size, typename Type>
double PolyVox::Vector< Size, Type >::angleTo ( const Vector< Size, Type > &  vector) const
inline

Find the angle between this vector and that which is passed as a parameter.

This function is commutative, such that a.angleTo(b) == b.angleTo(a).

The angle returned is in radians and varies between 0 and 3.14(pi). It is always positive.

Note:
This function does not make much sense on integer Vectors.
Parameters:
vectorThe Vector to find the angle to.
Returns:
The angle between them in radians.

Definition at line 552 of file Vector.inl.

+ Here is the call graph for this function:

template<uint32_t Size, typename Type>
Vector< Size, Type > PolyVox::Vector< Size, Type >::cross ( const Vector< Size, Type > &  vector) const
inline

Find the cross product between this vector and the vector passed as a parameter.

This function is used to calculate the cross product of two Vectors.

The cross product is the Vector which is perpendicular to the two given Vectors. It is worth remembering that, unlike the dot product, it is not commutative. E.g a.b != b.a. The cross product obeys the right-hand rule such that if the two vectors are given by the index finger and middle finger respectively then the cross product is given by the thumb.

Parameters:
vectorThe vector to cross with this
Returns:
The value of the cross product.
See also:
dot()

Definition at line 570 of file Vector.inl.

+ Here is the call graph for this function:

template<uint32_t Size, typename Type>
Type PolyVox::Vector< Size, Type >::dot ( const Vector< Size, Type > &  rhs) const
inline

Find the dot product between this vector and the vector passed as a parameter.

Calculates the dot product of the Vector and the parameter.

This function is commutative, such that a.dot(b) == b.dot(a).

Parameters:
rhsThe Vector to find the dot product with.
Returns:
The value of the dot product.
See also:
cross()

Definition at line 586 of file Vector.inl.

template<uint32_t Size, typename Type >
Type PolyVox::Vector< Size, Type >::getElement ( uint32_t  index) const
inline

Element Access.

Returns the element at the given position.

Parameters:
indexThe index of the element to return.
Returns:
The element.

Definition at line 387 of file Vector.inl.

Referenced by PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::operator<<(), PolyVox::LargeVolume< VoxelType >::prefetch(), and PolyVox::Vector< Size, Type >::Vector().

template<uint32_t Size, typename Type >
Type PolyVox::Vector< Size, Type >::getW ( void  ) const
inline

Get the w component of the vector.

Returns:
A const reference to the W component of a 4 dimensional Vector.

Definition at line 423 of file Vector.inl.

template<uint32_t Size, typename Type >
Type PolyVox::Vector< Size, Type >::getX ( void  ) const
inline

Get the x component of the vector.

Returns:
A const reference to the X component of a 1, 2, 3, or 4 dimensional Vector.

Definition at line 396 of file Vector.inl.

Referenced by PolyVox::calculateAmbientOcclusion(), PolyVox::Region::containsPoint(), PolyVox::Region::containsPointInX(), PolyVox::Region::cropTo(), PolyVox::Vector< Size, Type >::cross(), PolyVox::LowPassFilter< SrcVolumeType, DstVolumeType, AccumulationType >::executeSAT(), PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::ConstVolumeProxy< VoxelType >::getVoxelAt(), PolyVox::Block< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::getVoxelAt(), PolyVox::LargeVolume< VoxelType >::getVoxelAt(), PolyVox::Region::getWidthInCells(), PolyVox::Node::operator<(), PolyVox::LargeVolume< VoxelType >::prefetch(), PolyVox::raycastWithEndpoints(), PolyVox::Region::Region(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::setPosition(), PolyVox::RawVolume< VoxelType >::Sampler::setPosition(), PolyVox::SimpleVolume< VoxelType >::Sampler::setPosition(), PolyVox::LargeVolume< VoxelType >::Sampler::setPosition(), PolyVox::ConstVolumeProxy< VoxelType >::setVoxelAt(), PolyVox::Block< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::setVoxelAt(), PolyVox::RawVolume< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::setVoxelAt(), and PolyVox::LargeVolume< VoxelType >::setVoxelAt().

template<uint32_t Size, typename Type >
Type PolyVox::Vector< Size, Type >::getY ( void  ) const
inline

Get the y component of the vector.

Returns:
A const reference to the Y component of a 2, 3, or 4 dimensional Vector.

Definition at line 405 of file Vector.inl.

Referenced by PolyVox::calculateAmbientOcclusion(), PolyVox::Region::containsPoint(), PolyVox::Region::containsPointInY(), PolyVox::Region::cropTo(), PolyVox::Vector< Size, Type >::cross(), PolyVox::LowPassFilter< SrcVolumeType, DstVolumeType, AccumulationType >::executeSAT(), PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::Region::getHeightInCells(), PolyVox::ConstVolumeProxy< VoxelType >::getVoxelAt(), PolyVox::Block< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::getVoxelAt(), PolyVox::LargeVolume< VoxelType >::getVoxelAt(), PolyVox::Node::operator<(), PolyVox::LargeVolume< VoxelType >::prefetch(), PolyVox::raycastWithEndpoints(), PolyVox::Region::Region(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::setPosition(), PolyVox::RawVolume< VoxelType >::Sampler::setPosition(), PolyVox::SimpleVolume< VoxelType >::Sampler::setPosition(), PolyVox::LargeVolume< VoxelType >::Sampler::setPosition(), PolyVox::ConstVolumeProxy< VoxelType >::setVoxelAt(), PolyVox::Block< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::setVoxelAt(), PolyVox::RawVolume< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::setVoxelAt(), and PolyVox::LargeVolume< VoxelType >::setVoxelAt().

template<uint32_t Size, typename Type >
Type PolyVox::Vector< Size, Type >::getZ ( void  ) const
inline

Get the z component of the vector.

Returns:
A const reference to the Z component of a 3 or 4 dimensional Vector.

Definition at line 414 of file Vector.inl.

Referenced by PolyVox::calculateAmbientOcclusion(), PolyVox::Region::containsPoint(), PolyVox::Region::containsPointInZ(), PolyVox::Region::cropTo(), PolyVox::Vector< Size, Type >::cross(), PolyVox::LowPassFilter< SrcVolumeType, DstVolumeType, AccumulationType >::executeSAT(), PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::Region::getDepthInCells(), PolyVox::ConstVolumeProxy< VoxelType >::getVoxelAt(), PolyVox::Block< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::getVoxelAt(), PolyVox::LargeVolume< VoxelType >::getVoxelAt(), PolyVox::Node::operator<(), PolyVox::LargeVolume< VoxelType >::prefetch(), PolyVox::raycastWithEndpoints(), PolyVox::Region::Region(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::setPosition(), PolyVox::RawVolume< VoxelType >::Sampler::setPosition(), PolyVox::SimpleVolume< VoxelType >::Sampler::setPosition(), PolyVox::LargeVolume< VoxelType >::Sampler::setPosition(), PolyVox::ConstVolumeProxy< VoxelType >::setVoxelAt(), PolyVox::Block< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::setVoxelAt(), PolyVox::RawVolume< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::setVoxelAt(), and PolyVox::LargeVolume< VoxelType >::setVoxelAt().

template<uint32_t Size, typename Type >
double PolyVox::Vector< Size, Type >::length ( void  ) const
inline

Get the length of the vector.

Note:
This function does not make much sense on integer Vectors.
Returns:
Length of the Vector.

Definition at line 523 of file Vector.inl.

Referenced by PolyVox::Vector< Size, Type >::angleTo().

template<uint32_t Size, typename Type >
double PolyVox::Vector< Size, Type >::lengthSquared ( void  ) const
inline

Get the squared length of the vector.

Returns:
Squared length of the Vector.

Definition at line 532 of file Vector.inl.

template<uint32_t Size, typename Type >
void PolyVox::Vector< Size, Type >::normalise ( void  )
inline

Normalise the vector.

Divides the i, j, and k components by the length to give a Vector of length 1.0.

Note:
This function does not make much sense on integer Vectors.

Definition at line 602 of file Vector.inl.

template<uint32_t Size, typename Type>
bool PolyVox::Vector< Size, Type >::operator!= ( const Vector< Size, Type > &  rhs) const
inline

Inequality Operator.

Checks whether two Vectors are not equal.

Parameters:
rhsThe Vector to compare to.
Returns:
true if the Vectors do not match.
See also:
operator==

Definition at line 160 of file Vector.inl.

template<uint32_t Size, typename Type>
Vector< Size, Type > & PolyVox::Vector< Size, Type >::operator*= ( const Vector< Size, Type > &  rhs)
inline

Multiplication and Assignment Operator.

Multiplication operator multiplies corresponding elements of the two Vectors.

Parameters:
rhsVector to multiply by
Returns:
The resulting Vector.

Definition at line 221 of file Vector.inl.

template<uint32_t Size, typename Type>
Vector< Size, Type > & PolyVox::Vector< Size, Type >::operator*= ( const Type &  rhs)
inline

Multiplication and Assignment Operator.

Multiplication operator multiplies each element of the Vector by a number.

Parameters:
rhsthe number the Vector is multiplied by.
Returns:
The resulting Vector.

Definition at line 251 of file Vector.inl.

template<uint32_t Size, typename Type>
Vector< Size, Type > & PolyVox::Vector< Size, Type >::operator+= ( const Vector< Size, Type > &  rhs)
inline

Addition and Assignment Operator.

Addition operator adds corresponding elements of the two Vectors.

Parameters:
rhsVector to add
Returns:
The resulting Vector.

Definition at line 191 of file Vector.inl.

template<uint32_t Size, typename Type>
Vector< Size, Type > & PolyVox::Vector< Size, Type >::operator-= ( const Vector< Size, Type > &  rhs)
inline

Subtraction and Assignment Operator.

Subtraction operator subtracts corresponding elements of one Vector from the other.

Parameters:
rhsVector to subtract
Returns:
The resulting Vector.

Definition at line 206 of file Vector.inl.

template<uint32_t Size, typename Type>
Vector< Size, Type > & PolyVox::Vector< Size, Type >::operator/= ( const Vector< Size, Type > &  rhs)
inline

Division and Assignment Operator.

Division operator divides corresponding elements of one Vector by the other.

Parameters:
rhsVector to divide by
Returns:
The resulting Vector.

Definition at line 236 of file Vector.inl.

template<uint32_t Size, typename Type>
Vector< Size, Type > & PolyVox::Vector< Size, Type >::operator/= ( const Type &  rhs)
inline

Division and Assignment Operator.

Division operator divides each element of the Vector by a number.

Parameters:
rhsthe number the Vector is divided by.
Returns:
The resulting Vector.

Definition at line 266 of file Vector.inl.

template<uint32_t Size, typename Type>
bool PolyVox::Vector< Size, Type >::operator< ( const Vector< Size, Type > &  rhs) const
inline

Comparison Operator.

Checks whether this vector is less than the parameter.

The metric is meaningless but it allows Vectors to me used as key in sdt::map, etc.

Parameters:
rhsThe Vector to compare to.
Returns:
true if this is less than the parameter
See also:
operator!=

Definition at line 173 of file Vector.inl.

template<uint32_t Size, typename Type>
Vector< Size, Type > & PolyVox::Vector< Size, Type >::operator= ( const Vector< Size, Type > &  rhs)

Assignment Operator.

Assignment operator copies each element of first Vector to the second.

Parameters:
rhsVector to assign to.
Returns:
A reference to the result to allow chaining.

Definition at line 122 of file Vector.inl.

template<uint32_t Size, typename Type>
bool PolyVox::Vector< Size, Type >::operator== ( const Vector< Size, Type > &  rhs) const
inline

Equality Operator.

Checks whether two Vectors are equal.

Parameters:
rhsThe Vector to compare to.
Returns:
true if the Vectors match.
See also:
operator!=

Definition at line 139 of file Vector.inl.

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setElement ( uint32_t  index,
Type  tValue 
)
inline

Element Access.

Parameters:
indexThe index of the element to set.
tValueThe new value for the element.

Definition at line 433 of file Vector.inl.

Referenced by PolyVox::LargeVolume< VoxelType >::flush(), and PolyVox::LargeVolume< VoxelType >::prefetch().

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setElements ( Type  x,
Type  y 
)
inline

Element Access.

Sets several elements of a vector at once.

Parameters:
xx component to set.
yy component to set.

Definition at line 444 of file Vector.inl.

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setElements ( Type  x,
Type  y,
Type  z 
)
inline

Element Access.

Sets several elements of a vector at once.

Parameters:
xx component to set.
yy component to set.
zz component to set.

Definition at line 458 of file Vector.inl.

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setElements ( Type  x,
Type  y,
Type  z,
Type  w 
)
inline

Element Access.

Sets several elements of a vector at once.

Parameters:
xx component to set.
yy component to set.
zz component to set.
ww component to set.

Definition at line 474 of file Vector.inl.

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setW ( Type  tW)
inline

Set the w component of the vector.

Parameters:
tWThe new value for the W component of a 4 dimensional Vector.

Definition at line 513 of file Vector.inl.

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setX ( Type  tX)
inline

Set the x component of the vector.

Parameters:
tXThe new value for the X component of a 1, 2, 3, or 4 dimensional Vector.

Definition at line 486 of file Vector.inl.

Referenced by PolyVox::Region::cropTo(), PolyVox::IteratorController< IteratorType >::moveForward(), and PolyVox::Node::Node().

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setY ( Type  tY)
inline

Set the y component of the vector.

Parameters:
tYThe new value for the Y component of a 2, 3, or 4 dimensional Vector.

Definition at line 495 of file Vector.inl.

Referenced by PolyVox::Region::cropTo(), and PolyVox::Node::Node().

template<uint32_t Size, typename Type>
void PolyVox::Vector< Size, Type >::setZ ( Type  tZ)
inline

Set the z component of the vector.

Parameters:
tZThe new value for the Z component of a 3 or 4 dimensional Vector.

Definition at line 504 of file Vector.inl.

Referenced by PolyVox::Region::cropTo(), PolyVox::MarchingCubesSurfaceExtractor< VolumeType, Controller >::execute(), and PolyVox::Node::Node().


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