Visual Servoing Platform  version 3.6.1 under development (2024-03-29)
vpRotationVector Class Reference

#include <visp3/core/vpRotationVector.h>

+ Inheritance diagram for vpRotationVector:

Public Member Functions

 vpRotationVector ()
 
 vpRotationVector (unsigned int n)
 
 vpRotationVector (const vpRotationVector &v)
 
Inherited functionalities from vpArray2D
unsigned int getCols () const
 
double getMaxValue () const
 
double getMinValue () const
 
unsigned int getRows () const
 
unsigned int size () const
 
void resize (unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
 
void reshape (unsigned int nrows, unsigned int ncols)
 
void insert (const vpArray2D< double > &A, unsigned int r, unsigned int c)
 
bool operator== (const vpArray2D< double > &A) const
 
bool operator!= (const vpArray2D< double > &A) const
 
vpArray2D< double > hadamard (const vpArray2D< double > &m) const
 

Public Attributes

double * data
 

Protected Attributes

unsigned int rowNum
 
unsigned int colNum
 
double ** rowPtrs
 
unsigned int dsize
 

Related Functions

(Note that these are not member functions.)

vpColVector operator* (const double &x, const vpRotationVector &v)
 
enum  vpGEMMmethod
 
bool operator== (const vpArray2D< double > &A) const
 
bool operator== (const vpArray2D< float > &A) const
 
bool operator!= (const vpArray2D< double > &A) const
 
void vpGEMM (const vpArray2D< double > &A, const vpArray2D< double > &B, const double &alpha, const vpArray2D< double > &C, const double &beta, vpArray2D< double > &D, const unsigned int &ops=0)
 

Inherited functionalities from vpRotationVector

unsigned int m_index
 
double & operator[] (unsigned int i)
 
const double & operator[] (unsigned int i) const
 
vpRotationVectoroperator= (const vpRotationVector &v)
 
vpColVector operator* (double x) const
 
vpRotationVectoroperator<< (double val)
 
vpRotationVectoroperator, (double val)
 
double sumSquare () const
 
vpRowVector t () const
 
std::vector< double > toStdVector () const
 

Inherited I/O from vpArray2D with Static Public Member Functions

vpArray2D< double > insert (const vpArray2D< double > &A, const vpArray2D< double > &B, unsigned int r, unsigned int c)
 
static void insert (const vpArray2D< double > &A, const vpArray2D< double > &B, vpArray2D< double > &C, unsigned int r, unsigned int c)
 
static bool load (const std::string &filename, vpArray2D< double > &A, bool binary=false, char *header=nullptr)
 
static bool loadYAML (const std::string &filename, vpArray2D< double > &A, char *header=nullptr)
 
static bool save (const std::string &filename, const vpArray2D< double > &A, bool binary=false, const char *header="")
 
static bool saveYAML (const std::string &filename, const vpArray2D< double > &A, const char *header="")
 
static vpArray2D< double > conv2 (const vpArray2D< double > &M, const vpArray2D< double > &kernel, const std::string &mode)
 
static void conv2 (const vpArray2D< double > &M, const vpArray2D< double > &kernel, vpArray2D< double > &res, const std::string &mode)
 

Detailed Description

Implementation of a generic rotation vector.

Class that consider the case of a generic rotation vector (cannot be used as is !) consisting in three or four angles.

The vpRotationVector class is derived from vpArray2D<double>. The vpRotationVector class is also the base class of specific rotations vectors such as vpThetaUVector, vpRxyzVector, vpRzyxVector, vpRzyzVector and vpQuaternionVector.

The code below shows how this class can be used to manipulate a vpRxyzVector.

#include <iostream>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpRxyzVector.h>
int main()
{
vpRxyzVector r; // By default initialized to zero
// Rotation around x set to 45 degres converted in radians
r[0] = vpMath::rad(45);
// Rotation around y set to PI radians
r[1] = M_PI;
// Rotation around z set to 0 radians
r[2] = 0;
std::cout << "Rxyz rotation vector: " << r << std::endl;
double rx = r[0]; // Get the value of the angle around x axis
double ry = r[1]; // Get the value of the angle around y axis
double rz = r[2]; // Get the value of the angle around z axis
}
static double rad(double deg)
Definition: vpMath.h:127
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:176
Examples
testMatrixInitialization.cpp, and testRotation.cpp.

Definition at line 95 of file vpRotationVector.h.

Constructor & Destructor Documentation

◆ vpRotationVector() [1/3]

vpRotationVector::vpRotationVector ( )
inline

Constructor that constructs a 0-size rotation vector.

Definition at line 99 of file vpRotationVector.h.

◆ vpRotationVector() [2/3]

vpRotationVector::vpRotationVector ( unsigned int  n)
inlineexplicit

Constructor that constructs a vector of size n and initialize all values to zero.

Definition at line 103 of file vpRotationVector.h.

◆ vpRotationVector() [3/3]

vpRotationVector::vpRotationVector ( const vpRotationVector v)
inline

Copy operator.

Definition at line 108 of file vpRotationVector.h.

Member Function Documentation

◆ conv2() [1/2]

vpArray2D< double > vpArray2D< double >::conv2 ( const vpArray2D< Type > &  M,
const vpArray2D< Type > &  kernel,
const std::string &  mode 
)
staticinherited

Perform a 2D convolution similar to Matlab conv2 function: $ M \star kernel $.

Parameters
M: First matrix.
kernel: Second matrix.
mode: Convolution mode: "full" (default), "same", "valid".
Convolution mode: full, same, valid (image credit: Theano doc).
Note
This is a very basic implementation that does not use FFT.
Examples
testMatrixConvolution.cpp.

Definition at line 976 of file vpArray2D.h.

◆ conv2() [2/2]

void vpArray2D< double >::conv2 ( const vpArray2D< Type > &  M,
const vpArray2D< Type > &  kernel,
vpArray2D< Type > &  res,
const std::string &  mode 
)
staticinherited

Perform a 2D convolution similar to Matlab conv2 function: $ M \star kernel $.

Parameters
M: First array.
kernel: Second array.
res: Result.
mode: Convolution mode: "full" (default), "same", "valid".
Convolution mode: full, same, valid (image credit: Theano doc).
Note
This is a very basic implementation that does not use FFT.

Definition at line 990 of file vpArray2D.h.

◆ getCols()

◆ getMaxValue()

double vpArray2D< double >::getMaxValue
inherited

Return the array max value.

Examples
servoMomentImage.cpp.

Definition at line 276 of file vpArray2D.h.

◆ getMinValue()

double vpArray2D< double >::getMinValue
inherited

Return the array min value.

Examples
servoMomentImage.cpp.

Definition at line 278 of file vpArray2D.h.

◆ getRows()

◆ hadamard()

vpArray2D< double > vpArray2D< double >::hadamard ( const vpArray2D< Type > &  m) const
inherited

Compute the Hadamard product (element wise matrix multiplication).

Parameters
m: Second matrix;
Returns
m1.hadamard(m2) The Hadamard product : $ m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j} $

