Isis 3 Programmer Reference
KaguyaTcCameraDistortionMap.cpp
Go to the documentation of this file.
1 
24 #include <QDebug>
25 #include <QtGlobal>
26 #include <QtMath>
27 
29 
30 namespace Isis {
46  : CameraDistortionMap(parent) {
47  QString odtxkey = "INS" + toString(naifIkCode) + "_DISTORTION_COEF_X";
48  QString odtykey = "INS" + toString(naifIkCode) + "_DISTORTION_COEF_Y";
49 
50  for(int i = 0; i < 4; ++i) {
51  p_odkx.push_back(p_camera->getDouble(odtxkey, i));
52  p_odky.push_back(p_camera->getDouble(odtykey, i));
53  }
54  }
55 
56 
57 
62  }
63 
64 
100  bool KaguyaTcCameraDistortionMap::SetFocalPlane(double dx, double dy) {
101  p_focalPlaneX = dx;
102  p_focalPlaneY = dy;
103 
104  double x = dx;
105  double y = dy;
106 
107  double r2 = x*x + y*y;
108  double r = qSqrt(r2);
109  double r3 = r2 * r;
110 
111  // Apply distortion correction
112  double dr_x = p_odkx[0] + p_odkx[1] * r + p_odkx[2] * r2 + p_odkx[3] * r3;
113  double dr_y = p_odky[0] + p_odky[1] * r + p_odky[2] * r2 + p_odky[3] * r3;
114 
115  p_undistortedFocalPlaneX = x + dr_x;
116  p_undistortedFocalPlaneY = y + dr_y;
117 
118  return true;
119  }
120 
121 
142  const double uy) {
143 
146 
147  double xt = ux;
148  double yt = uy;
149 
150  double xx, yy, r, rr, rrr, dr_x, dr_y;
151  double xdistortion, ydistortion;
152  double xdistorted, ydistorted;
153  double xprevious, yprevious;
154 
155  xprevious = 1000000.0;
156  yprevious = 1000000.0;
157 
158  double tolerance = 0.000001;
159  bool bConverged = false;
160 
161  // Iterating to introduce distortion...
162  // We stop when the difference between distorted coordinates
163  // in successive iterations is below the given tolerance
164  for (int i = 0; i < 50; i++) {
165  xx = xt * xt;
166  yy = yt * yt;
167  rr = xx + yy;
168  r = qSqrt(rr);
169  rrr = rr * r;
170 
171  // Radial distortion
172  // dr is the radial distortion contribution
173  dr_x = p_odkx[0] + p_odkx[1] * r + p_odkx[2] * rr + p_odkx[3] * rrr; // why did hayabusa have a -1
174  dr_y = p_odky[0] + p_odky[1] * r + p_odky[2] * rr + p_odky[3] * rrr; // why did hayabusa have a -1
175 
176  // Distortion at the current point location
177  xdistortion = dr_x;
178  ydistortion = dr_y;
179 
180  // updated image coordinates
181  xt = ux - xdistortion;
182  yt = uy - ydistortion;
183 
184  // distorted point corrected for principal point
185  xdistorted = xt;
186  ydistorted = yt;
187 
188  // check for convergence
189  if ((fabs(xt - xprevious) < tolerance) && (fabs(yt - yprevious) < tolerance)) {
190  bConverged = true;
191  break;
192  }
193 
194  xprevious = xt;
195  yprevious = yt;
196  }
197 
198  if (bConverged) {
199  p_focalPlaneX = xdistorted;
200  p_focalPlaneY = ydistorted;
201  }
202 
203  return bConverged;
204  }
205 }
206 
double p_focalPlaneX
Distorted focal plane x.
std::vector< double > p_odkx
distortion x coefficients
KaguyaTcCameraDistortionMap(Camera *parent, int naifIkCode)
Kaguya TC Camera distortion map constructor.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Camera * p_camera
The camera to distort/undistort.
Distort/undistort focal plane coordinates.
double p_focalPlaneY
Distorted focal plane y.
std::vector< double > p_odky
distortion y coefficients
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition: Spice.cpp:963