ldpk
tde4_ldp_radial_fisheye_equidistant_longlat_z_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 protected:
25  bool decypher(const char* name,int& i)
26  {
27  typedef base_type bt;
28  int n;
30  for(i = 0;i < n;++i)
31  {
32  if(0 == strcmp(name,_para[i]))
33  { return true; }
34  }
35  return false;
36  }
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 // Distance from origin in dn-coordinates
76  double r_ed_dist_dn = norm2(p_ed_dist_dn);
77 
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_new = ::atan2(p_ed_dist_dn[1],p_ed_dist_dn[0]);
85  double the_new = the_undist;
86  if((the_new < -M_PI) || (the_new > M_PI))
87  { return false; }
88 // spherical coordinates to unit vector, pole at z.
89  double x = ::sin(-the_new) * ::cos(phi_new);
90  double y = ::sin(-the_new) * ::sin(phi_new);
91  double z = ::cos(the_new);
92  double r = ::sqrt(x * x + z * z);
93 // unit vector to spherical coordinates, pole at y
94  double phi = ::atan2(x,-z);
95  double the = ::atan2(r,y);
96  if(phi < 0.0)
97  { phi += 2.0 * M_PI; }
98 // spherical coordinates to unit coordinates
99  x1 = phi / (2.0 * M_PI);
100  y1 = the / M_PI;
101  return true;
102  }
103  bool distort(double x0,double y0,double &x1,double &y1)
104  {
105  typedef base_type bt;
106 // unit coordinates to spherical coordinates
107  double phi = x0 * (2.0 * M_PI);
108  double the = y0 * M_PI;
109 // spherical coordinates to unit vector, pole at y
110  double z = -::sin(the) * ::cos(phi);
111  double y = ::cos(the);
112  double x = +::sin(the) * ::sin(phi);
113 // unit vector to other spherical coordinates, pole at z.
114  double r = ::sqrt(x * x + y * y);
115  double the_new = -::atan2(r,z);
116  double phi_new = ::atan2(y,x);
117 // Spherical coordinates to equidistant position in dn-coordinates and distort
118  double r_ed_dist_dn = _fl_dn * _distortion.map_inverse(the_new);
119  vec2 p_ed_dn = r_ed_dist_dn * vec2(::cos(phi_new),::sin(phi_new));
120 // dn- to unit-coordinates
121  vec2 q_ed_unit = bt::map_dn_to_unit(p_ed_dn);
122  x1 = q_ed_unit[0];
123  y1 = q_ed_unit[1];
124  return true;
125  }
126 
127 public:
128 // Mutex initialized and destroyed in baseclass.
130  { }
132  { }
133  double r_clip_factor() const
134  { return _r_clip_factor; }
135  void r_clip_factor(double f)
136  { _r_clip_factor = f; }
137  bool getModelName(char *name)
138  {
139 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
140  strcpy(name,"3DE4 Radial - Fisheye, Equidistant, Longlat-Z, Degree 8 [Plugin]");
141 #else
142  strcpy(name,"3DE4 Radial - Fisheye, Equidistant, Longlat-Z, Degree 8");
143 #endif
144  return true;
145  }
146  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
147  {
148  typedef base_type bt;
149  int i;
150  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
151  if(!decypher(identifier,i)) return false;
152  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
153  return true;
154  }
155  bool getParameterDefaultValue(const char* identifier,double& v)
156  {
157  typedef base_type bt;
158  int i;
159  if(!decypher(identifier,i)) return false;
160  v = 0.0;
161  return true;
162  }
163  bool getParameterRange(const char* identifier,double& a,double& b)
164  {
165  typedef base_type bt;
166  int i;
167  if(!decypher(identifier,i)) return false;
168  a = -0.5;
169  b = 0.5;
170  return true;
171  }
172 /* bool getJacobianMatrix(double x0,double y0,double& m00,double& m01,double& m10,double& m11)
173  {
174  typedef base_type bt;
175  m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
176  return true;
177  }*/
178  };
179 
180 template <class VEC2,class MAT2>
182  "Degree 2",
183  "Degree 4",
184  "Degree 6",
185  "Degree 8"
186  };
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 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_z_deg_8.experimental.h:146
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_z_deg_8.experimental.h:163
bool undistort(double x0, double y0, double &x1, double &y1)
warp/unwarp 2D points...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_z_deg_8.experimental.h:70
bool getNumParameters(int &n)
returns the number of plugin parameters...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_z_deg_8.experimental.h:45
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_z_deg_8.experimental.h:137
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_z_deg_8.experimental.h:155
bool getParameterName(int i, char *identifier)
returns "identifier" name of parameter "i" (maximum length of "identifier": 100 bytes)...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_z_deg_8.experimental.h:50
bool setParameterValue(const char *identifier, double v)
set parameter values... parameters predefined by 3DE4: "tde4_focal_length_cm", "tde4_filmback_width_c...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_z_deg_8.experimental.h:55
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_z_deg_8.experimental.h:12
bool initializeParameters()
prepare the current set of parameters...
Definition: tde4_ldp_radial_fisheye_equidistant_longlat_z_deg_8.experimental.h:37
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