Definition at line 572 of file vpArray2D.h.

◆ insert() [1/2]

vpArray2D< double > vpArray2D< double >::insert ( const vpArray2D< Type > &  A,
const vpArray2D< Type > &  B,
unsigned int  r,
unsigned int  c 
)
inherited

Insert array B in array A at the given position.

Parameters
A: Main array.
B: Array to insert.
r: Index of the row where to add the array.
c: Index of the column where to add the array.
Returns
Array with B insert in A.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.

Definition at line 1004 of file vpArray2D.h.

◆ insert() [2/2]

void vpArray2D< double >::insert ( const vpArray2D< Type > &  A,
unsigned int  r,
unsigned int  c 
)
inlineinherited

Insert array A at the given position in the current array.

Warning
Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.
Parameters
A: The array to insert.
r: The index of the row to begin to insert data.
c: The index of the column to begin to insert data.

Definition at line 431 of file vpArray2D.h.

◆ load()

static bool vpArray2D< double >::load ( const std::string &  filename,
vpArray2D< Type > &  A,
bool  binary = false,
char *  header = nullptr 
)
inlinestaticinherited

Load a matrix from a file.

Parameters
filename: Absolute file name.
A: Array to be loaded
binary: If true the matrix is loaded from a binary file, else from a text file.
header: Header of the file is loaded in this parameter.
Returns
Returns true if success.
See also
save()

