Isis 3 Programmer Reference
OsirisRexDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <QDebug>
10 #include <QtGlobal>
11 #include <QtMath>
12 
13 #include "NaifStatus.h"
14 #include "OsirisRexDistortionMap.h"
15 #include "CameraFocalPlaneMap.h"
16 
17 namespace Isis {
34  : CameraDistortionMap(parent, zDirection) {
35 
39  }
40 
41 
46  }
47 
48 
71  void OsirisRexDistortionMap::SetDistortion(int naifIkCode, QString filter="UNKNOWN") {
72  // Load distortion coefficients, including filter if we have it.
73  QString odkkey;
74 
75  if (filter.toUpper().compare("UNKNOWN") == 0) {
76  odkkey = "INS" + toString(naifIkCode) + "_OD_K";
77  }
78  else {
79  odkkey = "INS" + toString(naifIkCode) + "_OD_K_" + filter.trimmed().toUpper();
80  }
81 
82  try {
83  for (int i = 0; i < 5; ++i) {
84  p_odk.push_back(p_camera->Spice::getDouble(odkkey, i));
85  }
86  }
87  catch (IException &e) {
88  // This means that this is an older image without a filter provided
89  // don't update p_odk, we will not apply the distortion in this case
92  return;
93  }
94 
95  // Load center-of-distortion coordinates, including filter if we have it
96  QString odcenterkey;
97  if (filter.toUpper().compare("UNKNOWN") == 0) {
98  odcenterkey = "INS" + toString(naifIkCode) + "_OD_CENTER";
99  }
100  else {
101  odcenterkey = "INS" + toString(naifIkCode) + "_OD_CENTER_" + filter.trimmed().toUpper();
102  }
103  m_distortionOriginSample = p_camera->Spice::getDouble(odcenterkey, 0);
104  m_distortionOriginLine = p_camera->Spice::getDouble(odcenterkey, 1);
105  }
106 
107 
120  bool OsirisRexDistortionMap::SetFocalPlane(double dx, double dy) {
121  p_focalPlaneX = dx;
122  p_focalPlaneY = dy;
123 
124  // Only apply the distortion if we have the correct number of coefficients
125  if (p_odk.size() < 2) {
128  return true;
129  }
130 
133 
134  double xt = dx;
135  double yt = dy;
136 
137  double xx, yy, r, rr, rrr, rrrr;
138  double xdistortion, ydistortion;
139  double xdistorted, ydistorted;
140  double xprevious, yprevious;
141  double drOverR;
142 
143  xprevious = 1000000.0;
144  yprevious = 1000000.0;
145 
146  double tolerance = 0.000001;
147 
148  bool bConverged = false;
149 
150  // Iterating to introduce distortion...
151  // We stop when the difference between distorted coordinates
152  // in successive iterations is at or below the given tolerance.
153  for(int i = 0; i < 50; i++) {
154  xx = (xt-x0) * (xt-x0);
155  yy = (yt-y0) * (yt-y0);
156  rr = xx + yy;
157  r = qSqrt(rr);
158  rrr = rr * r;
159  rrrr = rr * rr;
160 
161  drOverR = p_odk[0] + p_odk[1]*r + p_odk[2]*rr + p_odk[3]*rrr + p_odk[4]*rrrr;
162 
163  // distortion at the current point location
164  xdistortion = drOverR * (xt-x0);
165  ydistortion = drOverR * (yt-y0);
166 
167  // updated image coordinates
168  xt = dx - xdistortion;
169  yt = dy - ydistortion;
170 
171  xdistorted = xt;
172  ydistorted = yt;
173 
174  // check for convergence
175  if((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
176  bConverged = true;
177  break;
178  }
179 
180  xprevious = xt;
181  yprevious = yt;
182  }
183 
184  if(bConverged) {
185  p_undistortedFocalPlaneX = xdistorted;
186  p_undistortedFocalPlaneY = ydistorted;
187  }
188  return bConverged;
189  }
190 
191 
207  const double uy) {
210 
211  // Only apply the distortion if we have the correct number of coefficients.
212  if (p_odk.size() < 2) {
213  p_focalPlaneX = ux;
214  p_focalPlaneY = uy;
215  return true;
216  }
219 
220  // Compute the distance from the focal plane center. If we are
221  // close to the center then no distortion is required
222  double x = ux;
223  double y = uy;
224  double r = qSqrt(((x-x0) * (x-x0)) + ((y - y0) * (y-y0)));
225 
226  if (r <= 1.0E-6) {
227  p_focalPlaneX = ux;
228  p_focalPlaneY = uy;
229  return true;
230  }
231 
232  double r2 = r*r;
233  double r3 = r2*r;
234  double r4 = r2*r2;
235 
236  double drOverR = p_odk[0] + p_odk[1]*r + p_odk[2]*r2 + p_odk[3]*r3 + p_odk[4]*r4;
237 
238  p_focalPlaneX = x + drOverR * (x-x0);
239  p_focalPlaneY = y + drOverR * (y-y0);
240  return true;
241  }
242 }
Isis::OsirisRexDistortionMap::m_distortionOriginLine
double m_distortionOriginLine
The distortion's origin line coordinate.
Definition: OsirisRexDistortionMap.h:47
Isis::CameraDistortionMap::p_focalPlaneX
double p_focalPlaneX
Distorted focal plane x.
Definition: CameraDistortionMap.h:65
Isis::OsirisRexDistortionMap::SetDistortion
virtual void SetDistortion(int naifIkCode, QString filterName)
Load distortion coefficients and center-of-distortion for OCAMS.
Definition: OsirisRexDistortionMap.cpp:71
Isis::CameraDistortionMap::p_undistortedFocalPlaneY
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Definition: CameraDistortionMap.h:68
Isis::CameraDistortionMap::p_undistortedFocalPlaneX
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Definition: CameraDistortionMap.h:67
Isis::OsirisRexDistortionMap::m_detectorOriginSample
double m_detectorOriginSample
The origin of the detector's sample coordinate.
Definition: OsirisRexDistortionMap.h:44
Isis::OsirisRexDistortionMap::m_detectorOriginLine
double m_detectorOriginLine
The origin of the detector's line coordinate.
Definition: OsirisRexDistortionMap.h:45
Isis::Camera
Definition: Camera.h:236
Isis::CameraFocalPlaneMap::DetectorSampleOrigin
double DetectorSampleOrigin() const
Definition: CameraFocalPlaneMap.cpp:310
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::CameraFocalPlaneMap::DetectorLineOrigin
double DetectorLineOrigin() const
Definition: CameraFocalPlaneMap.cpp:302
Isis::OsirisRexDistortionMap::m_distortionOriginSample
double m_distortionOriginSample
The distortion's origin sample coordinate.
Definition: OsirisRexDistortionMap.h:46
Isis::CameraDistortionMap::p_camera
Camera * p_camera
The camera to distort/undistort.
Definition: CameraDistortionMap.h:63
Isis::CameraDistortionMap
Distort/undistort focal plane coordinates.
Definition: CameraDistortionMap.h:41
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Camera::FocalPlaneMap
CameraFocalPlaneMap * FocalPlaneMap()
Returns a pointer to the CameraFocalPlaneMap object.
Definition: Camera.cpp:2836
Isis::Camera::PixelPitch
double PixelPitch() const
Returns the pixel pitch.
Definition: Camera.cpp:2742
Isis::OsirisRexDistortionMap::~OsirisRexDistortionMap
virtual ~OsirisRexDistortionMap()
Default Destructor.
Definition: OsirisRexDistortionMap.cpp:45
Isis::E
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:39
Isis::OsirisRexDistortionMap::m_pixelPitch
double m_pixelPitch
The pixel pitch for OCAMS.
Definition: OsirisRexDistortionMap.h:43
Isis::OsirisRexDistortionMap::OsirisRexDistortionMap
OsirisRexDistortionMap(Camera *parent, double zDirection=1.0)
OSIRIS REx Camera distortion map constructor.
Definition: OsirisRexDistortionMap.cpp:33
Isis::CameraDistortionMap::p_odk
std::vector< double > p_odk
Vector of distortion coefficients.
Definition: CameraDistortionMap.h:71
Isis::OsirisRexDistortionMap::SetUndistortedFocalPlane
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
Definition: OsirisRexDistortionMap.cpp:206
Isis::OsirisRexDistortionMap::SetFocalPlane
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
Definition: OsirisRexDistortionMap.cpp:120
Isis::CameraDistortionMap::p_focalPlaneY
double p_focalPlaneY
Distorted focal plane y.
Definition: CameraDistortionMap.h:66
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16