Transform.h
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #ifndef TRANSFORM_H_
00029 #define TRANSFORM_H_
00030 
00031 #include <rtabmap/core/RtabmapExp.h>
00032 #include <vector>
00033 #include <string>
00034 #include <Eigen/Core>
00035 #include <Eigen/Geometry>
00036 #include <opencv2/core/core.hpp>
00037 
00038 namespace rtabmap {
00039 
00040 class RTABMAP_EXP Transform
00041 {
00042 public:
00043 
00044         // Zero by default
00045         Transform();
00046         // rotation matrix r## and origin o##
00047         Transform(float r11, float r12, float r13, float o14,
00048                       float r21, float r22, float r23, float o24,
00049                           float r31, float r32, float r33, float o34);
00050         // should have 3 rows, 4 cols and type CV_32FC1
00051         Transform(const cv::Mat & transformationMatrix);
00052         // x,y,z, roll,pitch,yaw
00053         Transform(float x, float y, float z, float roll, float pitch, float yaw);
00054         // x,y,z, qx,qy,qz,qw
00055         Transform(float x, float y, float z, float qx, float qy, float qz, float qw);
00056         // x,y, theta
00057         Transform(float x, float y, float theta);
00058 
00059         float r11() const {return data()[0];}
00060         float r12() const {return data()[1];}
00061         float r13() const {return data()[2];}
00062         float r21() const {return data()[4];}
00063         float r22() const {return data()[5];}
00064         float r23() const {return data()[6];}
00065         float r31() const {return data()[8];}
00066         float r32() const {return data()[9];}
00067         float r33() const {return data()[10];}
00068 
00069         float o14() const {return data()[3];}
00070         float o24() const {return data()[7];}
00071         float o34() const {return data()[11];}
00072 
00073         float & operator[](int index) {return data()[index];}
00074         const float & operator[](int index) const {return data()[index];}
00075         float & operator()(int row, int col) {return data()[row*4 + col];}
00076         const float & operator()(int row, int col) const {return data()[row*4 + col];}
00077 
00078         bool isNull() const;
00079         bool isIdentity() const;
00080 
00081         void setNull();
00082         void setIdentity();
00083 
00084         const cv::Mat & dataMatrix() const {return data_;}
00085         const float * data() const {return (const float *)data_.data;}
00086         float * data() {return (float *)data_.data;}
00087         int size() const {return 12;}
00088 
00089         float & x() {return data()[3];}
00090         float & y() {return data()[7];}
00091         float & z() {return data()[11];}
00092         const float & x() const {return data()[3];}
00093         const float & y() const {return data()[7];}
00094         const float & z() const {return data()[11];}
00095 
00096         float theta() const;
00097 
00098         Transform inverse() const;
00099         Transform rotation() const;
00100         Transform translation() const;
00101         Transform to3DoF() const;
00102 
00103         cv::Mat rotationMatrix() const;
00104         cv::Mat translationMatrix() const;
00105 
00106         void getTranslationAndEulerAngles(float & x, float & y, float & z, float & roll, float & pitch, float & yaw) const;
00107         void getEulerAngles(float & roll, float & pitch, float & yaw) const;
00108         void getTranslation(float & x, float & y, float & z) const;
00109         float getNorm() const;
00110         float getNormSquared() const;
00111         float getDistance(const Transform & t) const;
00112         float getDistanceSquared(const Transform & t) const;
00113         Transform interpolate(float t, const Transform & other) const;
00114         std::string prettyPrint() const;
00115 
00116         Transform operator*(const Transform & t) const;
00117         Transform & operator*=(const Transform & t);
00118         bool operator==(const Transform & t) const;
00119         bool operator!=(const Transform & t) const;
00120 
00121         Eigen::Matrix4f toEigen4f() const;
00122         Eigen::Matrix4d toEigen4d() const;
00123         Eigen::Affine3f toEigen3f() const;
00124         Eigen::Affine3d toEigen3d() const;
00125 
00126         Eigen::Quaternionf getQuaternionf() const;
00127         Eigen::Quaterniond getQuaterniond() const;
00128 
00129 public:
00130         static Transform getIdentity();
00131         static Transform fromEigen4f(const Eigen::Matrix4f & matrix);
00132         static Transform fromEigen4d(const Eigen::Matrix4d & matrix);
00133         static Transform fromEigen3f(const Eigen::Affine3f & matrix);
00134         static Transform fromEigen3d(const Eigen::Affine3d & matrix);
00135         static Transform fromEigen3f(const Eigen::Isometry3f & matrix);
00136         static Transform fromEigen3d(const Eigen::Isometry3d & matrix);
00137 
00145         static Transform fromString(const std::string & string);
00146         static bool canParseString(const std::string & string);
00147 
00148 private:
00149         cv::Mat data_;
00150 };
00151 
00152 RTABMAP_EXP std::ostream& operator<<(std::ostream& os, const Transform& s);
00153 
00154 }
00155 
00156 #endif /* TRANSFORM_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:27