Definition at line 600 of file vpArray2D.h.

◆ loadYAML()

static bool vpArray2D< double >::loadYAML ( const std::string &  filename,
vpArray2D< Type > &  A,
char *  header = nullptr 
)
inlinestaticinherited

Load an array from a YAML-formatted file.

Parameters
filename: absolute file name.
A: array to be loaded from the file.
header: header of the file is loaded in this parameter.
Returns
Returns true on success.
See also
saveYAML()
Examples
servoFlirPtuIBVS.cpp, servoFrankaIBVS.cpp, servoFrankaPBVS.cpp, servoUniversalRobotsIBVS.cpp, servoUniversalRobotsPBVS.cpp, and tutorial-flir-ptu-ibvs.cpp.

Definition at line 714 of file vpArray2D.h.

◆ operator!=()

bool operator!= ( const vpArray2D< Type > &  A) const
inherited

Not equal to comparison operator of a 2D array.

Definition at line 456 of file vpArray2D.h.

◆ operator*()

vpColVector vpRotationVector::operator* ( double  x) const

Operator that allows to multiply each element of a rotation vector by a scalar.

Parameters
x: The scalar.
Returns
The rotation vector multiplied by the scalar as a column vector. The current rotation vector (*this) is unchanged.

Definition at line 86 of file vpRotationVector.cpp.

References vpArray2D< double >::dsize.

◆ operator,()

vpRotationVector & vpRotationVector::operator, ( double  val)

Set vector second and third element values.

Parameters
val: Value of the vector element [rad].
Returns
An updated vector.

The following example shows how to initialize a $\theta_u$ vector from a list of 3 values [rad].

#include <visp3/core/vpThetaUVector.h>
int main()
{
tu << 0, M_PI_2, M_PI;
std::cout << "tu: " << tu.t() << std::endl;
}
vpRowVector t() const
Implementation of a rotation vector as axis-angle minimal representation.

It produces the following printings:

tu: 0 1.570796327 3.141592654
See also
operator<<()

Definition at line 159 of file vpRotationVector.cpp.

References vpArray2D< double >::data, vpException::dimensionError, m_index, and vpArray2D< double >::size().

◆ operator<<()

vpRotationVector & vpRotationVector::operator<< ( double  val)

Set vector first element value.

Parameters
val: Value of the vector first element [rad].
Returns
An updated vector.

The following example shows how to initialize a $\theta_u$ vector from a list of 3 values [rad].

#include <visp3/core/vpThetaUVector.h>
int main()
{
tu << 0, M_PI_2, M_PI;
std::cout << "tu: " << tu.t() << std::endl;
}

It produces the following printings:

tu: 0 1.570796327 3.141592654
See also
operator,()

Definition at line 129 of file vpRotationVector.cpp.

References vpArray2D< double >::data, and m_index.

◆ operator=()

vpRotationVector& vpRotationVector::operator= ( const vpRotationVector v)
inline

Affectation of two vectors.

Definition at line 127 of file vpRotationVector.h.

References vpArray2D< Type >::data, vpArray2D< Type >::resize(), and vpArray2D< Type >::size().

◆ operator==()

bool vpArray2D< double >::operator== ( const vpArray2D< Type > &  A) const
inherited

Equal to comparison operator of a 2D array.

Definition at line 452 of file vpArray2D.h.

◆ operator[]() [1/2]

double& vpRotationVector::operator[] ( unsigned int  i)
inline

Operator that allows to set the value of an element of the rotation vector: r[i] = value

Definition at line 117 of file vpRotationVector.h.

