ldpk
tde4_ldp_all_par_types.h
Go to the documentation of this file.
1 #ifndef tde4_ldp_all_par_types_sdv
2 #define tde4_ldp_all_par_types_sdv
3 
4 #include <ldpk/ldpk_ldp_builtin.h>
5 #include <ldpk/ldpk_generic_anamorphic_distortion.h>
6 #include <ldpk/ldpk_rotation_extender.h>
7 #include <ldpk/ldpk_squeeze_extender.h>
8 #include <ldpk/ldpk_linear_extender.h>
9 #include <fstream>
10 
13 
18 template <class VEC2,class MAT2>
20  {
21 private:
22  typedef VEC2 vec2_type;
23  typedef MAT2 mat2_type;
25 
26  static const char* _para[9];
27 
28  bool _debugging_enabled;
29  std::string _debugging_filename;
30  std::ofstream _debugging_fout;
31  int _dummy;
32 
33 // Wir kombinieren hier anamorphische Verzeichung Grad 4
34 // mit einer Rotation und einem Squeeze. Das ist der anamorphe Anteil
40 
44 protected:
45  bool decypher(const char* name,int& i)
46  {
47  typedef base_type bt;
48  int n;
50  for(i = 0;i < n;++i)
51  {
52  if(0 == strcmp(name,_para[i]))
53  { return true; }
54  }
55  return false;
56  }
58  {
59  typedef base_type bt;
60  bt::check_builtin_parameters();
61  _pa.set_sq(bt::pa());
62 // This method is the last one invoked, before the object can be used,
63 // therefore we have to prepare the concatenated extenders here.
64  _rot_sqx_sqy_pa.set(_rotation,_squeeze_x,_squeeze_y,_pa);
65  if(_squeeze_x.get_sq() == 0)
66  { std::cerr << "tde4_ldp_anamorphic_deg_4_rotate_squeeze_xy::initializeParameters, error: Squeeze-X is 0." << std::endl; }
67  if(_squeeze_y.get_sq() == 0)
68  { std::cerr << "tde4_ldp_anamorphic_deg_4_rotate_squeeze_xy::initializeParameters, error: Squeeze-Y is 0." << std::endl; }
69  _pa_rot.set(_pa,_rotation);
70  _anamorphic.prepare();
71  if(_debugging_enabled && _debugging_fout.is_open())
72  {
73  _debugging_fout << "initializeParameters()" << std::endl;
74  }
75  return true;
76  }
77  bool getNumParameters(int& n)
78  {
79  n = 9;
80  return true;
81  }
82  bool getParameterName(int i,char* identifier)
83  {
84  strcpy(identifier,_para[i]);
85  return true;
86  }
87  bool setParameterValue(const char *identifier,double v)
88  {
89  typedef base_type bt;
90  int i;
91  if(_debugging_enabled && _debugging_fout.is_open())
92  { _debugging_fout << "setParameterValue(\"" << identifier << "\"," << v << ")" << std::endl; }
93 // Does the base class know the parameter?
94  if(bt::set_builtin_parameter_value(identifier,v))
95  { return true; }
96  if(!decypher(identifier,i))
97  { return false; }
98  switch(i)
99  {
100 // adjustable double and double parameters
101  case 0:
102  case 1:
103  case 2:
104  case 3:
105  {
106 // parameters 0, 1, 2 and 3 in anamorphic.
107  if(_anamorphic.get_coeff(i) != v)
108  { bt::no_longer_uptodate_lut(); }
109  _anamorphic.set_coeff(i,v);
110  return true;
111  }
112  }
113  return false;
114  }
115  bool setParameterValue(const char *identifier,const char* t)
116  {
117  typedef base_type bt;
118  int i;
119  if(_debugging_enabled && _debugging_fout.is_open())
120  { _debugging_fout << "setParameterValue(\"" << identifier << "\",\"" << t << "\")" << std::endl; }
121 // Does the base class know the parameter?
122  if(!decypher(identifier,i))
123  { return false; }
124  switch(i)
125  {
126 // string parameters
127  case 4:
128  {
129  double v;
130  sscanf(t,"%lf",&v);
131  if(_squeeze_x.get_sq() != v)
132  { bt::no_longer_uptodate_lut(); }
133  _squeeze_x.set_sq(v);
134  return true;
135  }
136  case 5:
137  {
138  double v;
139  sscanf(t,"%lf",&v);
140  if(_squeeze_y.get_sq() != v)
141  { bt::no_longer_uptodate_lut(); }
142  _squeeze_y.set_sq(v);
143  return true;
144  }
145 // file parameter
146  case 6:
147  {
148  if(_debugging_filename != t)
149  {
150  _debugging_fout.close();
151  _debugging_filename = t;
152  if(strcmp(t,"") == 0)
153  {
154 // We cannot do this here.
155 // std::cout << "open " << _debugging_filename << std::endl;
156 // _debugging_fout.open(_debugging_filename.c_str());
157  }
158  }
159  return true;
160  }
161  }
162  return false;
163  }
164  bool setParameterValue(const char *identifier,bool v)
165  {
166  typedef base_type bt;
167  int i;
168  if(_debugging_enabled && _debugging_fout.is_open())
169  { _debugging_fout << "setParameterValue(\"" << identifier << "\"," << v << ")" << std::endl; }
170 // Does the base class know the parameter?
171  if(!decypher(identifier,i))
172  { return false; }
173  switch(i)
174  {
175 // bool parameter
176  case 7:
177  {
178  _debugging_enabled = v;
179  return true;
180  }
181  }
182  return false;
183  }
184  bool setParameterValue(const char *identifier,int v)
185  {
186  typedef base_type bt;
187  int i;
188  if(_debugging_enabled && _debugging_fout.is_open())
189  { _debugging_fout << "setParameterValue(\"" << identifier << "\"," << v << ")" << std::endl; }
190 // Does the base class know the parameter?
191  if(!decypher(identifier,i))
192  { return false; }
193  switch(i)
194  {
195 // int parameter
196  case 8:
197  {
198  _dummy = v;
199  return true;
200  }
201  }
202  return false;
203  }
204  virtual bool undistort(double x0,double y0,double &x1,double &y1)
205  {
206  typedef base_type bt;
207  vec2_type q = bt::map_dn_to_unit(
208  _rot_sqx_sqy_pa.eval(
209  _anamorphic.eval(
210  _pa_rot.eval_inv(
211  bt::map_unit_to_dn(vec2_type(x0,y0))))));
212  x1 = q[0];
213  y1 = q[1];
214  return true;
215  }
216  virtual bool distort(double x0,double y0,double &x1,double &y1)
217  {
218  typedef base_type bt;
219 // The distort-method without initial values is not constant by semantics,
220 // since it may cause an update of the lookup-tables. Implementing a Nuke node
221 // it turned out that we need to prevent threads from trying so simultaneously.
222 // By the following double check of is_uptodate_lut() we keep the mutex lock
223 // out of our frequently called distort stuff (for performance reasons) and
224 // prevent threads from updating without need.
225  if(!bt::is_uptodate_lut())
226  {
227  bt::lock();
228  if(!bt::is_uptodate_lut())
229  {
230  bt::update_lut();
231  }
232  bt::unlock();
233  }
234 // Get initial value from lookup-table
235  vec2_type qs = bt::get_lut().get_initial_value(vec2_type(x0,y0));
236 // Call version of distort with initial value.
237  vec2_type q = bt::map_dn_to_unit(
238  _pa_rot.eval(
239  _anamorphic.map_inverse(
240  _rot_sqx_sqy_pa.eval_inv(
241  bt::map_unit_to_dn(vec2_type(x0,y0))),
242  _rot_sqx_sqy_pa.eval_inv(
243  bt::map_unit_to_dn(qs)))));
244  x1 = q[0];
245  y1 = q[1];
246  return true;
247  }
248  virtual bool distort(double x0,double y0,double x1_start,double y1_start,double &x1,double &y1)
249  {
250  typedef base_type bt;
251  vec2_type q = bt::map_dn_to_unit(
252  _pa_rot.eval(
253  _anamorphic.map_inverse(
254  _rot_sqx_sqy_pa.eval_inv(
255  bt::map_unit_to_dn(vec2_type(x0,y0))),
256  _rot_sqx_sqy_pa.eval_inv(
257  bt::map_unit_to_dn(vec2_type(x1_start,y1_start))))));
258  x1 = q[0];
259  y1 = q[1];
260  return true;
261  }
262 public:
263 // Mutex initialized and destroyed in baseclass.
264  tde4_ldp_all_par_types():_debugging_enabled(false)
265  { }
267  { }
268  bool getModelName(char *name)
269  {
270 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
271  strcpy(name,"3DE4 All Parameter Types [Plugin]");
272 #else
273  strcpy(name,"3DE4 All Parameter Types");
274 #endif
275  return true;
276  }
277  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
278  {
279  typedef base_type bt;
280  int i;
281  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
282  if(!decypher(identifier,i)) return false;
283  switch(i)
284  {
285  case 0:
286  case 1:
287  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;break;
288  case 2:
289  case 3:
290  ptype = TDE4_LDP_DOUBLE;break;
291  case 4:
292  case 5:
293  ptype = TDE4_LDP_STRING;break;
294  case 6:
295  ptype = TDE4_LDP_FILE;break;
296  case 7:
297  ptype = TDE4_LDP_TOGGLE;break;
298  case 8:
299  ptype = TDE4_LDP_INT;break;
300  }
301  return true;
302  }
303  bool getParameterDefaultValue(const char* identifier,double& v)
304  {
305  typedef base_type bt;
306  int i;
307  if(!decypher(identifier,i)) return false;
308  switch(i)
309  {
310  case 0:
311  case 1:
312  case 2:
313  case 3:
314  {
315  v = 0.0;
316  return true;
317  }
318  }
319  return false;
320  }
321  bool getParameterDefaultValue(const char* identifier,char* v)
322  {
323  typedef base_type bt;
324  int i;
325  if(!decypher(identifier,i)) return false;
326  switch(i)
327  {
328  case 4:
329  case 5:
330  {
331  strcpy(v,"1.0");
332  return true;
333  }
334  case 6:
335  {
336  strcpy(v,"");
337  return true;
338  }
339  }
340  return false;
341  }
342  bool getParameterDefaultValue(const char* identifier,bool& v)
343  {
344  typedef base_type bt;
345  int i;
346  if(!decypher(identifier,i)) return false;
347  switch(i)
348  {
349  case 7:
350  {
351  v = false;
352  return true;
353  }
354  }
355  return false;
356  }
357  bool getParameterDefaultValue(const char* identifier,int& v)
358  {
359  typedef base_type bt;
360  int i;
361  if(!decypher(identifier,i)) return false;
362  switch(i)
363  {
364  case 8:
365  {
366  v = -1;
367  return true;
368  }
369  }
370  return false;
371  }
372  bool getParameterRange(const char* identifier,double& a,double& b)
373  {
374  typedef base_type bt;
375  int i;
376  if(!decypher(identifier,i)) return false;
377  a = -0.5;
378  b = 0.5;
379  return true;
380  }
382  bool getJacobianMatrix(double x0,double y0,double& m00,double& m01,double& m10,double& m11)
383  {
384  typedef base_type bt;
385  mat2_type m = _rot_sqx_sqy_pa.get_mat()
386  * _anamorphic.jacobi(
387  _pa_rot.eval_inv(
388  bt::map_unit_to_dn(vec2_type(x0,y0))))
389  * _pa_rot.get_mat_inv();
390  mat2_type u2d(bt::w_fb_cm() / bt::r_fb_cm(),0.0,0.0,bt::h_fb_cm() / bt::r_fb_cm());
391  mat2_type d2u(bt::r_fb_cm() / bt::w_fb_cm(),0.0,0.0,bt::r_fb_cm() / bt::h_fb_cm());
392  m = d2u * m * u2d;
393  m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
394  return true;
395  }
396  };
397 
398 template <class VEC2,class MAT2>
400  "Par - Adjustable Double [Cx02]",
401  "Par - Adjustable Double [Cy02]",
402  "Par - Double [Cx22]",
403  "Par - Double [Cy22]",
404  "Par - String [Squeeze-X]",
405  "Par - String [Squeeze-Y]",
406  "Par - File [Debug Output]",
407  "Par - Toggle [Debugging On/Off]",
408  "Par - Int [Dunno]",
409  };
410 
411 #endif
bool getJacobianMatrix(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
Tested against difference quotients.
Definition: tde4_ldp_all_par_types.h:382
virtual bool undistort(double x0, double y0, double &x1, double &y1)
warp/unwarp 2D points...
Definition: tde4_ldp_all_par_types.h:204
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_all_par_types.h:248
virtual mat2_type jacobi(const vec2_type &p_dn) const
Jacobi-Matrix. The result is a matrix g_{ij} = d/dp_j f(p)_i, where f represents the undistort-functi...
Definition: ldpk_generic_distortion_base.h:82
vec2_type eval(const vec2_type &p) const
eval() is per definition removal of lens distortion (undistort).
Definition: ldpk_linear_extender.h:65
Example plugin class containing one parameter of each type. The main purpose of this model is to test...
Definition: tde4_ldp_all_par_types.h:19
bool getParameterDefaultValue(const char *identifier, double &v)
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
Definition: tde4_ldp_all_par_types.h:303
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_all_par_types.h:277
vec2_type eval(const vec2_type &p) const
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:77
void set_coeff(int i, double q)
Set coefficient as demanded by base class.
Definition: ldpk_generic_anamorphic_distortion.h:77
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_all_par_types.h:87
bool getNumParameters(int &n)
returns the number of plugin parameters...
Definition: tde4_ldp_all_par_types.h:77
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_all_par_types.h:372
bool getParameterName(int i, char *identifier)
returns "identifier" name of parameter "i" (maximum length of "identifier": 100 bytes)...
Definition: tde4_ldp_all_par_types.h:82
const mat2_type & get_mat_inv() const
The inverse matrix for this extender.
Definition: ldpk_linear_extender.h:77
void set(const mat2_type &m)
Passing the matrix.
Definition: ldpk_linear_extender.h:24
bool initializeParameters()
prepare the current set of parameters...
Definition: tde4_ldp_all_par_types.h:57
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
const mat2_type & get_mat() const
The matrix for this extender.
Definition: ldpk_linear_extender.h:74
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
vec2_type eval_inv(const vec2_type &q) const
eval_inv() is applying lens distortion (distort)
Definition: ldpk_linear_extender.h:68
double get_coeff(int i) const
Get coefficient as demanded by base class.
Definition: ldpk_generic_anamorphic_distortion.h:71
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_all_par_types.h:268