ldpk
tde4_ldp_radial_decentered_deg_4_cylindric.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ldpk/ldpk_ldp_builtin.h>
5 #include <ldpk/ldpk_cylindric_extender.h>
6 
10 
14 template <class VEC2,class MAT2>
16  {
17 private:
18  typedef VEC2 vec2_type;
19  typedef MAT2 mat2_type;
21 
24 
25  static const char* _para[8];
26 protected:
27  bool decypher(const char* name,int& i)
28  {
29  typedef base_type bt;
30  int n;
32  for(i = 0;i < n;++i)
33  {
34  if(0 == strcmp(name,_para[i]))
35  {
36  return true;
37  }
38  }
39  return false;
40  }
42  {
43  typedef base_type bt;
44  bt::check_builtin_parameters();
45  return true;
46  }
47  bool getNumParameters(int& n)
48  {
49  n = 8;
50  return true;
51  }
52  bool getParameterName(int i,char* identifier)
53  {
54  strcpy(identifier,_para[i]);
55  return true;
56  }
57  bool setParameterValue(const char *identifier,double v)
58  {
59  typedef base_type bt;
60  int i;
61 // Does the base class know the parameter?
62  if(bt::set_builtin_parameter_value(identifier,v))
63  {
64  return true;
65  }
66  if(!decypher(identifier,i))
67  {
68  return false;
69  }
70  if(i < 6)
71  {
72  if(_radial.get_coeff(i) != v)
73  { bt::no_longer_uptodate_lut(); }
74  _radial.set_coeff(i,v);
75  }
76  else if(i == 6)
77  {
78  if(_cylindric.get_phi() != v)
79  { bt::no_longer_uptodate_lut(); }
80  _cylindric.set_phi(v);
81  }
82  else if(i == 7)
83  {
84  if(_cylindric.get_b() != v)
85  { bt::no_longer_uptodate_lut(); }
86  _cylindric.set_b(v);
87  }
88  return true;
89  }
90  virtual bool undistort(double x0,double y0,double &x1,double &y1)
91  {
92  typedef base_type bt;
93  vec2_type q = bt::map_dn_to_unit(
94  _cylindric.eval(
95  _radial.eval(
96  bt::map_unit_to_dn(vec2_type(x0,y0)))));
97  x1 = q[0];
98  y1 = q[1];
99  return true;
100  }
101  virtual bool distort(double x0,double y0,double &x1,double &y1)
102  {
103  typedef base_type bt;
104 // The distort-method without initial values is not constant by semantics,
105 // since it may cause an update of the lookup-tables. Implementing a Nuke node
106 // it turned out that we need to prevent threads from trying so simultaneously.
107 // By the following double check of is_uptodate_lut() we keep the mutex lock
108 // out of our frequently called distort stuff (for performance reasons) and
109 // prevent threads from updating without need.
110  if(!bt::is_uptodate_lut())
111  {
112  bt::lock();
113  if(!bt::is_uptodate_lut())
114  {
115  bt::update_lut();
116  }
117  bt::unlock();
118  }
119 
120 // Get initial value from lookup-table
121  vec2_type qs = bt::get_lut().get_initial_value(vec2_type(x0,y0));
122 // Call version of distort with initial value.
123  vec2_type q = bt::map_dn_to_unit(
124  _radial.map_inverse(
125  _cylindric.eval_inv(
126  bt::map_unit_to_dn(vec2_type(x0,y0))),
127  _cylindric.eval_inv(
128  bt::map_unit_to_dn(qs))));
129  x1 = q[0];
130  y1 = q[1];
131  return true;
132  }
133  virtual bool distort(double x0,double y0,double x1_start,double y1_start,double &x1,double &y1)
134  {
135  typedef base_type bt;
136  vec2_type q = bt::map_dn_to_unit(
137  _radial.map_inverse(
138  _cylindric.eval_inv(
139  bt::map_unit_to_dn(vec2_type(x0,y0))),
140  _cylindric.eval_inv(
141  bt::map_unit_to_dn(vec2_type(x1_start,y1_start)))));
142  x1 = q[0];
143  y1 = q[1];
144  return true;
145  }
146 public:
147 // Mutex initialized and destroyed in baseclass.
149  { }
151  { }
152  bool getModelName(char *name)
153  {
154 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
155  strcpy(name,"3DE4 Radial - Standard, Degree 4 [Plugin]");
156 #else
157  strcpy(name,"3DE4 Radial - Standard, Degree 4");
158 #endif
159  return true;
160  }
161  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
162  {
163  typedef base_type bt;
164  int i;
165  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
166  if(!decypher(identifier,i)) return false;
167  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
168  return true;
169  }
170  bool getParameterDefaultValue(const char* identifier,double& v)
171  {
172  typedef base_type bt;
173  int i;
174  if(!decypher(identifier,i)) return false;
175  v = 0.0;
176  return true;
177  }
178  bool getParameterRange(const char* identifier,double& a,double& b)
179  {
180  typedef base_type bt;
181  int i;
182  if(!decypher(identifier,i)) return false;
183  if((i == 0) || (i == 3))
184  {
185 // Distortion - Degree 2, Quartic Distortion - Degree 4
186  a = -0.5;b = 0.5;
187  }
188  else if((i == 1) || (i == 2) || (i == 4) || (i == 5))
189  {
190 // U2,V2,U4,V4.
191  a = -0.5;b = 0.5;
192  }
193  else if(i == 6)
194  {
195 // Phi - Cylindric Direction. In the symmetric extender version -45 to 45 would be sufficient.
196  a = -90.0;b = +90.0;
197  }
198  else if(i == 7)
199  {
200 // B - Cylindric Bending
201  a = -0.1;b = 0.1;
202  }
203  return true;
204  }
205  bool getJacobianMatrix(double x0,double y0,double& m00,double& m01,double& m10,double& m11)
206  {
207  typedef base_type bt;
208  mat2_type m = _cylindric.get_mat()
209  * _radial.jacobi(
210  bt::map_unit_to_dn(vec2_type(x0,y0)));
211 // to myself: Eigentlich w/2,h/2 bei beiden. Kuerzt sich weg.
212  mat2_type u2d(bt::w_fb_cm() / bt::r_fb_cm(),0.0,0.0,bt::h_fb_cm() / bt::r_fb_cm());
213  mat2_type d2u(bt::r_fb_cm() / bt::w_fb_cm(),0.0,0.0,bt::r_fb_cm() / bt::h_fb_cm());
214  m = d2u * m * u2d;
215  m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
216  return true;
217  }
218  };
219 
220 template <class VEC2,class MAT2>
222  "Distortion - Degree 2",
223  "U - Degree 2",
224  "V - Degree 2",
225  "Quartic Distortion - Degree 4",
226  "U - Degree 4",
227  "V - Degree 4",
228  "Phi - Cylindric Direction",
229  "B - Cylindric Bending"
230  };
231 
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_decentered_deg_4_cylindric.h:205
virtual vec2_type eval_inv(const vec2_type &q) const
eval_inv() is applying lens distortion (distort)
Definition: ldpk_cylindric_extender.h:102
virtual bool distort(double x0, double y0, double x1_start, double y1_start, double &x1, double &y1)
potentially more efficient function which uses initial values...
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:133
vec2_type eval(const vec2_type &p) const
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:77
void set_b(double b)
This parameter expresses the strength of the cylindric deformation ("bending").
Definition: ldpk_cylindric_extender.h:94
bool getNumParameters(int &n)
returns the number of plugin parameters...
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:47
bool getParameterName(int i, char *identifier)
returns "identifier" name of parameter "i" (maximum length of "identifier": 100 bytes)...
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:52
mat2_type jacobi(const vec2_type &p_dn) const
Analytic version of the Jacobi-matrix, about two times faster than the base class version which uses ...
Definition: ldpk_radial_decentered_distortion.h:71
const mat2_type & get_mat() const
The matrix for this extender.
Definition: ldpk_cylindric_extender.h:108
A polynomial radially symmetric model of degree 4 with decentering.
Plugin class for radial distortion with decentering and optional compensation for beam-splitter artef...
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:15
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_decentered_deg_4_cylindric.h:57
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_decentered_deg_4_cylindric.h:152
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:178
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
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:95
void set_coeff(int i, double q)
Set coefficient c[i], 0 <= i < 6.
Definition: ldpk_radial_decentered_distortion.h:44
double get_coeff(int i) const
Get coefficient c[i], 0 <= i < 6.
Definition: ldpk_radial_decentered_distortion.h:38
vec2_type eval(const vec2_type &p) const
eval() is per definition removal of lens distortion (undistort).
Definition: ldpk_cylindric_extender.h:99
void set_phi(double phi)
The cylindric extender has a parameter called phi.
Definition: ldpk_cylindric_extender.h:89
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_decentered_deg_4_cylindric.h:161
bool getParameterDefaultValue(const char *identifier, double &v)
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:170
virtual bool undistort(double x0, double y0, double &x1, double &y1)
warp/unwarp 2D points...
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:90
bool initializeParameters()
prepare the current set of parameters...
Definition: tde4_ldp_radial_decentered_deg_4_cylindric.h:41