27 #ifndef G2O_SE3QUAT_H_ 28 #define G2O_SE3QUAT_H_ 33 #include <Eigen/Geometry> 36 using namespace Eigen;
58 SE3Quat(
const Matrix3d& R,
const Vector3d& t):_r(Quaterniond(R)),_t(t){
62 SE3Quat(
const Quaterniond& q,
const Vector3d& t):_r(q),_t(t){
69 template <
typename Derived>
70 explicit SE3Quat(
const MatrixBase<Derived>& v)
72 assert((v.size() == 6 || v.size() == 7) &&
"Vector dimension does not match");
74 for (
int i=0; i<3; i++){
76 _r.coeffs()(i)=v[i+3];
82 double w2=1.-_r.squaredNorm();
83 _r.w()= (w2<0.) ? 0. : sqrt(w2);
86 else if (v.size() == 7) {
88 for (
int i=0; i<3; ++i, ++idx)
90 for (
int i=0; i<4; ++i, ++idx)
91 _r.coeffs()(i) = v(idx);
100 inline const Quaterniond&
rotation()
const {
return _r;}
106 result.
_t += _r*tr2.
_t;
119 inline Vector3d operator* (
const Vector3d& v)
const {
125 ret.
_r=_r.conjugate();
126 ret.
_t=ret.
_r*(_t*-1.);
130 inline double operator [](
int i)
const {
134 return _r.coeffs()[i-3];
151 _r=Quaterniond(v[6], v[3], v[4], v[5]);
152 _t=Vector3d(v[0], v[1], v[2]);
167 double w = 1.-v[3]*v[3]-v[4]*v[4]-v[5]*v[5];
169 _r=Quaterniond(sqrt(w), v[3], v[4], v[5]);
171 _r=Quaterniond(0, -v[3], -v[4], -v[5]);
173 _t=Vector3d(v[0], v[1], v[2]);
180 Matrix3d _R = _r.toRotationMatrix();
181 double d = 0.5*(_R(0,0)+_R(1,1)+_R(2,2)-1);
193 Matrix3d Omega =
skew(omega);
194 V_inv = Matrix3d::Identity()- 0.5*Omega + (1./12.)*(Omega*Omega);
198 double theta = acos(d);
199 omega = theta/(2*sqrt(1-d*d))*dR;
200 Matrix3d Omega =
skew(omega);
201 V_inv = ( Matrix3d::Identity() - 0.5*Omega
202 + ( 1-theta/(2*tan(theta/2)))/(theta*theta)*(Omega*Omega) );
206 for (
int i=0; i<3;i++){
209 for (
int i=0; i<3;i++){
217 Vector3d
map(
const Vector3d & xyz)
const 226 for (
int i=0; i<3; i++)
229 for (
int i=0; i<3; i++)
230 upsilon[i]=update[i+3];
232 double theta = omega.norm();
233 Matrix3d Omega =
skew(omega);
240 R = (Matrix3d::Identity() + Omega + Omega*Omega);
246 Matrix3d Omega2 = Omega*Omega;
248 R = (Matrix3d::Identity()
249 + sin(theta)/theta *Omega
250 + (1-cos(theta))/(theta*theta)*Omega2);
252 V = (Matrix3d::Identity()
253 + (1-cos(theta))/(theta*theta)*Omega
254 + (theta-sin(theta))/(pow(theta,3))*Omega2);
256 return SE3Quat(Quaterniond(R),V*upsilon);
259 Matrix<double, 6, 6>
adj()
const 261 Matrix3d R = _r.toRotationMatrix();
262 Matrix<double, 6, 6> res;
263 res.block(0,0,3,3) = R;
264 res.block(3,3,3,3) = R;
265 res.block(3,0,3,3) =
skew(_t)*R;
266 res.block(0,3,3,3) = Matrix3d::Zero(3,3);
272 Matrix<double,4,4> homogeneous_matrix;
273 homogeneous_matrix.setIdentity();
274 homogeneous_matrix.block(0,0,3,3) = _r.toRotationMatrix();
275 homogeneous_matrix.col(3).head(3) = translation();
277 return homogeneous_matrix;
290 operator Eigen::Isometry3d()
const 292 Eigen::Isometry3d result = (Eigen::Isometry3d) rotation();
293 result.translation() = translation();
Matrix< double, 7, 1 > Vector7d
std::ostream & operator<<(std::ostream &os, const G2OBatchStatistics &st)
void setRotation(const Quaterniond &r_)
Vector3d deltaR(const Matrix3d &R)
Vector7d toVector() const
Matrix< double, 6, 1 > Vector6d
void setTranslation(const Vector3d &t_)
static SE3Quat exp(const Vector6d &update)
Vector6d toMinimalVector() const
SE3Quat(const MatrixBase< Derived > &v)
void fromMinimalVector(const Vector6d &v)
SE3Quat(const Quaterniond &q, const Vector3d &t)
void fromVector(const Vector7d &v)
const Vector3d & translation() const
TFSIMD_FORCE_INLINE const tfScalar & w() const
Matrix3d skew(const Vector3d &v)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Matrix< double, 4, 4 > to_homogeneous_matrix() const
const Quaterniond & rotation() const
Vector3d map(const Vector3d &xyz) const
SE3Quat(const Matrix3d &R, const Vector3d &t)
Matrix< double, 6, 6 > adj() const