1 #ifndef tde4_ldp_radial_deg_8_sdv 2 #define tde4_ldp_radial_deg_8_sdv 4 #include <ldpk/ldpk_ldp_builtin.h> 13 template <
class VEC2,
class MAT2>
17 typedef VEC2 vec2_type;
18 typedef MAT2 mat2_type;
23 static const char* _para[4];
24 double _r_clip_factor;
26 bool decypher(
const char* name,
int& i)
33 if(0 == strcmp(name,_para[i]))
40 bool initializeParameters()
43 bt::check_builtin_parameters();
46 bool getNumParameters(
int& n)
51 bool getParameterName(
int i,
char* identifier)
53 strcpy(identifier,_para[i]);
56 bool setParameterValue(
const char *identifier,
double v)
61 if(bt::set_builtin_parameter_value(identifier,v))
65 if(!decypher(identifier,i))
71 bt::no_longer_uptodate_lut();
79 bool esa2plain(
const vec2_type& p_esa_dn,vec2_type& p_plain_dn)
82 double f_dn = this->fl_cm() / this->r_fb_cm();
84 double r_esa_dn = norm2(p_esa_dn);
87 p_plain_dn = p_esa_dn;
90 double arg = r_esa_dn / (2.0 * f_dn),arg_clip = arg;
96 double phi = 2.0 * asin(arg_clip);
100 phi = M_PI / 2.0 - 1e-5;
103 double r_plain_dn = f_dn * tan(phi);
104 if(r_plain_dn > _r_clip_factor)
107 r_plain_dn = _r_clip_factor;
109 p_plain_dn = r_plain_dn * unit(p_esa_dn);
112 bool plain2esa(
const vec2_type& p_plain_dn,vec2_type& p_esa_dn)
114 typedef base_type bt;
115 double f_dn = bt::fl_cm() / bt::r_fb_cm();
117 double r_plain_dn = norm2(p_plain_dn);
118 if(r_plain_dn == 0.0)
120 p_esa_dn = p_plain_dn;
123 double phi = atan2(r_plain_dn,f_dn);
124 double r_esa_dn = 2.0 * f_dn * std::sin(phi / 2.0);
125 p_esa_dn = r_esa_dn * unit(p_plain_dn);
130 bool undistort(
double x0,
double y0,
double &x1,
double &y1)
132 typedef base_type bt;
133 vec2_type p_esa_dn = bt::map_unit_to_dn(vec2_type(x0,y0));
134 vec2_type p_plain_dn;
135 if(!esa2plain(p_esa_dn,p_plain_dn))
return false;
138 vec2_type q_dn = _distortion.
eval(p_plain_dn);
139 if(norm2(q_dn) > 100.0) q_dn = 100.0 * unit(q_dn);
141 vec2_type q = bt::map_dn_to_unit(q_dn);
146 bool distort(
double x0,
double y0,
double &x1,
double &y1)
148 typedef base_type bt;
155 if(!bt::is_uptodate_lut())
158 if(!bt::is_uptodate_lut())
166 vec2_type qs = bt::get_lut().get_initial_value(vec2_type(x0,y0));
168 vec2_type p_plain_dn = _distortion.
map_inverse(bt::map_unit_to_dn(vec2_type(x0,y0)),bt::map_unit_to_dn(qs));
170 if(!plain2esa(p_plain_dn,p_esa_dn))
return false;
172 vec2_type q = bt::map_dn_to_unit(p_esa_dn);
177 bool distort(
double x0,
double y0,
double x1_start,
double y1_start,
double &x1,
double &y1)
179 typedef base_type bt;
180 vec2_type p_plain_dn = _distortion.
map_inverse(bt::map_unit_to_dn(vec2_type(x0,y0)),bt::map_unit_to_dn(vec2_type(x1_start,y1_start)));
182 if(!plain2esa(p_plain_dn,p_esa_dn))
return false;
184 vec2_type q = bt::map_dn_to_unit(p_esa_dn);
195 double r_clip_factor()
const 196 {
return _r_clip_factor; }
197 void r_clip_factor(
double f)
198 { _r_clip_factor = f; }
201 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV 202 strcpy(name,
"3DE4 Radial - Fisheye, Degree 8 [Plugin]");
204 strcpy(name,
"3DE4 Radial - Fisheye, Degree 8");
210 typedef base_type bt;
212 if(bt::get_builtin_parameter_type(identifier,ptype))
return true;
213 if(!decypher(identifier,i))
return false;
214 ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
219 typedef base_type bt;
221 if(!decypher(identifier,i))
return false;
227 typedef base_type bt;
229 if(!decypher(identifier,i))
return false;
236 typedef base_type bt;
240 vec2_type p_esa_dn = bt::map_unit_to_dn(vec2_type(x0,y0));
241 vec2_type p_plain_dn;
242 if(!esa2plain(p_esa_dn,p_plain_dn))
244 m00 = 1;m01 = 0;m10 = 0;m11 = 1;
247 mat2_type m = _distortion.
jacobi(p_plain_dn);
250 double f_dn = this->fl_cm() / this->r_fb_cm();
251 double r_esa_dn = norm2(p_esa_dn);
252 double r_esa_div_2f = r_esa_dn / (2.0 * f_dn);
254 if(fabs(r_esa_div_2f) > 0.99)
256 m00 = 1;m01 = 0;m10 = 0;m11 = 1;
259 double asn = asin(r_esa_div_2f);
261 if(fabs(2.0 * asn) > 0.99 * M_PI / 2.0)
263 m00 = 1;m01 = 0;m10 = 0;m11 = 1;
266 double csn = cos(2.0 * asn);
268 double sqr = sqrt(1.0 - r_esa_div_2f * r_esa_div_2f);
272 e = (mat2_type(1) -
tensq(p_esa_dn / r_esa_dn)) * (f_dn / r_esa_dn) * tan(2.0 * asn)
273 + (
tensq(p_esa_dn / r_esa_dn)) / (csn * csn * sqr);
282 mat2_type u2d((bt::w_fb_cm() / 2) / bt::r_fb_cm(),0.0,0.0,(bt::h_fb_cm() / 2) / bt::r_fb_cm());
283 mat2_type d2u(bt::r_fb_cm() / (bt::w_fb_cm() / 2),0.0,0.0,bt::r_fb_cm() / (bt::h_fb_cm() / 2));
284 m = d2u * m * e * u2d;
286 if(tr(trans(m) * m) > 100.0)
291 m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
296 template <
class VEC2,
class MAT2>
298 "Distortion - Degree 2",
299 "Quartic Distortion - Degree 4",
A polynomial radially symmetric model of degree N (even)
mat2d tensq(const vec2d &a)
Tensor (dyadic) product square.
Definition: ldpk_vec2d.h:186
Plugin class for radial distortion. Does not compensate for decentering. Parameters can be calculated...
Definition: tde4_ldp_radial_deg_8.h:14
vec2_type eval(const vec2_type &p) const
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:104
bool getJacobianMatrix(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
calculate the Jacobian matrix of the undistort()-Method. Overwrite this, if you know the Jacobian for...
Definition: tde4_ldp_radial_deg_8.h:234
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_radial_deg_8.h:225
bool getParameterDefaultValue(const char *identifier, double &v)
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
Definition: tde4_ldp_radial_deg_8.h:217
mat2_type jacobi(const vec2_type &p_dn) const
Analytic version of the Jacobi-matrix, about 2.5 times faster than the base class version which uses ...
Definition: ldpk_generic_radial_distortion.h:59
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
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_deg_8.h:208
virtual vec2_type map_inverse(const vec2_type &q) const
Inverse mapping by solving the fixed point equation without providing initial values. Virtual, because the derived class might use some smart data structure for calculating an initial value.
Definition: ldpk_generic_distortion_base.h:122
void set_coeff(int i, double q)
Set coefficient c[i], 0 <= i < N.
Definition: ldpk_generic_radial_distortion.h:38
double get_coeff(int i) const
Get coefficient c[i], 0 <= i < N (i.e. coefficient power r^(2i))
Definition: ldpk_generic_radial_distortion.h:32
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_deg_8.h:199