gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LieVector.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
18 #pragma once
19 
20 #include <gtsam/base/Lie.h>
21 #include <gtsam/base/Vector.h>
22 #include <gtsam/base/DerivedValue.h>
23 
24 namespace gtsam {
25 
29 struct LieVector : public Vector, public DerivedValue<LieVector> {
30 
32  LieVector() {}
33 
35  LieVector(const Vector& v) : Vector(v) {}
36 
37 // Currently TMP constructor causes ICE on MSVS 2013
38 #if (_MSC_VER < 1800)
39 
40  template<int N>
41  LieVector(const Eigen::Matrix<double, N, 1>& v) : Vector(v) {}
42 #endif
43 
45  LieVector(double d) : Vector((Vector(1) << d)) {}
46 
48  GTSAM_EXPORT LieVector(size_t m, const double* const data);
49 
51  Vector vector() const {
52  return static_cast<Vector>(*this);
53  }
54 
56  GTSAM_EXPORT void print(const std::string& name="") const;
57 
59  bool equals(const LieVector& expected, double tol=1e-5) const {
60  return gtsam::equal(vector(), expected.vector(), tol);
61  }
62 
63  // Manifold requirements
64 
66  size_t dim() const { return this->size(); }
67 
69  LieVector retract(const Vector& v) const { return LieVector(vector() + v); }
70 
72  Vector localCoordinates(const LieVector& t2) const { return LieVector(t2 - vector()); }
73 
74  // Group requirements
75 
77  static LieVector identity() {
78  throw std::runtime_error("LieVector::identity(): Don't use this function");
79  return LieVector();
80  }
81 
82  // Note: Manually specifying the 'gtsam' namespace for the optional Matrix arguments
83  // This is a work-around for linux g++ 4.6.1 that incorrectly selects the Eigen::Matrix class
84  // instead of the gtsam::Matrix class. This is related to deriving this class from an Eigen Vector
85  // as the other geometry objects (Point3, Rot3, etc.) have this problem
88  boost::optional<gtsam::Matrix&> H1=boost::none,
89  boost::optional<gtsam::Matrix&> H2=boost::none) const {
90  if(H1) *H1 = eye(dim());
91  if(H2) *H2 = eye(p.dim());
92 
93  return LieVector(vector() + p);
94  }
95 
98  boost::optional<gtsam::Matrix&> H1=boost::none,
99  boost::optional<gtsam::Matrix&> H2=boost::none) const {
100  if(H1) *H1 = -eye(dim());
101  if(H2) *H2 = eye(l2.dim());
102  return LieVector(l2.vector() - vector());
103  }
104 
106  LieVector inverse(boost::optional<gtsam::Matrix&> H=boost::none) const {
107  if(H) *H = -eye(dim());
108 
109  return LieVector(-1.0 * vector());
110  }
111 
112  // Lie functions
113 
115  static LieVector Expmap(const Vector& v) { return LieVector(v); }
116 
118  static Vector Logmap(const LieVector& p) { return p; }
119 
120 private:
121 
122  // Serialization function
123  friend class boost::serialization::access;
124  template<class Archive>
125  void serialize(Archive & ar, const unsigned int version) {
126  ar & boost::serialization::make_nvp("LieVector",
127  boost::serialization::base_object<Value>(*this));
128  ar & boost::serialization::make_nvp("Vector",
129  boost::serialization::base_object<Vector>(*this));
130  }
131 
132 };
133 } // \namespace gtsam
LieVector retract(const Vector &v) const
Update the LieVector with a tangent space update.
Definition: LieVector.h:69
static LieVector identity()
identity - NOTE: no known size at compile time - so zero length
Definition: LieVector.h:77
typedef and functions to augment Eigen's VectorXd
LieVector between(const LieVector &l2, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none) const
between operation
Definition: LieVector.h:97
Base class and basic functions for Lie types.
size_t dim() const
Returns dimensionality of the tangent space.
Definition: LieVector.h:66
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
Vector localCoordinates(const LieVector &t2) const
Definition: LieVector.h:72
static LieVector Expmap(const Vector &v)
Expmap around identity.
Definition: LieVector.h:115
LieVector inverse(boost::optional< gtsam::Matrix & > H=boost::none) const
invert the object and yield a new one
Definition: LieVector.h:106
LieVector(double d)
wrap a double
Definition: LieVector.h:45
bool equals(const LieVector &expected, double tol=1e-5) const
equality up to tolerance
Definition: LieVector.h:59
GTSAM_EXPORT void print(const std::string &name="") const
print
Definition: LieVector.cpp:34
LieVector(const Vector &v)
initialize from a normal vector
Definition: LieVector.h:35
bool equal(const T &obj1, const T &obj2, double tol)
Call equal on the object.
Definition: Testable.h:75
static Vector Logmap(const LieVector &p)
Logmap around identity - just returns with default cast back.
Definition: LieVector.h:118
Vector vector() const
get the underlying vector
Definition: LieVector.h:51
LieVector is a wrapper around vector to allow it to be a Lie type.
Definition: LieVector.h:29
LieVector()
default constructor - should be unnecessary
Definition: LieVector.h:32
LieVector(const Eigen::Matrix< double, N, 1 > &v)
initialize from a fixed size normal vector
Definition: LieVector.h:41
LieVector compose(const LieVector &p, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none) const
compose with another object
Definition: LieVector.h:87
Definition: DerivedValue.h:44