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 { TDE4_LDP_STRING=0, TDE4_LDP_DOUBLE=1, TDE4_LDP_INT=2, TDE4_LDP_FILE=3, TDE4_LDP_TOGGLE=4, TDE4_LDP_ADJUSTABLE_DOUBLE=5 };
19 
22 {
23 public:
24 
25  virtual ~tde4_ld_plugin() {}
26 
27  const char* getVersionString() const
28  { return TDE4_LDP_VERSION; }
29 
31  virtual bool getModelName(char *model) = 0;
32 
34  virtual bool getNumParameters(int &n) = 0;
35 
37  virtual bool getParameterName(int i, char *identifier) = 0;
38 
41  virtual bool getParameterType(const char *identifier, tde4_ldp_ptype &type) = 0;
42 
44  virtual bool getParameterDefaultValue(const char *identifier, double &v) = 0;
45  virtual bool getParameterDefaultValue(const char *identifier, char *v)
46  {
47  std::cerr << "getParameterDefaultValue(" << identifier << ",char*): unimplemented method." << std::endl;
48  v[0] = 0;
49  return false;
50  }
51  virtual bool getParameterDefaultValue(const char *identifier, int &v)
52  {
53  std::cerr << "getParameterDefaultValue(" << identifier << ",int&): unimplemented method." << std::endl;
54  v = 0;
55  return false;
56  }
57  virtual bool getParameterDefaultValue(const char *identifier, bool &v)
58  {
59  std::cerr << "getParameterDefaultValue(" << identifier << ",bool&): unimplemented method." << std::endl;
60  v = false;
61  return false;
62  }
63 
65  virtual bool getParameterRange(const char *identifier, double &a, double &b) = 0;
66 
70  virtual bool setParameterValue(const char *identifier, double v) = 0;
71  virtual bool setParameterValue(const char *identifier, const char *v)
72  {
73  std::cerr << "setParameterValue(" << identifier << ",const char* " << v << "): unimplemented method." << std::endl;
74  return false;
75  }
76  virtual bool setParameterValue(const char *identifier, int v)
77  {
78  std::cerr << "setParameterValue(" << identifier << ",int " << v << "): unimplemented method." << std::endl;
79  return false;
80  }
81  virtual bool setParameterValue(const char *identifier, bool v)
82  {
83  std::cerr << "setParameterValue(" << identifier << ",bool " << v << "): unimplemented method." << std::endl;
84  return false;
85  }
86 
88  virtual bool initializeParameters() = 0;
89 
91  virtual bool undistort(double x0, double y0, double &x1, double &y1) = 0;
92  virtual bool distort(double x0, double y0, double &x1, double &y1) = 0;
93 
95  virtual bool distort(double x0, double y0, double x1_start , double y1_start, double &x1, double &y1) { return distort(x0,y0,x1,y1); }
96 
98  virtual bool providesParameterDerivatives() { return false; }
100  virtual bool calcParameterDerivatives(double x, double y, int num_parameters, double *dx_dy) { return false; }
101 
104  bool getJacobianMatrixDQ(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
105  {
106  bool ok = true;
107  double eps = 1e-4,x00,x10,x01,x11,y00,y10,y01,y11;
108  ok &= undistort(x0 - eps,y0,x00,y00);
109  ok &= undistort(x0 + eps,y0,x01,y01);
110  ok &= undistort(x0,y0 - eps,x10,y10);
111  ok &= undistort(x0,y0 + eps,x11,y11);
112  m00 = (x01 - x00) / (2.0 * eps);
113  m01 = (x11 - x10) / (2.0 * eps);
114  m10 = (y01 - y00) / (2.0 * eps);
115  m11 = (y11 - y10) / (2.0 * eps);
116  return ok;
117  }
120  virtual bool getJacobianMatrix(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
121  {
122  return getJacobianMatrixDQ(x0,y0,m00,m01,m10,m11);
123  }
126  virtual bool getTwistVector(double x0, double y0, double &t0, double &t1)
127  {
128  bool ok = true;
129  double eps = 1e-4,x00,x10,x01,x11,y00,y10,y01,y11;
130  ok &= undistort(x0 - eps,y0 - eps,x00,y00);
131  ok &= undistort(x0 + eps,y0 - eps,x10,y10);
132  ok &= undistort(x0 - eps,y0 + eps,x01,y01);
133  ok &= undistort(x0 + eps,y0 + eps,x11,y11);
134  t0 = (x11 - x01 - x10 + x00) / (4.0 * eps * eps);
135  t1 = (y11 - y01 - y10 + y00) / (4.0 * eps * eps);
136  return ok;
137  }
139  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)
140  {
141  xa_out = HUGE_VAL;
142  ya_out = HUGE_VAL;
143  xb_out = -HUGE_VAL;
144  yb_out = -HUGE_VAL;
145  double dx_in = xb_in - xa_in,dy_in = yb_in - ya_in;
146 // Avoid double evaluation at the corners.
147  for(int ix = 0;ix < nx;++ix)
148  {
149  double xa = xa_in + dx_in * double(ix ) / nx;
150  double xb = xa_in + dx_in * double(ix + 1) / nx;
151  accumulate_undistort(xa,ya_in,xa_out,ya_out,xb_out,yb_out);
152  accumulate_undistort(xb,yb_in,xa_out,ya_out,xb_out,yb_out);
153  }
154  for(int iy = 0;iy < ny;++iy)
155  {
156  double ya = ya_in + dy_in * double(iy + 1) / ny;
157  double yb = ya_in + dy_in * double(iy ) / ny;
158  accumulate_undistort(xa_in,ya,xa_out,ya_out,xb_out,yb_out);
159  accumulate_undistort(xb_in,yb,xa_out,ya_out,xb_out,yb_out);
160  }
161  }
163  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)
164  {
165  xa_out = HUGE_VAL;
166  ya_out = HUGE_VAL;
167  xb_out = -HUGE_VAL;
168  yb_out = -HUGE_VAL;
169  double dx_in = xb_in - xa_in,dy_in = yb_in - ya_in;
170 // Avoid double evaluation at the corners.
171  for(int ix = 0;ix < nx;++ix)
172  {
173  double xa = xa_in + dx_in * double(ix ) / nx;
174  double xb = xa_in + dx_in * double(ix + 1) / nx;
175  accumulate_distort(xa,ya_in,xa_out,ya_out,xb_out,yb_out);
176  accumulate_distort(xb,yb_in,xa_out,ya_out,xb_out,yb_out);
177  }
178  for(int iy = 0;iy < ny;++iy)
179  {
180  double ya = ya_in + dy_in * double(iy + 1) / ny;
181  double yb = ya_in + dy_in * double(iy ) / ny;
182  accumulate_distort(xa_in,ya,xa_out,ya_out,xb_out,yb_out);
183  accumulate_distort(xb_in,yb,xa_out,ya_out,xb_out,yb_out);
184  }
185  }
186 private:
187 // Methods we need in the bounding box methods.
188  void accumulate_undistort(double x0,double y0,double& xa_out,double& ya_out,double& xb_out,double& yb_out)
189  {
190  double x1,y1;
191  undistort(x0,y0,x1,y1);
192  xa_out = std::min(xa_out,x1);
193  ya_out = std::min(ya_out,y1);
194  xb_out = std::max(xb_out,x1);
195  yb_out = std::max(yb_out,y1);
196  }
197  void accumulate_distort(double x0,double y0,double& xa_out,double& ya_out,double& xb_out,double& yb_out)
198  {
199  double x1,y1;
200  distort(x0,y0,x1,y1);
201  xa_out = std::min(xa_out,x1);
202  ya_out = std::min(ya_out,y1);
203  xb_out = std::max(xb_out,x1);
204  yb_out = std::max(yb_out,y1);
205  }
206 };
207 
208 
209 // extern "C" style pseudo constructor & destructor...
210 typedef tde4_ld_plugin* tde4ldp_create_fct_t();
211 typedef void tde4ldp_destroy_fct_t(tde4_ld_plugin*);
212 
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:126
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:139
Lens Distortion Plugin Base Class.
Definition: tde4_ld_plugin.h:21
virtual bool providesParameterDerivatives()
parameter derivatives to be used for distortion grid controls' matrix calculation routine...
Definition: tde4_ld_plugin.h:98
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:95
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:100
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:163
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:120
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:104
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...