opensurgsim
Namespaces | Typedefs | Functions
Vector.h File Reference

Definitions of small fixed-size vector types. More...

#include <array>
#include <vector>
#include <Eigen/Core>
#include <Eigen/Geometry>
#include "SurgSim/Framework/Assert.h"

Go to the source code of this file.

Namespaces

 SurgSim
 Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui needs glew but we need to call glewInit() from a osg callback, using this call we avoid getting warnings about redefinitions.
 

Typedefs

typedef Eigen::Matrix< float, 2, 1 > SurgSim::Math::Vector2f
 A 2D vector of floats. More...
 
typedef Eigen::Matrix< float, 3, 1 > SurgSim::Math::Vector3f
 A 3D vector of floats. More...
 
typedef Eigen::Matrix< float, 4, 1 > SurgSim::Math::Vector4f
 A 4D vector of floats. More...
 
typedef Eigen::Matrix< float, 6, 1 > SurgSim::Math::Vector6f
 A 6D vector of floats. More...
 
typedef Eigen::Matrix< double, 2, 1 > SurgSim::Math::Vector2d
 A 2D vector of doubles. More...
 
typedef Eigen::Matrix< double, 3, 1 > SurgSim::Math::Vector3d
 A 3D vector of doubles. More...
 
typedef Eigen::Matrix< double, 4, 1 > SurgSim::Math::Vector4d
 A 4D vector of doubles. More...
 
typedef Eigen::Matrix< double, 6, 1 > SurgSim::Math::Vector6d
 A 6D matrix of doubles. More...
 
typedef Eigen::Matrix< double, Eigen::Dynamic, 1 > SurgSim::Math::Vector
 A dynamic size column vector.
 

Functions

template<class Vector , class SubVector >
void SurgSim::Math::addSubVector (const SubVector &subVector, Eigen::Index blockId, Eigen::Index blockSize, Vector *vector)
 Helper method to add a sub-vector into a vector, for the sake of clarity. More...
 
template<class Vector , class SubVector >
void SurgSim::Math::addSubVector (const Eigen::Ref< const SubVector > &subVector, const std::vector< size_t > &blockIds, Eigen::Index blockSize, Vector *vector)
 Helper method to add a sub-vector per block into a vector, for the sake of clarity. More...
 
template<class Vector , class SubVector >
void SurgSim::Math::setSubVector (const SubVector &subVector, Eigen::Index blockId, Eigen::Index blockSize, Vector *vector)
 Helper method to set a sub-vector into a vector, for the sake of clarity. More...
 
template<class Vector >
Eigen::VectorBlock< Vector > SurgSim::Math::getSubVector (Vector &vector, Eigen::Index blockId, Eigen::Index blockSize)
 Helper method to access a sub-vector from a vector, for the sake of clarity. More...
 
template<class Vector , class SubVector >
void SurgSim::Math::getSubVector (const Vector &vector, const std::vector< size_t > &blockIds, Eigen::Index blockSize, SubVector *subVector)
 Helper method to get a sub-vector per block from a vector, for the sake of clarity. More...
 
template<typename T , int size, int TOpt>
Eigen::Matrix< T, size, 1, TOpt > SurgSim::Math::interpolate (const Eigen::Matrix< T, size, 1, TOpt > &previous, const Eigen::Matrix< T, size, 1, TOpt > &next, T t)
 Interpolate (slerp) between 2 vectors. More...
 
template<class T , int VOpt>
bool SurgSim::Math::buildOrthonormalBasis (Eigen::Matrix< T, 3, 1, VOpt > *i, Eigen::Matrix< T, 3, 1, VOpt > *j, Eigen::Matrix< T, 3, 1, VOpt > *k)
 Helper method to construct an orthonormal basis (i, j, k) given the 1st vector direction. More...
 
template<class T , int VOpt>
Eigen::Matrix< T, 3, 1, VOpt > SurgSim::Math::robustCrossProduct (const std::array< Eigen::Matrix< T, 3, 1, VOpt >, 2 > &p, const std::array< Eigen::Matrix< T, 3, 1, VOpt >, 2 > &q, T epsilon)
 Calculate the best unit normal we can find in the direction of pXq for one of the endpoints of q. More...
 

Detailed Description

Definitions of small fixed-size vector types.

Typedef Documentation

§ Vector2d

typedef Eigen::Matrix<double, 2, 1> SurgSim::Math::Vector2d

A 2D vector of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Vector2f

typedef Eigen::Matrix<float, 2, 1> SurgSim::Math::Vector2f

A 2D vector of floats.

This type (and any structs that contain it) can be safely allocated via new.

§ Vector3d

typedef Eigen::Matrix<double, 3, 1> SurgSim::Math::Vector3d

A 3D vector of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Vector3f

typedef Eigen::Matrix<float, 3, 1> SurgSim::Math::Vector3f

A 3D vector of floats.

This type (and any structs that contain it) can be safely allocated via new.

§ Vector4d

typedef Eigen::Matrix<double, 4, 1> SurgSim::Math::Vector4d

A 4D vector of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Vector4f

typedef Eigen::Matrix<float, 4, 1> SurgSim::Math::Vector4f

A 4D vector of floats.

This type (and any structs that contain it) can be safely allocated via new.

§ Vector6d

typedef Eigen::Matrix<double, 6, 1> SurgSim::Math::Vector6d

A 6D matrix of doubles.

This type (and any structs that contain it) can be safely allocated via new.

§ Vector6f

typedef Eigen::Matrix<float, 6, 1> SurgSim::Math::Vector6f

A 6D vector of floats.

This type (and any structs that contain it) can be safely allocated via new.

