gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Cal3_S2.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 
22 #pragma once
23 
24 #include <gtsam/base/DerivedValue.h>
25 #include <gtsam/geometry/Point2.h>
26 
27 namespace gtsam {
28 
34 class GTSAM_EXPORT Cal3_S2: public DerivedValue<Cal3_S2> {
35 private:
36  double fx_, fy_, s_, u0_, v0_;
37 
38 public:
39 
40  typedef boost::shared_ptr<Cal3_S2> shared_ptr;
41 
44 
46  Cal3_S2() :
47  fx_(1), fy_(1), s_(0), u0_(0), v0_(0) {
48  }
49 
51  Cal3_S2(double fx, double fy, double s, double u0, double v0) :
52  fx_(fx), fy_(fy), s_(s), u0_(u0), v0_(v0) {
53  }
54 
56  Cal3_S2(const Vector &d) :
57  fx_(d(0)), fy_(d(1)), s_(d(2)), u0_(d(3)), v0_(d(4)) {
58  }
59 
66  Cal3_S2(double fov, int w, int h);
67 
71 
73  Cal3_S2(const std::string &path);
74 
78 
80  void print(const std::string& s = "Cal3_S2") const;
81 
83  bool equals(const Cal3_S2& K, double tol = 10e-9) const;
84 
88 
90  inline double fx() const {
91  return fx_;
92  }
93 
95  inline double fy() const {
96  return fy_;
97  }
98 
100  inline double skew() const {
101  return s_;
102  }
103 
105  inline double px() const {
106  return u0_;
107  }
108 
110  inline double py() const {
111  return v0_;
112  }
113 
116  return Point2(u0_, v0_);
117  }
118 
120  Vector vector() const {
121  double r[] = { fx_, fy_, s_, u0_, v0_ };
122  Vector v(5);
123  std::copy(r, r + 5, v.data());
124  return v;
125  }
126 
128  Matrix K() const {
129  return (Matrix(3, 3) << fx_, s_, u0_, 0.0, fy_, v0_, 0.0, 0.0, 1.0);
130  }
131 
133  Matrix matrix() const {
134  return K();
135  }
136 
138  Matrix matrix_inverse() const {
139  const double fxy = fx_ * fy_, sv0 = s_ * v0_, fyu0 = fy_ * u0_;
140  return (Matrix(3, 3) << 1.0 / fx_, -s_ / fxy, (sv0 - fyu0) / fxy, 0.0,
141  1.0 / fy_, -v0_ / fy_, 0.0, 0.0, 1.0);
142  }
143 
151  Point2 uncalibrate(const Point2& p, boost::optional<Matrix&> Dcal =
152  boost::none, boost::optional<Matrix&> Dp = boost::none) const;
153 
159  Point2 calibrate(const Point2& p) const;
160 
166  Vector3 calibrate(const Vector3& p) const;
167 
169  inline Cal3_S2 between(const Cal3_S2& q,
170  boost::optional<Matrix&> H1=boost::none,
171  boost::optional<Matrix&> H2=boost::none) const {
172  if(H1) *H1 = -eye(5);
173  if(H2) *H2 = eye(5);
174  return Cal3_S2(q.fx_-fx_, q.fy_-fy_, q.s_-s_, q.u0_-u0_, q.v0_-v0_);
175  }
176 
177 
181 
183  inline size_t dim() const {
184  return 5;
185  }
186 
188  static size_t Dim() {
189  return 5;
190  }
191 
193  inline Cal3_S2 retract(const Vector& d) const {
194  return Cal3_S2(fx_ + d(0), fy_ + d(1), s_ + d(2), u0_ + d(3), v0_ + d(4));
195  }
196 
198  Vector localCoordinates(const Cal3_S2& T2) const {
199  return T2.vector() - vector();
200  }
201 
205 
206 private:
207 
209  friend class boost::serialization::access;
210  template<class Archive>
211  void serialize(Archive & ar, const unsigned int version) {
212  ar
213  & boost::serialization::make_nvp("Cal3_S2",
214  boost::serialization::base_object<Value>(*this));
215  ar & BOOST_SERIALIZATION_NVP(fx_);
216  ar & BOOST_SERIALIZATION_NVP(fy_);
217  ar & BOOST_SERIALIZATION_NVP(s_);
218  ar & BOOST_SERIALIZATION_NVP(u0_);
219  ar & BOOST_SERIALIZATION_NVP(v0_);
220  }
221 
223 
224 };
225 
226 } // \ namespace gtsam
Vector localCoordinates(const Cal3_S2 &T2) const
Unretraction for the calibration.
Definition: Cal3_S2.h:198
double py() const
image center in y
Definition: Cal3_S2.h:110
Matrix matrix() const
Definition: Cal3_S2.h:133
Cal3_S2(const Vector &d)
constructor from vector
Definition: Cal3_S2.h:56
size_t dim() const
return DOF, dimensionality of tangent space
Definition: Cal3_S2.h:183
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
Definition: Cal3_S2.h:34
Matrix K() const
return calibration matrix K
Definition: Cal3_S2.h:128
Definition: Point2.h:35
static size_t Dim()
return DOF, dimensionality of tangent space
Definition: Cal3_S2.h:188
Cal3_S2()
Create a default calibration that leaves coordinates unchanged.
Definition: Cal3_S2.h:46
2D Point
double fx() const
focal length x
Definition: Cal3_S2.h:90
double skew() const
skew
Definition: Cal3_S2.h:100
boost::shared_ptr< Cal3_S2 > shared_ptr
shared pointer to calibration object
Definition: Cal3_S2.h:40
Cal3_S2 between(const Cal3_S2 &q, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
"Between", subtracts calibrations. between(p,q) == compose(inverse(p),q)
Definition: Cal3_S2.h:169
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Cal3_S2 retract(const Vector &d) const
Given 5-dim tangent vector, create new calibration.
Definition: Cal3_S2.h:193
Matrix matrix_inverse() const
return inverted calibration matrix inv(K)
Definition: Cal3_S2.h:138
Template to create a binary predicate.
Definition: Testable.h:102
double px() const
image center in x
Definition: Cal3_S2.h:105
Point2 principalPoint() const
return the principal point
Definition: Cal3_S2.h:115
double fy() const
focal length y
Definition: Cal3_S2.h:95
Cal3_S2(double fx, double fy, double s, double u0, double v0)
constructor from doubles
Definition: Cal3_S2.h:51
Vector vector() const
vectorized form (column-wise)
Definition: Cal3_S2.h:120
Definition: DerivedValue.h:44