MIRA
RigidTransform.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_RIGID_TRANSFORM_H_
48 #define _MIRA_RIGID_TRANSFORM_H_
49 
50 #include <algorithm>
51 #include <limits>
52 
53 #include <math/Angle.h>
54 #include <math/Eigen.h>
55 #include <math/Lerp.h>
56 #include <math/YawPitchRoll.h>
57 
59 
60 #include <platform/Types.h>
61 
62 #include <utils/IsCheapToCopy.h>
63 
64 namespace mira {
65 
67 
69 
72 template< int D,
73  typename TransformDerived,
74  typename OtherDerived,
75  int OtherRows=OtherDerived::RowsAtCompileTime,
76  int OtherCols=OtherDerived::ColsAtCompileTime>
77 struct ei_rigidtransform_product_impl
78 {
79  static_assert(D!=D,"You are trying to apply a rigid transform to a matrix "
80  "of invalid size");
81 };
83 
85 
100 template <typename T, int D>
102 {
103  static_assert(D!=D,"RigidTransform is not defined for this dimension. "
104  "Only 2 and 3 dimensions are available.");
105 };
106 
108 
127 template <typename T, int D>
129 {
130  static_assert(D!=D,"RigidTransformCov is not defined for this dimension. "
131  "Only 2 and 3 dimensions are available.");
132 };
133 
135 
140 template <typename T, int D, typename TRotation, typename TransformDerived>
142 {
143 public:
144 
146  typedef T Type;
147 
153 
158  typedef TRotation RotationType;
159 
160  enum {
161  Dim = D,
162  HDim = D+1
163  };
164 
170 
171 public:
172 
173  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
174 
176  t(translation), r(rotation) {}
177 
178 
179 public:
180 
182  TransformDerived inverse() const
183  {
184  RotationType inv = r.inverse();
185  return TransformDerived(inv.RotationType::operator*(-t), inv);
186  }
187 
193  bool isApprox(const RigidTransformBase& other,
194  T prec = std::numeric_limits<T>::epsilon()) const
195  {
196  return t.isApprox(other.t,prec) && r.isApprox(other.r, prec);
197  }
198 
199 public:
200 
204  TransformDerived& operator*= (const RigidTransformBase& other)
205  {
206  t += r * other.t;
207  r *= other.r;
208  return *This();
209  }
210 
214  friend TransformDerived operator* (const RigidTransformBase& a,
215  const RigidTransformBase& b) {
216  return mul(a,b);
217  }
218 
224  template <typename OtherDerived>
225  typename ei_rigidtransform_product_impl<D, TransformDerived, OtherDerived>::TResult
227  {
228  return ei_rigidtransform_product_impl<D, TransformDerived, OtherDerived>::run(*this, other.derived());
229  }
230 
231 public:
232 
238  {
239  // order of transforms is from right to left (i.e. rotate first and
240  // translate afterwards)
241  return Eigen::Translation<T,D>(t)*r;
242  }
243 
244 public:
245 
253  {
254  MatrixType m = MatrixType::Identity ();
255  m.template block<Dim,Dim>(0,0) = r.toRotationMatrix();
256  m.template block<Dim,1>(0,Dim) = t.transpose();
257  return m;
258  }
259 
260 protected:
261 
263  TransformDerived* This() { return static_cast<TransformDerived*>(this); }
265  const TransformDerived* This() const {
266  return static_cast<const TransformDerived*>(this);
267  }
268 
269 protected:
270 
271  static TransformDerived mul(const RigidTransformBase& a,
272  const RigidTransformBase& b)
273  {
274  RotationType r = a.r*b.r; // this must be assigned to a temp variable
275  // (due to a bug in Eigen::Rotation2D<>? )
276  return TransformDerived(a.r * b.t + a.t, r);
277  }
278 
279 public:
280 
283 
286 };
287 
289 
296 template <typename T>
297 class RigidTransform<T,2> : public RigidTransformBase<T, 2,
298  Eigen::Rotation2D<T>, RigidTransform<T,2> >
299 {
301 
302 public:
303 
305  Base(Eigen::Matrix<T,2,1>(0,0),Eigen::Rotation2D<T>(0)) {}
306 
312  const Eigen::Rotation2D<T>& rotation) :
313  Base(translation,rotation) {}
314 
319  RigidTransform(const Eigen::Matrix<T,2,1>& translation, T angle) :
320  Base(translation,Eigen::Rotation2D<T>(angle)) {}
321 
326  RigidTransform(T x, T y, T angle) :
327  Base(Eigen::Matrix<T,2,1>(x,y),
328  Eigen::Rotation2D<T>(angle)) {}
329 
335  template <typename UnitTag, typename Derived>
337  Base(Eigen::Matrix<T,2,1>(x,y),
338  Eigen::Rotation2D<T>(angle.rad())) {}
339 
340 public:
341 
343  template <typename U>
345  return RigidTransform<U,2>(this->t.template cast<U>(),
346  this->r.template cast<U>());
347  }
348 
349 public:
350 
352  T& x() { return this->t.x(); }
354  T x() const { return this->t.x(); }
355 
357  T& y() { return this->t.y(); }
359  T y() const { return this->t.y(); }
360 
362  T& phi() { return this->r.angle(); }
364  T phi() const { return this->r.angle(); }
365 
366 public:
367 
368  template <typename Reflector>
369  void reflect(Reflector& m)
370  {
371  m.property("X", this->t[0], "The translational part of the transform");
372  m.property("Y", this->t[1], "The translational part of the transform");
373  m.property("Phi", getter<T>(rad2deg<T>, this->r.angle()),
374  setter<T>(deg2rad<T>, this->r.angle()),
375  "The orientation in degrees");
376  }
377 
378  friend std::ostream& operator<<(std::ostream& os, const RigidTransform& tf)
379  {
380  os << "t: " << tf.t.transpose() << "\n";
381  os << "r: " << tf.r.angle() << "\n";
382  return os;
383  }
384 };
385 
387 
403 template <typename T>
404 class RigidTransformCov<T,2> : public RigidTransform<T, 2>
405 {
406  typedef RigidTransform<T, 2> Base;
407 
408 public:
409 
411  static const int CovarianceDim = 3;
412 
418 
423  return CovMatrixType::Zero();
424  }
425 
426 public:
427 
428  RigidTransformCov() : Base(), cov(nullCov())
429  {}
430 
435  RigidTransformCov(const Base& transform) : Base(transform),
436  cov(nullCov()) {}
437 
443  const Eigen::Rotation2D<T>& rotation,
444  const CovMatrixType& covariance) :
445  Base(translation,rotation), cov(covariance) {}
446 
451  RigidTransformCov(const Eigen::Matrix<T,2,1>& translation, T angle,
452  const CovMatrixType& covariance) :
453  Base(translation,Eigen::Rotation2D<T>(angle)),
454  cov(covariance) {}
455 
460  RigidTransformCov(T x, T y, T angle, const CovMatrixType& covariance) :
461  Base(Eigen::Matrix<T,2,1>(x,y),
462  Eigen::Rotation2D<T>(angle)), cov(covariance) {}
463 
469  template <typename UnitTag, typename Derived>
471  const CovMatrixType& covariance) :
472  Base(Eigen::Matrix<T,2,1>(x,y),
473  Eigen::Rotation2D<T>(angle.rad())), cov(covariance) {}
474 
481  RigidTransformCov(T x, T y, T angle, T covX, T covY, T covAngle) :
482  Base(Eigen::Matrix<T,2,1>(x,y),
483  Eigen::Rotation2D<T>(angle)),
484  cov(Eigen::DiagonalMatrix<T,3>(covX, covY, covAngle)) {}
485 
491  template <typename UnitTag, typename Derived>
493  T covX, T covY, T covAngle) :
494  Base(Eigen::Matrix<T,2,1>(x,y),
495  Eigen::Rotation2D<T>(angle.rad())),
496  cov(Eigen::DiagonalMatrix<T,3>(covX, covY, covAngle)) {}
497 
498 public:
499 
501  template <typename U>
503  return RigidTransformCov<U,2>(this->t.template cast<U>(),
504  this->r.template cast<U>(),
505  this->cov.template cast<U>());
506  }
507 
508 public:
509 
510  template <typename Reflector>
511  void reflect(Reflector& r)
512  {
514  r.property("Cov", cov, "The covariance matrix (using radians for phi)");
515  }
516 
517  friend std::ostream& operator<<(std::ostream& os, const RigidTransformCov& tf)
518  {
519  os << "t: " << tf.t.transpose() << "\n";
520  os << "r: " << tf.r.angle() << "\n";
521  os << "cov:\n" << tf.cov << "\n";
522  return os;
523  }
524 
525 public:
526  // overwritten to implement covariance propagation
527 
529  {
530  typedef typename Base::RotationType RotationType;
531  RotationType inv = this->r.inverse();
532 
533  CovMatrixType J;
534 
535  T sinr = std::sin(this->r.angle());
536  T cosr = std::cos(this->r.angle());
537 
538  // compute the jacobians
539  J << -cosr, -sinr, this->t(0)*sinr -this->t(1)*cosr,
540  sinr, -cosr, this->t(0)*cosr +this->t(1)*sinr,
541  0, 0, -1;
542 
543  CovMatrixType c = J*cov*J.transpose();
544  return RigidTransformCov(inv.RotationType::operator*(-this->t), inv, c);
545  }
546 
547  RigidTransformCov& operator*= (const RigidTransformCov& other)
548  {
549  propagateCov(cov,*this,other); //< must be done here, since operator* changes our value
550  Base::operator*=(other);
551  return *this;
552  }
553 
554  RigidTransformCov& operator*= (const Base& other)
555  {
556  propagateCov(cov,*this,other); //< must be done here, since operator* changes our value
557  Base::operator*=(other);
558  return *this;
559  }
560 
561  friend RigidTransformCov operator* (const RigidTransformCov& a,
562  const RigidTransformCov& b)
563  {
564  RigidTransformCov t = Base::mul(a,b);
565  propagateCov(t.cov,a,b);
566  return t;
567  }
568 
569  friend RigidTransformCov operator* (const RigidTransformCov& a,
570  const Base& b)
571  {
572  RigidTransformCov t = Base::mul(a,b);
573  propagateCov(t.cov,a,b);
574  return t;
575  }
576 
577  friend RigidTransformCov operator* (const Base& a,
578  const RigidTransformCov& b)
579  {
580  RigidTransformCov t = Base::mul(a,b);
581  propagateCov(t.cov,a,b);
582  return t;
583  }
584 
585 private:
586 
587  // propagates the covariance matices of both transforms (impl. see below)
588  static void propagateCov(CovMatrixType& oC, const RigidTransformCov& a,
589  const RigidTransformCov& w);
590  // same as above, but w does not carry any covariance (impl. see below)
591  static void propagateCov(CovMatrixType& oC, const RigidTransformCov& a,
592  const Base& w);
593  // same as above, but a does not carry any covariance (impl. see below)
594  static void propagateCov(CovMatrixType& C, const Base& a,
595  const RigidTransformCov& w);
596 
597 public:
598 
601 };
602 
604 
605 namespace {
606 
607 template<int index, typename T>
608 T getYPR(const Eigen::Quaternion<T>& r)
609 {
610  auto ypr = quaternionToYawPitchRoll(r);
611  return rad2deg(ypr.template get<index>());
612 }
613 
614 template<int index, typename T>
615 void setYPR(Eigen::Quaternion<T>& r, T degree)
616 {
617  auto ypr = quaternionToYawPitchRoll(r);
618  ypr.template get<index>() = deg2rad(degree);
620 }
621 
622 }
623 
625 
632 template <typename T>
633 class RigidTransform<T,3> : public RigidTransformBase<T, 3,
634  Eigen::Quaternion<T>, RigidTransform<T,3> >
635 {
637 
638 public:
639 
641  Base(Eigen::Matrix<T,3,1>(0,0,0), Eigen::Quaternion<T>::Identity()) {}
642 
644  const Eigen::Quaternion<T>& rotation) :
645  Base(translation,rotation) {}
646 
647  RigidTransform(T x, T y, T z, T yaw, T pitch, T roll) :
648  Base(Eigen::Matrix<T,3,1>(x,y,z),
649  quaternionFromYawPitchRoll(yaw,pitch,roll)) {}
650 
651 public:
652 
654  template <typename U>
656  return RigidTransform<U,3>(this->t.template cast<U>(),
657  this->r.template cast<U>());
658  }
659 
660 public:
661 
663  T& x() { return this->t.x(); }
665  T x() const { return this->t.x(); }
666 
668  T& y() { return this->t.y(); }
670  T y() const { return this->t.y(); }
671 
673  T& z() { return this->t.z(); }
675  T z() const { return this->t.z(); }
676 
677 
684  T yaw() const { return eulerAngles(this->r.toRotationMatrix(), 2,1,0)(0,0); }
685 
692  T pitch() const { return eulerAngles(this->r.toRotationMatrix(), 2,1,0)(1,0); }
693 
700  T roll() const { return eulerAngles(this->r.toRotationMatrix(), 2,1,0)(2,0); }
701 
702 public:
703 
704  template <typename Reflector>
705  typename std::enable_if<std::is_base_of<BinarySerializer<Reflector>, Reflector>::value>::type
706  reflect(Reflector& r)
707  {
708  r.property("X", this->t[0], "The translational part of the transform");
709  r.property("Y", this->t[1], "The translational part of the transform");
710  r.property("Z", this->t[2], "The translational part of the transform");
711  // rotation
712  r.member("Rotation", this->r.coeffs(), "The rotational part");
713  }
714 
715  template <typename Derived>
717  {
718  r.property("X", this->t[0], "The translational part of the transform");
719  r.property("Y", this->t[1], "The translational part of the transform");
720  r.property("Z", this->t[2], "The translational part of the transform");
721  // rotation
722  r.member("Rotation", this->r.coeffs(), "The rotational part");
723  }
724 
726 
727  template <typename Reflector>
728  void reflectRead(Reflector& r)
729  {
730  r.property("X", this->t[0], "The translational part of the transform");
731  r.property("Y", this->t[1], "The translational part of the transform");
732  r.property("Z", this->t[2], "The translational part of the transform");
733 
734  auto ypr = quaternionToYawPitchRoll(this->r);
735  T yaw = rad2deg(ypr.template get<0>());
736  T pitch = rad2deg(ypr.template get<1>());
737  T roll = rad2deg(ypr.template get<2>());
738  r.member("Yaw" , yaw, "The yaw angle (phi, in degrees)");
739  r.member("Pitch", pitch, "The pitch angle (theta, in degrees)");
740  r.member("Roll" , roll, "The roll angle (psi, in degrees)");
741  }
742 
743  template <typename Reflector>
744  void reflectWrite(Reflector& r)
745  {
746  T yaw, pitch, roll;
747  r.property("X", this->t[0], "The translational part of the transform");
748  r.property("Y", this->t[1], "The translational part of the transform");
749  r.property("Z", this->t[2], "The translational part of the transform");
750  r.member("Yaw" , yaw, "The yaw angle (phi, in degrees)");
751  r.member("Pitch", pitch, "The pitch angle (theta, in degrees)");
752  r.member("Roll" , roll, "The roll angle (psi, in degrees)");
753  this->r = quaternionFromYawPitchRoll(deg2rad(yaw),deg2rad(pitch),deg2rad(roll));
754  }
755 
757  {
758  r.property("X", this->t[0], "The translational part of the transform");
759  r.property("Y", this->t[1], "The translational part of the transform");
760  r.property("Z", this->t[2], "The translational part of the transform");
761  r.property("Yaw",
762  getter<T>([this](){ return getYPR<0>(this->r); }),
763  setter<T>([this](T yaw){ setYPR<0>(this->r, yaw); }),
764  "The yaw angle (phi, in degrees)");
765  r.property("Pitch",
766  getter<T>([this](){ return getYPR<1>(this->r); }),
767  setter<T>([this](T pitch){ setYPR<1>(this->r, pitch); }),
768  "The pitch angle (theta, in degrees)");
769  r.property("Roll",
770  getter<T>([this](){ return getYPR<2>(this->r); }),
771  setter<T>([this](T roll){ setYPR<2>(this->r, roll); }),
772  "The roll angle (psi, in degrees)");
773  }
774 
775  friend std::ostream& operator<<(std::ostream& os, const RigidTransform& tf)
776  {
777  os << "t: " << tf.t.transpose() << "\n";
778  os << "r: " << tf.r.w() << " " << tf.r.x() << " " << tf.r.y() << " " << tf.r.z() << "\n";
779  return os;
780  }
781 };
782 
784 
803 template <typename T>
804 class RigidTransformCov<T,3> : public RigidTransform<T, 3>
805 {
806  typedef RigidTransform<T, 3> Base;
807 
808 public:
810  static const int CovarianceDim = 7;
811 
813  static const int EulerCovarianceDim = 6;
814 
820 
826 
827 public:
828 
833  return CovMatrixType::Zero();
834  }
835 
841  return YawPitchRollCovMatrixType::Zero();
842  }
843 
844 public:
845 
846  RigidTransformCov() : Base(), cov(nullCov()) {}
847 
852  RigidTransformCov(const Base& transform) : Base(transform),
853  cov(nullCov()) {}
854 
860  const Eigen::Quaternion<T>& rotation,
861  const CovMatrixType& covariance) :
862  Base(translation,rotation), cov(covariance) {}
863 
869  const Eigen::Quaternion<T>& rotation,
870  const YawPitchRollCovMatrixType& yawPitchRollCov) :
871  Base(translation, rotation),
872  cov(quaternionCovFromYawPitchRollCov(yawPitchRollCov, rotation)){}
873 
878  RigidTransformCov(T x, T y, T z, T yaw, T pitch, T roll,
879  const YawPitchRollCovMatrixType& yawPitchRollCov) {
880  Eigen::Quaternion<T> rotation;
881  quaternionCovFromYawPitchRollCov(yawPitchRollCov, yaw, pitch, roll,
882  rotation, cov);
883  this->t = Eigen::Matrix<T,3,1>(x,y,z);
884  this->r = rotation;
885  }
886 
887 public:
888 
890  template <typename U>
892  typedef typename RigidTransformCov<U,3>::CovMatrixType CovMatrixTypeU;
893  return RigidTransformCov<U,3>(this->t.template cast<U>(),
894  this->r.template cast<U>(),
895  CovMatrixTypeU(this->cov.template cast<U>()));
896  }
897 
898 public:
899 
905  return quaternionCovToYawPitchRollCov(cov,this->r);
906  }
907 
908 public:
909 
910  template <typename Reflector>
911  typename std::enable_if<std::is_base_of<BinarySerializer<Reflector>, Reflector>::value>::type
912  reflect(Reflector& r)
913  {
914  r.property("X", this->t[0], "The translational part of the transform");
915  r.property("Y", this->t[1], "The translational part of the transform");
916  r.property("Z", this->t[2], "The translational part of the transform");
917  // rotation
918  r.member("Rotation", this->r.coeffs(), "The rotational part");
919  // 7x7 cov matrix
920  r.member("Cov", cov, "The covariance matrix");
921  }
922 
923  template <typename Derived>
925  {
926  r.property("X", this->t[0], "The translational part of the transform");
927  r.property("Y", this->t[1], "The translational part of the transform");
928  r.property("Z", this->t[2], "The translational part of the transform");
929  // rotation
930  r.member("Rotation", this->r.coeffs(), "The rotational part");
931  // 7x7 cov matrix
932  r.member("Cov", cov, "The covariance matrix");
933  }
934 
936 
937  template <typename Reflector>
938  void reflectRead(Reflector& r)
939  {
940  r.property("X", this->t[0], "The translational part of the transform");
941  r.property("Y", this->t[1], "The translational part of the transform");
942  r.property("Z", this->t[2], "The translational part of the transform");
943 
944  auto ypr = quaternionToYawPitchRoll(this->r);
945  T yaw = rad2deg(ypr.template get<0>());
946  T pitch = rad2deg(ypr.template get<1>());
947  T roll = rad2deg(ypr.template get<2>());
948  r.member("Yaw" , yaw, "The yaw angle (phi, in degrees)");
949  r.member("Pitch", pitch, "The pitch angle (theta, in degrees)");
950  r.member("Roll" , roll, "The roll angle (psi, in degrees)");
951 
952  // convert to yaw pitch roll cov
953  YawPitchRollCovMatrixType yprcov = quaternionCovToYawPitchRollCov(this->cov, this->r);
954  r.member("Cov", yprcov, "The covariance matrix for [x,y,z,y,p,r]");
955  }
956 
957  template <typename Reflector>
958  void reflectWrite(Reflector& r)
959  {
960  T yaw, pitch, roll;
961  r.property("X", this->t[0], "The translational part of the transform");
962  r.property("Y", this->t[1], "The translational part of the transform");
963  r.property("Z", this->t[2], "The translational part of the transform");
964  r.member("Yaw" , yaw, "The yaw angle (phi, in degrees)");
965  r.member("Pitch", pitch, "The pitch angle (theta, in degrees)");
966  r.member("Roll" , roll, "The roll angle (psi, in degrees)");
967 
968  yaw = deg2rad(yaw);
969  pitch = deg2rad(pitch);
970  roll = deg2rad(roll);
971  this->r = quaternionFromYawPitchRoll(yaw,pitch,roll);
972 
974  r.member("Cov", yprcov, "The covariance matrix for [x,y,z,y,p,r]");
975 
976  // convert to quaternion cov
977  this->cov = quaternionCovFromYawPitchRollCov(yprcov, yaw, pitch, roll);
978  }
979 
981  {
982  r.property("X", this->t[0], "The translational part of the transform");
983  r.property("Y", this->t[1], "The translational part of the transform");
984  r.property("Z", this->t[2], "The translational part of the transform");
985  r.property("Yaw",
986  getter<T>([this](){ return getYPR<0>(this->r); }),
987  setter<T>([this](T yaw){ setYPR<0>(this->r, yaw); }),
988  "The yaw angle (phi, in degrees)");
989  r.property("Pitch",
990  getter<T>([this](){ return getYPR<1>(this->r); }),
991  setter<T>([this](T pitch){ setYPR<1>(this->r, pitch); }),
992  "The pitch angle (theta, in degrees)");
993  r.property("Roll",
994  getter<T>([this](){ return getYPR<2>(this->r); }),
995  setter<T>([this](T roll){ setYPR<2>(this->r, roll); }),
996  "The roll angle (psi, in degrees)");
997  using CovType = YawPitchRollCovMatrixType;
998  r.property("Cov",
999  getter<CovType>([this](){
1000  return quaternionCovToYawPitchRollCov(this->cov, this->r);
1001  }),
1002  setter<CovType>([this](const CovType& yprcov){
1003  this->cov = quaternionCovFromYawPitchRollCov(yprcov, this->r);
1004  }),
1005  "The covariance matrix for [x,y,z,y,p,r]");
1006  }
1007 
1008  friend std::ostream& operator<<(std::ostream& os, const RigidTransformCov& tf)
1009  {
1010  os << "t: " << tf.t.transpose() << "\n";
1011  os << "r: " << tf.r.w() << " " << tf.r.x() << " " << tf.r.y() << " " << tf.r.z() << "\n";
1012  os << "cov:\n" << tf.cov << "\n";
1013  return os;
1014  }
1015 
1016 public:
1017 
1018  // overwritten to implement covariance propagation
1019 
1021  {
1022  typedef typename Base::RotationType RotationType;
1023  RotationType inv = this->r.inverse();
1024 
1025  CovMatrixType J = -CovMatrixType::Identity();
1026 
1027  J(3,3) = 1.0;
1028  J.template block<3,3>(0,0) <<
1029  (T)2.0 * (this->r.y() * this->r.y() + this->r.z() * this->r.z()) - (T)1.0,
1030  -(T)2.0 * (this->r.w() * this->r.z() + this->r.x() * this->r.y()) ,
1031  (T)2.0 * (this->r.w() * this->r.y() - this->r.x() * this->r.z()) ,
1032 
1033  (T)2.0 * (this->r.w() * this->r.z() - this->r.x() * this->r.y()) ,
1034  (T)2.0 * (this->r.x() * this->r.x() + this->r.z() * this->r.z()) - (T)1.0,
1035  -(T)2.0 * (this->r.w() * this->r.x() + this->r.y() * this->r.z()) ,
1036 
1037  -(T)2.0 * (this->r.w() * this->r.y() + this->r.x() * this->r.z()) ,
1038  (T)2.0 * (this->r.w() * this->r.x() - this->r.y() * this->r.z()) ,
1039  (T)2.0 * (this->r.x() * this->r.x() + this->r.y() * this->r.y()) - (T)1.0;
1040 
1041  // signs seem to be partially wrong in blanco2010se3 (see YawPitchRoll.h)
1042  // this now corresponds to MRPT 1.5.5 CPose3DQuat::inverseComposePoint
1043  J.template block<3,4>(0,3) <<
1044  -(T)2.0 * (this->r.z() * this->t(1) - this->r.y() * this->t(2) ),
1045  -(T)2.0 * (this->r.y() * this->t(1) + this->r.z() * this->t(2) ),
1046  -(T)2.0 * (this->r.x() * this->t(1) - (T)2.0 * this->r.y() * this->t(0) - this->r.w() * this->t(2)),
1047  -(T)2.0 * (this->r.x() * this->t(2) + this->r.w() * this->t(1) - (T)2.0 * this->r.z() * this->t(0)),
1048 
1049  -(T)2.0 * (this->r.x() * this->t(2) - this->r.z() * this->t(0) ),
1050  -(T)2.0 * (this->r.y() * this->t(0) - (T)2.0 * this->r.x() * this->t(1) + this->r.w() * this->t(2)),
1051  -(T)2.0 * (this->r.x() * this->t(0) + this->r.z() * this->t(2) ),
1052  -(T)2.0 * (this->r.y() * this->t(2) - (T)2.0 * this->r.z() * this->t(1) - this->r.w() * this->t(0)),
1053 
1054  -(T)2.0 * (this->r.y() * this->t(0) - this->r.x() * this->t(1) ),
1055  -(T)2.0 * (this->r.z() * this->t(0) - this->r.w() * this->t(1) - (T)2.0 * this->r.x() * this->t(2)),
1056  -(T)2.0 * (this->r.z() * this->t(1) + this->r.w() * this->t(0) - (T)2.0 * this->r.y() * this->t(2)),
1057  -(T)2.0 * (this->r.x() * this->t(0) + this->r.y() * this->t(1) );
1058 
1059  CovMatrixType c = J*cov*J.transpose();
1060  return RigidTransformCov(inv.RotationType::operator*(-this->t), inv, c);
1061  }
1062 
1063  RigidTransformCov& operator*= (const RigidTransformCov& other)
1064  {
1065  propagateCov(cov,*this,other); // must be done here, since operator* changes our value
1066  Base::operator*=(other);
1067  return *this;
1068  }
1069 
1070  RigidTransformCov& operator*= (const Base& other)
1071  {
1072  propagateCov(cov,*this,other); // must be done here, since operator* changes our value
1073  Base::operator*=(other);
1074  return *this;
1075  }
1076 
1077  friend RigidTransformCov operator* (const RigidTransformCov& a,
1078  const RigidTransformCov& b)
1079  {
1080  RigidTransformCov t = Base::mul(a,b);
1081  propagateCov(t.cov,a,b);
1082  return t;
1083  }
1084 
1085  friend RigidTransformCov operator* (const RigidTransformCov& a,
1086  const Base& b)
1087  {
1088  RigidTransformCov t = Base::mul(a,b);
1089  propagateCov(t.cov,a,b);
1090  return t;
1091  }
1092 
1093  friend RigidTransformCov operator* (const Base& a,
1094  const RigidTransformCov& b)
1095  {
1096  RigidTransformCov t = Base::mul(a,b);
1097  propagateCov(t.cov,a,b);
1098  return t;
1099  }
1100 
1101 private:
1102 
1103  // propagates the covariance matices to of both transforms (impl. see below)
1104  static void propagateCov(CovMatrixType& oC,
1105  const RigidTransformCov& w, const RigidTransformCov& a);
1106  // same as above, but w does not carry any covariance (impl. see below)
1107  static void propagateCov(CovMatrixType& oC,
1108  const RigidTransformCov& w, const Base& a);
1109  // same as above, but a does not carry any covariance (impl. see below)
1110  static void propagateCov(CovMatrixType& C,
1111  const Base& w, const RigidTransformCov& a);
1112 
1113 public:
1114 
1117 };
1118 
1120 
1125 
1130 
1135 
1140 
1142 
1143 template <>
1144 class IsCheapToCopy<RigidTransform2f> : public std::true_type {};
1145 
1146 template <>
1147 class IsCheapToCopy<RigidTransform3f> : public std::true_type {};
1148 
1149 template <>
1150 class IsCheapToCopy<RigidTransform2d> : public std::true_type {};
1151 
1152 template <>
1153 class IsCheapToCopy<RigidTransform3d> : public std::true_type {};
1154 
1155 template <>
1156 class IsCheapToCopy<RigidTransformCov2f> : public std::true_type {};
1157 
1158 template <>
1159 class IsCheapToCopy<RigidTransformCov3f> : public std::true_type {};
1160 
1161 template <>
1162 class IsCheapToCopy<RigidTransformCov2d> : public std::true_type {};
1163 
1164 template <>
1165 class IsCheapToCopy<RigidTransformCov3d> : public std::true_type {};
1166 
1168 // Covariance propagation maths
1169 
1170 // 2D case:
1171 //
1172 // g(a,w) = w * a
1173 // = [ Rw * ta + tw ;
1174 // phia + phiw ]
1175 //
1176 // Ja = d g(a,w) / da
1177 // Jw = d g(a,w) / dw
1178 // C = Ja*Ca*Ja' + Jw*Cw*Jw'
1179 
1180 template <typename T>
1181 inline void RigidTransformCov<T,2>::propagateCov(CovMatrixType& oC,
1182  const RigidTransformCov& w,
1183  const RigidTransformCov& a)
1184 {
1185  // NOTE: change oC at the end only, since it may be a reference on
1186  // the parameter w or a!
1187 
1188  typedef Eigen::Matrix<T,3,3> Mat3;
1189  Mat3 Ja, Jw;
1190 
1191  T sinrw = std::sin(w.r.angle());
1192  T cosrw = std::cos(w.r.angle());
1193 
1194  // compute the jacobians
1195  Ja << cosrw, -sinrw, 0,
1196  sinrw, cosrw, 0,
1197  0, 0, 1;
1198 
1199  Jw << 1, 0, -a.t(0)*sinrw -a.t(1)*cosrw,
1200  0, 1, a.t(0)*cosrw -a.t(1)*sinrw,
1201  0, 0, 1;
1202 
1203  // propagate the covariances:
1204  oC = Ja * a.cov * Ja.transpose() + Jw * w.cov * Jw.transpose();
1205 }
1206 
1207 // same as above, but w does not carry any covariance
1208 template <typename T>
1209 inline void RigidTransformCov<T,2>::propagateCov(CovMatrixType& oC,
1210  const RigidTransformCov& w,
1211  const Base& a)
1212 {
1213  // NOTE: change oC at the end only,
1214  // since it may be a reference on the parameter w or a!
1215 
1216  typedef Eigen::Matrix<T,3,3> Mat3;
1217  Mat3 Jw;
1218 
1219  T sinrw = std::sin(w.r.angle());
1220  T cosrw = std::cos(w.r.angle());
1221 
1222  // compute the jacobians
1223  Jw << 1, 0, -a.t(0)*sinrw -a.t(1)*cosrw,
1224  0, 1, a.t(0)*cosrw -a.t(1)*sinrw,
1225  0, 0, 1;
1226 
1227  // propagate the covariances:
1228  oC = Jw * w.cov * Jw.transpose();
1229 }
1230 
1231 template <typename T>
1232 inline void RigidTransformCov<T,2>::propagateCov(CovMatrixType& oC,
1233  const Base& w,
1234  const RigidTransformCov& a)
1235 {
1236  // NOTE: change oC at the end only,
1237  // since it may be a reference on the parameter w or a!
1238 
1239  typedef Eigen::Matrix<T,3,3> Mat3;
1240  Mat3 Ja;
1241 
1242  T sinrw = std::sin(w.r.angle());
1243  T cosrw = std::cos(w.r.angle());
1244 
1245  // compute the jacobians
1246  Ja << cosrw, -sinrw, 0,
1247  sinrw, cosrw, 0,
1248  0, 0, 1;
1249 
1250  // propagate the covariances:
1251  oC = Ja * a.cov * Ja.transpose();
1252 }
1253 
1254 // 3D case:
1255 //
1256 //
1257 // g(a,w) = w * a
1258 // = [ qw * ta + tw ;
1259 // qw * qa ]
1260 //
1261 // Ja = d g(a,w) / da
1262 // Jw = d g(a,w) / dw
1263 // C = Ja*Ca*Ja' + Jw*Cw*Jw'
1264 template <typename T>
1265 inline void RigidTransformCov<T,3>::propagateCov(CovMatrixType& oC,
1266  const RigidTransformCov& w,
1267  const RigidTransformCov& a)
1268 {
1269  // NOTE: change oC at the end only,
1270  // since it may be a reference on the parameter w or a!
1271 
1272  CovMatrixType Jw = CovMatrixType::Identity();
1273 
1274  Jw.template block<3,4>(0,3) <<
1275  - w.r.z()*a.t(1,0)+ w.r.y()*a.t(2,0),
1276  w.r.y()*a.t(1,0)+ w.r.z()*a.t(2,0),
1277  -(T)2.0*w.r.y()*a.t(0,0)+ w.r.x()*a.t(1,0)+ w.r.w()*a.t(2,0),
1278  -(T)2.0*w.r.z()*a.t(0,0)- w.r.w()*a.t(1,0)+ w.r.x()*a.t(2,0),
1279 
1280  w.r.z()*a.t(0,0) - w.r.x()*a.t(2,0),
1281  w.r.y()*a.t(0,0)-(T)2.0*w.r.x()*a.t(1,0)- w.r.w()*a.t(2,0),
1282  w.r.x()*a.t(0,0) + w.r.z()*a.t(2,0),
1283  w.r.w()*a.t(0,0)-(T)2.0*w.r.z()*a.t(1,0)+ w.r.y()*a.t(2,0),
1284 
1285  -w.r.y()*a.t(0,0)+ w.r.x()*a.t(1,0) ,
1286  w.r.z()*a.t(0,0)+ w.r.w()*a.t(1,0)-(T)2.0*w.r.x()*a.t(2,0),
1287  -w.r.w()*a.t(0,0)+ w.r.z()*a.t(1,0)-(T)2.0*w.r.y()*a.t(2,0),
1288  w.r.x()*a.t(0,0)+ w.r.y()*a.t(1,0);
1289  Jw.template block<3,4>(0,3) *= (T)2.0;
1290 
1291  Jw.template block<4,4>(3,3) <<
1292  a.r.w(),-a.r.x(),-a.r.y(),-a.r.z(),
1293  a.r.x(), a.r.w(), a.r.z(),-a.r.y(),
1294  a.r.y(),-a.r.z(), a.r.w(), a.r.x(),
1295  a.r.z(), a.r.y(),-a.r.x(), a.r.w();
1296 
1297  CovMatrixType Ja = CovMatrixType::Identity();
1298 
1299  Ja.template block<3,3>(0,0) <<
1300  (T)0.5-w.r.y()*w.r.y()-w.r.z()*w.r.z(),
1301  w.r.x()*w.r.y()-w.r.w()*w.r.z(),
1302  w.r.w()*w.r.y()+w.r.x()*w.r.z(),
1303 
1304  w.r.w()*w.r.z()+w.r.x()*w.r.y(),
1305  (T)0.5-w.r.x()*w.r.x()-w.r.z()*w.r.z(),
1306  w.r.y()*w.r.z()-w.r.w()*w.r.x(),
1307 
1308  w.r.x()*w.r.z()-w.r.w()*w.r.y(),
1309  w.r.w()*w.r.x()+w.r.y()*w.r.z(),
1310  (T)0.5-w.r.x()*w.r.x()-w.r.y()*w.r.y();
1311  Ja.template block<3,3>(0,0) *= (T)2.0;
1312 
1313  Ja.template block<4,4>(3,3) <<
1314  w.r.w(), -w.r.x(), -w.r.y(), -w.r.z(),
1315  w.r.x(), w.r.w(), -w.r.z(), w.r.y(),
1316  w.r.y(), w.r.z(), w.r.w(), -w.r.x(),
1317  w.r.z(), -w.r.y(), w.r.x(), w.r.w();
1318 
1319  // propagate the covariances:
1320  oC = Jw * w.cov * Jw.transpose() + Ja * a.cov * Ja.transpose();
1321 }
1322 
1323 template <typename T>
1324 inline void RigidTransformCov<T,3>::propagateCov(CovMatrixType& oC,
1325  const RigidTransformCov& w,
1326  const Base& a)
1327 {
1328  // NOTE: change oC at the end only,
1329  // since it may be a reference on the parameter w or a!
1330 
1331  CovMatrixType Jw = CovMatrixType::Identity();
1332 
1333  Jw.template block<3,4>(0,3) <<
1334  - w.r.z()*a.t(1,0)+ w.r.y()*a.t(2,0),
1335  w.r.y()*a.t(1,0)+ w.r.z()*a.t(2,0),
1336  -(T)2.0*w.r.y()*a.t(0,0)+ w.r.x()*a.t(1,0)+ w.r.w()*a.t(2,0),
1337  -(T)2.0*w.r.z()*a.t(0,0)- w.r.w()*a.t(1,0)+ w.r.x()*a.t(2,0),
1338 
1339  w.r.z()*a.t(0,0) - w.r.x()*a.t(2,0),
1340  w.r.y()*a.t(0,0)-(T)2.0*w.r.x()*a.t(1,0)- w.r.w()*a.t(2,0),
1341  w.r.x()*a.t(0,0) + w.r.z()*a.t(2,0),
1342  w.r.w()*a.t(0,0)-(T)2.0*w.r.z()*a.t(1,0)+ w.r.y()*a.t(2,0),
1343 
1344  -w.r.y()*a.t(0,0)+ w.r.x()*a.t(1,0) ,
1345  w.r.z()*a.t(0,0)+ w.r.w()*a.t(1,0)-2.0*w.r.x()*a.t(2,0),
1346  -w.r.w()*a.t(0,0)+ w.r.z()*a.t(1,0)-2.0*w.r.y()*a.t(2,0),
1347  w.r.x()*a.t(0,0)+ w.r.y()*a.t(1,0);
1348  Jw.template block<3,4>(0,3) *= (T)2.0;
1349 
1350  Jw.template block<4,4>(3,3) <<
1351  a.r.w(),-a.r.x(),-a.r.y(),-a.r.z(),
1352  a.r.x(), a.r.w(), a.r.z(),-a.r.y(),
1353  a.r.y(),-a.r.z(), a.r.w(), a.r.x(),
1354  a.r.z(), a.r.y(),-a.r.x(), a.r.w();
1355 
1356  // propagate the covariances:
1357  oC = Jw * w.cov * Jw.transpose();
1358 }
1359 
1360 template <typename T>
1361 inline void RigidTransformCov<T,3>::propagateCov(CovMatrixType& oC,
1362  const Base& w,
1363  const RigidTransformCov& a)
1364 {
1365  // NOTE: change oC at the end only,
1366  // since it may be a reference on the parameter w or a!
1367 
1368  CovMatrixType Ja = CovMatrixType::Identity();
1369 
1370  Ja.template block<3,3>(0,0) <<
1371  (T)0.5-w.r.y()*w.r.y()-w.r.z()*w.r.z(),
1372  w.r.x()*w.r.y()-w.r.w()*w.r.z(),
1373  w.r.w()*w.r.y()+w.r.x()*w.r.z(),
1374 
1375  w.r.w()*w.r.z()+w.r.x()*w.r.y(),
1376  (T)0.5-w.r.x()*w.r.x()-w.r.z()*w.r.z(),
1377  w.r.y()*w.r.z()-w.r.w()*w.r.x(),
1378 
1379  w.r.x()*w.r.z()-w.r.w()*w.r.y(),
1380  w.r.w()*w.r.x()+w.r.y()*w.r.z(),
1381  (T)0.5-w.r.x()*w.r.x()-w.r.y()*w.r.y();
1382  Ja.template block<3,3>(0,0) *= (T)2.0;
1383 
1384  Ja.template block<4,4>(3,3) <<
1385  w.r.w(), -w.r.x(), -w.r.y(), -w.r.z(),
1386  w.r.x(), w.r.w(), -w.r.z(), w.r.y(),
1387  w.r.y(), w.r.z(), w.r.w(), -w.r.x(),
1388  w.r.z(), -w.r.y(), w.r.x(), w.r.w();
1389 
1390  // propagate the covariances:
1391  oC = Ja * a.cov * Ja.transpose();
1392 }
1393 
1395 // Linear interpolation stuff
1396 
1406 template <typename T, int D, typename S>
1408  const RigidTransform<T, D>& t2,
1409  S alpha)
1410 {
1411  return RigidTransform<T, D>(lerp(t1.t, t2.t, alpha), // interpolate translation
1412  lerp(t1.r, t2.r, alpha)); // interpolate rotation
1413 }
1414 
1424 template <typename T, int D, typename S>
1426  const RigidTransformCov<T, D>& t2,
1427  S alpha)
1428 {
1429  return RigidTransformCov<T, D>(lerp(t1.t, t2.t, alpha), // interpolate translation
1430  lerp(t1.r, t2.r, alpha), // interpolate rotation
1431  lerp(t1.cov, t2.cov, alpha)); // interpolate covariance
1432 }
1433 
1434 
1436 // Sanity checks
1437 
1447 template<typename T, int D>
1449 {
1450  const auto transformMatrix = p.getMatrix();
1451  constexpr auto matrixDim = RigidTransform<T, D>::HDim;
1452  for (int i = 0; i < matrixDim; ++i) {
1453  for (int j = 0; j < matrixDim; ++j) {
1454  if (boost::math::isnan(transformMatrix(i,j))) {
1455  return false;
1456  }
1457  }
1458  }
1459  return true;
1460 }
1461 
1472 template<typename T, int D>
1474 {
1475  const auto transformValid = isWellDefined(static_cast<const RigidTransform<T, D>&>(p));
1476  if (!transformValid) {
1477  return false;
1478  }
1479 
1480  constexpr auto precision = Eigen::NumTraits<T>::dummy_precision();
1481  constexpr auto covDim = RigidTransformCov<T, D>::CovarianceDim;
1482 
1483  // check for nan
1484  for (int i = 0; i < covDim; ++i) {
1485  for (int j = 0; j < covDim; ++j) {
1486  if (boost::math::isnan(p.cov(i, j))) {
1487  return false;
1488  }
1489  }
1490  }
1491 
1492  // check for symmetry
1493  for (int i = 0; i < covDim; ++i) {
1494  for (int j = i + 1; j < covDim; ++j) {
1495  const bool almostEqual = std::abs(p.cov(i, j) - p.cov(j, i)) <= precision;
1496  if (!almostEqual) {
1497  return false;
1498  }
1499  }
1500  }
1501 
1502  // is positive semi definite?
1504  const auto covValid = ldlt.info() != Eigen::NumericalIssue && ldlt.isPositive();
1505  return covValid;
1506 }
1507 
1509 // specializations for Dx1 and dynamic matrices
1510 
1512 template< int D, typename TransformDerived, typename OtherDerived>
1513 struct ei_rigidtransform_product_impl<D, TransformDerived, OtherDerived,D, 1>
1514 {
1515  typedef typename OtherDerived::Scalar Scalar;
1516  typedef RigidTransformBase<Scalar, D, typename TransformDerived::RotationType, TransformDerived> TTransform;
1517  typedef const Eigen::Matrix<Scalar, D, 1> TResult;
1518 
1519 
1520  static TResult run(const TTransform& t, const OtherDerived& v)
1521  {
1522  // TODO: increase performance by using expression templates see Eigen/Geometry/Transform.h
1523  return t.r*v + t.t;
1524  }
1525 };
1526 
1527 template< int D, typename TransformDerived, typename OtherDerived>
1528 struct ei_rigidtransform_product_impl<D, TransformDerived, OtherDerived,Eigen::Dynamic, Eigen::Dynamic>
1529 {
1530  typedef typename OtherDerived::Scalar Scalar;
1531  typedef RigidTransformBase<Scalar, D, typename TransformDerived::RotationType, TransformDerived> TTransform;
1532  typedef const Eigen::Matrix<Scalar, D, 1> TResult;
1533 
1534 
1535  static TResult run(const TTransform& t, const OtherDerived& v)
1536  {
1537  // TODO: increase performance by using expression templates see Eigen/Geometry/Transform.h
1538  return t.r*v + t.t;
1539  }
1540 };
1541 
1543 
1545 
1546 }
1547 
1548 #endif
RigidTransformCov(const Base &transform)
Initialization from corresponding RigidTransform (without covariance).
Definition: RigidTransform.h:435
T Type
The used floating point type (float, double, long double)
Definition: RigidTransform.h:146
CovMatrixType cov
the covariance of the transform as matrix:
Definition: RigidTransform.h:1116
INTERNAL std::enable_if< std::is_floating_point< T >::value, T >::type deg2rad(T value)
Convert degree to radian, for floating point arguments (return type = argument type) ...
Definition: Angle.h:82
Specialization of RigidTransform for 3 dimensions.
Definition: RigidTransform.h:633
ei_rigidtransform_product_impl< D, TransformDerived, OtherDerived >::TResult operator*(const Eigen::MatrixBase< OtherDerived > &other) const
Apply the transformation to an Eigen matrix.
Definition: RigidTransform.h:226
static CovMatrixType nullCov()
Returns a "null covariance matrix".
Definition: RigidTransform.h:832
Eigen::Matrix< T, 6, 6 > quaternionCovToYawPitchRollCov(const Eigen::Matrix< T, 7, 7 > &covariance, const Eigen::Quaternion< T > &q)
Converts a 7x7 dimensional quaternion covariance (3D + Quaternion) back to a 6x6 dimensional euler co...
Definition: YawPitchRoll.h:318
RigidTransformCov()
Definition: RigidTransform.h:846
Include file for all eigen related things.
RigidTransformCov< U, 2 > cast() const
Returns *this casted to U.
Definition: RigidTransform.h:502
RigidTransform< float, 2 > RigidTransform2f
Typedef for 2D float transform.
Definition: RigidTransform.h:1122
size of the corresponding homogeneous space
Definition: RigidTransform.h:162
T phi() const
Returns the rotation angle represented by this transform in radian.
Definition: RigidTransform.h:364
boost::tuples::tuple< T, T, T > quaternionToYawPitchRoll(const Eigen::Quaternion< T > &q)
Converts a quaternion back to yaw, pitch, roll angles.
Definition: YawPitchRoll.h:299
static CovMatrixType nullCov()
Returns a "null covariance matrix".
Definition: RigidTransform.h:422
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
RigidTransformCov(T x, T y, const AngleBase< T, UnitTag, Derived > &angle, T covX, T covY, T covAngle)
Creates a new 2D transform with the specified translation and a rotation that is specified as Angle (...
Definition: RigidTransform.h:492
RigidTransformCov()
Definition: RigidTransform.h:428
RigidTransformCov(T x, T y, const AngleBase< T, UnitTag, Derived > &angle, const CovMatrixType &covariance)
Creates a new 2D transform with the specified translation and a rotation that is specified as Angle (...
Definition: RigidTransform.h:470
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:947
This class represents an affine transformation that supports a translation followed by a rotation (a ...
Definition: RigidTransform.h:128
void quaternionCovFromYawPitchRollCov(const Eigen::Matrix< T, 6, 6 > &eulerCovariance, float yaw, float pitch, float roll, Eigen::Quaternion< T > &oOrientation, Eigen::Matrix< T, 7, 7 > &oCovariance)
Converts 6x6 dimensional covariance matrix (3D + yaw, pitch and roll) angles to a 7x7 dimensional qua...
Definition: YawPitchRoll.h:201
T & phi()
Returns the rotation angle represented by this transform in radian.
Definition: RigidTransform.h:362
TransformDerived * This()
casts this to the actual derived type (see Curiously recurring template pattern)
Definition: RigidTransform.h:263
#define MIRA_SPLIT_REFLECT_MEMBER
Macro that insert a class member reflect() method just splitting reflection into a reflectRead() and ...
Definition: SplitReflect.h:189
Eigen::Matrix< T, CovarianceDim, CovarianceDim > CovMatrixType
The type of the matrix representing the covariance of the transformation.
Definition: RigidTransform.h:417
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
Definition: YawPitchRoll.h:684
Quaternion inverse(void) const
RigidTransform< float, 3 > RigidTransform3f
Typedef for 3D float transform.
Definition: RigidTransform.h:1124
bool isWellDefined(const RigidTransform< T, D > &p)
Checks whether a RigidTransform is valid.
Definition: RigidTransform.h:1448
T lerp(const T &a, const T &b, S alpha)
Linear interpolation of different types like scalars, angles and rotations, vectors, etc.
Definition: Lerp.h:76
RigidTransformCov(T x, T y, T z, T yaw, T pitch, T roll, const YawPitchRollCovMatrixType &yawPitchRollCov)
Initialization from the translation, rotation given as yaw/pitch/roll angles and the covariance matri...
Definition: RigidTransform.h:878
Implementation of RigidTransforms with different dimensionality D.
Definition: RigidTransform.h:141
static TransformDerived mul(const RigidTransformBase &a, const RigidTransformBase &b)
Definition: RigidTransform.h:271
Rotation2D inverse() const
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1049
Eigen::Matrix< T, EulerCovarianceDim, EulerCovarianceDim > YawPitchRollCovMatrixType
The type of the matrix representing the euler covariance of the transformation.
Definition: RigidTransform.h:825
EIGEN_MAKE_ALIGNED_OPERATOR_NEW RigidTransformBase(TranslationType translation, RotationType rotation)
Definition: RigidTransform.h:175
YawPitchRollCovMatrixType getYawPitchRollCov() const
Returns covariance matrix where the rotation covariance is represented using yaw, pitch...
Definition: RigidTransform.h:904
Functions for linear interpolation of different types like scalars, angles and rotations.
CovMatrixType cov
The covariance of the transform as matrix.
Definition: RigidTransform.h:600
void reflectWrite(Reflector &r)
Definition: RigidTransform.h:958
RigidTransformCov(const Base &transform)
Initialization from corresponding RigidTransform (without covariance).
Definition: RigidTransform.h:852
RigidTransformCov inverse() const
Definition: RigidTransform.h:528
Eigen::Matrix< T, D, 1 > TranslationType
Vector type used to represent the translational part (dimension depends on dimensionality of transfor...
Definition: RigidTransform.h:152
RigidTransformCov(T x, T y, T angle, T covX, T covY, T covAngle)
Creates a new 2D transform with the specified translation and a rotation that is specified in rad...
Definition: RigidTransform.h:481
friend std::ostream & operator<<(std::ostream &os, const RigidTransformCov &tf)
Definition: RigidTransform.h:517
RigidTransformCov< double, 3 > RigidTransformCov3d
Typedef for 3D double transform with covariance.
Definition: RigidTransform.h:1139
RigidTransform< U, 2 > cast() const
Returns *this casted to U.
Definition: RigidTransform.h:344
T pitch() const
Returns the pitch angle in rad.
Definition: RigidTransform.h:692
dimension of the Eucleadian space
Definition: RigidTransform.h:161
Conversion from yaw, pitch and roll to Quaternion and vice versa.
Deserializer that uses BinaryIstream to deserialize the objects from binary format.
Definition: BinarySerializer.h:925
RigidTransformCov< double, 2 > RigidTransformCov2d
Typedef for 2D double transform with covariance.
Definition: RigidTransform.h:1137
RigidTransform(T x, T y, const AngleBase< T, UnitTag, Derived > &angle)
Creates a new 2D transform with the specified translation and a rotation that is specified as Angle (...
Definition: RigidTransform.h:336
TRotation RotationType
Type used to represent the rotational part (Eigen::Rotation2D for 2D transforms, Eigen::Quaternion fo...
Definition: RigidTransform.h:158
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:296
RigidTransformCov(const Eigen::Matrix< T, 2, 1 > &translation, const Eigen::Rotation2D< T > &rotation, const CovMatrixType &covariance)
Creates a new 2D transform with the specified translation, the specified Rotation2D and a covairance ...
Definition: RigidTransform.h:442
T roll() const
Returns the roll angle in rad.
Definition: RigidTransform.h:700
RigidTransform(const Eigen::Matrix< T, 2, 1 > &translation, T angle)
Creates a new 2D transform with the specified translation and a rotation that is specified in rad...
Definition: RigidTransform.h:319
MatrixType getMatrix() const
Computes and returns the matrix that describes the affine transformation in homogeneous space...
Definition: RigidTransform.h:252
T & x()
Returns the x-coordinate of the translational part of the transform.
Definition: RigidTransform.h:663
RigidTransformCov< float, 2 > RigidTransformCov2f
Typedef for 2D float transform with covariance.
Definition: RigidTransform.h:1132
Type trait to define if a class is cheap to copy.
void reflect(PropertySerializer &r)
Definition: RigidTransform.h:980
Implementations of angles (values in periodic interval of width 2*pi) with arbitrary base type...
T & x()
Returns the x-coordinate of the translational part of the transform.
Definition: RigidTransform.h:352
RigidTransform< U, 3 > cast() const
Returns *this casted to U.
Definition: RigidTransform.h:655
TransformDerived & operator*=(const RigidTransformBase &other)
Concatenates this transform with an other transform.
Definition: RigidTransform.h:204
A special PropertyReflector that creates a PropertyNode for each reflected property.
Definition: PropertySerializer.h:68
RotationType r
The rotational part of the transform.
Definition: RigidTransform.h:285
friend std::ostream & operator<<(std::ostream &os, const RigidTransform &tf)
Definition: RigidTransform.h:378
T yaw() const
Returns the yaw angle in rad (This corresponds to phi in a 2D transform).
Definition: RigidTransform.h:684
RigidTransformCov(const Eigen::Matrix< T, 3, 1 > &translation, const Eigen::Quaternion< T > &rotation, const CovMatrixType &covariance)
Initialization from the translation, rotation as quaternion and the covariance matrix in quaternion s...
Definition: RigidTransform.h:859
Specialization of RigidTransform for 2 dimensions.
Definition: RigidTransform.h:297
friend TransformDerived operator*(const RigidTransformBase &a, const RigidTransformBase &b)
Concatenates the two transformations.
Definition: RigidTransform.h:214
void reflect(Reflector &m)
Definition: RigidTransform.h:369
friend std::ostream & operator<<(std::ostream &os, const RigidTransform &tf)
Definition: RigidTransform.h:775
RigidTransformCov< U, 3 > cast() const
Returns *this casted to U.
Definition: RigidTransform.h:891
bool isApprox(const RigidTransformBase &other, T prec=std::numeric_limits< T >::epsilon()) const
Returns true if this is approximately equal to other, within the precision determined by prec...
Definition: RigidTransform.h:193
void reflect(PropertySerializer &r)
Definition: RigidTransform.h:756
RigidTransformCov< float, 3 > RigidTransformCov3f
Typedef for 3D float transform with covariance.
Definition: RigidTransform.h:1134
T & y()
Returns the y-coordinate of the translational part of the transform.
Definition: RigidTransform.h:668
RigidTransformCov inverse() const
Definition: RigidTransform.h:1020
TransformDerived inverse() const
Computes and returns the inverse transform of this.
Definition: RigidTransform.h:182
T & y()
Returns the y-coordinate of the translational part of the transform.
Definition: RigidTransform.h:357
void reflect(Reflector &r)
Definition: RigidTransform.h:511
static YawPitchRollCovMatrixType nullYawPitchRollCov()
Returns an "null covariance matrix" witch yaw, pitch, roll rotation representation.
Definition: RigidTransform.h:840
T x() const
Returns the x-coordinate of the translational part of the transform.
Definition: RigidTransform.h:354
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Definition: RigidTransform.h:938
RigidTransform< double, 3 > RigidTransform3d
Typedef for 3D double transform.
Definition: RigidTransform.h:1129
T y() const
Returns the y-coordinate of the translational part of the transform.
Definition: RigidTransform.h:359
friend std::ostream & operator<<(std::ostream &os, const RigidTransformCov &tf)
Definition: RigidTransform.h:1008
Eigen::Matrix< typename Eigen::MatrixBase< Derived >::Scalar, 3, 1 > eulerAngles(const Eigen::MatrixBase< Derived > &mat, typename Eigen::MatrixBase< Derived >::Index a0, typename Eigen::MatrixBase< Derived >::Index a1, typename Eigen::MatrixBase< Derived >::Index a2)
Returns the Euler-angles of the rotation matrix mat using the convention defined by the triplet (a0...
Definition: YawPitchRoll.h:86
Eigen::Matrix< T, HDim, HDim > MatrixType
Type of the matrix that can describe the full affine transform in homogeneous space.
Definition: RigidTransform.h:169
T x() const
Returns the x-coordinate of the translational part of the transform.
Definition: RigidTransform.h:665
T y() const
Returns the y-coordinate of the translational part of the transform.
Definition: RigidTransform.h:670
RigidTransform(T x, T y, T angle)
Creates a new 2D transform with the specified translation and a rotation that is specified in rad...
Definition: RigidTransform.h:326
std::enable_if< std::is_base_of< BinarySerializer< Reflector >, Reflector >::value >::type reflect(Reflector &r)
Definition: RigidTransform.h:912
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Definition: RigidTransform.h:728
RigidTransform< double, 2 > RigidTransform2d
Typedef for 2D double transform.
Definition: RigidTransform.h:1127
const TransformDerived * This() const
casts this to the actual derived type (see Curiously recurring template pattern)
Definition: RigidTransform.h:265
PropertyHint precision(int p)
Sets the attribute "precision".
Definition: PropertyHint.h:286
RigidTransform(T x, T y, T z, T yaw, T pitch, T roll)
Definition: RigidTransform.h:647
RigidTransform(const Eigen::Matrix< T, 3, 1 > &translation, const Eigen::Quaternion< T > &rotation)
Definition: RigidTransform.h:643
void reflect(BinaryDeserializer< Derived > &r)
Definition: RigidTransform.h:716
std::enable_if< std::is_floating_point< T >::value, T >::type rad2deg(T value)
Convert radian to degree, for floating point arguments (return type = argument type) ...
Definition: Angle.h:106
RigidTransform()
Definition: RigidTransform.h:640
Eigen::Quaternion< T > quaternionFromYawPitchRoll(T yaw, T pitch, T roll)
Converts yaw, pitch and roll angles to a quaternion.
Definition: YawPitchRoll.h:156
RigidTransform()
Definition: RigidTransform.h:304
std::enable_if< std::is_base_of< BinarySerializer< Reflector >, Reflector >::value >::type reflect(Reflector &r)
Definition: RigidTransform.h:706
T & z()
Returns the z-coordinate of the translational part of the transform.
Definition: RigidTransform.h:673
void reflectWrite(Reflector &r)
Definition: RigidTransform.h:744
This class represents an affine transformation that supports a translation followed by a rotation (a ...
Definition: RigidTransform.h:101
RigidTransformCov(const Eigen::Matrix< T, 2, 1 > &translation, T angle, const CovMatrixType &covariance)
Creates a new 2D transform with the specified translation, a rotation that is specified in rad...
Definition: RigidTransform.h:451
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: PropertyReflector.h:126
RigidTransformCov(const Eigen::Matrix< T, 3, 1 > &translation, const Eigen::Quaternion< T > &rotation, const YawPitchRollCovMatrixType &yawPitchRollCov)
Initialization from the translation, rotation as quaternion and the covariance matrix in yaw/pitch/ro...
Definition: RigidTransform.h:868
Eigen::Matrix< T, CovarianceDim, CovarianceDim > CovMatrixType
The type of the matrix representing the covariance of the transformation.
Definition: RigidTransform.h:819
RigidTransformCov(T x, T y, T angle, const CovMatrixType &covariance)
Creates a new 2D transform with the specified translation, a rotation that is specified in rad...
Definition: RigidTransform.h:460
TranslationType t
Vector that describes the translational part of the transform.
Definition: RigidTransform.h:282
Provides definition for getters and setters that are used with the serialization framework.
void reflect(BinaryDeserializer< Derived > &r)
Definition: RigidTransform.h:924
T z() const
Returns the z-coordinate of the translational part of the transform.
Definition: RigidTransform.h:675
Base class template for derived Angle implementations.
Definition: Angle.h:183
RigidTransform(const Eigen::Matrix< T, 2, 1 > &translation, const Eigen::Rotation2D< T > &rotation)
Creates a new 2D transform with the specified translation and the specified Rotation2D.
Definition: RigidTransform.h:311