ldpk
tde4_ldp_radial_fisheye_equidistant_longlat_y_deg_8.experimental.h
1 #pragma once
2 
3 #include <ldpk/ldpk_ldp_builtin.h>
5 
8 
11 template <class VEC2,class MAT2>
13  {
14 private:
15  typedef VEC2 vec2;
16  typedef MAT2 mat2;
18 
20 
21  static const char* _para[4];
22  double _r_clip_factor;
23  double _fl_dn;
24 
25  bool decypher(const char* name,int& i)
26  {
27  typedef base_type bt;
28  int n;
29  getNumParameters(n);
30  for(i = 0;i < n;++i)
31  {
32  if(0 == strcmp(name,_para[i]))
33  { return true; }
34  }
35  return false;
36  }
37  bool initializeParameters()
38  {
39  typedef base_type bt;
40  bt::check_builtin_parameters();
41 // Focal length in dn-coordinates.
42  _fl_dn = bt::fl_cm() / bt::r_fb_cm();
43  return true;
44  }
45  bool getNumParameters(int& n)
46  {
47  n = 4;
48  return true;
49  }
50  bool getParameterName(int i,char* identifier)
51  {
52  strcpy(identifier,_para[i]);
53  return true;
54  }
55  bool setParameterValue(const char *identifier,double v)
56  {
57  typedef base_type bt;
58  int i;
59 // Does the base class know the parameter?
60  if(bt::set_builtin_parameter_value(identifier,v))
61  { return true; }
62  if(!decypher(identifier,i))
63  { return false; }
64  if(_distortion.get_coeff(i) != v)
65  { bt::no_longer_uptodate_lut(); }
66  _distortion.set_coeff(i,v);
67  return true;
68  }
69 // Overwriting tde4_ldp_common
70  bool undistort(double x0,double y0,double &x1,double &y1)
71  {
72  typedef base_type bt;
73 
74  vec2 p_ed_dist_dn = bt::map_unit_to_dn(vec2(x0,y0));
75 
76 // Distance from origin in dn-coordinates
77  double r_ed_dist_dn = norm2(p_ed_dist_dn);
78 // The literature commonly says, undistorting should be done
79 // before applying the remapping. Usually it's applied to
80 // elongation angle theta = r/f. That's what we do here.
81 // The result is the angle without distortion.
82  double the_undist = _distortion(r_ed_dist_dn / _fl_dn);
83 // Coordinates in longlat image.
84  double phi = ::atan2(p_ed_dist_dn[1],p_ed_dist_dn[0]);
85  double the = the_undist;
86 // We need phi in [0,2pi[.
87  if(phi < 0)
88  { phi += 2.0 * M_PI; }
89 
90  x1 = phi / (2.0 * M_PI);
91  y1 = the / M_PI;
92  return true;
93  }
94  bool distort(double x0,double y0,double &x1,double &y1)
95  {
96  typedef base_type bt;
97 
98  double phi = x0 * (2.0 * M_PI);
99  double the = y0 * M_PI;
100 
101  double r_ed_dist_dn = _fl_dn * _distortion.map_inverse(the);
102  vec2 p_ed_dn = r_ed_dist_dn * vec2(::cos(phi),::sin(phi));
103 
104  vec2 q_ed_unit = bt::map_dn_to_unit(p_ed_dn);
105  x1 = q_ed_unit[0];
106  y1 = q_ed_unit[1];
107  return true;
108  }
109 
110 public:
111 // Mutex initialized and destroyed in baseclass.
113  { }
115  { }
116  double r_clip_factor() const
117  { return _r_clip_factor; }
118  void r_clip_factor(double f)
119  { _r_clip_factor = f; }
120  bool getModelName(char *name)
121  {
122 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
123  strcpy(name,"3DE4 Radial - Fisheye, Equidistant, Longlat, Degree 8 [Plugin]");
124 #else
125  strcpy(name,"3DE4 Radial - Fisheye, Equidistant, Longlat, Degree 8");
126 #endif
127  return true;
128  }
129  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
130  {
131  typedef base_type bt;
132  int i;
133  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
134  if(!decypher(identifier,i)) return false;
135  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
136  return true;
137  }
138  bool getParameterDefaultValue(const char* identifier,double& v)
139  {
140  typedef base_type bt;
141  int i;
142  if(!decypher(identifier,i)) return false;
143  v = 0.0;
144  return true;
145  }
146  bool getParameterRange(const char* identifier,double& a,double& b)
147  {
148  typedef base_type bt;
149  int i;
150  if(!decypher(identifier,i)) return false;
151  a = -0.5;
152  b = 0.5;
153  return true;
154  }
155 /* bool getJacobianMatrix(double x0,double y0,double& m00,double& m01,double& m10,double& m11)
156  {
157  typedef base_type bt;
158  m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
159  return true;
160  }*/
161  };
162 
163 template <class VEC2,class MAT2>
165  "Degree 2",
166  "Degree 4",
167  "Degree 6",
168  "Degree 8"
169  };
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
bool getModelName(char *name)
returns a name for the model as to show up in the GUI (maximum length of "name": 100 bytes)...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_y_deg_8.experimental.h:120
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_equidistant_longlat_y_deg_8.experimental.h:138
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_y_deg_8.experimental.h:146
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_equidistant_longlat_y_deg_8.experimental.h:129
A polynomial radially symmetric model of degree N (even)
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
Plugin class for radial distortion. Does not compensate for decentering.
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_y_deg_8.experimental.h:12
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