ldpk
tde4_ldp_radial_deg_8_release_1.h
Go to the documentation of this file.
1 #ifndef tde4_ldp_radial_deg_8_release_1_sdv
2 #define tde4_ldp_radial_deg_8_release_1_sdv
3 
4 #include <ldpk/ldpk_ldp_builtin.h>
6 
9 
13 template <class VEC2,class MAT2>
15  {
16 private:
17  typedef VEC2 vec2_type;
18  typedef MAT2 mat2_type;
20 
22 
23  static const char* _para[4];
24 
25  bool decypher(const char* name,int& i)
26  {
27  typedef base_type bt;
28  int n;
29  getNumParameters(n);
30  for(i = 0;i < n;++i)
31  {
32  if(0 == strcmp(name,_para[i]))
33  {
34  return true;
35  }
36  }
37  return false;
38  }
39  bool initializeParameters()
40  {
41  typedef base_type bt;
42  bt::check_builtin_parameters();
43  return true;
44  }
45  bool getNumParameters(int& n)
46  {
47  n = 4;
48  return true;
49  }
50  bool getParameterName(int i,char* identifier)
51  {
52  strcpy(identifier,_para[i]);
53  return true;
54  }
55  bool setParameterValue(const char *identifier,double v)
56  {
57  typedef base_type bt;
58  int i;
59 // Does the base class know the parameter?
60  if(bt::set_builtin_parameter_value(identifier,v))
61  {
62  return true;
63  }
64  if(!decypher(identifier,i))
65  {
66  return false;
67  }
68  if(_distortion.get_coeff(i) != v)
69  {
70  bt::no_longer_uptodate_lut();
71  }
72  _distortion.set_coeff(i,v);
73  return true;
74  }
75 
76 // Overwriting tde4_ldp_common
77  bool undistort(double x0,double y0,double &x1,double &y1)
78  {
79  typedef base_type bt;
80  vec2_type p_plain_dn = bt::map_unit_to_dn(vec2_type(x0,y0));
81 
82 // Clipping to a reasonable area, still n times as large as the image.
83  vec2_type q_dn = _distortion.eval(p_plain_dn);
84  if(norm2(q_dn) > 50.0) q_dn = 50.0 * unit(q_dn);
85 
86  vec2_type q = bt::map_dn_to_unit(q_dn);
87  x1 = q[0];
88  y1 = q[1];
89  return true;
90  }
91  bool distort(double x0,double y0,double &x1,double &y1)
92  {
93  typedef base_type bt;
94 // The distort-method without initial values is not constant by semantics,
95 // since it may cause an update of the lookup-tables. Implementing a Nuke node
96 // it turned out that we need to prevent threads from trying so simultaneously.
97 // By the following double check of is_uptodate_lut() we keep the mutex lock
98 // out of our frequently called distort stuff (for performance reasons) and
99 // prevent threads from updating without need.
100  if(!bt::is_uptodate_lut())
101  {
102  bt::lock();
103  if(!bt::is_uptodate_lut())
104  {
105  bt::update_lut();
106  }
107  bt::unlock();
108  }
109 
110 // Get initial value from lookup-table
111  vec2_type qs = bt::get_lut().get_initial_value(vec2_type(x0,y0));
112 // Call version of distort with initial value.
113  vec2_type p_plain_dn = _distortion.map_inverse(bt::map_unit_to_dn(vec2_type(x0,y0)),bt::map_unit_to_dn(qs));
114 
115  vec2_type q = bt::map_dn_to_unit(p_plain_dn);
116  x1 = q[0];
117  y1 = q[1];
118  return true;
119  }
120  bool distort(double x0,double y0,double x1_start,double y1_start,double &x1,double &y1)
121  {
122  typedef base_type bt;
123  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)));
124 
125  vec2_type q = bt::map_dn_to_unit(p_plain_dn);
126  x1 = q[0];
127  y1 = q[1];
128  return true;
129  }
130 public:
132  { }
133  bool getModelName(char *name)
134  {
135 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
136  strcpy(name,"3DE4 Radial - Fisheye, Degree 8, Release 1 [Plugin]");
137 #else
138  strcpy(name,"3DE4 Radial - Fisheye, Degree 8, Release 1");
139 #endif
140  return true;
141  }
142  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
143  {
144  typedef base_type bt;
145  int i;
146  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
147  if(!decypher(identifier,i)) return false;
148  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
149  return true;
150  }
151  bool getParameterDefaultValue(const char* identifier,double& v)
152  {
153  typedef base_type bt;
154  int i;
155  if(!decypher(identifier,i)) return false;
156  v = 0.0;
157  return true;
158  }
159  bool getParameterRange(const char* identifier,double& a,double& b)
160  {
161  typedef base_type bt;
162  int i;
163  if(!decypher(identifier,i)) return false;
164  a = -0.5;
165  b = 0.5;
166  return true;
167  }
168  };
169 
170 template <class VEC2,class MAT2>
172  "Distortion - Degree 2",
173  "Quartic Distortion - Degree 4",
174  "Degree 6",
175  "Degree 8"
176  };
177 
178 #endif
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_deg_8_release_1.h:151
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_release_1.h:133
Plugin class for radial distortion. Does not compensate for decentering. Parameters can be calculated...
Definition: tde4_ldp_radial_deg_8_release_1.h:14
vec2_type eval(const vec2_type &p) const
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:102
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_release_1.h:142
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_radial_deg_8_release_1.h:159
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:120
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