ldpk
tde4_ld_plugin.h
1 //
2 //
3 // 3DEqualizer4 - Lens Distortion Plugin Interface
4 //
5 // File tde4_ld_plugin.h
6 // Author RS
7 // Date 01.10.10
8 //
9 // Version: see macro
10 
11 #pragma once
12 #include <cmath>
13 #include <iostream>
14 
15 #define TDE4_LDP_VERSION "1.0.8"
16 
17 // parameter types...
18 enum tde4_ldp_ptype
19  {
20  TDE4_LDP_STRING = 0,
21  TDE4_LDP_DOUBLE = 1,
22  TDE4_LDP_INT = 2,
23  TDE4_LDP_FILE = 3,
24  TDE4_LDP_TOGGLE = 4,
25  TDE4_LDP_ADJUSTABLE_DOUBLE = 5
26  };
27 
30  {
31 public:
32 
33  virtual ~tde4_ld_plugin() {}
34 
35  const char* getVersionString() const
36  { return TDE4_LDP_VERSION; }
37 
39  virtual bool getModelName(char *model) = 0;
40 
42  virtual bool getNumParameters(int &n) = 0;
43 
45  virtual bool getParameterName(int i, char *identifier) = 0;
46 
49  virtual bool getParameterType(const char *identifier, tde4_ldp_ptype &type) = 0;
50 
52  virtual bool getParameterDefaultValue(const char *identifier, double &v) = 0;
53  virtual bool getParameterDefaultValue(const char *identifier, char *v)
54  {
55  std::cerr << "getParameterDefaultValue(" << identifier << ",char*): unimplemented method." << std::endl;
56  v[0] = 0;
57  return false;
58  }
59  virtual bool getParameterDefaultValue(const char *identifier, int &v)
60  {
61  std::cerr << "getParameterDefaultValue(" << identifier << ",int&): unimplemented method." << std::endl;
62  v = 0;
63  return false;
64  }
65  virtual bool getParameterDefaultValue(const char *identifier, bool &v)
66  {
67  std::cerr << "getParameterDefaultValue(" << identifier << ",bool&): unimplemented method." << std::endl;
68  v = false;
69  return false;
70  }
71 
73  virtual bool getParameterRange(const char *identifier, double &a, double &b) = 0;
74 
78  virtual bool setParameterValue(const char *identifier, double v) = 0;
79  virtual bool setParameterValue(const char *identifier, const char *v)
80  {
81  std::cerr << "setParameterValue(" << identifier << ",const char* " << v << "): unimplemented method." << std::endl;
82  return false;
83  }
84  virtual bool setParameterValue(const char *identifier, int v)
85  {
86  std::cerr << "setParameterValue(" << identifier << ",int " << v << "): unimplemented method." << std::endl;
87  return false;
88  }
89  virtual bool setParameterValue(const char *identifier, bool v)
90  {
91  std::cerr << "setParameterValue(" << identifier << ",bool " << v << "): unimplemented method." << std::endl;
92  return false;
93  }
94 
96  virtual bool initializeParameters() = 0;
97 
99  virtual bool undistort(double x0, double y0, double &x1, double &y1) = 0;
100  virtual bool distort(double x0, double y0, double &x1, double &y1) = 0;
101 
103  virtual bool distort(double x0, double y0, double x1_start , double y1_start, double &x1, double &y1) { return distort(x0,y0,x1,y1); }
104 
106  virtual bool providesParameterDerivatives() { return false; }
108  virtual bool calcParameterDerivatives(double x, double y, int num_parameters, double *dx_dy) { return false; }
109 
112  bool getJacobianMatrixDQ(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
113  {
114  bool ok = true;
115  double eps = 1e-4,x00,x10,x01,x11,y00,y10,y01,y11;
116  ok &= undistort(x0 - eps,y0,x00,y00);
117  ok &= undistort(x0 + eps,y0,x01,y01);
118  ok &= undistort(x0,y0 - eps,x10,y10);
119  ok &= undistort(x0,y0 + eps,x11,y11);
120  m00 = (x01 - x00) / (2.0 * eps);
121  m01 = (x11 - x10) / (2.0 * eps);
122  m10 = (y01 - y00) / (2.0 * eps);
123  m11 = (y11 - y10) / (2.0 * eps);
124  return ok;
125  }
128  virtual bool getJacobianMatrix(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
129  {
130  return getJacobianMatrixDQ(x0,y0,m00,m01,m10,m11);
131  }
134  virtual bool getTwistVector(double x0, double y0, double &t0, double &t1)
135  {
136  bool ok = true;
137  double eps = 1e-4,x00,x10,x01,x11,y00,y10,y01,y11;
138  ok &= undistort(x0 - eps,y0 - eps,x00,y00);
139  ok &= undistort(x0 + eps,y0 - eps,x10,y10);
140  ok &= undistort(x0 - eps,y0 + eps,x01,y01);
141  ok &= undistort(x0 + eps,y0 + eps,x11,y11);
142  t0 = (x11 - x01 - x10 + x00) / (4.0 * eps * eps);
143  t1 = (y11 - y01 - y10 + y00) / (4.0 * eps * eps);
144  return ok;
145  }
147  virtual void getBoundingBoxUndistort(double xa_in,double ya_in,double xb_in,double yb_in,double& xa_out,double& ya_out,double& xb_out,double& yb_out,int nx = 32,int ny = 32)
148  {
149  xa_out = HUGE_VAL;
150  ya_out = HUGE_VAL;
151  xb_out = -HUGE_VAL;
152  yb_out = -HUGE_VAL;
153  double dx_in = xb_in - xa_in,dy_in = yb_in - ya_in;
154 // Avoid double evaluation at the corners.
155  for(int ix = 0;ix < nx;++ix)
156  {
157  double xa = xa_in + dx_in * double(ix ) / nx;
158  double xb = xa_in + dx_in * double(ix + 1) / nx;
159  accumulate_undistort(xa,ya_in,xa_out,ya_out,xb_out,yb_out);
160  accumulate_undistort(xb,yb_in,xa_out,ya_out,xb_out,yb_out);
161  }
162  for(int iy = 0;iy < ny;++iy)
163  {
164  double ya = ya_in + dy_in * double(iy + 1) / ny;
165  double yb = ya_in + dy_in * double(iy ) / ny;
166  accumulate_undistort(xa_in,ya,xa_out,ya_out,xb_out,yb_out);
167  accumulate_undistort(xb_in,yb,xa_out,ya_out,xb_out,yb_out);
168  }
169  }
171  virtual void getBoundingBoxDistort(double xa_in,double ya_in,double xb_in,double yb_in,double& xa_out,double& ya_out,double& xb_out,double& yb_out,int nx = 32,int ny = 32)
172  {
173  xa_out = HUGE_VAL;
174  ya_out = HUGE_VAL;
175  xb_out = -HUGE_VAL;
176  yb_out = -HUGE_VAL;
177  double dx_in = xb_in - xa_in,dy_in = yb_in - ya_in;
178 // Avoid double evaluation at the corners.
179  for(int ix = 0;ix < nx;++ix)
180  {
181  double xa = xa_in + dx_in * double(ix ) / nx;
182  double xb = xa_in + dx_in * double(ix + 1) / nx;
183  accumulate_distort(xa,ya_in,xa_out,ya_out,xb_out,yb_out);
184  accumulate_distort(xb,yb_in,xa_out,ya_out,xb_out,yb_out);
185  }
186  for(int iy = 0;iy < ny;++iy)
187  {
188  double ya = ya_in + dy_in * double(iy + 1) / ny;
189  double yb = ya_in + dy_in * double(iy ) / ny;
190  accumulate_distort(xa_in,ya,xa_out,ya_out,xb_out,yb_out);
191  accumulate_distort(xb_in,yb,xa_out,ya_out,xb_out,yb_out);
192  }
193  }
194 private:
195 // Methods we need in the bounding box methods.
196  void accumulate_undistort(double x0,double y0,double& xa_out,double& ya_out,double& xb_out,double& yb_out)
197  {
198  double x1,y1;
199  undistort(x0,y0,x1,y1);
200  xa_out = std::min(xa_out,x1);
201  ya_out = std::min(ya_out,y1);
202  xb_out = std::max(xb_out,x1);
203  yb_out = std::max(yb_out,y1);
204  }
205  void accumulate_distort(double x0,double y0,double& xa_out,double& ya_out,double& xb_out,double& yb_out)
206  {
207  double x1,y1;
208  distort(x0,y0,x1,y1);
209  xa_out = std::min(xa_out,x1);
210  ya_out = std::min(ya_out,y1);
211  xb_out = std::max(xb_out,x1);
212  yb_out = std::max(yb_out,y1);
213  }
214  };
215 
216 
217 // extern "C" style pseudo constructor & destructor...
218 typedef tde4_ld_plugin* tde4ldp_create_fct_t();
219 typedef void tde4ldp_destroy_fct_t(tde4_ld_plugin*);
220 
virtual bool undistort(double x0, double y0, double &x1, double &y1)=0
warp/unwarp 2D points...
virtual bool getParameterDefaultValue(const char *identifier, double &v)=0
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
virtual bool initializeParameters()=0
prepare the current set of parameters...
virtual bool getParameterRange(const char *identifier, double &a, double &b)=0
returns range for adjustable double parameters...
virtual bool getModelName(char *model)=0
returns a name for the model as to show up in the GUI (maximum length of "name": 100 bytes)...
virtual bool getTwistVector(double x0, double y0, double &t0, double &t1)
calculate the mixed derivatives ("twist vector") of the undistort()-Method. Overwrite this...
Definition: tde4_ld_plugin.h:134
virtual void getBoundingBoxUndistort(double xa_in, double ya_in, double xb_in, double yb_in, double &xa_out, double &ya_out, double &xb_out, double &yb_out, int nx=32, int ny=32)
Iterate around the specified box, undistort the points and compute the bounding box.
Definition: tde4_ld_plugin.h:147
Lens Distortion Plugin Base Class.
Definition: tde4_ld_plugin.h:29
virtual bool providesParameterDerivatives()
parameter derivatives to be used for distortion grid controls&#39; matrix calculation routine...
Definition: tde4_ld_plugin.h:106
virtual bool getParameterName(int i, char *identifier)=0
returns "identifier" name of parameter "i" (maximum length of "identifier": 100 bytes)...
virtual bool setParameterValue(const char *identifier, double v)=0
set parameter values... parameters predefined by 3DE4: "tde4_focal_length_cm", "tde4_filmback_width_c...
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_ld_plugin.h:103
virtual bool calcParameterDerivatives(double x, double y, int num_parameters, double *dx_dy)
dx_dy is an array with 2 * num_parameters elements (x- and y- component for each of n derivatives) ...
Definition: tde4_ld_plugin.h:108
virtual void getBoundingBoxDistort(double xa_in, double ya_in, double xb_in, double yb_in, double &xa_out, double &ya_out, double &xb_out, double &yb_out, int nx=32, int ny=32)
Iterate around the specified box, distort the points and compute the bounding box.
Definition: tde4_ld_plugin.h:171
virtual 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_ld_plugin.h:128
bool getJacobianMatrixDQ(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
calculate the Jacobian matrix of the undistort()-Method by means of difference quotients. This is the default implementation. Also use it for testing your own implementation of getJacobianMatrix().
Definition: tde4_ld_plugin.h:112
virtual bool getParameterType(const char *identifier, tde4_ldp_ptype &type)=0
returns type of given parameter... The method should return false, if the parameter addressed by iden...
virtual bool getNumParameters(int &n)=0
returns the number of plugin parameters...