mirror of
https://github.com/introlab/rtabmap.git
synced 2026-10-07 02:27:47 +08:00
* added doc and tests for util2d.h * updated cmake-ros ci * Added util3d.h doc and tests * util3d_transforms.h: Added doc and tests * util3d_filtering.h: started doc and test * util3d_filtering.h: more tests and doc * Added more doc/tests * finished util3d_filtering doc and tests * added test for util2d::depthBleedingFiltering * Added util3d_registration tests * Added util3d_features.h doc/tests * added doc/tests for util3d_correspondences.h * added doc/gtest for util3d_mapping.h (missing hpp functions) * finished testing util3d_mapping.hpp * Added util3d_motion_estimation.h tests (2D->3D done) * finished util3d_motion_estimation.h tests * minimal util3d_surface.h * Added Transform and VisualWord tests * Added doc for CameraModel and StereoCameraModel * Added more logs in ros ci * Passing tests on fical * improved all devcontainer * added devcontainer kilted, fixed source setup.bash, removed ldconfig in ros-cmake workflow * cleanup * source ros * Added utilite tests * Added testing to appveyor, github actions cancellable on re-commit on same branch * appveyor testing without all targets * appveyor: specifying ALL_BUILD target * Fixed Util2dTest.NMSImageBoundsRespected test * Fixing PCL Indices error on old pcl * Added VWDictionary tests and doc. Fixed LSH not working (fix from https://github.com/flann-lib/flann/pull/472 * fixing some appveyor CI errors, added test to check dictionary serialization against all type * Added StereoDense, StereoBM and StereoSGBM doc and tests * Added Stereo tests * Added CameraModel and StereoCameraModel tests * Added doc and test for Statistics * Added doc/tests for Signature * Added doc/test for SensorEvent, added doc for SensorCaptureInfo * Added doc to SensorData * Added SensorData tests * Added SensorCapture and SensorCaptureThread doc and tests * fixed sensordata test * updated SSC test and doc * Added doc and tests for BayesFilter class * Enabled testing on mac, updated windows testing like on linux * added test_link * fixed unresolved on windows * fixed ThreadHandle error on macos ci * Added GPS and GeodeticCoords tests * Added tests for compression * Added Odometry tests (base class only) * Added DBDriver tests * Added coverage report * uniformized test names * fixing concurancy and coverage ci * dont built tools, examples and app for coverage build * fixed report tool rebuilt without qt compilation error * updated coverage option * updated coverage config * added doc CI job * fixing windows and mac ci errors * Added DBDriverSqlite3 tests * Added IMU tests * Added Graph tests * fixing flaky macos test * Added IMUThread and IMUFilter tests * Added Landmarks tests * Added LASWriter tests * fixing seed flaky test * fixing flaky macos timing tests * Added LocalGrid tests * Added LocalGridMaker tests * fixing ci errors * Added GlobalMap tests * Added doc for EnvSensor * Added Features2D tests * Added Registration tests * Added RegistrationVis tests * Added doc for Rtabmap and Memory classes * Added Memory and Rtabmap tests * making some tests less flaky * lcov 1.14 support * updated compatible tool arguments * Added integration tests (RGB-D, Stereo, Lidar2d, Lidar3d) * More octomap checks * Refactored how/when python interpretor is created to simplify library usage * Added python tests * fixed some flaky tests * suppressed some third party related warnings * fixed ceres tests * more flaky fixes * Fixing tests without libpointmatcher * Added RANSAC rejection filter to PCL ICP * fixing multi platform flakiness * Added test to detect regression * Fixing windows pcl link error * fixed some macos flakiness * bigger 2D2D registration error on opencv 4.6.0 * flakiness * fixing flaky tests on windows and mac * flaky thread test on slow mac VM * windows slow test * fixing more ci erros * fxing temp dir on windows * Added Optimizer tests and discovered some bugs (fixed) * fixing flaky tests in mac and windows * Added Optimizer doc * Added GTSAM BA, updated Ceres to use g2o ba parameters. Renamed g2o's ba related parameters to Optimizer group and used by both gtsam and ceres. * fixing build without gtsam * fixing home dir * fixing python ci isssues * Added multicam ba tests * Added Ceres multicam BA support * Aligned BundleAdjustment parameters with Optimizer/Strategy to avoid confusion in the code * Added BA integration test * Added robust graph optimization integration test * Added loop3it test * Added stereo20Hz test * Added smartfactor gtsam * Fixed bugged check and warn if python didn't return any descriptors * Fixing gtsam version build issues * fixing tilt on windows ci * loosing ceres integration test for ci * mac ci flakiness * updating missing param in gui * updating test bound for mac * added appearance-based tests, set min gftt quality to quality level * testing more stuff * improving features2d tests * ci flakiness * fixing flaky ci * ci fixes * flaky fixes * Added RegistrationIcp tests * Added icp integration test with real-worl corridor like env * intermediate nodes * fixing enum * Updated test to catch #1714 * Fixed 2d corridor failing on pcl * flaky pnp test * flaky brisk test * Set rtabmap_integration test as long * updating loop closure test * flaky ci tests * TEsting roundtrip g2o/toro save/load * loosing test bound * fixed cuda capable checks * flaky tests * Debugging test hanging * more debugging stuff * updating limit * windows: disabled cuda on ci to avoid incompatible driver issue. Fixing a bad test mem allocation * trying fixing cuda hanging issue * fixing ci flakyness * flaky tests * Updated BOW flaky tests by checking min precision/recall instead of recall@100precision. Fixed signature test * CameraModel::load() test initRectificationMap param * test dbdriver load dictionary idsOnly * Memory: test keepLinkedInDb param * added dummyDictionary tests * test intermediate nodes count * Added MarkerDetector tests * reverted breaking change of UMutex and USemaphore * Features2d: fixed compiltion warnings with clang about override * clang warnings * fixing test build with pcl 1.8 * g2o and gtsam build errors on android * opencv5 test fixes * disabled testing for ios and android builds * normalized endline characters for easier diff * added LF CRLF rule * bump 0.23.10. fixing doc version * Publish rtabmap website doc from ci * fixing MSCVC build error * macos icp flaky test * fixing ceres macos test bound * ficing more flaky tests * fixing opencv5 related test errors. Also fixed an actual bug in ENU_WGS84ToGeocentric_WGS84() * added comment about mrpt change * removed rosdoc2 (will add it for rtabmap_ros later) * fixing website style * updated download links * locally deployable website with api * sweep doxygen issues * improved/revised doxygen main pages * removed examples empty page * Updated doxygen style * more concise doxygen groups * added api link on main readme * fixing utilite test error * fixing CommonFilteringGroundNormalsUp test * updated precisionRecall test bounds for Freak and brief descriptors * fixing scale check in ba tests * disabled tests on windows cuda build (missing dlls amd runner cannot test cuda anyway) * ceres: missing suitesparse dep in windows ci * adjusting recall thr for fast/freak * ficing more flaky tests * fixing flaky tests * disabled coverage in ros ci * Enable integration tests for ros ci jobs * loosing up some threshold for failing tests * trigger cache * fixing test data in ros ci. Updated flaky test for mac * slaking some test limit * Fixed rtabmap-detectMoreLoopClosures inverted output value * loosing up sift recall on mac * optimizer re-ordered distribution for reproducible results (mac g2o) * macos dump test crash log * combining all tests to save time on shared library reload. Also fixed Logs with missing arguments. * Added ENABLE_FORMAT_ERRORS cmake option * do test only one time * fixed all format warnings * format security android build errors * less verbose tests * updated ImuUThread test * fixed a log * Fixed libpointmatcher 2d normals eigen issue * Fixing libpointmatcher conversion issues * fixing libpointmatcher test on windows ci * cleanup comments, relax some test thr * disabled sequoia-intel ci build (too flaky, would need extensive testing directly on that machine)
628 lines
17 KiB
C++
628 lines
17 KiB
C++
/*
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are met:
|
|
* Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
notice, this list of conditions and the following disclaimer in the
|
|
documentation and/or other materials provided with the distribution.
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
names of its contributors may be used to endorse or promote products
|
|
derived from this software without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <rtabmap/core/Transform.h>
|
|
|
|
#include <pcl/common/eigen.h>
|
|
#include <pcl/common/common.h>
|
|
#include <rtabmap/core/util3d.h>
|
|
#include <rtabmap/utilite/UConversion.h>
|
|
#include <rtabmap/utilite/UMath.h>
|
|
#include <rtabmap/utilite/ULogger.h>
|
|
#include <rtabmap/utilite/UStl.h>
|
|
#include <iomanip>
|
|
|
|
namespace rtabmap {
|
|
|
|
Transform::Transform() : data_(cv::Mat::zeros(3,4,CV_32FC1))
|
|
{
|
|
}
|
|
|
|
// rotation matrix r## and origin o##
|
|
Transform::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)
|
|
{
|
|
data_ = (cv::Mat_<float>(3,4) <<
|
|
r11, r12, r13, o14,
|
|
r21, r22, r23, o24,
|
|
r31, r32, r33, o34);
|
|
|
|
if( r11>0.0f || r12>0.0f || r13>0.0f ||
|
|
r21>0.0f || r22>0.0f || r23>0.0f ||
|
|
r31>0.0f || r32>0.0f || r33>0.0f)
|
|
{
|
|
Eigen::Matrix3f m;
|
|
m << r11, r12, r13,
|
|
r21, r22, r23,
|
|
r31, r32, r33;
|
|
float d = m.determinant();
|
|
if(fabs(d-1.0f) > 0.0001)
|
|
{
|
|
UWARN("Created transform doesn't have normalized rotation. Any transformation with this transform can cause unexpected results!"
|
|
" Determinant([%f %f %f;%f %f %f;%f %f %f])=%f",
|
|
r11, r12, r13,
|
|
r21, r22, r23,
|
|
r31, r32, r33,
|
|
d);
|
|
}
|
|
}
|
|
}
|
|
|
|
Transform::Transform(const cv::Mat & transformationMatrix)
|
|
{
|
|
UASSERT(transformationMatrix.cols == 4 &&
|
|
transformationMatrix.rows == 3 &&
|
|
(transformationMatrix.type() == CV_32FC1 || transformationMatrix.type() == CV_64FC1));
|
|
if(transformationMatrix.type() == CV_32FC1)
|
|
{
|
|
data_ = transformationMatrix;
|
|
}
|
|
else
|
|
{
|
|
transformationMatrix.convertTo(data_, CV_32F);
|
|
}
|
|
}
|
|
|
|
Transform::Transform(float x, float y, float z, float roll, float pitch, float yaw)
|
|
{
|
|
Eigen::Affine3f t = pcl::getTransformation (x, y, z, roll, pitch, yaw);
|
|
*this = fromEigen3f(t);
|
|
}
|
|
|
|
Transform::Transform(float x, float y, float z, float qx, float qy, float qz, float qw) :
|
|
data_(cv::Mat::zeros(3,4,CV_32FC1))
|
|
{
|
|
Eigen::Matrix3f rotation = Eigen::Quaternionf(qw, qx, qy, qz).normalized().toRotationMatrix();
|
|
data()[0] = rotation(0,0);
|
|
data()[1] = rotation(0,1);
|
|
data()[2] = rotation(0,2);
|
|
data()[3] = x;
|
|
data()[4] = rotation(1,0);
|
|
data()[5] = rotation(1,1);
|
|
data()[6] = rotation(1,2);
|
|
data()[7] = y;
|
|
data()[8] = rotation(2,0);
|
|
data()[9] = rotation(2,1);
|
|
data()[10] = rotation(2,2);
|
|
data()[11] = z;
|
|
}
|
|
|
|
Transform::Transform(float x, float y, float theta)
|
|
{
|
|
Eigen::Affine3f t = pcl::getTransformation (x, y, 0, 0, 0, theta);
|
|
*this = fromEigen3f(t);
|
|
}
|
|
|
|
Transform Transform::clone() const
|
|
{
|
|
return Transform(data_.clone());
|
|
}
|
|
|
|
bool Transform::isNull() const
|
|
{
|
|
return (data_.empty() ||
|
|
(data()[0] == 0.0f &&
|
|
data()[1] == 0.0f &&
|
|
data()[2] == 0.0f &&
|
|
data()[3] == 0.0f &&
|
|
data()[4] == 0.0f &&
|
|
data()[5] == 0.0f &&
|
|
data()[6] == 0.0f &&
|
|
data()[7] == 0.0f &&
|
|
data()[8] == 0.0f &&
|
|
data()[9] == 0.0f &&
|
|
data()[10] == 0.0f &&
|
|
data()[11] == 0.0f) ||
|
|
uIsNan(data()[0]) ||
|
|
uIsNan(data()[1]) ||
|
|
uIsNan(data()[2]) ||
|
|
uIsNan(data()[3]) ||
|
|
uIsNan(data()[4]) ||
|
|
uIsNan(data()[5]) ||
|
|
uIsNan(data()[6]) ||
|
|
uIsNan(data()[7]) ||
|
|
uIsNan(data()[8]) ||
|
|
uIsNan(data()[9]) ||
|
|
uIsNan(data()[10]) ||
|
|
uIsNan(data()[11]));
|
|
}
|
|
|
|
bool Transform::isIdentity() const
|
|
{
|
|
return data()[0] == 1.0f &&
|
|
data()[1] == 0.0f &&
|
|
data()[2] == 0.0f &&
|
|
data()[3] == 0.0f &&
|
|
data()[4] == 0.0f &&
|
|
data()[5] == 1.0f &&
|
|
data()[6] == 0.0f &&
|
|
data()[7] == 0.0f &&
|
|
data()[8] == 0.0f &&
|
|
data()[9] == 0.0f &&
|
|
data()[10] == 1.0f &&
|
|
data()[11] == 0.0f;
|
|
}
|
|
|
|
void Transform::setNull()
|
|
{
|
|
*this = Transform();
|
|
}
|
|
|
|
void Transform::setIdentity()
|
|
{
|
|
*this = getIdentity();
|
|
}
|
|
|
|
float Transform::theta() const
|
|
{
|
|
float roll, pitch, yaw;
|
|
this->getEulerAngles(roll, pitch, yaw);
|
|
return yaw;
|
|
}
|
|
|
|
bool Transform::isInvertible() const
|
|
{
|
|
bool invertible = false;
|
|
Eigen::Matrix4f inverse;
|
|
Eigen::Matrix4f::RealScalar det;
|
|
toEigen4f().computeInverseAndDetWithCheck(inverse, det, invertible);
|
|
return invertible;
|
|
}
|
|
|
|
Transform Transform::inverse() const
|
|
{
|
|
bool invertible = false;
|
|
Eigen::Matrix4f inverse;
|
|
Eigen::Matrix4f::RealScalar det;
|
|
toEigen4f().computeInverseAndDetWithCheck(inverse, det, invertible);
|
|
UASSERT_MSG(invertible, uFormat("This transform is not invertible! %s \n"
|
|
"[%f %f %f %f;\n"
|
|
" %f %f %f %f;\n"
|
|
" %f %f %f %f;\n"
|
|
" 0 0 0 1]", prettyPrint().c_str(),
|
|
r11(), r12(), r13(), o14(),
|
|
r21(), r22(), r23(), o24(),
|
|
r31(), r32(), r33(), o34()).c_str());
|
|
return fromEigen4f(inverse);
|
|
}
|
|
|
|
Transform Transform::rotation() const
|
|
{
|
|
return Transform(
|
|
data()[0], data()[1], data()[2], 0,
|
|
data()[4], data()[5], data()[6], 0,
|
|
data()[8], data()[9], data()[10], 0);
|
|
}
|
|
|
|
Transform Transform::translation() const
|
|
{
|
|
return Transform(1,0,0, data()[3],
|
|
0,1,0, data()[7],
|
|
0,0,1, data()[11]);
|
|
}
|
|
|
|
Transform Transform::to3DoF() const
|
|
{
|
|
float x,y,z,roll,pitch,yaw;
|
|
this->getTranslationAndEulerAngles(x,y,z,roll,pitch,yaw);
|
|
float A = std::cos(yaw);
|
|
float B = std::sin(yaw);
|
|
return Transform(
|
|
A,-B, 0, x,
|
|
B, A, 0, y,
|
|
0, 0, 1, 0);
|
|
}
|
|
|
|
Transform Transform::to4DoF() const
|
|
{
|
|
float x,y,z,roll,pitch,yaw;
|
|
this->getTranslationAndEulerAngles(x,y,z,roll,pitch,yaw);
|
|
float A = std::cos(yaw);
|
|
float B = std::sin(yaw);
|
|
return Transform(
|
|
A,-B, 0, x,
|
|
B, A, 0, y,
|
|
0, 0, 1, z);
|
|
}
|
|
|
|
bool Transform::is3DoF() const
|
|
{
|
|
return is4DoF() && z() == 0.0;
|
|
}
|
|
|
|
bool Transform::is4DoF() const
|
|
{
|
|
return r13() == 0.0 &&
|
|
r23() == 0.0 &&
|
|
r31() == 0.0 &&
|
|
r32() == 0.0 &&
|
|
r33() == 1.0;
|
|
}
|
|
|
|
cv::Mat Transform::rotationMatrix() const
|
|
{
|
|
return data_.colRange(0, 3).clone();
|
|
}
|
|
|
|
cv::Mat Transform::translationMatrix() const
|
|
{
|
|
return data_.col(3).clone();
|
|
}
|
|
|
|
void Transform::getTranslationAndEulerAngles(float & x, float & y, float & z, float & roll, float & pitch, float & yaw) const
|
|
{
|
|
pcl::getTranslationAndEulerAngles(toEigen3f(), x, y, z, roll, pitch, yaw);
|
|
}
|
|
|
|
void Transform::getEulerAngles(float & roll, float & pitch, float & yaw) const
|
|
{
|
|
float x,y,z;
|
|
pcl::getTranslationAndEulerAngles(toEigen3f(), x, y, z, roll, pitch, yaw);
|
|
}
|
|
|
|
void Transform::getTranslation(float & x, float & y, float & z) const
|
|
{
|
|
x = this->x();
|
|
y = this->y();
|
|
z = this->z();
|
|
}
|
|
|
|
float Transform::getAngle(const Transform & t) const
|
|
{
|
|
return getQuaternionf().angularDistance(t.getQuaternionf());
|
|
}
|
|
|
|
float Transform::getNorm() const
|
|
{
|
|
return uNorm(this->x(), this->y(), this->z());
|
|
}
|
|
|
|
float Transform::getNormSquared() const
|
|
{
|
|
return uNormSquared(this->x(), this->y(), this->z());
|
|
}
|
|
|
|
float Transform::getDistance(const Transform & t) const
|
|
{
|
|
return uNorm(this->x()-t.x(), this->y()-t.y(), this->z()-t.z());
|
|
}
|
|
|
|
float Transform::getDistanceSquared(const Transform & t) const
|
|
{
|
|
return uNormSquared(this->x()-t.x(), this->y()-t.y(), this->z()-t.z());
|
|
}
|
|
|
|
Transform Transform::interpolate(float t, const Transform & other) const
|
|
{
|
|
Eigen::Quaternionf qa=this->getQuaternionf();
|
|
Eigen::Quaternionf qb=other.getQuaternionf();
|
|
Eigen::Quaternionf qres = qa.slerp(t, qb);
|
|
|
|
float x = this->x() + t*(other.x() - this->x());
|
|
float y = this->y() + t*(other.y() - this->y());
|
|
float z = this->z() + t*(other.z() - this->z());
|
|
|
|
return Transform(x,y,z, qres.x(), qres.y(), qres.z(), qres.w());
|
|
}
|
|
|
|
void Transform::normalizeRotation()
|
|
{
|
|
if(!this->isNull())
|
|
{
|
|
Eigen::Affine3f m = toEigen3f();
|
|
m.linear() = Eigen::Quaternionf(m.linear()).normalized().toRotationMatrix();
|
|
*this = fromEigen3f(m);
|
|
}
|
|
}
|
|
|
|
std::string Transform::prettyPrint() const
|
|
{
|
|
if(this->isNull())
|
|
{
|
|
return uFormat("xyz=[null] rpy=[null]");
|
|
}
|
|
else
|
|
{
|
|
float x,y,z,roll,pitch,yaw;
|
|
getTranslationAndEulerAngles(x, y, z, roll, pitch, yaw);
|
|
return uFormat("xyz=%f,%f,%f rpy=%f,%f,%f", x,y,z, roll,pitch,yaw);
|
|
}
|
|
}
|
|
|
|
Transform Transform::operator*(const Transform & t) const
|
|
{
|
|
Eigen::Affine3f m = Eigen::Affine3f(toEigen4f()*t.toEigen4f());
|
|
// make sure rotation is always normalized!
|
|
m.linear() = Eigen::Quaternionf(m.linear()).normalized().toRotationMatrix();
|
|
return fromEigen3f(m);
|
|
}
|
|
|
|
Transform & Transform::operator*=(const Transform & t)
|
|
{
|
|
*this = *this * t;
|
|
return *this;
|
|
}
|
|
|
|
bool Transform::operator==(const Transform & t) const
|
|
{
|
|
return memcmp(data_.data, t.data_.data, data_.total() * sizeof(float)) == 0;
|
|
}
|
|
|
|
bool Transform::operator!=(const Transform & t) const
|
|
{
|
|
return !(*this == t);
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, const Transform& s)
|
|
{
|
|
os << "[" << s.data()[0] << ", " << s.data()[1] << ", " << s.data()[2] << ", " << s.data()[3] << ";" << std::endl
|
|
<< " " << s.data()[4] << ", " << s.data()[5] << ", " << s.data()[6] << ", " << s.data()[7] << ";" << std::endl
|
|
<< " " << s.data()[8] << ", " << s.data()[9] << ", " << s.data()[10]<< ", " << s.data()[11] << "]";
|
|
return os;
|
|
}
|
|
|
|
Eigen::Matrix4f Transform::toEigen4f() const
|
|
{
|
|
Eigen::Matrix4f m;
|
|
m << data()[0], data()[1], data()[2], data()[3],
|
|
data()[4], data()[5], data()[6], data()[7],
|
|
data()[8], data()[9], data()[10], data()[11],
|
|
0,0,0,1;
|
|
return m;
|
|
}
|
|
Eigen::Matrix4d Transform::toEigen4d() const
|
|
{
|
|
Eigen::Matrix4d m;
|
|
m << data()[0], data()[1], data()[2], data()[3],
|
|
data()[4], data()[5], data()[6], data()[7],
|
|
data()[8], data()[9], data()[10], data()[11],
|
|
0,0,0,1;
|
|
return m;
|
|
}
|
|
|
|
Eigen::Affine3f Transform::toEigen3f() const
|
|
{
|
|
return Eigen::Affine3f(toEigen4f());
|
|
}
|
|
|
|
Eigen::Affine3d Transform::toEigen3d() const
|
|
{
|
|
return Eigen::Affine3d(toEigen4d());
|
|
}
|
|
|
|
Eigen::Quaternionf Transform::getQuaternionf() const
|
|
{
|
|
return Eigen::Quaternionf(this->toEigen3f().linear()).normalized();
|
|
}
|
|
|
|
Eigen::Quaterniond Transform::getQuaterniond() const
|
|
{
|
|
return Eigen::Quaterniond(this->toEigen3d().linear()).normalized();
|
|
}
|
|
|
|
Transform Transform::getIdentity()
|
|
{
|
|
return Transform(1,0,0,0, 0,1,0,0, 0,0,1,0);
|
|
}
|
|
|
|
Transform Transform::fromEigen4f(const Eigen::Matrix4f & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
Transform Transform::fromEigen4d(const Eigen::Matrix4d & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
|
|
Transform Transform::fromEigen3f(const Eigen::Affine3f & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
Transform Transform::fromEigen3d(const Eigen::Affine3d & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
|
|
Transform Transform::fromEigen3f(const Eigen::Isometry3f & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
Transform Transform::fromEigen3d(const Eigen::Isometry3d & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
|
|
Transform Transform::fromEigen3f(const Eigen::Matrix<float, 3, 4> & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
Transform Transform::fromEigen3d(const Eigen::Matrix<double, 3, 4> & matrix)
|
|
{
|
|
return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
|
|
}
|
|
|
|
/**
|
|
* Format (3 values): x y z
|
|
* Format (6 values): x y z roll pitch yaw
|
|
* Format (7 values): x y z qx qy qz qw
|
|
* Format (9 values, 3x3 rotation): r11 r12 r13 r21 r22 r23 r31 r32 r33
|
|
* Format (12 values, 3x4 transform): r11 r12 r13 tx r21 r22 r23 ty r31 r32 r33 tz
|
|
*/
|
|
Transform Transform::fromString(const std::string & string)
|
|
{
|
|
std::list<std::string> list = uSplit(string, ' ');
|
|
UASSERT_MSG(list.empty() || list.size() == 3 || list.size() == 6 || list.size() == 7 || list.size() == 9 || list.size() == 12,
|
|
uFormat("Cannot parse \"%s\"", string.c_str()).c_str());
|
|
|
|
std::vector<float> numbers(list.size());
|
|
int i = 0;
|
|
for(std::list<std::string>::iterator iter=list.begin(); iter!=list.end(); ++iter)
|
|
{
|
|
numbers[i++] = uStr2Float(*iter);
|
|
}
|
|
|
|
Transform t;
|
|
if(numbers.size() == 3)
|
|
{
|
|
t = Transform(numbers[0], numbers[1], numbers[2]);
|
|
}
|
|
else if(numbers.size() == 6)
|
|
{
|
|
t = Transform(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]);
|
|
}
|
|
else if(numbers.size() == 7)
|
|
{
|
|
|
|
t = Transform(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5], numbers[6]);
|
|
}
|
|
else if(numbers.size() == 9)
|
|
{
|
|
t = Transform(numbers[0], numbers[1], numbers[2], 0,
|
|
numbers[3], numbers[4], numbers[5], 0,
|
|
numbers[6], numbers[7], numbers[8], 0);
|
|
}
|
|
else if(numbers.size() == 12)
|
|
{
|
|
t = Transform(numbers[0], numbers[1], numbers[2], numbers[3],
|
|
numbers[4], numbers[5], numbers[6], numbers[7],
|
|
numbers[8], numbers[9], numbers[10], numbers[11]);
|
|
}
|
|
// Always normalize
|
|
if(!t.isNull())
|
|
{
|
|
t.normalizeRotation();
|
|
}
|
|
return t;
|
|
}
|
|
|
|
/**
|
|
* Format (3 values): x y z
|
|
* Format (6 values): x y z roll pitch yaw
|
|
* Format (7 values): x y z qx qy qz qw
|
|
* Format (9 values, 3x3 rotation): r11 r12 r13 r21 r22 r23 r31 r32 r33
|
|
* Format (12 values, 3x4 transform): r11 r12 r13 tx r21 r22 r23 ty r31 r32 r33 tz
|
|
*/
|
|
bool Transform::canParseString(const std::string & string)
|
|
{
|
|
std::list<std::string> list = uSplit(string, ' ');
|
|
return list.size() == 0 || list.size() == 3 || list.size() == 6 || list.size() == 7 || list.size() == 9 || list.size() == 12;
|
|
}
|
|
|
|
Transform Transform::getTransform(
|
|
const std::map<double, Transform> & tfBuffer,
|
|
const double & stamp)
|
|
{
|
|
UASSERT(!tfBuffer.empty());
|
|
std::map<double, Transform>::const_iterator iterB = tfBuffer.lower_bound(stamp);
|
|
std::map<double, Transform>::const_iterator iterA = iterB;
|
|
if(iterA != tfBuffer.begin())
|
|
{
|
|
iterA = --iterA;
|
|
}
|
|
if(iterB == tfBuffer.end())
|
|
{
|
|
iterB = --iterB;
|
|
}
|
|
Transform t;
|
|
if(iterB->first == stamp)
|
|
{
|
|
t = iterB->second;
|
|
}
|
|
else if(iterA != iterB)
|
|
{
|
|
//interpolate:
|
|
t = iterA->second.interpolate((stamp-iterA->first) / (iterB->first-iterA->first), iterB->second);
|
|
}
|
|
else if(stamp > iterB->first)
|
|
{
|
|
UWARN("No transform found for stamp %f! Latest is %f", stamp, iterB->first);
|
|
}
|
|
else
|
|
{
|
|
UWARN("No transform found for stamp %f! Earliest is %f", stamp, iterA->first);
|
|
}
|
|
return t;
|
|
}
|
|
|
|
Transform Transform::getClosestTransform(
|
|
const std::map<double, Transform> & tfBuffer,
|
|
const double & stamp,
|
|
double * stampDiff)
|
|
{
|
|
UASSERT(!tfBuffer.empty());
|
|
std::map<double, Transform>::const_iterator imuIterB = tfBuffer.lower_bound(stamp);
|
|
std::map<double, Transform>::const_iterator imuIterA = imuIterB;
|
|
if(imuIterA != tfBuffer.begin())
|
|
{
|
|
imuIterA = --imuIterA;
|
|
}
|
|
if(imuIterB == tfBuffer.end())
|
|
{
|
|
imuIterB = --imuIterB;
|
|
}
|
|
Transform imuT;
|
|
if(imuIterB->first == stamp || imuIterA == imuIterB)
|
|
{
|
|
imuT = imuIterB->second;
|
|
if(stampDiff)
|
|
{
|
|
*stampDiff = fabs(imuIterB->first - stamp);
|
|
}
|
|
}
|
|
else if(imuIterA != imuIterB)
|
|
{
|
|
//interpolate:
|
|
imuT = imuIterA->second.interpolate((stamp-imuIterA->first) / (imuIterB->first-imuIterA->first), imuIterB->second);
|
|
if(stampDiff)
|
|
{
|
|
*stampDiff = 0.0;
|
|
}
|
|
}
|
|
return imuT;
|
|
}
|
|
|
|
|
|
}
|