◆ operator[]() [2/2]

const double& vpRotationVector::operator[] ( unsigned int  i) const
inline

Operator that allows to get the value of an element of the rotation vector: value = r[i]

Definition at line 122 of file vpRotationVector.h.

◆ reshape()

void vpArray2D< double >::reshape ( unsigned int  nrows,
unsigned int  ncols 
)
inlineinherited
Examples
testMatrixInitialization.cpp.

Definition at line 390 of file vpArray2D.h.

◆ resize()

void vpArray2D< double >::resize ( unsigned int  nrows,
unsigned int  ncols,
bool  flagNullify = true,
bool  recopy_ = true 
)
inlineinherited

Set the size of the array and initialize all the values to zero.

Parameters
nrows: number of rows.
ncols: number of column.
flagNullify: if true, then the array is re-initialized to 0 after resize. If false, the initial values from the common part of the array (common part between old and new version of the array) are kept. Default value is true.
recopy_: if true, will perform an explicit recopy of the old data.
Examples
testArray2D.cpp, testMatrix.cpp, testMatrixDeterminant.cpp, testMatrixInverse.cpp, testMatrixPseudoInverse.cpp, and testSvd.cpp.

Definition at line 299 of file vpArray2D.h.

◆ save()

static bool vpArray2D< double >::save ( const std::string &  filename,
const vpArray2D< Type > &  A,
bool  binary = false,
const char *  header = "" 
)
inlinestaticinherited

Save a matrix to a file.

Parameters
filename: Absolute file name.
A: Array to be saved.
binary: If true the matrix is saved in a binary file, else a text file.
header: Optional line that will be saved at the beginning of the file.
Returns
Returns true if success.

Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.

See also
load()

Definition at line 802 of file vpArray2D.h.

◆ saveYAML()

static bool vpArray2D< double >::saveYAML ( const std::string &  filename,
const vpArray2D< Type > &  A,
const char *  header = "" 
)
inlinestaticinherited

Save an array in a YAML-formatted file.

Parameters
filename: absolute file name.
A: array to be saved in the file.
header: optional lines that will be saved at the beginning of the file. Should be YAML-formatted and will adapt to the indentation if any.
Returns
Returns true if success.

Here is an example of outputs.

vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header");
vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted \
header\n - with inner indentation");
static bool saveYAML(const std::string &filename, const vpArray2D< Type > &A, const char *header="")
Definition: vpArray2D.h:897

Content of matrix.yml:

example: a YAML-formatted header
rows: 3
cols: 4
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
double * data
Address of the first element of the data array.
Definition: vpArray2D.h:138

Content of matrixIndent.yml:

example:
- a YAML-formatted header
- with inner indentation
rows: 3
cols: 4
- [0, 0, 0, 0]
- [0, 0, 0, 0]
- [0, 0, 0, 0]
See also
loadYAML()

Definition at line 897 of file vpArray2D.h.

◆ size()

◆ sumSquare()

double vpRotationVector::sumSquare ( ) const

Return the sum square of all the elements $r_{i}$ of the rotation vector r(m).

Returns
The value

\[\sum{i=0}^{m} r_i^{2}\]

.
Examples
servoAfma6AprilTagPBVS.cpp, servoAfma6MegaposePBVS.cpp, servoFrankaPBVS.cpp, and servoUniversalRobotsPBVS.cpp.

Definition at line 178 of file vpRotationVector.cpp.

References vpArray2D< double >::rowNum, and vpArray2D< double >::rowPtrs.

◆ t()

◆ toStdVector()

std::vector< double > vpRotationVector::toStdVector ( ) const

Converts the vpRotationVector to a std::vector.

Returns
The corresponding std::vector<double>.

Definition at line 67 of file vpRotationVector.cpp.

References vpArray2D< double >::data, and vpArray2D< double >::size().

Friends And Related Function Documentation

◆ insert()

void vpArray2D< double >::insert ( const vpArray2D< Type > &  A,
const vpArray2D< Type > &  B,
vpArray2D< Type > &  C,
unsigned int  r,
unsigned int  c 
)
related

