30 #include <pcl/common/eigen.h> 31 #include <pcl/common/common.h> 51 data_ = (cv::Mat_<float>(3,4) <<
59 UASSERT(transformationMatrix.cols == 4 &&
60 transformationMatrix.rows == 3 &&
61 (transformationMatrix.type() == CV_32FC1 || transformationMatrix.type() == CV_64FC1));
62 if(transformationMatrix.type() == CV_32FC1)
64 data_ = transformationMatrix;
68 transformationMatrix.convertTo(
data_, CV_32F);
74 Eigen::Affine3f t = pcl::getTransformation (x, y, z, roll, pitch, yaw);
79 data_(
cv::Mat::zeros(3,4,CV_32FC1))
81 Eigen::Matrix3f
rotation = Eigen::Quaternionf(qw, qx, qy, qz).normalized().toRotationMatrix();
98 Eigen::Affine3f t = pcl::getTransformation (x, y, 0, 0, 0, theta);
109 return (
data_.empty() ||
110 (
data()[0] == 0.0f &&
120 data()[10] == 0.0f &&
121 data()[11] == 0.0f) ||
138 return data()[0] == 1.0f &&
148 data()[10] == 1.0f &&
171 bool invertible =
false;
173 Eigen::Matrix4f::RealScalar det;
174 toEigen4f().computeInverseAndDetWithCheck(inverse, det, invertible);
180 bool invertible =
false;
182 Eigen::Matrix4f::RealScalar det;
183 toEigen4f().computeInverseAndDetWithCheck(inverse, det, invertible);
219 return data_.colRange(0, 3).clone();
224 return data_.col(3).clone();
229 pcl::getTranslationAndEulerAngles(
toEigen3f(), x, y, z, roll, pitch, yaw);
235 pcl::getTranslationAndEulerAngles(
toEigen3f(), x, y, z, roll, pitch, yaw);
247 Eigen::Vector3f vA(x,y,z);
248 Eigen::Vector3f vB = this->
toEigen3f().linear()*Eigen::Vector3f(1,0,0);
249 return pcl::getAngle3D(Eigen::Vector4f(vA[0], vA[1], vA[2], 0), Eigen::Vector4f(vB[0], vB[1], vB[2], 0));
254 return uNorm(this->
x(), this->
y(), this->
z());
264 return uNorm(this->
x()-t.
x(), this->
y()-t.
y(), this->
z()-t.
z());
276 Eigen::Quaternionf qres = qa.slerp(t, qb);
278 float x = this->
x() + t*(other.
x() - this->
x());
279 float y = this->
y() + t*(other.
y() - this->
y());
280 float z = this->
z() + t*(other.
z() - this->
z());
282 return Transform(x,y,z, qres.x(), qres.y(), qres.z(), qres.w());
290 m.linear() = Eigen::Quaternionf(m.linear()).normalized().toRotationMatrix();
299 return uFormat(
"xyz=[null] rpy=[null]");
305 return uFormat(
"xyz=%f,%f,%f rpy=%f,%f,%f", x,y,z, roll,pitch,yaw);
313 m.linear() = Eigen::Quaternionf(m.linear()).normalized().toRotationMatrix();
325 return memcmp(
data_.data, t.
data_.data,
data_.total() *
sizeof(float)) == 0;
330 return !(*
this == t);
335 os <<
"[" << s.
data()[0] <<
", " << s.
data()[1] <<
", " << s.
data()[2] <<
", " << s.
data()[3] <<
";" << std::endl
336 <<
" " << s.
data()[4] <<
", " << s.
data()[5] <<
", " << s.
data()[6] <<
", " << s.
data()[7] <<
";" << std::endl
337 <<
" " << s.
data()[8] <<
", " << s.
data()[9] <<
", " << s.
data()[10]<<
", " << s.
data()[11] <<
"]";
372 return Eigen::Quaternionf(this->
toEigen3f().linear()).normalized();
377 return Eigen::Quaterniond(this->
toEigen3d().linear()).normalized();
382 return Transform(1,0,0,0, 0,1,0,0, 0,0,1,0);
387 return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
388 matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
389 matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
393 return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
394 matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
395 matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
400 return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
401 matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
402 matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
406 return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
407 matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
408 matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
413 return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
414 matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
415 matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
419 return Transform(matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
420 matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
421 matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3));
433 std::list<std::string> list =
uSplit(
string,
' ');
434 UASSERT_MSG(list.empty() || list.size() == 3 || list.size() == 6 || list.size() == 7 || list.size() == 9 || list.size() == 12,
435 uFormat(
"Cannot parse \"%s\"",
string.c_str()).c_str());
437 std::vector<float> numbers(list.size());
439 for(std::list<std::string>::iterator iter=list.begin(); iter!=list.end(); ++iter)
445 if(numbers.size() == 3)
447 t =
Transform(numbers[0], numbers[1], numbers[2]);
449 else if(numbers.size() == 6)
451 t =
Transform(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]);
453 else if(numbers.size() == 7)
456 t =
Transform(numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5], numbers[6]);
458 else if(numbers.size() == 9)
460 t =
Transform(numbers[0], numbers[1], numbers[2], 0,
461 numbers[3], numbers[4], numbers[5], 0,
462 numbers[6], numbers[7], numbers[8], 0);
464 else if(numbers.size() == 12)
466 t =
Transform(numbers[0], numbers[1], numbers[2], numbers[3],
467 numbers[4], numbers[5], numbers[6], numbers[7],
468 numbers[8], numbers[9], numbers[10], numbers[11]);
482 std::list<std::string> list =
uSplit(
string,
' ');
483 return list.size() == 0 || list.size() == 3 || list.size() == 6 || list.size() == 7 || list.size() == 9 || list.size() == 12;
487 const std::map<double, Transform> & tfBuffer,
488 const double & stamp)
491 std::map<double, Transform>::const_iterator imuIterB = tfBuffer.lower_bound(stamp);
492 std::map<double, Transform>::const_iterator imuIterA = imuIterB;
493 if(imuIterA != tfBuffer.begin())
495 imuIterA = --imuIterA;
497 if(imuIterB == tfBuffer.end())
499 imuIterB = --imuIterB;
502 if(imuIterB->first == stamp)
504 imuT = imuIterB->second;
506 else if(imuIterA != imuIterB)
509 imuT = imuIterA->second.
interpolate((stamp-imuIterA->first) / (imuIterB->first-imuIterA->first), imuIterB->second);
511 else if(stamp > imuIterB->first)
513 UWARN(
"No transform found for stamp %f! Latest is %f", stamp, imuIterB->first);
517 UWARN(
"No transform found for stamp %f! Earliest is %f", stamp, imuIterA->first);
522 Transform Transform::getClosestTransform(
523 const std::map<double, Transform> & tfBuffer,
524 const double & stamp,
528 std::map<double, Transform>::const_iterator imuIterB = tfBuffer.lower_bound(stamp);
529 std::map<double, Transform>::const_iterator imuIterA = imuIterB;
530 if(imuIterA != tfBuffer.begin())
532 imuIterA = --imuIterA;
534 if(imuIterB == tfBuffer.end())
536 imuIterB = --imuIterB;
539 if(imuIterB->first == stamp || imuIterA == imuIterB)
541 imuT = imuIterB->second;
544 *stampDiff = fabs(imuIterB->first - stamp);
547 else if(imuIterA != imuIterB)
550 imuT = imuIterA->second.
interpolate((stamp-imuIterA->first) / (imuIterB->first-imuIterA->first), imuIterB->second);
GLM_FUNC_DECL T roll(detail::tquat< T, P > const &x)
T uNorm(const std::vector< T > &v)
float UTILITE_EXP uStr2Float(const std::string &str)
Basic mathematics functions.
Some conversion functions.
GLM_FUNC_DECL T pitch(detail::tquat< T, P > const &x)
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
#define UASSERT(condition)
Wrappers of STL for convenient functions.
#define UASSERT_MSG(condition, msg_str)
T uNormSquared(const std::vector< T > &v)
RTABMAP_EXP std::ostream & operator<<(std::ostream &os, const CameraModel &model)
ULogger class and convenient macros.
GLM_FUNC_DECL T yaw(detail::tquat< T, P > const &x)
bool uIsNan(const T &value)
std::string UTILITE_EXP uFormat(const char *fmt,...)