gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EssentialMatrix.h
1 /*
2  * @file EssentialMatrix.h
3  * @brief EssentialMatrix class
4  * @author Frank Dellaert
5  * @date December 17, 2013
6  */
7 
8 #pragma once
9 
10 #include <gtsam/geometry/Pose3.h>
11 #include <gtsam/geometry/Unit3.h>
12 #include <gtsam/geometry/Point2.h>
13 #include <iostream>
14 
15 namespace gtsam {
16 
23 class GTSAM_EXPORT EssentialMatrix: public DerivedValue<EssentialMatrix> {
24 
25 private:
26 
27  Rot3 aRb_;
28  Unit3 aTb_;
29  Matrix3 E_;
30 
31 public:
32 
34  static Vector Homogeneous(const Point2& p) {
35  return Vector(3) << p.x(), p.y(), 1;
36  }
37 
40 
43  aTb_(1, 0, 0), E_(aTb_.skew()) {
44  }
45 
47  EssentialMatrix(const Rot3& aRb, const Unit3& aTb) :
48  aRb_(aRb), aTb_(aTb), E_(aTb_.skew() * aRb_.matrix()) {
49  }
50 
52  static EssentialMatrix FromPose3(const Pose3& _1P2_,
53  boost::optional<Matrix&> H = boost::none);
54 
56  template<typename Engine>
57  static EssentialMatrix Random(Engine & rng) {
58  return EssentialMatrix(Rot3::Random(rng), Unit3::Random(rng));
59  }
60 
62 
65 
67  void print(const std::string& s = "") const;
68 
70  bool equals(const EssentialMatrix& other, double tol = 1e-8) const {
71  return aRb_.equals(other.aRb_, tol) && aTb_.equals(other.aTb_, tol);
72  }
73 
75 
78 
80  inline static size_t Dim() {
81  return 5;
82  }
83 
85  virtual size_t dim() const {
86  return 5;
87  }
88 
90  virtual EssentialMatrix retract(const Vector& xi) const;
91 
93  virtual Vector localCoordinates(const EssentialMatrix& other) const;
94 
96 
99 
101  inline const Rot3& rotation() const {
102  return aRb_;
103  }
104 
106  inline const Unit3& direction() const {
107  return aTb_;
108  }
109 
111  inline const Matrix3& matrix() const {
112  return E_;
113  }
114 
116  inline const Unit3& epipole_a() const {
117  return aTb_; // == direction()
118  }
119 
121  inline Unit3 epipole_b() const {
122  return aRb_.unrotate(aTb_); // == rotation.unrotate(direction())
123  }
124 
132  Point3 transform_to(const Point3& p,
133  boost::optional<Matrix&> DE = boost::none,
134  boost::optional<Matrix&> Dpoint = boost::none) const;
135 
141  EssentialMatrix rotate(const Rot3& cRb, boost::optional<Matrix&> HE =
142  boost::none, boost::optional<Matrix&> HR = boost::none) const;
143 
149  friend EssentialMatrix operator*(const Rot3& cRb, const EssentialMatrix& E) {
150  return E.rotate(cRb);
151  }
152 
154  double error(const Vector& vA, const Vector& vB, //
155  boost::optional<Matrix&> H = boost::none) const;
156 
158 
161 
163  GTSAM_EXPORT friend std::ostream& operator <<(std::ostream& os, const EssentialMatrix& E);
164 
166  GTSAM_EXPORT friend std::istream& operator >>(std::istream& is, EssentialMatrix& E);
167 
169 
170 private:
171 
174 
176  friend class boost::serialization::access;
177  template<class ARCHIVE>
178  void serialize(ARCHIVE & ar, const unsigned int version) {
179  ar & boost::serialization::make_nvp("EssentialMatrix",
180  boost::serialization::base_object<Value>(*this));
181  ar & BOOST_SERIALIZATION_NVP(aRb_);
182  ar & BOOST_SERIALIZATION_NVP(aTb_);
183 
184  ar & boost::serialization::make_nvp("E11", E_(0,0));
185  ar & boost::serialization::make_nvp("E12", E_(0,1));
186  ar & boost::serialization::make_nvp("E13", E_(0,2));
187  ar & boost::serialization::make_nvp("E21", E_(1,0));
188  ar & boost::serialization::make_nvp("E22", E_(1,1));
189  ar & boost::serialization::make_nvp("E23", E_(1,2));
190  ar & boost::serialization::make_nvp("E31", E_(2,0));
191  ar & boost::serialization::make_nvp("E32", E_(2,1));
192  ar & boost::serialization::make_nvp("E33", E_(2,2));
193  }
194 
196 
197 };
198 
199 } // gtsam
200 
Unit3 epipole_b() const
Return epipole in image_b, as Unit3 to allow for infinity.
Definition: EssentialMatrix.h:121
static size_t Dim()
Dimensionality of tangent space = 5 DOF.
Definition: EssentialMatrix.h:80
EssentialMatrix rotate(const Rot3 &cRb, boost::optional< Matrix & > HE=boost::none, boost::optional< Matrix & > HR=boost::none) const
Given essential matrix E in camera frame B, convert to body frame C.
Definition: EssentialMatrix.cpp:80
static Rot3 Random(boost::mt19937 &rng)
Random, generates a random axis, then random angle [-p,pi].
Definition: Rot3.cpp:48
friend EssentialMatrix operator*(const Rot3 &cRb, const EssentialMatrix &E)
Given essential matrix E in camera frame B, convert to body frame C.
Definition: EssentialMatrix.h:149
static Unit3 Random(boost::mt19937 &rng)
Random direction, using boost::uniform_on_sphere.
Definition: Unit3.cpp:56
Definition: Point2.h:35
const Unit3 & epipole_a() const
Return epipole in image_a , as Unit3 to allow for infinity.
Definition: EssentialMatrix.h:116
Definition: Pose3.h:42
static Vector Homogeneous(const Point2 &p)
Static function to convert Point2 to homogeneous coordinates.
Definition: EssentialMatrix.h:34
2D Point
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Represents a 3D point on a unit sphere.
Definition: Unit3.h:31
An essential matrix is like a Pose3, except with translation up to scale It is named after the 3*3 ma...
Definition: EssentialMatrix.h:23
Definition: Rot3.h:61
bool equals(const EssentialMatrix &other, double tol=1e-8) const
assert equality up to a tolerance
Definition: EssentialMatrix.h:70
EssentialMatrix()
Default constructor.
Definition: EssentialMatrix.h:42
double y() const
get y
Definition: Point2.h:213
3D Pose
const Unit3 & direction() const
Direction.
Definition: EssentialMatrix.h:106
double x() const
get x
Definition: Point2.h:210
istream & operator>>(istream &inputStream, Matrix &destinationMatrix)
Read a matrix from an input stream, such as a file.
Definition: Matrix.cpp:209
const Matrix3 & matrix() const
Return 3*3 matrix representation.
Definition: EssentialMatrix.h:111
EssentialMatrix(const Rot3 &aRb, const Unit3 &aTb)
Construct from rotation and translation.
Definition: EssentialMatrix.h:47
Definition: DerivedValue.h:44
const Rot3 & rotation() const
Rotation.
Definition: EssentialMatrix.h:101
static EssentialMatrix Random(Engine &rng)
Random, using Rot3::Random and Unit3::Random.
Definition: EssentialMatrix.h:57
Definition: Point3.h:39
virtual size_t dim() const
Return the dimensionality of the tangent space.
Definition: EssentialMatrix.h:85