ldpk
ldpk_classic_3de_mixed_distortion.h
Go to the documentation of this file.
1 #ifndef ldpk_classic_3de_mixed_distortion_sdv
2 #define ldpk_classic_3de_mixed_distortion_sdv
3 
6 
8 
9 namespace ldpk
10  {
12  template <class VEC2,class MAT2>
14  {
15  private:
16  typedef VEC2 vec2_type;
17  typedef MAT2 mat2_type;
18 
19  union
20  {
21  struct
22  {
23  double _ld,_sq,_cx,_cy,_qu;
24  };
25  double _c[5];
26  };
27  mutable double _cxx,_cxy,_cyx,_cyy,_cxxx,_cxxy,_cxyy,_cyxx,_cyyx,_cyyy;
28  mutable bool _uptodate;
29 
30  void update() const
31  {
32  _cxx = _ld / _sq;
33  _cxy = (_ld + _cx) / _sq;
34  _cyx = _ld + _cy;
35  _cyy = _ld;
36  _cxxx = _qu / _sq;
37  _cxxy = 2.0 * _qu / _sq;
38  _cxyy = _qu / _sq;
39  _cyxx = _qu;
40  _cyyx = 2.0 * _qu;
41  _cyyy = _qu;
42  _uptodate = true;
43  }
44  public:
45  classic_3de_mixed_distortion():_ld(0),_sq(1),_cx(0),_cy(0),_qu(0),_uptodate(false)
46  { }
48  double get_coeff(int i) const
49  { return _c[i]; }
51  void set_coeff(int i,double q)
52  { _c[i] = q;_uptodate = false; }
53 
55  vec2_type operator()(const vec2_type& p) const
56  {
57  if(!_uptodate) update();
58  double p0_2 = p[0] * p[0];
59  double p1_2 = p[1] * p[1];
60  double p0_4 = p0_2 * p0_2;
61  double p1_4 = p1_2 * p1_2;
62  double p01_2 = p0_2 * p1_2;
63 
64  vec2_type q;
65  q[0] = p[0] * (1 + _cxx * p0_2 + _cxy * p1_2 + _cxxx * p0_4 + _cxxy * p01_2 + _cxyy * p1_4);
66  q[1] = p[1] * (1 + _cyx * p0_2 + _cyy * p1_2 + _cyxx * p0_4 + _cyyx * p01_2 + _cyyy * p1_4);
67  return q;
68  }
69 // @brief Analytic version of the Jacobi-matrix
70  mat2_type jacobi(const vec2_type& p_dn) const
71  {
72  if(!_uptodate) update();
73  double x = p_dn[0],x2 = x * x,x3 = x2 * x,x4 = x2 * x2;
74  double y = p_dn[1],y2 = y * y,y3 = y2 * y,y4 = y2 * y2;
75  mat2_type m;
76  m[0][0] = 1.0 + x2 * 3.0 * _cxx + y2 * _cxy
77  + x4 * 5.0 * _cxxx + x2 * y2 * 3.0 * _cxxy + y4 * _cxyy;
78  m[1][1] = 1.0 + x2 * _cyx + y2 * 3.0 * _cyy
79  + x4 * _cyxx + x2 * y2 * 3.0 * _cyyx + y4 * 5.0 * _cyyy;
80  m[0][1] = x * y * 2.0 * _cxy + x3 * y * 2.0 * _cxxy + x * y3 * 4.0 * _cxyy;
81  m[1][0] = x * y * 2.0 * _cyx + x3 * y * 4.0 * _cyxx + x * y3 * 2.0 * _cyyx;
82  return m;
83  }
84  std::ostream& out(std::ostream& cout) const
85  {
86  int p = int(cout.precision());
87  cout.precision(5);
88  cout << " Distortion: " << std::right << std::fixed << _ld << "\n";
89  cout << "Anamorphic Squeeze: " << std::right << std::fixed << _sq << "\n";
90  cout << " Curvature X: " << std::right << std::fixed << _cx << "\n";
91  cout << " Curvature Y: " << std::right << std::fixed << _cy << "\n";
92  cout << "Quartic Distortion: " << std::right << std::fixed << _qu << "\n";
93  cout.precision(p);
94  return cout;
95  }
96  };
97  }
98 
99 #endif
Base class for a distortion model with N parameters. You may find it useful to derive your own distor...
Definition: ldpk_generic_distortion_base.h:21
void set_coeff(int i, double q)
Set coefficient as demanded by base class.
Definition: ldpk_classic_3de_mixed_distortion.h:51
The namespace of (most of the) things related to the Lens Distortion Plugin Kit.
Definition: ldpk.h:19
Base class for distortion models.
Degree-2 anamorphic and degree-4 radial mixed model.
Definition: ldpk_classic_3de_mixed_distortion.h:13
std::ostream & out(std::ostream &cout) const
The derived class implements a method for printing values inside 3DE4&#39;s matrix tool dialog...
Definition: ldpk_classic_3de_mixed_distortion.h:84
double get_coeff(int i) const
Get coefficient as demanded by base class.
Definition: ldpk_classic_3de_mixed_distortion.h:48
mat2_type jacobi(const vec2_type &p_dn) const
Jacobi-Matrix. The result is a matrix g_{ij} = d/dp_j f(p)_i, where f represents the undistort-functi...
Definition: ldpk_classic_3de_mixed_distortion.h:70
vec2_type operator()(const vec2_type &p) const
Remove distortion. p is a point in diagonally normalized coordinates.
Definition: ldpk_classic_3de_mixed_distortion.h:55