34 for (
const auto& [
a,
b] : abPointPairs) {
35 Point3 da =
a - centroids.first;
36 Point3 db =
b - centroids.second;
37 d_abPointPairs.emplace_back(da, db);
39 return d_abPointPairs;
49 for (
const auto& [da, db] : d_abPointPairs) {
50 const Vector3 da_prime = aRb * db;
51 y += da.transpose() * da_prime;
52 x += da_prime.transpose() * da_prime;
61 for (
const auto& [da, db] : d_abPointPairs) {
62 H += da * db.transpose();
74 const Point3 aTb = (centroids.first - s * (aRb * centroids.second)) /
s;
82 auto centroids =
means(abPointPairs);
84 return align(d_abPointPairs, aRb, centroids);
118 std::cout << std::endl;
121 std::cout <<
"t: " <<
translation().transpose() <<
" s: " <<
scale() << std::endl;
143 const Matrix3 DR = sR *
skewSymmetric(-p.x(), -p.y(), -p.z());
144 *H1 << DR, sR, sR *
p;
164 if (abPointPairs.size() < 3)
165 throw std::runtime_error(
"input should have at least 3 pairs of points");
166 auto centroids =
means(abPointPairs);
175 const size_t n = abPosePairs.size();
177 throw std::runtime_error(
"input should have at least 2 pairs of poses");
180 vector<Rot3> rotations;
182 rotations.reserve(n);
183 abPointPairs.reserve(n);
186 for (
const auto &[aTi, bTi] : abPosePairs) {
188 rotations.emplace_back(aRb);
191 const Rot3 aRb_estimate = FindKarcherMean<Rot3>(rotations);
198 const auto w = xi.head<3>();
199 const auto u = xi.segment<3>(3);
200 const double lambda = xi[6];
212 adj <<
R, Z_3x3, Matrix31::Zero(),
220 const double theta2 = w.transpose() *
w;
223 const double theta =
sqrt(theta2);
224 const double X =
sin(theta) / theta;
225 Y = (1 -
cos(theta)) / theta2;
226 Z = (1 -
X) / theta2;
227 W = (0.5 -
Y) / theta2;
230 Y = 0.5 - theta2 / 24.0;
231 Z = 1.0 / 6.0 - theta2 / 120.0;
232 W = 1.0 / 24.0 - theta2 / 720.0;
234 const double lambda2 = lambda *
lambda, lambda3 = lambda2 *
lambda;
235 const double expMinLambda =
exp(-lambda);
237 if (lambda2 > 1
e-9) {
238 A = (1.0 - expMinLambda) / lambda;
239 alpha = 1.0 / (1.0 + theta2 / lambda2);
240 beta = (expMinLambda - 1 +
lambda) / lambda2;
241 mu = (1 - lambda + (0.5 * lambda2) - expMinLambda) / lambda3;
243 A = 1.0 - lambda / 2.0 + lambda2 / 6.0;
244 beta = 0.5 - lambda / 6.0 + lambda2 / 24.0 - lambda3 / 120.0;
245 mu = 1.0 / 6.0 - lambda / 24.0 + lambda2 / 120.0 - lambda3 / 720.0;
247 const double gamma = Y - (lambda *
Z), upsilon = Z - (lambda * W);
248 const double B = alpha * (beta - gamma) + gamma;
249 const double C = alpha * (mu - upsilon) + upsilon;
251 return A * I_3x3 + B * Wx + C * Wx * Wx;
262 throw std::runtime_error(
"Similarity3::Logmap: derivative not implemented");
268 const auto w = v.head<3>();
269 const auto u = v.segment<3>(3);
270 const double lambda = v[6];
272 throw std::runtime_error(
"Similarity3::Expmap: derivative not implemented");
274 const Matrix3
V =
GetV(
w, lambda);
287 T.bottomRows<1>() << 0, 0, 0, 1.0 /
s_;
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
bool operator==(const Similarity3 &other) const
Exact equality.
static Similarity3 Align(const Point3Pairs &abPointPairs)
static Vector7 Logmap(const Similarity3 &s, OptionalJacobian< 7, 7 > Hm={})
void print(const std::string &s) const
Print with optional string.
Jet< T, N > cos(const Jet< T, N > &f)
const Point3 & translation(OptionalJacobian< 3, 6 > Hself={}) const
get translation
Rot3 rotation() const
Return a GTSAM rotation.
bool equals(const Rot3 &p, double tol=1e-9) const
Rot2 R(Rot2::fromAngle(0.1))
Jet< T, N > sin(const Jet< T, N > &f)
Similarity3 inverse() const
Return the inverse.
static Matrix4 wedge(const Vector7 &xi)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange [*:*] noreverse nowriteback set trange [*:*] noreverse nowriteback set urange [*:*] noreverse nowriteback set vrange [*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Similarity3 operator*(const Similarity3 &S) const
Composition.
EIGEN_DEVICE_FUNC const LogReturnType log() const
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
static Rot3 Expmap(const Vector3 &v, OptionalJacobian< 3, 3 > H={})
Matrix7 AdjointMap() const
Project from one tangent space to another.
static Similarity3 Identity()
Return an identity transform.
mat1 topRightCorner(size/2, size/2)
static Similarity3 align(const Point3Pairs &d_abPointPairs, const Rot3 &aRb, const Point3Pair ¢roids)
This method estimates the similarity transform from differences point pairs,.
Rot3 inverse() const
inverse of a rotation
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
static double calculateScale(const Point3Pairs &d_abPointPairs, const Rot3 &aRb)
Form inner products x and y and calculate scale.
Vector3 xyz(OptionalJacobian< 3, 3 > H={}) const
static Vector3 Logmap(const Rot3 &R, OptionalJacobian< 3, 3 > H={})
Point3 translation() const
Return a GTSAM translation.
Base class and basic functions for Manifold types.
Similarity3()
Default constructor.
Array< int, Dynamic, 1 > v
static Point3Pairs subtractCentroids(const Point3Pairs &abPointPairs, const Point3Pair ¢roids)
Subtract centroids from point pairs.
Eigen::Triplet< double > T
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EIGEN_DEVICE_FUNC const Scalar & q
Class compose(const Class &g) const
Matrix4 matrix() const
Calculate 4*4 matrix group equivalent.
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
static Similarity3 Expmap(const Vector7 &v, OptionalJacobian< 7, 7 > Hm={})
Matrix< Scalar, Dynamic, Dynamic > C
Point3 transformFrom(const Point3 &p, OptionalJacobian< 3, 7 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
Action on a point p is s*(R*p+t)
friend std::ostream & operator<<(std::ostream &os, const Similarity3 &p)
Point2Pair means(const std::vector< Point2Pair > &abPointPairs)
Calculate the two means of a set of Point2 pairs.
Matrix3 skewSymmetric(double wx, double wy, double wz)
ofstream os("timeSchurFactors.csv")
static Matrix3 calculateH(const Point3Pairs &d_abPointPairs)
Form outer product H.
static Matrix3 GetV(Vector3 w, double lambda)
Calculate expmap and logmap coefficients.
bool equals(const Similarity3 &sim, double tol) const
Compare with tolerance.
static Rot3 ClosestTo(const Matrix3 &M)
void print(const std::string &s="") const
const Rot3 & rotation(OptionalJacobian< 3, 6 > Hself={}) const
get rotation
Jet< T, N > sqrt(const Jet< T, N > &f)
Implementation of Similarity3 transform.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
std::vector< Point3Pair > Point3Pairs
static Similarity3 alignGivenR(const Point3Pairs &abPointPairs, const Rot3 &aRb)
This method estimates the similarity transform from point pairs, given a known or estimated rotation...
double scale() const
Return the scale.
Eigen::Block< Derived > topLeftCorner(MatrixBase< Derived > &m, int rows, int cols)
std::pair< Point3, Point3 > Point3Pair