Function Documentation

§ addSubVector() [1/2]

template<class Vector , class SubVector >
void SurgSim::Math::addSubVector ( const SubVector &  subVector,
Eigen::Index  blockId,
Eigen::Index  blockSize,
Vector vector 
)

Helper method to add a sub-vector into a vector, for the sake of clarity.

Template Parameters
VectorThe vector type
SubVectorThe sub-vector type
Parameters
subVectorThe sub-vector
blockIdThe block index in vector
blockSizeThe block size
[out]vectorThe vector to add the sub-vector into

§ addSubVector() [2/2]

template<class Vector , class SubVector >
void SurgSim::Math::addSubVector ( const Eigen::Ref< const SubVector > &  subVector,
const std::vector< size_t > &  blockIds,
Eigen::Index  blockSize,
Vector vector 
)

Helper method to add a sub-vector per block into a vector, for the sake of clarity.

Template Parameters
VectorTypeThe vector type
Parameters
subVectorThe sub-vector (containing all the blocks)
blockIdsVector of block indices (for accessing vector) corresponding to the blocks in sub-vector
blockSizeThe block size
[out]vectorThe vector to add the sub-vector blocks into

§ buildOrthonormalBasis()

template<class T , int VOpt>
bool SurgSim::Math::buildOrthonormalBasis ( Eigen::Matrix< T, 3, 1, VOpt > *  i,
Eigen::Matrix< T, 3, 1, VOpt > *  j,
Eigen::Matrix< T, 3, 1, VOpt > *  k 
)

Helper method to construct an orthonormal basis (i, j, k) given the 1st vector direction.

Template Parameters
Tthe numeric data type used for the vector argument. Can usually be deduced.
VOptthe option flags (alignment etc.) used for the vector argument. Can be deduced.
Parameters
[in,out]iShould provide the 1st direction on input. The 1st vector of the basis (i, j, k) on output.
[out]j,kThe 2nd and 3rd orthonormal vectors of the basis (i, j, k)
Returns
True if (i, j, k) has been built successfully, False if 'i' is a (or close to a) null vector
Note
If any of the parameter is a nullptr, an exception will be raised

§ getSubVector() [1/2]

template<class Vector >
Eigen::VectorBlock<Vector> SurgSim::Math::getSubVector ( Vector vector,
Eigen::Index  blockId,
Eigen::Index  blockSize 
)

Helper method to access a sub-vector from a vector, for the sake of clarity.

Template Parameters
VectorThe vector type to get the sub-vector from
Parameters
vectorThe vector to get the sub-vector from
blockIdThe block index
blockSizeThe block size
Returns
The requested sub-vector
Note
Disable cpplint warnings for use of non-const reference
Eigen has a specific type for VectorBlock that we want to return with read/write access
therefore the Vector from which the VectorBlock is built from must not be const

§ getSubVector() [2/2]

template<class Vector , class SubVector >
void SurgSim::Math::getSubVector ( const Vector vector,
const std::vector< size_t > &  blockIds,
Eigen::Index  blockSize,
SubVector *  subVector 
)

Helper method to get a sub-vector per block from a vector, for the sake of clarity.

Template Parameters
VectorThe vector type
SubVectorThe sub-vector type
Parameters
vectorThe vector (containing the blocks in a sparse manner)
blockIdsVector of block indices (for accessing vector) corresponding to the blocks in vector
blockSizeThe block size
[out]subVectorThe sub-vector to store the requested blocks (blockIds) from vector into

§ interpolate()

template<typename T , int size, int TOpt>
Eigen::Matrix<T, size, 1, TOpt> SurgSim::Math::interpolate ( const Eigen::Matrix< T, size, 1, TOpt > &  previous,
const Eigen::Matrix< T, size, 1, TOpt > &  next,
t 
)

Interpolate (slerp) between 2 vectors.

Template Parameters
Tthe numeric data type used for arguments and the return value. Can usually be deduced.
sizethe size of the vectors. Can be deduced.
TOptthe option flags (alignment etc.) used for the Vector arguments. Can be deduced.
Parameters
previousThe starting vector (at time 0.0).
nextThe ending vector (at time 1.0).
tThe interpolation time requested. Within [0..1], although note bounds are not checked.
Returns
the transform resulting in the slerp interpolation at time t.
Note
t=0 => returns vector 'previous'
t=1 => returns vector 'next'

§ robustCrossProduct()

template<class T , int VOpt>
Eigen::Matrix<T, 3, 1, VOpt> SurgSim::Math::robustCrossProduct ( const std::array< Eigen::Matrix< T, 3, 1, VOpt >, 2 > &  p,
const std::array< Eigen::Matrix< T, 3, 1, VOpt >, 2 > &  q,
epsilon 
)

Calculate the best unit normal we can find in the direction of pXq for one of the endpoints of q.

Try multiple arrangements of the end points to reduce the artifacts when three of the vertices may be nearly collinear.

Parameters
psegment p
qsegment q
epsilonwhen the norm of p x q is above epsilon, the cross product is assumed to be valid. return the normalized cross product of p x q

§ setSubVector()

template<class Vector , class SubVector >
void SurgSim::Math::setSubVector ( const SubVector &  subVector,
Eigen::Index  blockId,
Eigen::Index  blockSize,
Vector vector 
)

Helper method to set a sub-vector into a vector, for the sake of clarity.

Template Parameters
VectorThe vector type
SubVectorThe sub-vector type
Parameters
subVectorThe sub-vector
blockIdThe block index in vector
blockSizeThe size of the sub-vector
[out]vectorThe vector to set the sub-vector into