ldpk
tde4_ldp_anamorphic_deg_6.h
Go to the documentation of this file.
1 #ifndef tde4_ldp_anamorphic_deg_6_sdv
2 #define tde4_ldp_anamorphic_deg_6_sdv
3 
4 #include <ldpk/ldpk_ldp_builtin.h>
5 #include <ldpk/ldpk_generic_anamorphic_distortion.h>
6 
9 
13 template <class VEC2,class MAT2>
15  {
16 private:
17  typedef VEC2 vec2_type;
18  typedef MAT2 mat2_type;
20 
21 // Anamorphic distortion of degree 6.
23 
24  static const char* _para[18];
25 protected:
26  bool decypher(const char* name,int& i)
27  {
28  typedef base_type bt;
29  int n;
31  for(i = 0;i < n;++i)
32  {
33  if(0 == strcmp(name,_para[i]))
34  { return true; }
35  }
36  return false;
37  }
39  {
40  typedef base_type bt;
41  bt::check_builtin_parameters();
42 // This method is the last one invoked, before the object can be used.
43  _anamorphic.prepare();
44  return true;
45  }
46  bool getNumParameters(int& n)
47  {
48  n = 18;
49  return true;
50  }
51  bool getParameterName(int i,char* identifier)
52  {
53  strcpy(identifier,_para[i]);
54  return true;
55  }
56  bool setParameterValue(const char *identifier,double v)
57  {
58  typedef base_type bt;
59  int i;
60 // Does the base class know the parameter?
61  if(bt::set_builtin_parameter_value(identifier,v))
62  {
63  return true;
64  }
65  if(!decypher(identifier,i))
66  {
67  return false;
68  }
69  if(i < 18)
70  {
71  if(_anamorphic.get_coeff(i) != v)
72  { bt::no_longer_uptodate_lut(); }
73  _anamorphic.set_coeff(i,v);
74  }
75  return true;
76  }
77 // slightly faster version
78  virtual bool undistort(double x0,double y0,double &x1,double &y1)
79  {
80  typedef base_type bt;
81  vec2_type q = bt::map_dn_to_unit(
82  _anamorphic.eval(
83  bt::map_unit_to_dn(vec2_type(x0,y0))));
84  x1 = q[0];
85  y1 = q[1];
86  return true;
87  }
88  virtual bool distort(double x0,double y0,double &x1,double &y1)
89  {
90  typedef base_type bt;
91 // The distort-method without initial values is not constant by semantics,
92 // since it may cause an update of the lookup-tables. Implementing a Nuke node
93 // it turned out that we need to prevent threads from trying so simultaneously.
94 // By the following double check of is_uptodate_lut() we keep the mutex lock
95 // out of our frequently called distort stuff (for performance reasons) and
96 // prevent threads from updating without need.
97  if(!bt::is_uptodate_lut())
98  {
99  bt::lock();
100  if(!bt::is_uptodate_lut())
101  {
102  bt::update_lut();
103  }
104  bt::unlock();
105  }
106 
107 // Get initial value from lookup-table
108  vec2_type qs = bt::get_lut().get_initial_value(vec2_type(x0,y0));
109 // vec2_type qs(x0,y0);
110 // Call version of distort with initial value.
111  vec2_type q = bt::map_dn_to_unit(
112  _anamorphic.map_inverse(
113  bt::map_unit_to_dn(vec2_type(x0,y0)),
114  bt::map_unit_to_dn(qs)));
115  x1 = q[0];
116  y1 = q[1];
117  return true;
118  }
119  virtual bool distort(double x0,double y0,double x1_start,double y1_start,double &x1,double &y1)
120  {
121  typedef base_type bt;
122  vec2_type q = bt::map_dn_to_unit(
123  _anamorphic.map_inverse(
124  bt::map_unit_to_dn(vec2_type(x0,y0)),
125  bt::map_unit_to_dn(vec2_type(x1_start,y1_start))));
126  x1 = q[0];
127  y1 = q[1];
128  return true;
129  }
130 public:
131 // Mutex initialized and destroyed in baseclass.
133  { }
135  { }
136  bool getModelName(char *name)
137  {
138 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
139  strcpy(name,"3DE4 Anamorphic, Degree 6 [Plugin]");
140 #else
141  strcpy(name,"3DE4 Anamorphic, Degree 6");
142 #endif
143  return true;
144  }
145  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
146  {
147  typedef base_type bt;
148  int i;
149  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
150  if(!decypher(identifier,i)) return false;
151  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
152  return true;
153  }
154  bool getParameterDefaultValue(const char* identifier,double& v)
155  {
156  typedef base_type bt;
157  int i;
158  if(!decypher(identifier,i)) return false;
159  v = 0.0;
160  return true;
161  }
162  bool getParameterRange(const char* identifier,double& a,double& b)
163  {
164  typedef base_type bt;
165  int i;
166  if(!decypher(identifier,i)) return false;
167  a = -0.5;
168  b = 0.5;
169  return true;
170  }
172  bool getJacobianMatrix(double x0,double y0,double& m00,double& m01,double& m10,double& m11)
173  {
174  typedef base_type bt;
175  mat2_type m = _anamorphic.jacobi(bt::map_unit_to_dn(vec2_type(x0,y0)));
176 // to myself: Eigentlich w/2,h/2 bei beiden. Kuerzt sich weg.
177  mat2_type u2d(bt::w_fb_cm() / bt::r_fb_cm(),0.0,0.0,bt::h_fb_cm() / bt::r_fb_cm());
178  mat2_type d2u(bt::r_fb_cm() / bt::w_fb_cm(),0.0,0.0,bt::r_fb_cm() / bt::h_fb_cm());
179  m = d2u * m * u2d;
180  m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
181  return true;
182  }
183  bool getTwistVector(double x0,double y0,double& t0,double& t1)
184  {
185  typedef base_type bt;
186  vec2_type t = _anamorphic.twist(bt::map_unit_to_dn(vec2_type(x0,y0)));
187  t0 = t[0] * (bt::h_fb_cm() / (bt::r_fb_cm()));t1 = t[1] * (bt::w_fb_cm() / (bt::r_fb_cm()));
188  return true;
189  }
190  };
191 
192 template <class VEC2,class MAT2>
194  "Cx02 - Degree 2","Cy02 - Degree 2",
195  "Cx22 - Degree 2","Cy22 - Degree 2",
196 
197  "Cx04 - Degree 4","Cy04 - Degree 4",
198  "Cx24 - Degree 4","Cy24 - Degree 4",
199  "Cx44 - Degree 4","Cy44 - Degree 4",
200 
201  "Cx06 - Degree 6","Cy06 - Degree 6",
202  "Cx26 - Degree 6","Cy26 - Degree 6",
203  "Cx46 - Degree 6","Cy46 - Degree 6",
204  "Cx66 - Degree 6","Cy66 - Degree 6"
205  };
206 
207 #endif
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_anamorphic_deg_6.h:136
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
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:77
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_anamorphic_deg_6.h:145
void set_coeff(int i, double q)
Set coefficient as demanded by base class.
Definition: ldpk_generic_anamorphic_distortion.h:77
virtual bool undistort(double x0, double y0, double &x1, double &y1)
warp/unwarp 2D points...
Definition: tde4_ldp_anamorphic_deg_6.h:78
bool initializeParameters()
prepare the current set of parameters...
Definition: tde4_ldp_anamorphic_deg_6.h:38
bool getParameterName(int i, char *identifier)
returns "identifier" name of parameter "i" (maximum length of "identifier": 100 bytes)...
Definition: tde4_ldp_anamorphic_deg_6.h:51
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_anamorphic_deg_6.h:162
bool getJacobianMatrix(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
Tested against difference quotients.
Definition: tde4_ldp_anamorphic_deg_6.h:172
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 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_anamorphic_deg_6.h:119
bool getParameterDefaultValue(const char *identifier, double &v)
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
Definition: tde4_ldp_anamorphic_deg_6.h:154
Plugin class for anamorphic distortion. Does not compensate for decentering. Parameters can be calcul...
Definition: tde4_ldp_anamorphic_deg_6.h:14
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 as demanded by base class.
Definition: ldpk_generic_anamorphic_distortion.h:71
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_anamorphic_deg_6.h:56
bool getNumParameters(int &n)
returns the number of plugin parameters...
Definition: tde4_ldp_anamorphic_deg_6.h:46