gtsam  4.0.0
gtsam
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/config.h>
25 #include <gtsam/base/VectorSpace.h>
26 #include <gtsam/base/Vector.h>
27 #include <gtsam/dllexport.h>
28 #include <boost/serialization/nvp.hpp>
29 
30 namespace gtsam {
31 
32 #ifdef GTSAM_TYPEDEF_POINTS_TO_VECTORS
33 
36  typedef Vector3 Point3;
37 
38 #else
39 
45 class GTSAM_EXPORT Point3 : public Vector3 {
46 
47  public:
48 
49  enum { dimension = 3 };
50 
53 
54  // Deprecated default constructor initializes to zero, in contrast to new behavior below
55 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4
56  Point3() { setZero(); }
57 #endif
58 
59  using Vector3::Vector3;
60 
64 
66  void print(const std::string& s = "") const;
67 
69  bool equals(const Point3& p, double tol = 1e-9) const;
70 
74 
76  inline static Point3 identity() { return Point3(0.0, 0.0, 0.0); }
77 
81 
83  double distance(const Point3& p2, OptionalJacobian<1, 3> H1 = boost::none,
84  OptionalJacobian<1, 3> H2 = boost::none) const;
85 
87  double norm(OptionalJacobian<1,3> H = boost::none) const;
88 
90  Point3 normalized(OptionalJacobian<3, 3> H = boost::none) const;
91 
93  Point3 cross(const Point3 &q, OptionalJacobian<3, 3> H_p = boost::none, //
94  OptionalJacobian<3, 3> H_q = boost::none) const;
95 
97  double dot(const Point3 &q, OptionalJacobian<1, 3> H_p = boost::none, //
98  OptionalJacobian<1, 3> H_q = boost::none) const;
99 
103 
105  const Vector3& vector() const { return *this; }
106 
108  inline double x() const {return (*this)[0];}
109 
111  inline double y() const {return (*this)[1];}
112 
114  inline double z() const {return (*this)[2];}
115 
117 
119  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &os, const Point3& p);
120 
121 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4
122  Point3 inverse() const { return -(*this);}
125  Point3 compose(const Point3& q) const { return (*this)+q;}
126  Point3 between(const Point3& q) const { return q-(*this);}
127  Vector3 localCoordinates(const Point3& q) const { return between(q);}
128  Point3 retract(const Vector3& v) const { return compose(Point3(v));}
129  static Vector3 Logmap(const Point3& p) { return p;}
130  static Point3 Expmap(const Vector3& v) { return Point3(v);}
131  inline double dist(const Point3& q) const { return (q - *this).norm(); }
132  Point3 normalize(OptionalJacobian<3, 3> H = boost::none) const { return normalized(H);}
133  Point3 add(const Point3& q, OptionalJacobian<3, 3> H1 = boost::none,
134  OptionalJacobian<3, 3> H2 = boost::none) const;
135  Point3 sub(const Point3& q, OptionalJacobian<3, 3> H1 = boost::none,
136  OptionalJacobian<3, 3> H2 = boost::none) const;
138 #endif
139 
140  private:
141 
143  friend class boost::serialization::access;
144  template<class ARCHIVE>
145  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
146  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Vector3);
147  }
148  };
149 
150 template<>
151 struct traits<Point3> : public internal::VectorSpace<Point3> {};
152 
153 template<>
154 struct traits<const Point3> : public internal::VectorSpace<Point3> {};
155 
156 #endif // GTSAM_TYPEDEF_POINTS_TO_VECTORS
157 
158 // Convenience typedef
159 typedef std::pair<Point3, Point3> Point3Pair;
160 GTSAM_EXPORT std::ostream &operator<<(std::ostream &os, const gtsam::Point3Pair &p);
161 
163 GTSAM_EXPORT double distance3(const Point3& p1, const Point3& q,
164  OptionalJacobian<1, 3> H1 = boost::none,
165  OptionalJacobian<1, 3> H2 = boost::none);
166 
168 GTSAM_EXPORT double norm3(const Point3& p, OptionalJacobian<1, 3> H = boost::none);
169 
171 GTSAM_EXPORT Point3 normalize(const Point3& p, OptionalJacobian<3, 3> H = boost::none);
172 
174 GTSAM_EXPORT Point3 cross(const Point3& p, const Point3& q,
175  OptionalJacobian<3, 3> H_p = boost::none,
176  OptionalJacobian<3, 3> H_q = boost::none);
177 
179 GTSAM_EXPORT double dot(const Point3& p, const Point3& q,
180  OptionalJacobian<1, 3> H_p = boost::none,
181  OptionalJacobian<1, 3> H_q = boost::none);
182 
183 template <typename A1, typename A2>
184 struct Range;
185 
186 template <>
187 struct Range<Point3, Point3> {
188  typedef double result_type;
189  double operator()(const Point3& p, const Point3& q,
190  OptionalJacobian<1, 3> H1 = boost::none,
191  OptionalJacobian<1, 3> H2 = boost::none) {
192  return distance3(p, q, H1, H2);
193  }
194 };
195 
196 } // namespace gtsam
197 
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:162
double x() const
get x
Definition: Point3.h:108
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
Definition: Point3.h:45
static Point3 identity()
identity for group operation
Definition: Point3.h:76
Point3 cross(const Point3 &p, const Point3 &q, OptionalJacobian< 3, 3 > H1, OptionalJacobian< 3, 3 > H2)
cross product
Definition: Point3.cpp:121
Point3 normalize(const Point3 &p, OptionalJacobian< 3, 3 > H)
normalize, with optional Jacobian
Definition: Point3.cpp:109
Template to create a binary predicate.
Definition: Testable.h:110
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
const Vector3 & vector() const
return as Vector3
Definition: Point3.h:105
double norm3(const Point3 &p, OptionalJacobian< 1, 3 > H)
Distance of the point from the origin, with Jacobian.
Definition: Point3.cpp:98
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Definition: BearingRange.h:39
VectorSpace provides both Testable and VectorSpaceTraits.
Definition: VectorSpace.h:207
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:183
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
T between(const T &t1, const T &t2)
binary functions
Definition: lieProxies.h:36
double y() const
get y
Definition: Point3.h:111
typedef and functions to augment Eigen's VectorXd
double z() const
get z
Definition: Point3.h:114
double distance3(const Point3 &p1, const Point3 &q, OptionalJacobian< 1, 3 > H1, OptionalJacobian< 1, 3 > H2)
distance between two points
Definition: Point3.cpp:84