PolyVox
0.3.0-dev
Open source voxel management library
|
Represents a vector in space. More...
#include <Vector.h>
Public Member Functions | |
Vector (void) | |
Constructor. | |
Vector (StorageType tFillValue) | |
Constructor. | |
Vector (StorageType x, StorageType y) | |
Constructor. | |
Vector (StorageType x, StorageType y, StorageType z) | |
Constructor. | |
Vector (StorageType x, StorageType y, StorageType z, StorageType w) | |
Constructor. | |
Vector (const Vector< Size, StorageType, OperationType > &vector) | |
Copy Constructor. | |
template<typename CastType > | |
Vector (const Vector< Size, CastType > &vector) | |
Copy Constructor which performs casting. | |
~Vector (void) | |
Destructor. | |
Vector< Size, StorageType, OperationType > & | operator= (const Vector< Size, StorageType, OperationType > &rhs) |
Assignment Operator. | |
bool | operator== (const Vector< Size, StorageType, OperationType > &rhs) const |
Equality Operator. | |
bool | operator!= (const Vector< Size, StorageType, OperationType > &rhs) const |
Inequality Operator. | |
bool | operator< (const Vector< Size, StorageType, OperationType > &rhs) const |
Comparison Operator. | |
Vector< Size, StorageType, OperationType > & | operator+= (const Vector< Size, StorageType, OperationType > &rhs) |
Addition and Assignment Operator. | |
Vector< Size, StorageType, OperationType > & | operator-= (const Vector< Size, StorageType, OperationType > &rhs) |
Subtraction and Assignment Operator. | |
Vector< Size, StorageType, OperationType > & | operator*= (const Vector< Size, StorageType, OperationType > &rhs) |
Multiplication and Assignment Operator. | |
Vector< Size, StorageType, OperationType > & | operator/= (const Vector< Size, StorageType, OperationType > &rhs) |
Division and Assignment Operator. | |
Vector< Size, StorageType, OperationType > & | operator*= (const StorageType &rhs) |
Multiplication and Assignment Operator. | |
Vector< Size, StorageType, OperationType > & | operator/= (const StorageType &rhs) |
Division and Assignment Operator. | |
StorageType | getElement (uint32_t index) const |
Element Access. | |
StorageType | getX (void) const |
Get the x component of the vector. | |
StorageType | getY (void) const |
Get the y component of the vector. | |
StorageType | getZ (void) const |
Get the z component of the vector. | |
StorageType | getW (void) const |
Get the w component of the vector. | |
void | setElement (uint32_t index, StorageType tValue) |
Element Access. | |
void | setElements (StorageType x, StorageType y) |
Element Access. | |
void | setElements (StorageType x, StorageType y, StorageType z) |
Element Access. | |
void | setElements (StorageType x, StorageType y, StorageType z, StorageType w) |
Element Access. | |
void | setX (StorageType tX) |
Set the x component of the vector. | |
void | setY (StorageType tY) |
Set the y component of the vector. | |
void | setZ (StorageType tZ) |
Set the z component of the vector. | |
void | setW (StorageType tW) |
Set the w component of the vector. | |
float | length (void) const |
Get the length of the vector. | |
OperationType | lengthSquared (void) const |
Get the squared length of the vector. | |
float | angleTo (const Vector< Size, StorageType, OperationType > &vector) const |
Find the angle between this vector and that which is passed as a parameter. | |
Vector< Size, StorageType, OperationType > | cross (const Vector< Size, StorageType, OperationType > &vector) const |
Find the cross product between this vector and the vector passed as a parameter. | |
OperationType | dot (const Vector< Size, StorageType, OperationType > &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 is a generl purpose vector class designed to represent both positions and directions. It is templatised on both size and data type but 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.
Every Vector must have at at least two elements, and the first four elements of any vector are known as the X, Y, Z and W elements. Note that W is last even though it comes before X in the alphabet. These elements can be accessed through getX(), setX(), getY(), setY(), getZ(), setZ(), getW() and setW(), while other elements can be accessed through getElemen() and setElement().
This class includes a number of common mathematical operations (addition, subtraction, etc) as well as vector specific operations such as the dot and cross products. Note that this class is also templatised on an OperationType which is used for many internal calculations and some results. For example, the square of a vector's length will always be an integer if all the elements are integers, but the value might be outside that which can be represented by the StorageType. You don't need to worry about this as long as you are using the built in typedefs for common configurations.
Typedefs are provided for 2, 3 and 4 dimensional vector with int8_t, uint8_t, int16_t, uint6_t, int32_t, uint32_t, float and double types. These typedefs are used as follows:
Vector< Size, StorageType, OperationType >::Vector | ( | void | ) |
Constructor.
Creates a Vector object but does not initialise it.
Definition at line 31 of file Vector.inl.
Vector< Size, StorageType, OperationType >::Vector | ( | StorageType | tFillValue | ) |
Constructor.
Creates a Vector object and initialises all components with the given value.
tFillValue | The value to write to every component. |
Definition at line 40 of file Vector.inl.
Vector< Size, StorageType, OperationType >::Vector | ( | StorageType | x, |
StorageType | y | ||
) |
Constructor.
Creates a Vector object and initialises it with given values.
x | The X component to set. |
y | The Y component to set. |
Definition at line 54 of file Vector.inl.
Vector< Size, StorageType, OperationType >::Vector | ( | StorageType | x, |
StorageType | y, | ||
StorageType | z | ||
) |
Constructor.
Creates a Vector3D object and initialises it with given values.
x | The X component to set. |
y | The Y component to set. |
z | the Z component to set. |
Definition at line 69 of file Vector.inl.
Vector< Size, StorageType, OperationType >::Vector | ( | StorageType | x, |
StorageType | y, | ||
StorageType | z, | ||
StorageType | w | ||
) |
Constructor.
Creates a Vector3D object and initialises it with given values.
x | The X component to set. |
y | The Y component to set. |
z | The Z component to set. |
w | The W component to set. |
Definition at line 87 of file Vector.inl.
Vector< Size, StorageType, OperationType >::Vector | ( | const Vector< Size, StorageType, OperationType > & | 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 102 of file Vector.inl.
|
explicit |
Copy Constructor which performs casting.
This copy constructor allows casting between vectors with different data types.
It makes it 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 118 of file Vector.inl.
|
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 593 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 611 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 627 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 415 of file Vector.inl.
Referenced by PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::operator<<(), PolyVox::LargeVolume< VoxelType >::prefetch(), and PolyVox::Vector< Size, StorageType, OperationType >::Vector().
|
inline |
Get the w component of the vector.
Definition at line 454 of file Vector.inl.
|
inline |
Get the x component of the vector.
Definition at line 425 of file Vector.inl.
Referenced by PolyVox::Region::accumulate(), PolyVox::computeDecimatedCentralDifferenceGradient(), PolyVox::computeSmoothCentralDifferenceGradient(), PolyVox::computeSmoothSobelGradient(), PolyVox::Region::containsPoint(), PolyVox::Vector< Size, StorageType, OperationType >::cross(), PolyVox::LowPassFilter< SrcVolumeType, DstVolumeType, AccumulationType >::executeSAT(), PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::RawVolume< VoxelType >::getVoxel(), PolyVox::SimpleVolume< VoxelType >::getVoxel(), PolyVox::LargeVolume< VoxelType >::getVoxel(), PolyVox::ConstVolumeProxy< VoxelType >::getVoxelAt(), PolyVox::Block< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::getVoxelAt(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::getVoxelAt(), PolyVox::LargeVolume< VoxelType >::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::SimpleVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::LargeVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::Region::grow(), PolyVox::Node::operator<(), PolyVox::LargeVolume< VoxelType >::prefetch(), PolyVox::raycastWithEndpoints(), PolyVox::Region::setLowerCorner(), PolyVox::RawVolume< VoxelType >::Sampler::setPosition(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::setPosition(), PolyVox::SimpleVolume< VoxelType >::Sampler::setPosition(), PolyVox::LargeVolume< VoxelType >::Sampler::setPosition(), PolyVox::Region::setUpperCorner(), PolyVox::ConstVolumeProxy< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::setVoxelAt(), PolyVox::Block< VoxelType >::setVoxelAt(), PolyVox::RawVolume< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::setVoxelAt(), PolyVox::LargeVolume< VoxelType >::setVoxelAt(), PolyVox::Region::shiftLowerCorner(), PolyVox::Region::shiftUpperCorner(), and PolyVox::Region::shrink().
|
inline |
Get the y component of the vector.
Definition at line 434 of file Vector.inl.
Referenced by PolyVox::Region::accumulate(), PolyVox::Region::containsPoint(), PolyVox::Vector< Size, StorageType, OperationType >::cross(), PolyVox::LowPassFilter< SrcVolumeType, DstVolumeType, AccumulationType >::executeSAT(), PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::RawVolume< VoxelType >::getVoxel(), PolyVox::SimpleVolume< VoxelType >::getVoxel(), PolyVox::LargeVolume< VoxelType >::getVoxel(), PolyVox::ConstVolumeProxy< VoxelType >::getVoxelAt(), PolyVox::Block< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::getVoxelAt(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::getVoxelAt(), PolyVox::LargeVolume< VoxelType >::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::SimpleVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::LargeVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::Region::grow(), PolyVox::Node::operator<(), PolyVox::LargeVolume< VoxelType >::prefetch(), PolyVox::raycastWithEndpoints(), PolyVox::Region::setLowerCorner(), PolyVox::RawVolume< VoxelType >::Sampler::setPosition(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::setPosition(), PolyVox::SimpleVolume< VoxelType >::Sampler::setPosition(), PolyVox::LargeVolume< VoxelType >::Sampler::setPosition(), PolyVox::Region::setUpperCorner(), PolyVox::ConstVolumeProxy< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::setVoxelAt(), PolyVox::Block< VoxelType >::setVoxelAt(), PolyVox::RawVolume< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::setVoxelAt(), PolyVox::LargeVolume< VoxelType >::setVoxelAt(), PolyVox::Region::shiftLowerCorner(), PolyVox::Region::shiftUpperCorner(), and PolyVox::Region::shrink().
|
inline |
Get the z component of the vector.
Definition at line 443 of file Vector.inl.
Referenced by PolyVox::Region::accumulate(), PolyVox::Region::containsPoint(), PolyVox::Vector< Size, StorageType, OperationType >::cross(), PolyVox::LowPassFilter< SrcVolumeType, DstVolumeType, AccumulationType >::executeSAT(), PolyVox::LargeVolume< VoxelType >::flush(), PolyVox::RawVolume< VoxelType >::getVoxel(), PolyVox::SimpleVolume< VoxelType >::getVoxel(), PolyVox::LargeVolume< VoxelType >::getVoxel(), PolyVox::ConstVolumeProxy< VoxelType >::getVoxelAt(), PolyVox::Block< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::getVoxelAt(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelAt(), PolyVox::SimpleVolume< VoxelType >::getVoxelAt(), PolyVox::LargeVolume< VoxelType >::getVoxelAt(), PolyVox::RawVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::SimpleVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::LargeVolume< VoxelType >::getVoxelWithWrapping(), PolyVox::Region::grow(), PolyVox::Node::operator<(), PolyVox::LargeVolume< VoxelType >::prefetch(), PolyVox::raycastWithEndpoints(), PolyVox::Region::setLowerCorner(), PolyVox::RawVolume< VoxelType >::Sampler::setPosition(), PolyVox::BaseVolume< _VoxelType >::Sampler< DerivedVolumeType >::setPosition(), PolyVox::SimpleVolume< VoxelType >::Sampler::setPosition(), PolyVox::LargeVolume< VoxelType >::Sampler::setPosition(), PolyVox::Region::setUpperCorner(), PolyVox::ConstVolumeProxy< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::Block::setVoxelAt(), PolyVox::Block< VoxelType >::setVoxelAt(), PolyVox::RawVolume< VoxelType >::setVoxelAt(), PolyVox::SimpleVolume< VoxelType >::setVoxelAt(), PolyVox::LargeVolume< VoxelType >::setVoxelAt(), PolyVox::Region::shiftLowerCorner(), PolyVox::Region::shiftUpperCorner(), and PolyVox::Region::shrink().
|
inline |
Get the length of the vector.
Definition at line 564 of file Vector.inl.
Referenced by PolyVox::Vector< Size, StorageType, OperationType >::angleTo().
|
inline |
Get the squared length of the vector.
Definition at line 573 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.
If the vector is very short (or zero) then a divide by zero may cause elements to take on invalid values. You may want to check for this before normalising.
Definition at line 645 of file Vector.inl.
|
inline |
Inequality Operator.
Checks whether two Vectors are not equal.
rhs | The Vector to compare to. |
Definition at line 186 of file Vector.inl.
|
inline |
Multiplication and Assignment Operator.
Multiplication operator multiplies corresponding elements of the two Vectors.
rhs | The Vector to multiply by |
Definition at line 249 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 279 of file Vector.inl.
|
inline |
Addition and Assignment Operator.
Addition operator adds corresponding elements of the two Vectors.
rhs | The Vector to add |
Definition at line 219 of file Vector.inl.
|
inline |
Subtraction and Assignment Operator.
Subtraction operator subtracts corresponding elements of one Vector from the other.
rhs | The Vector to subtract |
Definition at line 234 of file Vector.inl.
|
inline |
Division and Assignment Operator.
Division operator divides corresponding elements of one Vector by the other.
rhs | The Vector to divide by |
Definition at line 264 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 294 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. This function is deprecated. You should specify a seperate comparator to the std:map if you need one.
rhs | The Vector to compare to. |
Definition at line 201 of file Vector.inl.
Vector< Size, StorageType, OperationType > & Vector< Size, StorageType, OperationType >::operator= | ( | const Vector< Size, StorageType, OperationType > & | rhs | ) |
Assignment Operator.
Assignment operator copies each element of first Vector to the second.
rhs | Vector to assign to. |
Definition at line 148 of file Vector.inl.
|
inline |
Equality Operator.
Checks whether two Vectors are equal.
rhs | The Vector to compare to. |
Definition at line 165 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 466 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 | The X component to set. |
y | The Y component to set. |
Definition at line 478 of file Vector.inl.
|
inline |
Element Access.
Sets several elements of a vector at once.
x | The X component to set. |
y | The Y component to set. |
z | The Z component to set. |
Definition at line 492 of file Vector.inl.
|
inline |
Element Access.
Sets several elements of a vector at once.
x | The X component to set. |
y | The Y component to set. |
z | The Z component to set. |
w | The W component to set. |
Definition at line 509 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 552 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 523 of file Vector.inl.
Referenced by 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 532 of file Vector.inl.
Referenced by 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 541 of file Vector.inl.
Referenced by PolyVox::MarchingCubesSurfaceExtractor< VolumeType, Controller >::execute(), and PolyVox::Node::Node().