24 #include <gtsam/dllexport.h> 29 #include <type_traits> 50 class SO :
public LieGroup<SO<N>, internal::DimensionSO(N)> {
67 using
IsFixed = typename
std::enable_if<N_ >= 2,
void>::type;
69 using
IsSO3 = typename
std::enable_if<N_ == 3,
void>::type;
76 template <
int N_ =
N, typename =
IsFixed<N_>>
80 template <
int N_ = N,
typename = IsDynamic<N_>>
81 explicit SO(
size_t n = 0) {
84 matrix_ = Eigen::MatrixXd::Identity(
n,
n);
88 template <
typename Derived>
92 template <
typename Derived>
98 template <
typename Derived,
int N_ = N,
typename = IsDynamic<N_>>
100 Matrix Q = Matrix::Identity(n, n);
101 const int p = R.rows();
102 assert(p >= 0 && p <= static_cast<int>(n) && R.cols() ==
p);
108 template <
int M,
int N_ = N,
typename = IsDynamic<N_>>
112 template <
int N_ = N,
typename = IsSO3<N_>>
124 static SO ChordalMean(
const std::vector<SO>& rotations);
127 template <
int N_ = N,
typename = IsDynamic<N_>>
129 if (
n == 0)
throw std::runtime_error(
"SO: Dimensionality not known.");
131 static std::uniform_real_distribution<double> randomAngle(-
M_PI,
M_PI);
134 for (
size_t j = 0;
j <
d;
j++) {
135 xi(
j) = randomAngle(rng);
141 template <
int N_ = N,
typename = IsFixed<N_>>
154 size_t rows()
const {
return matrix_.rows(); }
155 size_t cols()
const {
return matrix_.cols(); }
161 void print(
const std::string&
s = std::string())
const;
173 assert(
dim() == other.
dim());
178 template <
int N_ = N,
typename = IsFixed<N_>>
184 template <
int N_ = N,
typename = IsDynamic<N_>>
200 static int Dim() {
return dimension; }
204 static size_t Dimension(
size_t n) {
return n * (n - 1) / 2; }
211 size_t dim()
const {
return Dimension(static_cast<size_t>(matrix_.rows())); }
251 template <
int N_ = N,
typename = IsDynamic<N_>>
253 const size_t d = Dimension(n);
254 return MatrixDD::Identity(d, d);
296 template <
int N_ = N,
typename = IsFixed<N_>>
298 constexpr
size_t N2 =
static_cast<size_t>(
N *
N);
300 for (
size_t j = 0;
j < dimension;
j++) {
301 const auto X = Hat(Vector::Unit(dimension,
j));
308 template <
int N_ = N,
typename = IsDynamic<N_>>
310 const size_t n2 =
n *
n,
dim = Dimension(n);
312 for (
size_t j = 0;
j <
dim;
j++) {
313 const auto X = Hat(Vector::Unit(dim,
j));
323 template <
class Archive>
324 friend void save(Archive&,
SO&,
const unsigned int);
325 template <
class Archive>
326 friend void load(Archive&,
SO&,
const unsigned int);
327 template <
class Archive>
328 friend void serialize(Archive&,
SO&,
const unsigned int);
329 friend class boost::serialization::access;
372 template<
class Archive>
375 const unsigned int file_version
378 ar& BOOST_SERIALIZATION_NVP(M);
void print(const Matrix &A, const string &s, ostream &stream)
static MatrixNN Hat(const TangentVector &xi)
static int Dim()
Return compile-time dimensionality: fixed size N or Eigen::Dynamic.
Matrix< RealScalar, Dynamic, Dynamic > M
void save(const Matrix &A, const string &s, const string &filename)
VectorN2 vec(OptionalJacobian< internal::NSquaredSO(N), dimension > H=boost::none) const
make_shared trampoline function to ensure proper alignment
std::string serialize(const T &input)
serializes to a string
JacobiRotation< float > G
static SO identity(size_t n=0)
SO<N> identity for N == Eigen::Dynamic.
A matrix or vector expression mapping an existing array of data.
Template implementations for SO(n)
typename std::enable_if< N_==3, void >::type IsSO3
EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL EIGEN_DEVICE_FUNC BlockXpr topLeftCorner(Index cRows, Index cCols)
SO operator*(const SO &other) const
Multiplication.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Rot2 R(Rot2::fromAngle(0.1))
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
static Matrix VectorizedGenerators()
Calculate N^2 x dim matrix of vectorized Lie algebra generators for SO(N)
Namespace containing all symbols from the Eigen library.
Pose2_ Expmap(const Vector3_ &xi)
const MatrixNN & matrix() const
Return matrix.
static size_t Dimension(size_t n)
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
SO inverse() const
inverse of a rotation = transpose
SO(const SO< M > &R)
Construct dynamic SO(n) from Fixed SO<M>
constexpr int DimensionSO(int N)
Calculate dimensionality of SO<N> manifold, or return Dynamic if so.
static Matrix VectorizedGenerators(size_t n=0)
Calculate n^2 x dim matrix of vectorized Lie algebra generators for SO(n)
void g(const string &key, int i)
constexpr int NSquaredSO(int N)
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
MatrixNN matrix_
Rotation matrix.
static size_t AmbientDim(size_t d)
Class compose(const Class &g) const
Base class and basic functions for Manifold types.
static SO identity()
SO<N> identity for N >= 2.
static SO Random(std::mt19937 &rng, size_t n=0)
Random SO(n) element (no big claims about uniformity). SO(3) is specialized in SO3.cpp.
typename std::enable_if< N_ >=2, void >::type IsFixed
SO(const Eigen::MatrixBase< Derived > &R)
Constructor from Eigen Matrix, dynamic version.
SO(const Eigen::AngleAxisd &angleAxis)
Constructor from AngleAxisd.
Base class and basic functions for Lie types.
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
static SO FromMatrix(const Eigen::MatrixBase< Derived > &R)
Named constructor from Eigen Matrix.
A matrix or vector expression mapping an existing expression.
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
static SO Lift(size_t n, const Eigen::MatrixBase< Derived > &R)
Named constructor from lower dimensional matrix.
Both LieGroupTraits and Testable.
The quaternion class used to represent 3D orientations and rotations.
Class between(const Class &g) const
static SO< N > Retract(const TangentVector &v)
Retract at origin: possible in Lie group because it has an identity.
static SO Random(std::mt19937 &rng)
Random SO(N) element (no big claims about uniformity)
internal::nested_eval< T, 1 >::type eval(const T &xpr)
static MatrixDD IdentityJacobian(size_t n)
SO(size_t n=0)
Construct SO<N> identity for N == Eigen::Dynamic.
void load(Archive &ar, Eigen::Matrix< Scalar_, Rows_, Cols_, Ops_, MaxRows_, MaxCols_ > &m, const unsigned int)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
static TangentVector Vee(const MatrixNN &X)
Inverse of Hat. See note about xi element order in Hat.
bool equals(const SO &other, double tol) const
Base class for all dense matrices, vectors, and expressions.
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
typename std::enable_if< N_==Eigen::Dynamic, void >::type IsDynamic
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const