PolyVox
0.2.1
Open source voxel management library
|
Represents a vector in space. More...
#include <Vector.h>
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. |
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:
PolyVox::Vector< Size, Type >::Vector | ( | Type | x, |
Type | y | ||
) |
Constructor.
Creates a Vector object and initialises it with given values.
x | x component to set. |
y | y component to set. |
Definition at line 33 of file Vector.inl.
PolyVox::Vector< Size, Type >::Vector | ( | Type | x, |
Type | y, | ||
Type | z | ||
) |
Constructor.
Creates a Vector3D object and initialises it with given values.
x | x component to set. |
y | y component to set. |
z | z component to set. |
Definition at line 47 of file Vector.inl.
PolyVox::Vector< Size, Type >::Vector | ( | Type | x, |
Type | y, | ||
Type | z, | ||
Type | w | ||
) |
Constructor.
Creates a Vector3D object and initialises it with given values.
x | x component to set. |
y | y component to set. |
z | z component to set. |
w | w component to set. |
Definition at line 63 of file Vector.inl.
PolyVox::Vector< Size, Type >::Vector | ( | void | ) |
Constructor.
Creates a Vector object but does not initialise it.
Definition at line 75 of file Vector.inl.
PolyVox::Vector< Size, Type >::Vector | ( | const Vector< Size, Type > & | vector | ) |
Copy Constructor.
Copy constructor builds object based on object passed as parameter.
vector | A reference to the Vector to be copied. |
Definition at line 84 of file Vector.inl.
|
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
vector | A reference to the Vector to be copied. |
Definition at line 100 of file Vector.inl.
PolyVox::Vector< Size, Type >::~Vector | ( | void | ) |
|
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.
vector | The Vector to find the angle to. |
Definition at line 552 of file Vector.inl.
|
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.
vector | The vector to cross with this |
Definition at line 570 of file Vector.inl.
|
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).
rhs | The Vector to find the dot product with. |
Definition at line 586 of file Vector.inl.
|
inline |
Element Access.
Returns the element at the given position.
index | The index of the element to return. |
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().
|
inline |
Get the w component of the vector.
Definition at line 423 of file Vector.inl.
|
inline |
Get the x component of the 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().
|
inline |
Get the y component of the 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().
|
inline |
Get the z component of the 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().
|
inline |
Get the length of the vector.
Definition at line 523 of file Vector.inl.
Referenced by PolyVox::Vector< Size, Type >::angleTo().
|
inline |
Get the squared length of the vector.
Definition at line 532 of file Vector.inl.
|
inline |
Normalise the vector.
Divides the i, j, and k components by the length to give a Vector of length 1.0.
Definition at line 602 of file Vector.inl.
|
inline |
Inequality Operator.
Checks whether two Vectors are not equal.
rhs | The Vector to compare to. |
Definition at line 160 of file Vector.inl.
|
inline |
Multiplication and Assignment Operator.
Multiplication operator multiplies corresponding elements of the two Vectors.
rhs | Vector to multiply by |
Definition at line 221 of file Vector.inl.
|
inline |
Multiplication and Assignment Operator.
Multiplication operator multiplies each element of the Vector by a number.
rhs | the number the Vector is multiplied by. |
Definition at line 251 of file Vector.inl.
|
inline |
Addition and Assignment Operator.
Addition operator adds corresponding elements of the two Vectors.
rhs | Vector to add |
Definition at line 191 of file Vector.inl.
|
inline |
Subtraction and Assignment Operator.
Subtraction operator subtracts corresponding elements of one Vector from the other.
rhs | Vector to subtract |
Definition at line 206 of file Vector.inl.
|
inline |
Division and Assignment Operator.
Division operator divides corresponding elements of one Vector by the other.
rhs | Vector to divide by |
Definition at line 236 of file Vector.inl.
|
inline |
Division and Assignment Operator.
Division operator divides each element of the Vector by a number.
rhs | the number the Vector is divided by. |
Definition at line 266 of file Vector.inl.
|
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.
rhs | The Vector to compare to. |
Definition at line 173 of file Vector.inl.
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.
rhs | Vector to assign to. |
Definition at line 122 of file Vector.inl.
|
inline |
Equality Operator.
Checks whether two Vectors are equal.
rhs | The Vector to compare to. |
Definition at line 139 of file Vector.inl.
|
inline |
Element Access.
index | The index of the element to set. |
tValue | The new value for the element. |
Definition at line 433 of file Vector.inl.
Referenced by PolyVox::LargeVolume< VoxelType >::flush(), and PolyVox::LargeVolume< VoxelType >::prefetch().
|
inline |
Element Access.
Sets several elements of a vector at once.
x | x component to set. |
y | y component to set. |
Definition at line 444 of file Vector.inl.
|
inline |
Element Access.
Sets several elements of a vector at once.
x | x component to set. |
y | y component to set. |
z | z component to set. |
Definition at line 458 of file Vector.inl.
|
inline |
Element Access.
Sets several elements of a vector at once.
x | x component to set. |
y | y component to set. |
z | z component to set. |
w | w component to set. |
Definition at line 474 of file Vector.inl.
|
inline |
Set the w component of the vector.
tW | The new value for the W component of a 4 dimensional Vector. |
Definition at line 513 of file Vector.inl.
|
inline |
Set the x component of the vector.
tX | The 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().
|
inline |
Set the y component of the vector.
tY | The 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().
|
inline |
Set the z component of the vector.
tZ | The 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().