Isis 3 Programmer Reference
OsirisRexDistortionMap.cpp
Go to the documentation of this file.
1 
24 #include <QDebug>
25 #include <QtGlobal>
26 #include <QtMath>
27 
28 #include "NaifStatus.h"
29 #include "OsirisRexDistortionMap.h"
30 #include "CameraFocalPlaneMap.h"
31 
32 namespace Isis {
49  : CameraDistortionMap(parent, zDirection) {
50 
54  }
55 
56 
61  }
62 
63 
86  void OsirisRexDistortionMap::SetDistortion(int naifIkCode, QString filter="UNKNOWN") {
87  // Load distortion coefficients, including filter if we have it.
88  QString odkkey;
89 
90  if (filter.toUpper().compare("UNKNOWN") == 0) {
91  odkkey = "INS" + toString(naifIkCode) + "_OD_K";
92  }
93  else {
94  odkkey = "INS" + toString(naifIkCode) + "_OD_K_" + filter.trimmed().toUpper();
95  }
96 
97  try {
98  for (int i = 0; i < 5; ++i) {
99  p_odk.push_back(p_camera->Spice::getDouble(odkkey, i));
100  }
101  }
102  catch (IException &e) {
103  // This means that this is an older image without a filter provided
104  // don't update p_odk, we will not apply the distortion in this case
107  return;
108  }
109 
110  // Load center-of-distortion coordinates, including filter if we have it
111  QString odcenterkey;
112  if (filter.toUpper().compare("UNKNOWN") == 0) {
113  odcenterkey = "INS" + toString(naifIkCode) + "_OD_CENTER";
114  }
115  else {
116  odcenterkey = "INS" + toString(naifIkCode) + "_OD_CENTER_" + filter.trimmed().toUpper();
117  }
118  m_distortionOriginSample = p_camera->Spice::getDouble(odcenterkey, 0);
119  m_distortionOriginLine = p_camera->Spice::getDouble(odcenterkey, 1);
120  }
121 
122 
135  bool OsirisRexDistortionMap::SetFocalPlane(double dx, double dy) {
136  p_focalPlaneX = dx;
137  p_focalPlaneY = dy;
138 
139  // Only apply the distortion if we have the correct number of coefficients
140  if (p_odk.size() < 2) {
143  return true;
144  }
145 
148 
149  double xt = dx;
150  double yt = dy;
151 
152  double xx, yy, r, rr, rrr, rrrr;
153  double xdistortion, ydistortion;
154  double xdistorted, ydistorted;
155  double xprevious, yprevious;
156  double drOverR;
157 
158  xprevious = 1000000.0;
159  yprevious = 1000000.0;
160 
161  double tolerance = 0.000001;
162 
163  bool bConverged = false;
164 
165  // Iterating to introduce distortion...
166  // We stop when the difference between distorted coordinates
167  // in successive iterations is at or below the given tolerance.
168  for(int i = 0; i < 50; i++) {
169  xx = (xt-x0) * (xt-x0);
170  yy = (yt-y0) * (yt-y0);
171  rr = xx + yy;
172  r = qSqrt(rr);
173  rrr = rr * r;
174  rrrr = rr * rr;
175 
176  drOverR = p_odk[0] + p_odk[1]*r + p_odk[2]*rr + p_odk[3]*rrr + p_odk[4]*rrrr;
177 
178  // distortion at the current point location
179  xdistortion = drOverR * (xt-x0);
180  ydistortion = drOverR * (yt-y0);
181 
182  // updated image coordinates
183  xt = dx - xdistortion;
184  yt = dy - ydistortion;
185 
186  xdistorted = xt;
187  ydistorted = yt;
188 
189  // check for convergence
190  if((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
191  bConverged = true;
192  break;
193  }
194 
195  xprevious = xt;
196  yprevious = yt;
197  }
198 
199  if(bConverged) {
200  p_undistortedFocalPlaneX = xdistorted;
201  p_undistortedFocalPlaneY = ydistorted;
202  }
203  return bConverged;
204  }
205 
206 
222  const double uy) {
225 
226  // Only apply the distortion if we have the correct number of coefficients.
227  if (p_odk.size() < 2) {
228  p_focalPlaneX = ux;
229  p_focalPlaneY = uy;
230  return true;
231  }
234 
235  // Compute the distance from the focal plane center. If we are
236  // close to the center then no distortion is required
237  double x = ux;
238  double y = uy;
239  double r = qSqrt(((x-x0) * (x-x0)) + ((y - y0) * (y-y0)));
240 
241  if (r <= 1.0E-6) {
242  p_focalPlaneX = ux;
243  p_focalPlaneY = uy;
244  return true;
245  }
246 
247  double r2 = r*r;
248  double r3 = r2*r;
249  double r4 = r2*r2;
250 
251  double drOverR = p_odk[0] + p_odk[1]*r + p_odk[2]*r2 + p_odk[3]*r3 + p_odk[4]*r4;
252 
253  p_focalPlaneX = x + drOverR * (x-x0);
254  p_focalPlaneY = y + drOverR * (y-y0);
255  return true;
256  }
257 }
258 
double p_focalPlaneX
Distorted focal plane x.
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
virtual void SetDistortion(int naifIkCode, QString filterName)
Load distortion coefficients and center-of-distortion for OCAMS.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
double m_detectorOriginSample
The origin of the detector&#39;s sample coordinate.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Camera * p_camera
The camera to distort/undistort.
double m_distortionOriginSample
The distortion&#39;s origin sample coordinate.
double m_detectorOriginLine
The origin of the detector&#39;s line coordinate.
Distort/undistort focal plane coordinates.
double PixelPitch() const
Returns the pixel pitch.
Definition: Camera.cpp:2754
virtual ~OsirisRexDistortionMap()
Default Destructor.
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:55
CameraFocalPlaneMap * FocalPlaneMap()
Returns a pointer to the CameraFocalPlaneMap object.
Definition: Camera.cpp:2848
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
OsirisRexDistortionMap(Camera *parent, double zDirection=1.0)
OSIRIS REx Camera distortion map constructor.
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.
double m_pixelPitch
The pixel pitch for OCAMS.
double m_distortionOriginLine
The distortion&#39;s origin line coordinate.