24 #include <gtsam/dllexport.h> 27 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 28 #include <boost/serialization/nvp.hpp> 33 #include <type_traits> 54 class SO :
public LieGroup<SO<N>, internal::DimensionSO(N)> {
71 using
IsFixed = typename
std::enable_if<N_ >= 2,
void>::type;
73 using
IsSO3 = typename
std::enable_if<N_ == 3,
void>::type;
80 template <
int N_ =
N, typename =
IsFixed<N_>>
84 template <
int N_ = N,
typename = IsDynamic<N_>>
85 explicit SO(
size_t n = 0) {
88 matrix_ = Eigen::MatrixXd::Identity(
n,
n);
92 template <
typename Derived>
96 template <
typename Derived>
102 template <
typename Derived,
int N_ = N,
typename = IsDynamic<N_>>
104 Matrix Q = Matrix::Identity(n, n);
105 const int p = R.rows();
106 assert(p >= 0 && p <= static_cast<int>(n) && R.cols() ==
p);
112 template <
int M,
int N_ = N,
typename = IsDynamic<N_>>
116 template <
int N_ = N,
typename = IsSO3<N_>>
120 static SO AxisAngle(
const Vector3& axis,
double theta);
129 static SO ChordalMean(
const std::vector<SO>& rotations);
132 template <
int N_ = N,
typename = IsDynamic<N_>>
134 if (
n == 0)
throw std::runtime_error(
"SO: Dimensionality not known.");
136 static std::uniform_real_distribution<double> randomAngle(-
M_PI,
M_PI);
139 for (
size_t j = 0;
j <
d;
j++) {
140 xi(
j) = randomAngle(rng);
146 template <
int N_ = N,
typename = IsFixed<N_>>
159 size_t rows()
const {
return matrix_.rows(); }
160 size_t cols()
const {
return matrix_.cols(); }
166 void print(
const std::string&
s = std::string())
const;
178 assert(dim() == other.
dim());
183 template <
int N_ = N,
typename = IsFixed<N_>>
189 template <
int N_ = N,
typename = IsDynamic<N_>>
205 static int Dim() {
return dimension; }
209 static size_t Dimension(
size_t n) {
return n * (n - 1) / 2; }
216 size_t dim()
const {
return Dimension(static_cast<size_t>(matrix_.rows())); }
256 template <
int N_ = N,
typename = IsDynamic<N_>>
258 const size_t d = Dimension(n);
259 return MatrixDD::Identity(d, d);
301 template <
int N_ = N,
typename = IsFixed<N_>>
303 constexpr
size_t N2 =
static_cast<size_t>(
N *
N);
305 for (
size_t j = 0;
j < dimension;
j++) {
306 const auto X = Hat(Vector::Unit(dimension,
j));
313 template <
int N_ = N,
typename = IsDynamic<N_>>
315 const size_t n2 =
n *
n, dim = Dimension(n);
317 for (
size_t j = 0;
j < dim;
j++) {
318 const auto X = Hat(Vector::Unit(dim,
j));
328 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 329 template <
class Archive>
330 friend void save(Archive&,
SO&,
const unsigned int);
331 template <
class Archive>
332 friend void load(Archive&,
SO&,
const unsigned int);
333 template <
class Archive>
334 friend void serialize(Archive&,
SO&,
const unsigned int);
335 friend class boost::serialization::access;
382 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 384 template<
class Archive>
387 const unsigned int file_version
390 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)
SO inverse() const
inverse of a rotation = transpose
make_shared trampoline function to ensure proper alignment
std::string serialize(const T &input)
serializes to a string
JacobiRotation< float > G
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
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
static SO Identity()
SO<N> identity for N >= 2.
Rot2 R(Rot2::fromAngle(0.1))
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)
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(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.
EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedBlockXpr< internal::get_fixed_value< NRowsType >::value, internal::get_fixed_value< NColsType >::value >::Type topLeftCorner(NRowsType cRows, NColsType cCols)
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
static Matrix VectorizedGenerators(size_t n=0)
Calculate n^2 x dim matrix of vectorized Lie algebra generators for SO(n)
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
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)
Base class and basic functions for Manifold types.
const MatrixNN & matrix() const
Return matrix.
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.
Vector::Scalar omega(const Vector &t, const Vector &s, RealScalar angle)
static SO Identity(size_t n=0)
SO<N> identity for N == Eigen::Dynamic.
typename std::enable_if< N_ >=2, void >::type IsFixed
SO(const Eigen::MatrixBase< Derived > &R)
Constructor from Eigen Matrix, dynamic version.
Class compose(const Class &g) const
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.
static SO Lift(size_t n, const Eigen::MatrixBase< Derived > &R)
Named constructor from lower dimensional matrix.
SO operator*(const SO &other) const
Multiplication.
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)
Jet< T, N > sqrt(const Jet< T, N > &f)
static MatrixDD IdentityJacobian(size_t n)
SO(size_t n=0)
Construct SO<N> identity for N == Eigen::Dynamic.
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.
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
bool equals(const SO &other, double tol) const
VectorN2 vec(OptionalJacobian< internal::NSquaredSO(N), dimension > H={}) const