ldpk
tde4_ldp_radial_fisheye_base_deg_8.experimental.h
1 #pragma once
2 
3 #include <ldpk/ldpk_ldp_builtin.h>
5 #include <ldpk/ldpk_vec2d.h>
6 
9 
12 
13 template <class VEC2,class MAT2>
15  {
16 private:
17  typedef VEC2 vec2_type;
18  typedef MAT2 mat2_type;
20 
22 
23  static const char* _para[4];
24 protected:
25  double _r_clip_factor;
26  double _fl_dn;
27 private:
28  bool decypher(const char* name,int& i)
29  {
30  typedef base_type bt;
31  int n;
32  getNumParameters(n);
33  for(i = 0;i < n;++i)
34  {
35  if(0 == strcmp(name,_para[i]))
36  { return true; }
37  }
38  return false;
39  }
40  bool initializeParameters()
41  {
42  typedef base_type bt;
43  bt::check_builtin_parameters();
44 // Focal length in dn-coordinates.
45  _fl_dn = bt::fl_cm() / bt::r_fb_cm();
46  return true;
47  }
48  bool getNumParameters(int& n)
49  {
50  n = 4;
51  return true;
52  }
53  bool getParameterName(int i,char* identifier)
54  {
55  strcpy(identifier,_para[i]);
56  return true;
57  }
58  bool setParameterValue(const char *identifier,double v)
59  {
60  typedef base_type bt;
61  int i;
62 // Does the base class know the parameter?
63  if(bt::set_builtin_parameter_value(identifier,v))
64  { return true; }
65  if(!decypher(identifier,i))
66  { return false; }
67  if(_distortion.get_coeff(i) != v)
68  { bt::no_longer_uptodate_lut(); }
69  _distortion.set_coeff(i,v);
70  return true;
71  }
72  virtual bool remap_fe2plain(double r_ed_dn,double& r_plain_dn) = 0;
73  virtual bool remap_plain2fe(double r_plain_dn,double& r_ed_dn) = 0;
74 // Overwriting tde4_ldp_common
75  bool undistort(double x0,double y0,double &x1,double &y1)
76  {
77  typedef base_type bt;
78 
79  vec2_type p_ed_dist_dn = bt::map_unit_to_dn(vec2_type(x0,y0));
80 
81 // Distance from origin in dn-coordinates
82  double r_ed_dist_dn = norm2(p_ed_dist_dn);
83 // The literature commonly says, undistorting should be done
84 // before applying the remapping. Usually it's applied to
85 // elongation angle theta = r/f. That's what we do here.
86 // theta = r/f is the equidistant projection, so here we have g o F^-1.
87  double r_ed_undist_dn = _fl_dn * _distortion(r_ed_dist_dn / _fl_dn);
88 // Remap equidistant to gnomonic
89  double r_plain_undist_dn;
90  if(!remap_fe2plain(r_ed_undist_dn,r_plain_undist_dn))
91  { return false; }
92 // Calc undistorted point from undistorted radius
93  vec2_type p_plain_undist_dn;
94  if(dotsq(p_ed_dist_dn) == 0.0)
95  { p_plain_undist_dn = vec2_type(0,0); }
96  else
97  { p_plain_undist_dn = r_plain_undist_dn * unit(p_ed_dist_dn); }
98 // Map back to unit coordinates
99  vec2_type p_plain_undist_unit = bt::map_dn_to_unit(p_plain_undist_dn);
100  x1 = p_plain_undist_unit[0];
101  y1 = p_plain_undist_unit[1];
102  return true;
103  }
104  bool distort(double x0,double y0,double &x1,double &y1)
105  {
106  typedef base_type bt;
107 
108  vec2_type p_plain_undis_dn = bt::map_unit_to_dn(vec2_type(x0,y0));
109 // Distance from origin in dn-coordinates
110  double r_ed_undis_dn,r_plain_undis_dn = norm2(p_plain_undis_dn);
111 // Remap gnomonic to equidistant
112  if(!remap_plain2fe(r_plain_undis_dn,r_ed_undis_dn))
113  { return false; }
114 // Apply distortion. We use the point itself as initial value, since coefficients will be small.
115  double r_ed_dis_dn = _fl_dn * _distortion.map_inverse(r_ed_undis_dn / _fl_dn,r_ed_undis_dn / _fl_dn);
116 // Calc distorted point from distorted radius
117  vec2_type p_ed_dis_dn;
118  if(dotsq(p_plain_undis_dn) == 0.0)
119  { p_ed_dis_dn = vec2_type(0,0); }
120  else
121  { p_ed_dis_dn = r_ed_dis_dn * unit(p_plain_undis_dn); }
122 // Map back to unit coordinates
123  vec2_type p_ed_dis_unit = bt::map_dn_to_unit(p_ed_dis_dn);
124  x1 = p_ed_dis_unit[0];
125  y1 = p_ed_dis_unit[1];
126  return true;
127  }
128 public:
129 // Mutex initialized and destroyed in baseclass.
130  tde4_ldp_radial_fisheye_base_deg_8():_r_clip_factor(50.0)
131  { }
133  { }
134  double r_clip_factor() const
135  { return _r_clip_factor; }
136  void r_clip_factor(double f)
137  { _r_clip_factor = f; }
138  virtual bool getModelName(char *name) = 0;
139  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
140  {
141  typedef base_type bt;
142  int i;
143  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
144  if(!decypher(identifier,i)) return false;
145  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
146  return true;
147  }
148  bool getParameterDefaultValue(const char* identifier,double& v)
149  {
150  typedef base_type bt;
151  int i;
152  if(!decypher(identifier,i)) return false;
153  v = 0.0;
154  return true;
155  }
156  bool getParameterRange(const char* identifier,double& a,double& b)
157  {
158  typedef base_type bt;
159  int i;
160  if(!decypher(identifier,i)) return false;
161  a = -0.5;
162  b = 0.5;
163  return true;
164  }
165  };
166 
167 template <class VEC2,class MAT2>
169  "Degree 2",
170  "Degree 4",
171  "Degree 6",
172  "Degree 8"
173  };
double map_inverse(double q) const
Inverse mapping by solving the fixed point equation without providing initial values.
Definition: ldpk_generic_radial_distortion_1d.h:96
void set_coeff(int i, double q)
Set coefficient c[i], 0 <= i < N.
Definition: ldpk_generic_radial_distortion_1d.h:59
virtual bool getModelName(char *name)=0
returns a name for the model as to show up in the GUI (maximum length of "name": 100 bytes)...
bool getParameterType(const char *identifier, tde4_ldp_ptype &ptype)
returns type of given parameter... The method should return false, if the parameter addressed by iden...
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:139
Plugin class for radial distortion. Does not compensate for decentering.
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:14
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:156
A polynomial radially symmetric model of degree N (even)
bool getParameterDefaultValue(const char *identifier, double &v)
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:148
This class handles the built-in parameter and the lookup table. You may find it useful for your own d...
Definition: ldpk_ldp_builtin.h:31
Double-valued vector and matrix class.
double get_coeff(int i) const
Get coefficient c[i], 0 <= i < N (i.e. coefficient power r^(2i))
Definition: ldpk_generic_radial_distortion_1d.h:53