Isis 3 Programmer Reference
JunoDistortionMap.cpp
Go to the documentation of this file.
1 
23 #include "IString.h"
24 #include "JunoDistortionMap.h"
25 
26 namespace Isis {
40  : CameraDistortionMap(parent, 1.0) {
41  }
42 
43 
48  }
49 
50 
78  void JunoDistortionMap::SetDistortion(int naifIkCode) {
79 
80  // Use the pixel pitch to scale k1 and k2 coefficients to operate in focal
81  // plane coordinates (millimeters). The coefficients found in the kernels
82  // are based on detector coordinates (pixels).
83 
84  double pp = p_camera->PixelPitch();
85  double p2 = pp * pp;
86 
87  // Currently k0 is non-existant in kernels (i.e equals zero). The try is
88  // here in case this coefficient is needed for future distortion models.
89  try {
90  QString odk0 = "INS" + toString(naifIkCode) + "_DISTORTION_K0";
91  p_odk.push_back(p_camera->Spice::getDouble(odk0));
92 
93  }
94  catch (IException &e) {
95  p_odk.push_back(0.0);
96  }
97 
98  QString odk1 = "INS" + toString(naifIkCode) + "_DISTORTION_K1";
99  p_odk.push_back(p_camera->Spice::getDouble(odk1) / p2);
100  QString odk2 = "INS" + toString(naifIkCode) + "_DISTORTION_K2";
101  p_odk.push_back(p_camera->Spice::getDouble(odk2) / (p2 * p2));
102  }
103 
104 
124  const double uy) {
125 
128 
129  // Compute the distance from the focal plane center and if we are
130  // close to the center then assume no distortion
131  double r2 = (ux * ux) + (uy * uy);
132  if (r2 <= 1.0E-6) {
133  p_focalPlaneX = ux;
134  p_focalPlaneY = uy;
135  return true;
136  }
137 
138  // The equation given in the IK computes the undistorted focal plane
139  // ux = dx * (1 + k1*r^2), r^2 = dx^2 + dy^2
140  double dr = 1 + p_odk[0] + p_odk[1]*r2 + p_odk[2]*r2*r2;
141  p_focalPlaneX = ux * dr;
142  p_focalPlaneY = uy * dr;
143 
144  return true;
145 
146  }
147 
148 
167  double dy) {
168  p_focalPlaneX = dx;
169  p_focalPlaneY = dy;
170 
171  // Get the distance from the focal plane center and if we are close
172  // then skip the distortion
173  double r2 = (dx * dx) + (dy * dy);
174  if (r2 <= 1.0E-6) {
177  return true;
178  }
179 
180  bool converged = false;
181  int i = 0;
182  int maximumIterations = 15;
183  double tolerance = p_camera->PixelPitch() / 100.0;
184  double uxEstimate = dx;
185  double uyEstimate = dy;
186  double uxPrev = dx;
187  double uyPrev = dy;
188  double xDistortion = 0.0;
189  double yDistortion = 0.0;
190  double dr = 0.0;
191  while (!converged) {
192  dr = p_odk[0] + p_odk[1]*r2 + p_odk[2]*r2*r2;
193  xDistortion = uxEstimate * dr;
194  yDistortion = uyEstimate * dr;
195  uxEstimate = dx - xDistortion;
196  uyEstimate = dy - yDistortion;
197  i++;
198  if (fabs(uxEstimate - uxPrev) < tolerance &&
199  fabs(uyEstimate - uyPrev) < tolerance ) {
200  converged = true;
201  }
202  // If doesn't converge, don't do correction
203  if (i > maximumIterations) {
206  break;
207  }
208  r2 = (uxEstimate * uxEstimate) + (uyEstimate * uyEstimate);
209  uxPrev = uxEstimate;
210  uyPrev = uyEstimate;
211  }
212  p_undistortedFocalPlaneX = uxEstimate;
213  p_undistortedFocalPlaneY = uyEstimate;
214  return true;
215  }
216 
217 }
double p_focalPlaneX
Distorted focal plane x.
virtual void SetDistortion(int naifIkCode)
Load distortion coefficients for JunoCam.
virtual ~JunoDistortionMap()
Destructor.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Camera * p_camera
The camera to distort/undistort.
Distort/undistort focal plane coordinates.
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
JunoDistortionMap(Camera *parent)
Juno JunoCam distortion map constructor.
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
std::vector< double > p_odk
Vector of distortion coefficients.
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.