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