gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Point3.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 
20 // \callgraph
21 
22 #pragma once
23 
24 #include <gtsam/base/Matrix.h>
25 #include <gtsam/base/DerivedValue.h>
26 #include <gtsam/base/Lie.h>
27 
28 #include <boost/serialization/nvp.hpp>
29 
30 #include <cmath>
31 
32 namespace gtsam {
33 
39  class GTSAM_EXPORT Point3 : public DerivedValue<Point3> {
40  public:
42  static const size_t dimension = 3;
43 
44  private:
45  double x_, y_, z_;
46 
47  public:
48 
51 
53  Point3(): x_(0), y_(0), z_(0) {}
54 
56  Point3(double x, double y, double z): x_(x), y_(y), z_(z) {}
57 
61 
63  Point3(const Vector& v) {
64  if(v.size() != 3)
65  throw std::invalid_argument("Point3 constructor from Vector requires that the Vector have dimension 3");
66  x_ = v(0);
67  y_ = v(1);
68  z_ = v(2);
69  }
70 
74 
76  void print(const std::string& s = "") const;
77 
79  bool equals(const Point3& p, double tol = 1e-9) const;
80 
84 
86  inline static Point3 identity() {
87  return Point3();
88  }
89 
91  inline Point3 inverse() const { return Point3(-x_, -y_, -z_); }
92 
94  Point3 operator - () const { return Point3(-x_,-y_,-z_);}
95 
97  inline Point3 compose(const Point3& p2,
98  boost::optional<Matrix&> H1=boost::none,
99  boost::optional<Matrix&> H2=boost::none) const {
100  if (H1) *H1 = eye(3);
101  if (H2) *H2 = eye(3);
102  return *this + p2;
103  }
104 
106  Point3 operator + (const Point3& q) const;
107 
109  inline Point3 between(const Point3& p2,
110  boost::optional<Matrix&> H1=boost::none,
111  boost::optional<Matrix&> H2=boost::none) const {
112  if(H1) *H1 = -eye(3);
113  if(H2) *H2 = eye(3);
114  return p2 - *this;
115  }
116 
118  Point3 operator - (const Point3& q) const;
119 
123 
125  inline static size_t Dim() { return dimension; }
126 
128  inline size_t dim() const { return dimension; }
129 
131  inline Point3 retract(const Vector& v) const { return Point3(*this + v); }
132 
134  inline Vector3 localCoordinates(const Point3& q) const { return (q -*this).vector(); }
135 
139 
141  static inline Point3 Expmap(const Vector& v) { return Point3(v); }
142 
144  static inline Vector3 Logmap(const Point3& dp) { return Vector3(dp.x(), dp.y(), dp.z()); }
145 
147  static Matrix dexpL(const Vector& v) {
148  return eye(3);
149  }
150 
152  static Matrix dexpInvL(const Vector& v) {
153  return eye(3);
154  }
155 
159 
161  Point3 operator * (double s) const;
162 
164  Point3 operator / (double s) const;
165 
167  inline double distance(const Point3& p2) const {
168  return (p2 - *this).norm();
169  }
170 
172  inline double dist(const Point3& p2) const {
173  return (p2 - *this).norm();
174  }
175 
177  double norm() const;
178 
180  Point3 normalize(boost::optional<Matrix&> H = boost::none) const;
181 
183  Point3 cross(const Point3 &q) const;
184 
186  double dot(const Point3 &q) const;
187 
191 
193  bool operator ==(const Point3& q) const;
194 
196  Vector3 vector() const { return Vector3(x_,y_,z_); }
197 
199  inline double x() const {return x_;}
200 
202  inline double y() const {return y_;}
203 
205  inline double z() const {return z_;}
206 
208  Point3 add (const Point3 &q,
209  boost::optional<Matrix&> H1=boost::none, boost::optional<Matrix&> H2=boost::none) const;
210 
212  Point3 sub (const Point3 &q,
213  boost::optional<Matrix&> H1=boost::none, boost::optional<Matrix&> H2=boost::none) const;
214 
216 
218  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &os, const Point3& p);
219 
220  private:
221 
224 
226  friend class boost::serialization::access;
227  template<class ARCHIVE>
228  void serialize(ARCHIVE & ar, const unsigned int version)
229  {
230  ar & boost::serialization::make_nvp("Point3",
231  boost::serialization::base_object<Value>(*this));
232  ar & BOOST_SERIALIZATION_NVP(x_);
233  ar & BOOST_SERIALIZATION_NVP(y_);
234  ar & BOOST_SERIALIZATION_NVP(z_);
235  }
236 
238 
239  };
240 
242  inline Point3 operator*(double s, const Point3& p) { return p*s;}
243 
244 }
static Matrix dexpInvL(const Vector &v)
Left-trivialized derivative inverse of the exponential map.
Definition: Point3.h:152
static Point3 identity()
identity for group operation
Definition: Point3.h:86
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:259
double dist(const Point3 &p2) const
Definition: Point3.h:172
Base class and basic functions for Lie types.
Point3 between(const Point3 &p2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
Between using the default implementation.
Definition: Point3.h:109
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
Eigen::Block< const MATRIX > sub(const MATRIX &A, size_t i1, size_t i2, size_t j1, size_t j2)
extract submatrix, slice semantics, i.e.
Definition: Matrix.h:205
double distance(const Point3 &p2) const
distance between two points
Definition: Point3.h:167
Vector3 vector() const
return vectorized form (column-wise)
Definition: Point3.h:196
Point3 compose(const Point3 &p2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
"Compose" - just adds coordinates of two points
Definition: Point3.h:97
Vector3 localCoordinates(const Point3 &q) const
Returns inverse retraction.
Definition: Point3.h:134
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:249
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition: Matrix.h:104
Point3 inverse() const
"Inverse" - negates the coordinates such that compose(p, inverse(p)) = Point3()
Definition: Point3.h:91
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Point3(double x, double y, double z)
Construct from x, y, and z coordinates.
Definition: Point3.h:56
double z() const
get z
Definition: Point3.h:205
Template to create a binary predicate.
Definition: Testable.h:102
double y() const
get y
Definition: Point3.h:202
static Point3 Expmap(const Vector &v)
Exponential map at identity - just create a Point3 from x,y,z.
Definition: Point3.h:141
static Vector3 Logmap(const Point3 &dp)
Log map at identity - return the x,y,z of this point.
Definition: Point3.h:144
Point3()
Default constructor creates a zero-Point3.
Definition: Point3.h:53
typedef and functions to augment Eigen's MatrixXd
double x() const
get x
Definition: Point3.h:199
static Matrix dexpL(const Vector &v)
Left-trivialized derivative of the exponential map.
Definition: Point3.h:147
Point3 retract(const Vector &v) const
Updates a with tangent space delta.
Definition: Point3.h:131
Definition: DerivedValue.h:44
static size_t Dim()
dimension of the variable - used to autodetect sizes
Definition: Point3.h:125
Definition: Point3.h:39
size_t dim() const
return dimensionality of tangent space, DOF = 3
Definition: Point3.h:128
Point3(const Vector &v)
Construct from 3-element vector.
Definition: Point3.h:63