31 #include <Eigen/Geometry> 35 using namespace Eigen;
37 typedef Matrix <double, 7, 1>
Vector7d;
43 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59 Sim3(
const Quaterniond & r,
const Vector3d & t,
double s)
64 Sim3(
const Matrix3d & R,
const Vector3d & t,
double s)
65 : r(Quaterniond(R)),t(t),s(s)
70 Sim3(
const Vector7d & update)
74 for (
int i=0; i<3; i++)
78 for (
int i=0; i<3; i++)
79 upsilon[i]=update[i+3];
81 double sigma = update[6];
82 double theta = omega.norm();
83 Matrix3d Omega =
skew(omega);
85 Matrix3d Omega2 = Omega*Omega;
99 R = (I + Omega + Omega*Omega);
103 double theta2= theta*theta;
104 A = (1-cos(theta))/(theta2);
105 B = (theta-sin(theta))/(theta2*theta);
106 R = I + sin(theta)/theta *Omega + (1-cos(theta))/(theta*theta)*Omega2;
114 double sigma2= sigma*sigma;
115 A = ((sigma-1)*s+1)/sigma2;
116 B= ((0.5*sigma2-sigma+1)*s)/(sigma2*sigma);
117 R = (I + Omega + Omega2);
121 R = I + sin(theta)/theta *Omega + (1-cos(theta))/(theta*theta)*Omega2;
125 double a=s*sin(theta);
126 double b=s*cos(theta);
127 double theta2= theta*theta;
128 double sigma2= sigma*sigma;
130 double c=theta2+sigma2;
131 A = (a*sigma+ (1-b)*theta)/(theta*c);
132 B = (C-((b-1)*sigma+a*theta)/(c))*1./(theta2);
140 Matrix3d W = A*Omega + B*Omega2 + C*I;
144 Vector3d
map (
const Vector3d& xyz)
const {
145 return s*(r*xyz) + t;
151 double sigma = std::log(s);
160 Matrix3d R = r.toRotationMatrix();
161 double d = 0.5*(R(0,0)+R(1,1)+R(2,2)-1);
165 double eps = 0.00001;
166 Matrix3d I = Matrix3d::Identity();
181 double theta = acos(d);
182 double theta2 = theta*theta;
183 omega = theta/(2*sqrt(1-d*d))*
deltaR(R);
185 A = (1-cos(theta))/(theta2);
186 B = (theta-sin(theta))/(theta2*theta);
195 double sigma2 = sigma*sigma;
198 A = ((sigma-1)*s+1)/(sigma2);
199 B = ((0.5*sigma2-sigma+1)*s)/(sigma2*sigma);
203 double theta = acos(d);
204 omega = theta/(2*sqrt(1-d*d))*
deltaR(R);
206 double theta2 = theta*theta;
207 double a=s*sin(theta);
208 double b=s*cos(theta);
209 double c=theta2 + sigma*sigma;
210 A = (a*sigma+ (1-b)*theta)/(theta*c);
211 B = (C-((b-1)*sigma+a*theta)/(c))*1./(theta2);
215 Matrix3d W = A*Omega + B*Omega*Omega + C*I;
217 upsilon = W.lu().solve(t);
220 for (
int i=0; i<3; i++)
223 for (
int i=0; i<3; i++)
224 res[i+3] = upsilon[i];
235 return Sim3(r.conjugate(), r.conjugate()*((-1./s)*t), 1./s);
244 return r.coeffs()[i];
257 return r.coeffs()[i];
269 ret.
t=s*(r*other.
t)+t;
275 Sim3 ret=(*this)*other;
284 inline const Quaterniond&
rotation()
const {
return r;}
288 inline const double&
scale()
const {
return s;}
297 out_str << sim3.
rotation().coeffs() << std::endl;
299 out_str << sim3.
scale() << std::endl;
Matrix< double, 7, 1 > Vector7d
std::ostream & operator<<(std::ostream &os, const G2OBatchStatistics &st)
Sim3(const Quaterniond &r, const Vector3d &t, double s)
Vector3d deltaR(const Matrix3d &R)
const Vector3d & translation() const
Sim3(const Matrix3d &R, const Vector3d &t, double s)
Matrix< double, 7, 7 > Matrix7d
double operator[](int i) const
double & operator[](int i)
Sim3(const Vector7d &update)
const double & scale() const
Matrix3d skew(const Vector3d &v)
Vector3d map(const Vector3d &xyz) const
const Quaterniond & rotation() const