RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
Transform.h
1/*
2Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef TRANSFORM_H_
29#define TRANSFORM_H_
30
31#include <rtabmap/core/rtabmap_core_export.h>
32#include <vector>
33#include <string>
34#include <map>
35#include <Eigen/Core>
36#include <Eigen/Geometry>
37#include <opencv2/core/core.hpp>
38
39namespace rtabmap {
40
52class RTABMAP_CORE_EXPORT Transform
53{
54public:
55
65 Transform(float r11, float r12, float r13, float o14,
66 float r21, float r22, float r23, float o24,
67 float r31, float r32, float r33, float o34);
72 Transform(const cv::Mat & transformationMatrix);
78 Transform(float x, float y, float z, float roll, float pitch, float yaw);
84 Transform(float x, float y, float z, float qx, float qy, float qz, float qw);
88 Transform(float x, float y, float theta);
89
94
95 // --- Accessors (rotation matrix elements, translation) ---
96 float r11() const {return data()[0];}
97 float r12() const {return data()[1];}
98 float r13() const {return data()[2];}
99 float r21() const {return data()[4];}
100 float r22() const {return data()[5];}
101 float r23() const {return data()[6];}
102 float r31() const {return data()[8];}
103 float r32() const {return data()[9];}
104 float r33() const {return data()[10];}
105
106 float o14() const {return data()[3];}
107 float o24() const {return data()[7];}
108 float o34() const {return data()[11];}
109
110 float & operator[](int index) {return data()[index];}
111 const float & operator[](int index) const {return data()[index];}
112 float & operator()(int row, int col) {return data()[row*4 + col];}
113 const float & operator()(int row, int col) const {return data()[row*4 + col];}
114
118 bool isNull() const;
122 bool isIdentity() const;
123
127 void setNull();
132
136 const cv::Mat & dataMatrix() const {return data_;}
140 const float * data() const {return (const float *)data_.data;}
141 float * data() {return (float *)data_.data;}
142
146 int size() const {return 12;}
147
149 float & x() {return data()[3];}
150 float & y() {return data()[7];}
151 float & z() {return data()[11];}
152 const float & x() const {return data()[3];}
153 const float & y() const {return data()[7];}
154 const float & z() const {return data()[11];}
155
159 float theta() const;
160
164 bool isInvertible() const;
188 bool is3DoF() const;
192 bool is4DoF() const;
193
197 cv::Mat rotationMatrix() const;
201 cv::Mat translationMatrix() const;
202
206 void getTranslationAndEulerAngles(float & x, float & y, float & z, float & roll, float & pitch, float & yaw) const;
210 void getEulerAngles(float & roll, float & pitch, float & yaw) const;
214 void getTranslation(float & x, float & y, float & z) const;
218 float getAngle(const Transform & t) const;
222 float getNorm() const;
226 float getNormSquared() const;
230 float getDistance(const Transform & t) const;
234 float getDistanceSquared(const Transform & t) const;
240 Transform interpolate(float t, const Transform & other) const;
248 std::string prettyPrint() const;
249
251 Transform operator*(const Transform & t) const;
252 Transform & operator*=(const Transform & t);
253 bool operator==(const Transform & t) const;
254 bool operator!=(const Transform & t) const;
255
256 // --- Eigen conversions ---
257 Eigen::Matrix4f toEigen4f() const;
258 Eigen::Matrix4d toEigen4d() const;
259 Eigen::Affine3f toEigen3f() const;
260 Eigen::Affine3d toEigen3d() const;
261
262 Eigen::Quaternionf getQuaternionf() const;
263 Eigen::Quaterniond getQuaterniond() const;
264
265public:
266 // --- Static helpers ---
267
272
274 static Transform fromEigen4f(const Eigen::Matrix4f & matrix);
275 static Transform fromEigen4d(const Eigen::Matrix4d & matrix);
276 static Transform fromEigen3f(const Eigen::Affine3f & matrix);
277 static Transform fromEigen3d(const Eigen::Affine3d & matrix);
278 static Transform fromEigen3f(const Eigen::Isometry3f & matrix);
279 static Transform fromEigen3d(const Eigen::Isometry3d & matrix);
280 static Transform fromEigen3f(const Eigen::Matrix<float, 3, 4> & matrix);
281 static Transform fromEigen3d(const Eigen::Matrix<double, 3, 4> & matrix);
282
290 0.0f, -1.0f, 0.0f, 0.0f,
291 0.0f, 0.0f, 1.0f, 0.0f,
292 -1.0f, 0.0f, 0.0f, 0.0f);}
300 0.0f, 0.0f,-1.0f, 0.0f,
301 -1.0f, 0.0f, 0.0f, 0.0f,
302 0.0f, 1.0f, 0.0f, 0.0f);}
303
313 static Transform fromString(const std::string & string);
317 static bool canParseString(const std::string & string);
318
329 const std::map<double, Transform> & tfBuffer,
330 const double & stamp);
334 RTABMAP_DEPRECATED static Transform getClosestTransform(
335 const std::map<double, Transform> & tfBuffer,
336 const double & stamp,
337 double * stampDiff);
338
339private:
340 cv::Mat data_;
341};
342
346RTABMAP_CORE_EXPORT std::ostream& operator<<(std::ostream& os, const Transform& s);
347
353{
354public:
355 TransformStamped(const Transform & transform, const double & stamp) :
356 transform_(transform),
357 stamp_(stamp)
358 {}
359 const Transform & transform() const {return transform_;}
360 const double & stamp() const {return stamp_;}
361
362private:
363 Transform transform_;
364 double stamp_;
365};
366
367}
368
369#endif /* TRANSFORM_H_ */
Associates a transform with a timestamp.
Definition Transform.h:353
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53
bool isNull() const
Checks whether the transform is null (all zeros).
Transform(float x, float y, float z, float roll, float pitch, float yaw)
Constructs a Transform from position and Euler angles (in radians).
float r11() const
Rotation matrix element at row 1, col 1.
Definition Transform.h:96
cv::Mat rotationMatrix() const
Returns the 3x3 rotation matrix (cv::Mat).
int size() const
Returns the number of float elements (always 12).
Definition Transform.h:146
void getTranslation(float &x, float &y, float &z) const
Extracts translation only.
float o34() const
Translation z.
Definition Transform.h:108
Transform to3DoF() const
Converts to 3 DoF (x, y, theta).
static Transform getTransform(const std::map< double, Transform > &tfBuffer, const double &stamp)
Retrieves the transform to a given timestamp.
Transform operator*(const Transform &t) const
Operator overloads.
float & x()
Translation getters/setters.
Definition Transform.h:149
bool is3DoF() const
Checks if the transform is 3 DoF (no pitch/roll).
std::string prettyPrint() const
Returns a string representation of the transform.
cv::Mat translationMatrix() const
Returns the 3x1 translation matrix (cv::Mat).
Transform inverse() const
Returns the inverse of the transform.
Transform(const cv::Mat &transformationMatrix)
Constructs a Transform from a 3x4 OpenCV matrix.
static Transform fromString(const std::string &string)
Parses a transform from a string representation. Supported formats:
const float * data() const
Returns a pointer to the raw data (12 floats).
Definition Transform.h:140
static Transform getIdentity()
Returns identity transform.
Transform clone() const
Returns a deep copy of the transform.
Transform to4DoF() const
Converts to 4 DoF (x, y, z, yaw).
Transform(float r11, float r12, float r13, float o14, float r21, float r22, float r23, float o24, float r31, float r32, float r33, float o34)
Constructor from rotation matrix elements and translation components.
static Transform rtabmap_T_opengl()
Returns the transform from OpenGL to RTAB-Map coordinate system.
Definition Transform.h:299
float o24() const
Translation y.
Definition Transform.h:107
const cv::Mat & dataMatrix() const
Returns the internal OpenCV matrix (3x4).
Definition Transform.h:136
void getTranslationAndEulerAngles(float &x, float &y, float &z, float &roll, float &pitch, float &yaw) const
Extracts translation and Euler angles (radians).
static RTABMAP_DEPRECATED Transform getClosestTransform(const std::map< double, Transform > &tfBuffer, const double &stamp, double *stampDiff)
float getAngle(const Transform &t) const
Returns angular difference (in radians) with another transform.
static Transform opengl_T_rtabmap()
Returns the transform from RTAB-Map to OpenGL coordinate system.
Definition Transform.h:289
Transform()
Default constructor. Initializes to a null (all zeros) transform.
float & y()
Translation y.
Definition Transform.h:150
void normalizeRotation()
Normalizes the rotation matrix.
float theta() const
Returns 2D orientation (theta) in radians.
bool is4DoF() const
Checks if the transform is 4 DoF (no pitch).
float o14() const
Translation x.
Definition Transform.h:106
bool isInvertible() const
Returns whether the transform is invertible.
float getDistance(const Transform &t) const
Returns the Euclidean distance to another transform.
void getEulerAngles(float &roll, float &pitch, float &yaw) const
Extracts Euler angles (roll, pitch, yaw).
bool isIdentity() const
Checks whether the transform is identity.
float getDistanceSquared(const Transform &t) const
Returns the squared distance to another transform.
static Transform fromEigen4f(const Eigen::Matrix4f &matrix)
Converts from Eigen representations.
float getNormSquared() const
Returns the squared norm of the translation vector.
Transform translation() const
Returns only the translation component.
Transform rotation() const
Returns only the rotation component.
void setNull()
Sets the transform to null (zero matrix).
float getNorm() const
Returns the Euclidean norm of the translation vector.
Transform interpolate(float t, const Transform &other) const
Interpolates between this and another transform.
Transform(float x, float y, float theta)
Constructs a 2D Transform (x, y, theta).
static bool canParseString(const std::string &string)
Checks if a string can be parsed into a transform.
Transform(float x, float y, float z, float qx, float qy, float qz, float qw)
Constructs a Transform from position and quaternion.
float & z()
Translation z.
Definition Transform.h:151
void setIdentity()
Sets the transform to the identity transform.
RTABMAP_CORE_EXPORT std::ostream & operator<<(std::ostream &os, const CameraModel &model)
Stream operator for printing a camera model to an output stream.