Isis 3 Programmer Reference
CameraDistortionMap.cpp
Go to the documentation of this file.
1 
23 #include "IString.h"
24 #include "CameraDistortionMap.h"
25 
26 namespace Isis {
40  CameraDistortionMap::CameraDistortionMap(Camera *parent, double zDirection) {
41  p_camera = parent;
43  p_zDirection = zDirection;
44  }
45 
46 
51  }
52 
53 
74  void CameraDistortionMap::SetDistortion(int naifIkCode) {
75  QString odkkey = "INS" + toString(naifIkCode) + "_OD_K";
76  for (int i = 0; i < 3; ++i) {
77  p_odk.push_back(p_camera->Spice::getDouble(odkkey, i));
78  }
79  }
80 
81 
99  bool CameraDistortionMap::SetFocalPlane(double dx, double dy) {
100  p_focalPlaneX = dx;
101  p_focalPlaneY = dy;
102 
103  // No coefficients == no distortion
104  if (p_odk.size() <= 0) {
107  return true;
108  }
109 
110  // Get the distance from the focal plane center and if we are close
111  // then skip the distortion
112  double r2 = (dx * dx) + (dy * dy);
113  if (r2 <= 1.0E-6) {
116  return true;
117  }
118 
119  // Ok we need to apply distortion correction
120  double drOverR = p_odk[0] + (r2 * (p_odk[1] + (r2 * p_odk[2])));
121  p_undistortedFocalPlaneX = dx - (drOverR * dx);
122  p_undistortedFocalPlaneY = dy - (drOverR * dy);
123  return true;
124  }
125 
126 
147  const double uy) {
150 
151  // No coefficients == nodistortion
152  if (p_odk.size() <= 0) {
153  p_focalPlaneX = ux;
154  p_focalPlaneY = uy;
155  return true;
156  }
157 
158  // Compute the distance from the focal plane center and if we are
159  // close to the center then no distortion is required
160  double rp2 = (ux * ux) + (uy * uy);
161  if (rp2 <= 1.0E-6) {
162  p_focalPlaneX = ux;
163  p_focalPlaneY = uy;
164  return true;
165  }
166 
167  // Ok make the correction, start by computing
168  // fractional distortion at rp (r-prime)
169  double rp = sqrt(rp2);
170  double drOverR = p_odk[0] + (rp2 * (p_odk[1] + (rp2 * p_odk[2])));
171 
172  // Estimate r
173  double r = rp + (drOverR * rp);
174  double r_prev, r2_prev;
175  double tolMilliMeters = p_camera->PixelPitch() / 100.0;
176  int iteration = 0;
177  do {
178  // Don't get in an end-less loop. This algorithm should
179  // converge quickly. If not then we are probably way outside
180  // of the focal plane. Just set the distorted position to the
181  // undistorted position. Also, make sure the focal plane is less
182  // than 1km, it is unreasonable for it to grow larger than that.
183  if (iteration >= 15 || r > 1E9) {
184  drOverR = 0.0;
185  break;
186  }
187 
188  r_prev = r;
189  r2_prev = r * r;
190 
191  // Compute new fractional distortion:
192  drOverR = p_odk[0] + (r2_prev * (p_odk[1] + (r2_prev * p_odk[2])));
193 
194  r = rp + (drOverR * r_prev); // Compute new estimate of r
195  iteration++;
196  }
197  while (fabs(r - r_prev) > tolMilliMeters);
198 
199  p_focalPlaneX = ux / (1.0 - drOverR);
200  p_focalPlaneY = uy / (1.0 - drOverR);
201  return true;
202  }
203 
204 
211  return p_odk;
212  }
213 
214 
221  return p_zDirection;
222  }
223 
224 
232  return p_focalPlaneX;
233  }
234 
235 
243  return p_focalPlaneY;
244  }
245 
246 
255  }
256 
257 
266  }
267 
268 
277  return p_zDirection *p_camera->FocalLength();
278  }
279 
280 }
281 
double p_focalPlaneX
Distorted focal plane x.
double UndistortedFocalPlaneZ() const
Gets the z-value in the undistorted focal plane coordinate system.
double ZDirection() const
Gets the z-direction for this camera.
CameraDistortionMap(Camera *parent, double zDirection=1.0)
Camera distortion map constructor.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
virtual void SetDistortion(int naifIkCode)
Load distortion coefficients.
std::vector< double > OpticalDistortionCoefficients() const
Retrieve the distortion coefficients used for this model.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Camera * p_camera
The camera to distort/undistort.
double FocalPlaneY() const
Gets the y-value in the focal plane coordinate system.
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
double FocalLength() const
Returns the focal length.
Definition: Camera.cpp:2744
double PixelPitch() const
Returns the pixel pitch.
Definition: Camera.cpp:2754
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:55
virtual ~CameraDistortionMap()
Destructor for the ISIS3 default camera distortion map.
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
void SetDistortionMap(CameraDistortionMap *map, bool deleteExisting=true)
Sets the Distortion Map.
Definition: Camera.cpp:2354
double p_zDirection
Undistorted focal plane z.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
std::vector< double > p_odk
Vector of distortion coefficients.
double UndistortedFocalPlaneY() const
Gets the y-value in the undistorted focal plane coordinate system.
double UndistortedFocalPlaneX() const
Gets the x-value in the undistorted focal plane coordinate system.
double FocalPlaneX() const
Gets the x-value in the focal plane coordinate system.