ldpk
tde4_ldp_classic_3de_mixed.h
Go to the documentation of this file.
1 #ifndef tde4_ldp_classic_3de_mixed_sdv
2 #define tde4_ldp_classic_3de_mixed_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[5];
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 = 5;
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  virtual bool undistort(double x0,double y0,double &x1,double &y1)
76  {
77  typedef base_type bt;
78  vec2_type q = bt::map_dn_to_unit(_distortion.eval(bt::map_unit_to_dn(vec2_type(x0,y0))));
79  x1 = q[0];
80  y1 = q[1];
81  return true;
82  }
83  virtual bool distort(double x0,double y0,double &x1,double &y1)
84  {
85  typedef base_type bt;
86 // The distort-method without initial values is not constant by semantics,
87 // since it may cause an update of the lookup-tables. Implementing a Nuke node
88 // it turned out that we need to prevent threads from trying so simultaneously.
89 // By the following double check of is_uptodate_lut() we keep the mutex lock
90 // out of our frequently called distort stuff (for performance reasons) and
91 // prevent threads from updating without need.
92  if(!bt::is_uptodate_lut())
93  {
94  bt::lock();
95  if(!bt::is_uptodate_lut())
96  {
97  bt::update_lut();
98  }
99  bt::unlock();
100  }
101 
102 // Get initial value from lookup-table
103  vec2_type qs = bt::get_lut().get_initial_value(vec2_type(x0,y0));
104 // Call version of distort with initial value.
105  vec2_type q = bt::map_dn_to_unit(_distortion.map_inverse(bt::map_unit_to_dn(vec2_type(x0,y0)),bt::map_unit_to_dn(qs)));
106  x1 = q[0];
107  y1 = q[1];
108  return true;
109  }
110  virtual bool distort(double x0,double y0,double x1_start,double y1_start,double &x1,double &y1)
111  {
112  typedef base_type bt;
113  vec2_type q = bt::map_dn_to_unit(_distortion.map_inverse(bt::map_unit_to_dn(vec2_type(x0,y0)),bt::map_unit_to_dn(vec2_type(x1_start,y1_start))));
114  x1 = q[0];
115  y1 = q[1];
116  return true;
117  }
118 public:
119 // Mutex initialized and destroyed in baseclass.
121  { }
123  { }
124  bool getModelName(char *name)
125  {
126 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
127  strcpy(name,"3DE Classic LD Model [Plugin]");
128 #else
129  strcpy(name,"3DE Classic LD Model");
130 #endif
131  return true;
132  }
133  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
134  {
135  typedef base_type bt;
136  int i;
137  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
138  if(!decypher(identifier,i)) return false;
139  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
140  return true;
141  }
142  bool getParameterDefaultValue(const char* identifier,double& v)
143  {
144  typedef base_type bt;
145  int i;
146  if(!decypher(identifier,i)) return false;
147 // Alle Parameter haben als Default-Wert 0, ausser Squeeze
148  v = (i == 1) ? 1.0 : 0.0;
149  return true;
150  }
151  bool getParameterRange(const char* identifier,double& a,double& b)
152  {
153  typedef base_type bt;
154  int i;
155  if(!decypher(identifier,i)) return false;
156 // squeeze
157  if(i == 1)
158  {
159  a = 1.0 / 4.0;
160  b = 4.0;
161  }
162  else
163  {
164  a = -0.5;
165  b = 0.5;
166  };
167  return true;
168  }
170  bool getJacobianMatrix(double x0,double y0,double& m00,double& m01,double& m10,double& m11)
171  {
172  typedef base_type bt;
173  mat2_type m = _distortion.jacobi(bt::map_unit_to_dn(vec2_type(x0,y0)));
174  mat2_type u2d(bt::w_fb_cm() / bt::r_fb_cm(),0.0,0.0,bt::h_fb_cm() / bt::r_fb_cm());
175  mat2_type d2u(bt::r_fb_cm() / bt::w_fb_cm(),0.0,0.0,bt::r_fb_cm() / bt::h_fb_cm());
176  m = d2u * m * u2d;
177  m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
178  return true;
179  }
180  };
181 
182 template <class VEC2,class MAT2>
184  "Distortion",
185  "Anamorphic Squeeze",
186  "Curvature X",
187  "Curvature Y",
188  "Quartic Distortion"
189  };
190 
191 #endif
bool getJacobianMatrix(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
Tested against difference quotients.
Definition: tde4_ldp_classic_3de_mixed.h:170
void set_coeff(int i, double q)
Set coefficient as demanded by base class.
Definition: ldpk_classic_3de_mixed_distortion.h:51
vec2_type eval(const vec2_type &p) const
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:104
Degree-2 anamorphic and degree-4 radial mixed model.
Degree-2 anamorphic and degree-4 radial mixed model. Does not compensate for decentering. Parameters can be calculated by 3DE&#39;s Matrix Tool.
Definition: tde4_ldp_classic_3de_mixed.h:14
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_classic_3de_mixed.h:151
bool getParameterDefaultValue(const char *identifier, double &v)
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
Definition: tde4_ldp_classic_3de_mixed.h:142
double get_coeff(int i) const
Get coefficient as demanded by base class.
Definition: ldpk_classic_3de_mixed_distortion.h:48
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_classic_3de_mixed_distortion.h:70
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_classic_3de_mixed.h:124
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:122
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_classic_3de_mixed.h:133