Insert array B in array A at the given position.

Parameters
A: Main array.
B: Array to insert.
C: Result array.
r: Index of the row where to insert array B.
c: Index of the column where to insert array B.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.

Definition at line 1019 of file vpArray2D.h.

◆ operator!=()

bool operator!= ( const vpArray2D< Type > &  A) const
related

Definition at line 1247 of file vpArray2D.h.

◆ operator*()

vpColVector operator* ( const double &  x,
const vpRotationVector v 
)
related

Allows to multiply a scalar by rotaion vector.

Definition at line 99 of file vpRotationVector.cpp.

◆ operator==() [1/2]

bool operator== ( const vpArray2D< double > &  A) const
related

Definition at line 1211 of file vpArray2D.h.

◆ operator==() [2/2]

bool operator== ( const vpArray2D< float > &  A) const
related

Definition at line 1229 of file vpArray2D.h.

◆ vpGEMM()

void vpGEMM ( const vpArray2D< double > &  A,
const vpArray2D< double > &  B,
const double &  alpha,
const vpArray2D< double > &  C,
const double &  beta,
vpArray2D< double > &  D,
const unsigned int &  ops = 0 
)
related

This function performs generalized matrix multiplication: D = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T. Operation on A, B and C matrices is described by enumeration vpGEMMmethod().

For example, to compute D = alpha*A^T*B^T+beta*C we need to call :

vpGEMM(A, B, alpha, C, beta, D, VP_GEMM_A_T + VP_GEMM_B_T);
void vpGEMM(const vpArray2D< double > &A, const vpArray2D< double > &B, const double &alpha, const vpArray2D< double > &C, const double &beta, vpArray2D< double > &D, const unsigned int &ops=0)
Definition: vpGEMM.h:388

If C is not used, vpGEMM must be called using an empty array null. Thus to compute D = alpha*A^T*B, we have to call:

vpGEMM(A, B, alpha, null, 0, D, VP_GEMM_B_T);
Exceptions
vpException::incorrectMatrixSizeErrorif the sizes of the matrices do not allow the operations.
Parameters
A: An array that could be a vpMatrix.
B: An array that could be a vpMatrix.
alpha: A scalar.
C: An array that could be a vpMatrix.
beta: A scalar.
D: The resulting array that could be a vpMatrix.
ops: A scalar describing operation applied on the matrices. Possible values are the one defined in vpGEMMmethod(): VP_GEMM_A_T, VP_GEMM_B_T, VP_GEMM_C_T.

Definition at line 388 of file vpGEMM.h.

◆ vpGEMMmethod

enum vpGEMMmethod
related

Enumeration of the operations applied on matrices in vpGEMM() function.

Operations are :

  • VP_GEMM_A_T to use the transpose matrix of A instead of the matrix A
  • VP_GEMM_B_T to use the transpose matrix of B instead of the matrix B
  • VP_GEMM_C_T to use the transpose matrix of C instead of the matrix C

Definition at line 52 of file vpGEMM.h.

Member Data Documentation

◆ colNum

unsigned int vpArray2D< double >::colNum
protectedinherited

Number of columns in the array.

Definition at line 130 of file vpArray2D.h.

◆ data

double * vpArray2D< double >::data
inherited

◆ dsize

unsigned int vpArray2D< double >::dsize
protectedinherited

Current array size (rowNum * colNum)

Definition at line 134 of file vpArray2D.h.

◆ m_index

unsigned int vpRotationVector::m_index
protected

Definition at line 151 of file vpRotationVector.h.

Referenced by operator,(), and operator<<().

◆ rowNum

unsigned int vpArray2D< double >::rowNum
protectedinherited

Number of rows in the array.

Definition at line 128 of file vpArray2D.h.

◆ rowPtrs

double ** vpArray2D< double >::rowPtrs
protectedinherited

Address of the first element of each rows.

Definition at line 132 of file vpArray2D.h.