PoseVector¶
- class PoseVector(*args, **kwargs)¶
Bases:
ArrayDouble2D
Implementation of a pose vector and operations on poses.
The vpPose class implements a complete representation of every rigid motion in the Euclidean space.
The vpPose class is derived from vpArray2D<double> .
The pose is composed of a translation and a rotation minimally represented by a 6 dimension pose vector as:
\[^{a}{\bf r}_b = [^{a}{\bf t}_{b},\theta {\bf u}]^\top \in R^6\]where \(^{a}{\bf r}_b\) is the pose from frame \(a\) to frame \(b\) , with \(^{a}{\bf t}_{b}\) being the translation vector between these frames along the x,y,z axis and \(\theta \bf u\) , the axis-angle representation of the rotation \(^{a}\bf{R}_{b}\) between these frames.
Translations are expressed in meters, while the angles in the \(\theta {\bf u}\) axis-angle representation are expressed in radians.
To know more about the \(\theta \bf u\) rotation representation, see vpThetaUVector documentation.
The following code shows how to initialize a pose vector:
#include <visp3/core/vpPoseVector.h> int main() { vpPoseVector pose; pose[0] = 0.1; // tx pose[1] = 0.2; // ty pose[2] = 0.3; // tz pose[3] = M_PI; // tux pose[4] = M_PI_2; // tux pose[5] = M_PI_4; // tuz std::cout << "pose vector:\n" << pose << std::endl; }
It produces the following printings:
pose vector: 0.1 0.2 0.3 3.141592654 1.570796327 0.7853981634
The same initialization could be achieved this way:
#include <visp3/core/vpPoseVector.h> int main() { vpTranslationVector t; vpThetaUVector tu; t << 0.1, 0.2, 0.3; tu << M_PI, M_PI_2, M_PI_4; vpPoseVector pose(t, tu); }
If ViSP is build with c++11 support, you could also initialize the vector using:
#include <visp3/core/vpPoseVector.h> int main() { vpTranslationVector t; vpThetaUVector tu; t = { 0.1, 0.2, 0.3 }; tu = { M_PI, M_PI_2, M_PI_4 }; vpPoseVector pose(t, tu); }
JSON serialization
Since ViSP 3.6.0, if ViSP is build with soft_tool_json 3rd-party we introduce JSON serialization capabilities for vpPoseVector . The following sample code shows how to save a pose vector in a file named pose-vector.json and reload the values from this JSON file.
#include <visp3/core/vpPoseVector.h> int main() { #if defined(VISP_HAVE_NLOHMANN_JSON) std::string filename = "pose-vector.json"; { vpPoseVector pose(0.1, 0.2, 0.3, M_PI, M_PI_2, M_PI_4); std::ofstream file(filename); const nlohmann::json j = pose; file << j; file.close(); } { std::ifstream file(filename); const nlohmann::json j = nlohmann::json::parse(file); vpPoseVector pose; pose = j; file.close(); std::cout << "Read pose vector from " << filename << ":\n" << pose.t() << std::endl; } #endif }
If you build and execute the sample code, it will produce the following output:
Read pose vector from pose-vector.json: 0.1 0.2 0.3 3.141592654 1.570796327 0.7853981634
The content of the pose-vector.json file is the following:
$ cat pose-vector.json {"cols":1,"data":[0.1,0.2,0.3,3.141592653589793,1.5707963267948966,0.7853981633974483],"rows":6,"type":"vpPoseVector"}
Overloaded function.
__init__(self: visp._visp.core.PoseVector) -> None
Default constructor that construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) where \(\theta \bf u\) is a rotation vector \([\theta u_x, \theta u_y, \theta u_z]^\top\) and \(\bf t\) is a translation vector \([t_x, t_y, t_z]^\top\) .
The pose vector is initialized to zero.
__init__(self: visp._visp.core.PoseVector, tx: float, ty: float, tz: float, tux: float, tuy: float, tuz: float) -> None
Construct a 6 dimension pose vector \([\bf{t}, \theta \bf{u}]^\top\) from 3 translations and 3 \(\theta \bf{u}\) angles.
Translations are expressed in meters, while rotations in radians.
- Parameters:
- tx
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- ty
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tz
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tux
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuy
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuz
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
__init__(self: visp._visp.core.PoseVector, M: visp._visp.core.HomogeneousMatrix) -> None
Construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from an homogeneous matrix \(\bf M\) .
- Parameters:
- M
Homogeneous matrix \(\bf M\) from which translation \(\bf t\) and \(\theta \bf u\) vectors are extracted to initialize the pose vector.
__init__(self: visp._visp.core.PoseVector, tv: visp._visp.core.TranslationVector, tu: visp._visp.core.ThetaUVector) -> None
Construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from a translation vector \(\bf tv\) and a \(\theta \bf u\) vector.
- Parameters:
- tv
Translation vector \(\bf t\) .
- tu
math:theta bf u rotation vector.
__init__(self: visp._visp.core.PoseVector, tv: visp._visp.core.TranslationVector, R: visp._visp.core.RotationMatrix) -> None
Construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from a translation vector \(\bf t\) and a rotation matrix \(\bf R\) .
- Parameters:
- tv
Translation vector \(\bf t\) .
- R
Rotation matrix \(\bf R\) from which \(\theta \bf u\) vector is extracted to initialise the pose vector.
Methods
Overloaded function.
Overloaded function.
Overloaded function.
Return the rotation matrix that corresponds to the rotation part of the pose vector.
Return the \(\theta {\bf u}\) vector that corresponds to the rotation part of the pose vector.
Return the translation vector that corresponds to the translation part of the pose vector.
Read a pose vector from an input file stream.
Overloaded function.
Overloaded function.
Save the pose vector in the output file stream.
Set the 6 dimension pose vector \([\bf{t}, \theta \bf{u}]^\top\) from 3 translations and 3 \(\theta \bf{u}\) angles.
Overloaded function.
- return:
The corresponding std::vector<double>.
Inherited Methods
Overloaded function.
Return the number of columns of the 2D array.
Insert array B in array A at the given position.
Return the number of rows of the 2D array.
Return the number of elements of the 2D array.
Return the array min value.
Return the array max value.
- param m:
Second matrix;
Save an array in a YAML-formatted file.
Overloaded function.
Numpy view of the underlying array data.
Operators
__doc__
Overloaded function.
__module__
Attributes
__annotations__
- __eq__(*args, **kwargs)¶
Overloaded function.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
- __getitem__(*args, **kwargs)¶
Overloaded function.
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: tuple[int, int]) -> float
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: int) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: slice) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: tuple) -> numpy.ndarray[numpy.float64]
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.PoseVector) -> None
Default constructor that construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) where \(\theta \bf u\) is a rotation vector \([\theta u_x, \theta u_y, \theta u_z]^\top\) and \(\bf t\) is a translation vector \([t_x, t_y, t_z]^\top\) .
The pose vector is initialized to zero.
__init__(self: visp._visp.core.PoseVector, tx: float, ty: float, tz: float, tux: float, tuy: float, tuz: float) -> None
Construct a 6 dimension pose vector \([\bf{t}, \theta \bf{u}]^\top\) from 3 translations and 3 \(\theta \bf{u}\) angles.
Translations are expressed in meters, while rotations in radians.
- Parameters:
- tx
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- ty
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tz
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tux
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuy
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuz
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
__init__(self: visp._visp.core.PoseVector, M: visp._visp.core.HomogeneousMatrix) -> None
Construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from an homogeneous matrix \(\bf M\) .
- Parameters:
- M
Homogeneous matrix \(\bf M\) from which translation \(\bf t\) and \(\theta \bf u\) vectors are extracted to initialize the pose vector.
__init__(self: visp._visp.core.PoseVector, tv: visp._visp.core.TranslationVector, tu: visp._visp.core.ThetaUVector) -> None
Construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from a translation vector \(\bf tv\) and a \(\theta \bf u\) vector.
- Parameters:
- tv
Translation vector \(\bf t\) .
- tu
math:theta bf u rotation vector.
__init__(self: visp._visp.core.PoseVector, tv: visp._visp.core.TranslationVector, R: visp._visp.core.RotationMatrix) -> None
Construct a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from a translation vector \(\bf t\) and a rotation matrix \(\bf R\) .
- Parameters:
- tv
Translation vector \(\bf t\) .
- R
Rotation matrix \(\bf R\) from which \(\theta \bf u\) vector is extracted to initialise the pose vector.
- __ne__(*args, **kwargs)¶
Overloaded function.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
- buildFrom(*args, **kwargs)¶
Overloaded function.
buildFrom(self: visp._visp.core.PoseVector, tx: float, ty: float, tz: float, tux: float, tuy: float, tuz: float) -> visp._visp.core.PoseVector
Build a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from 3 translations and 3 \(\theta \bf{u}\) angles.
Translations are expressed in meters, while rotations in radians.
Note
See set()
- Parameters:
- tx
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- ty
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tz
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tux
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuy
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuz
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- Returns:
The build pose vector.
buildFrom(self: visp._visp.core.PoseVector, M: visp._visp.core.HomogeneousMatrix) -> visp._visp.core.PoseVector
Build a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from an homogeneous matrix \(\bf M\) .
- Parameters:
- M
Homogeneous matrix \(\bf M\) from which translation \(\bf t\) and \(\theta \bf u\) vectors are extracted to initialize the pose vector.
- Returns:
The build pose vector.
buildFrom(self: visp._visp.core.PoseVector, tv: visp._visp.core.TranslationVector, tu: visp._visp.core.ThetaUVector) -> visp._visp.core.PoseVector
Build a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from a translation vector \(\bf t\) and a \(\theta \bf u\) vector.
- Parameters:
- tv
Translation vector \(\bf t\) .
- tu
math:theta bf u rotation vector.
- Returns:
The build pose vector.
buildFrom(self: visp._visp.core.PoseVector, tv: visp._visp.core.TranslationVector, R: visp._visp.core.RotationMatrix) -> visp._visp.core.PoseVector
Build a 6 dimension pose vector \([\bf t, \theta \bf u]^\top\) from a translation vector \(\bf t\) and a rotation matrix \(\bf R\) .
- Parameters:
- tv
Translation vector \(\bf t\) .
- R
Rotation matrix \(\bf R\) from which \(\theta \bf u\) vector is extracted to initialise the pose vector.
- Returns:
The build pose vector.
- static conv2(*args, **kwargs)¶
Overloaded function.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, mode: str) -> visp._visp.core.ArrayDouble2D
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a36292a0>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First matrix.
- kernel
Second matrix.
- mode
Convolution mode: “full” (default), “same”, “valid”.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7ff6a362aec0>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First array.
- kernel
Second array.
- res
Result.
- mode
Convolution mode: “full” (default), “same”, “valid”.
- extract(*args, **kwargs)¶
Overloaded function.
extract(self: visp._visp.core.PoseVector, R: visp._visp.core.RotationMatrix) -> None
Extract the rotation as a rotation matrix.
extract(self: visp._visp.core.PoseVector, tu: visp._visp.core.ThetaUVector) -> None
Extract the rotation as a \(\theta \bf u\) vector.
extract(self: visp._visp.core.PoseVector, tv: visp._visp.core.TranslationVector) -> None
Extract the translation vector from the homogeneous matrix.
extract(self: visp._visp.core.PoseVector, q: visp._visp.core.QuaternionVector) -> None
Extract the rotation as a quaternion vector.
- getRotationMatrix(self) visp._visp.core.RotationMatrix ¶
Return the rotation matrix that corresponds to the rotation part of the pose vector.
- getThetaUVector(self) visp._visp.core.ThetaUVector ¶
Return the \(\theta {\bf u}\) vector that corresponds to the rotation part of the pose vector.
- getTranslationVector(self) visp._visp.core.TranslationVector ¶
Return the translation vector that corresponds to the translation part of the pose vector.
- hadamard(self, m: visp._visp.core.ArrayDouble2D) visp._visp.core.ArrayDouble2D ¶
- Parameters:
- m: visp._visp.core.ArrayDouble2D¶
Second matrix;
- Returns:
m1.hadamard(m2) The Hadamard product : \(m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j}\)
- insert(*args, **kwargs)¶
Overloaded function.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None
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.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, r: int, c: int) -> visp._visp.core.ArrayDouble2D
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- 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.
- static insertStatic(A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, C: visp._visp.core.ArrayDouble2D, r: int, c: int) None ¶
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- Parameters:
- A: visp._visp.core.ArrayDouble2D¶
Main array.
- B: visp._visp.core.ArrayDouble2D¶
Array to insert.
- C: visp._visp.core.ArrayDouble2D¶
Result array.
- r: int¶
Index of the row where to insert array B.
- c: int¶
Index of the column where to insert array B.
- load(self: visp._visp.core.PoseVector, f: std::basic_ifstream<char, std::char_traits<char> >) None ¶
Read a pose vector from an input file stream.
Note
See save()
- Parameters:
- f
The input file stream..Should be open before entering in this method.
- numpy(self) numpy.ndarray[numpy.float64] ¶
Numpy view of the underlying array data. This numpy view can be used to directly modify the array.
- print(*args, **kwargs)¶
Overloaded function.
print(self: visp._visp.core.PoseVector) -> None
Prints to the standard stream the pose vector.
Warning
Values concerning the \(\theta {\bf u}\) rotation are converted in degrees.
The following code
// Create a pose vector vpPoseVector r(1, 2, 3, M_PI, -M_PI, 0); r.print();
produces the output:
1 2 3 180 -180 0
Note
See std::ostream & operator<<(std::ostream &s, const vpArray2D<Type> &A)
print(self: visp._visp.core.PoseVector, s: std::ostream, length: int, intro: str = 0) -> int
Pretty print a pose vector. The data are tabulated. The common widths before and after the decimal point are set with respect to the parameter maxlen.
Note
See std::ostream & operator<<(std::ostream &s, const vpArray2D<Type> &A)
- Parameters:
- s
Stream used for the printing.
- length
The suggested width of each vector element. The actual width grows in order to accommodate the whole integral part, and shrinks if the whole extent is not needed for all the numbers.
- intro
The introduction which is printed before the vector. Can be set to zero (or omitted), in which case the introduction is not printed.
- Returns:
Returns the common total width for all vector elements.
- resize(*args, **kwargs)¶
Overloaded function.
resize(self: visp._visp.core.PoseVector, nrows: int, ncols: int, flagNullify: bool = true) -> None
This function is not applicable to a pose vector that is always a 6-by-1 column vector.
resize(self: visp._visp.core.ArrayDouble2D, nrows: int, ncols: int, flagNullify: bool = true, recopy_: bool = true) -> None
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.
- save(self: visp._visp.core.PoseVector, f: std::basic_ofstream<char, std::char_traits<char> >) None ¶
Save the pose vector in the output file stream.
Note
See load()
- Parameters:
- f
Output file stream. Should be open before entering in this method.
- static saveYAML(filename: str, A: visp._visp.core.ArrayDouble2D, header: str =) bool ¶
Save an array in a YAML-formatted file.
Here is an example of outputs.
vpArray2D<double> M(3,4); 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");
Content of matrix.yml:
example: a YAML-formatted header rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Content of matrixIndent.yml:
example: - a YAML-formatted header - with inner indentation rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Note
See loadYAML()
- 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.
- set(self, tx: float, ty: float, tz: float, tux: float, tuy: float, tuz: float) None ¶
Set the 6 dimension pose vector \([\bf{t}, \theta \bf{u}]^\top\) from 3 translations and 3 \(\theta \bf{u}\) angles.
Translations are expressed in meters, while rotations in radians.
- Parameters:
- tx: float¶
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- ty: float¶
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tz: float¶
Translations \([t_x, t_y, t_z]^\top\) respectively along the x, y and z axis (in meters).
- tux: float¶
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuy: float¶
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- tuz: float¶
Rotations \([\theta u_x, \theta u_y, \theta u_z]^\top\) respectively around the x, y and z axis (in radians).
- t(*args, **kwargs)¶
Overloaded function.
t(self: visp._visp.core.PoseVector) -> visp._visp.core.RowVector
t(self: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
Compute the transpose of the array.
- Returns:
vpArray2D<Type> C = A^T
-
__hash__ =
None
¶