3 #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];
30 bool undistort_dn(
double r_ed_dist_dn,
double &r_plain_undist_dn)
36 double r_ed_undist_dn = _fl_dn * _distortion(r_ed_dist_dn / _fl_dn);
38 if(!remap_fe2plain(r_ed_undist_dn,r_plain_undist_dn))
43 double _r_clip_factor;
45 double _r_ed_dn_domain;
48 double _r_plain_dn_domain;
52 bool decypher(
const char* name,
int& i)
59 if(0 == strcmp(name,_para[i]))
67 bt::check_builtin_parameters();
69 _fl_dn = bt::fl_cm() / bt::r_fb_cm();
76 double radius_a = 0.0;
77 double radius_b = M_PI * _fl_dn;
81 for(
int i_pass = 0;i_pass < 5;++i_pass)
83 double r_ed_dist_dn_prev = -1.0;
84 double r_plain_undist_dn_prev = -1.0;
91 _r_ed_dn_domain = radius_b;
93 for(
int i = 0;i <= n;++i)
96 double q = double(i) / n;
98 r_ed_dist_dn = radius_a * (1.0 - q) + radius_b * q;
99 double r_plain_undist_dn;
100 if(!undistort_dn(r_ed_dist_dn,r_plain_undist_dn))
103 _r_ed_dn_domain = r_ed_dist_dn_prev;
104 _r_plain_dn_domain = r_plain_undist_dn_prev;
109 if(r_plain_undist_dn <= r_plain_undist_dn_prev)
112 _r_ed_dn_domain = r_ed_dist_dn_prev;
113 _r_plain_dn_domain = r_plain_undist_dn_prev;
118 r_ed_dist_dn_prev = r_ed_dist_dn;
119 r_plain_undist_dn_prev = r_plain_undist_dn;
121 _r_ed_dn_domain = r_ed_dist_dn;
122 _r_plain_dn_domain = r_plain_undist_dn;
125 radius_a = r_ed_dist_dn_prev;
126 radius_b = r_ed_dist_dn;
138 strcpy(identifier,_para[i]);
143 typedef base_type bt;
146 if(bt::set_builtin_parameter_value(identifier,v))
148 if(!decypher(identifier,i))
151 { bt::no_longer_uptodate_lut(); }
155 void getBoundingBoxUndistort(
double xa_in,
double ya_in,
double xb_in,
double yb_in,
double& xa_out,
double& ya_out,
double& xb_out,
double& yb_out,
int nx,
int ny)
157 typedef base_type bt;
178 void getBoundingBoxDistort(
double xa_in,
double ya_in,
double xb_in,
double yb_in,
double& xa_out,
double& ya_out,
double& xb_out,
double& yb_out,
int nx,
int ny)
180 typedef base_type bt;
204 virtual bool remap_fe2plain(
double r_ed_dn,
double& r_plain_dn) = 0;
205 virtual bool remap_plain2fe(
double r_plain_dn,
double& r_ed_dn) = 0;
207 bool undistort(
double x0,
double y0,
double &x1,
double &y1)
209 typedef base_type bt;
211 vec2_type p_ed_dist_dn = bt::map_unit_to_dn(vec2_type(x0,y0));
214 double r_ed_dist_dn = norm2(p_ed_dist_dn);
216 if(r_ed_dist_dn > _r_ed_dn_domain)
222 double r_ed_undist_dn = _fl_dn * _distortion(r_ed_dist_dn / _fl_dn);
224 double r_plain_undist_dn;
225 if(!remap_fe2plain(r_ed_undist_dn,r_plain_undist_dn))
228 vec2_type p_plain_undist_dn;
229 if(dotsq(p_ed_dist_dn) == 0.0)
230 { p_plain_undist_dn = vec2_type(0,0); }
232 { p_plain_undist_dn = r_plain_undist_dn * unit(p_ed_dist_dn); }
234 vec2_type p_plain_undist_unit = bt::map_dn_to_unit(p_plain_undist_dn);
235 x1 = p_plain_undist_unit[0];
236 y1 = p_plain_undist_unit[1];
239 bool distort(
double x0,
double y0,
double &x1,
double &y1)
241 typedef base_type bt;
243 vec2_type p_plain_undis_dn = bt::map_unit_to_dn(vec2_type(x0,y0));
245 double r_ed_undis_dn,r_plain_undis_dn = norm2(p_plain_undis_dn);
248 if(r_plain_undis_dn > _r_plain_dn_domain)
251 if(!remap_plain2fe(r_plain_undis_dn,r_ed_undis_dn))
254 double r_ed_dis_dn = _fl_dn * _distortion.
map_inverse(r_ed_undis_dn / _fl_dn,r_ed_undis_dn / _fl_dn);
256 vec2_type p_ed_dis_dn;
257 if(dotsq(p_plain_undis_dn) == 0.0)
258 { p_ed_dis_dn = vec2_type(0,0); }
260 { p_ed_dis_dn = r_ed_dis_dn * unit(p_plain_undis_dn); }
262 vec2_type p_ed_dis_unit = bt::map_dn_to_unit(p_ed_dis_dn);
263 x1 = p_ed_dis_unit[0];
264 y1 = p_ed_dis_unit[1];
273 double r_clip_factor()
const 274 {
return _r_clip_factor; }
275 void r_clip_factor(
double f)
276 { _r_clip_factor = f; }
280 typedef base_type bt;
282 if(bt::get_builtin_parameter_type(identifier,ptype))
return true;
283 if(!decypher(identifier,i))
return false;
284 ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
289 typedef base_type bt;
291 if(!decypher(identifier,i))
return false;
297 typedef base_type bt;
299 if(!decypher(identifier,i))
return false;
306 template <
class VEC2,
class MAT2>
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:278
bool getNumParameters(int &n)
returns the number of plugin parameters...
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:131
Plugin class for radial distortion. Does not compensate for decentering.
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:14
bool getParameterName(int i, char *identifier)
returns "identifier" name of parameter "i" (maximum length of "identifier": 100 bytes)...
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:136
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:295
void getBoundingBoxDistort(double xa_in, double ya_in, double xb_in, double yb_in, double &xa_out, double &ya_out, double &xb_out, double &yb_out, int nx, int ny)
Iterate around the specified box, distort the points and compute the bounding box.
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:178
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:287
bool undistort(double x0, double y0, double &x1, double &y1)
warp/unwarp 2D points...
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:207
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 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_base_deg_8.experimental.h:141
bool initializeParameters()
prepare the current set of parameters...
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:64
Double-valued vector and matrix class.
void getBoundingBoxUndistort(double xa_in, double ya_in, double xb_in, double yb_in, double &xa_out, double &ya_out, double &xb_out, double &yb_out, int nx, int ny)
Bounding box.
Definition: tde4_ldp_radial_fisheye_base_deg_8.experimental.h:155
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