Isis 3 Programmer Reference
LoMediumDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "LoMediumDistortionMap.h"
10 
11 #include <iostream>
12 #include <iomanip>
13 
14 #include "CameraFocalPlaneMap.h"
15 #include "IString.h"
16 
17 using namespace std;
18 
19 namespace Isis {
32  LoMediumDistortionMap::LoMediumDistortionMap(Camera *parent) :
33  CameraDistortionMap(parent, -1) {
34  }
35 
36 
74  void LoMediumDistortionMap::SetDistortion(const int naifIkCode) {
75  // Get the distortion center (point of symmetry of distortion)
77  double boreS = p_camera->FocalPlaneMap()->DetectorSample();
78  double boreL = p_camera->FocalPlaneMap()->DetectorLine();
79  QString centkey = "INS" + toString(naifIkCode) + "_POINT_OF_SYMMETRY";
80  p_sample0 = boreS - p_camera->Spice::getDouble(centkey, 0);
81  p_line0 = boreL + p_camera->Spice::getDouble(centkey, 1);
82 
83  // Get the distortion coefficients
85  }
86 
87 
103  const double dy) {
104 
105  // Set sRef needed for lo medium distortion algorithm
106  double sRef = 5000.;
107 
108  // lo medium distortion algorithm is applied in the image plane so convert back to sample/line
109  p_focalPlaneX = dx;
110  p_focalPlaneY = dy;
111 
112  // Test for extraneous data. Maximum x is about 38.045 and maximum y is about 31.899.
113  // First tried adding 10% and it was sufficient to trim off extraneous data, but
114  // also prevented lat/lons from being calculated to the images edges. Increased x to
115  // 20.361224% to pick up image edges. 3171 was the test image.
116  // 17.5% to pick up image edges. 3171 was the test image.
117  if(fabs(dx) > 45.79142767 || fabs(dy) > 35.09) return false;
118 
120  double ds = p_camera->FocalPlaneMap()->DetectorSample();
121  double dl = p_camera->FocalPlaneMap()->DetectorLine();
122 
123  // Translate the focal plane x/y coordinate to be relative to the
124  // distortion point of symmetry
125  double dists = ds - p_sample0;
126  double distl = dl - p_line0;
127 
128  // Get the distance from the focal plane center and if we are close
129  // skip the distortion
130  double origr2 = dists * dists + distl * distl;
131  double sp = sqrt(origr2); // pixels
132  if(sp <= .000001) {
135  return true;
136  }
137 
138  // Otherwise remove distortion
139  // Use the distorted radial coordinate, rp (r prime), to estimate the ideal radial coordinate
140  double nS = sp / sRef;
141  double dS = p_odk[0] * nS + p_odk[1] * pow(nS, 3) + p_odk[2] * pow(nS, 5);
142  double prevdS = 2 * dS;
143  double pixtol = .000001;
144  int numit = 0;
145  double s;
146 
147  // Now use the estimate to compute the radial coordinate and get an improved estimate
148  while(fabs(dS - prevdS) > pixtol) {
149 
150  if(numit > 14 || fabs(dS) > 1E9) {
151  dS = 0.;
152  // if (numit > 14) cout<<"Too many iterations"<<endl;
153  // if (fabs(dS) > 1E9) cout<<"Diverging"<<endl;
154  break;
155  }
156 
157  prevdS = dS;
158  s = sp - dS;
159  nS = s / sRef;
160  dS = p_odk[0] * nS + p_odk[1] * pow(nS, 3) + p_odk[2] * pow(nS, 5);
161  numit++;
162  }
163 
164  s = sp - dS;
165  double ratio = s / sp;
166  double undistortedSample = dists * ratio + p_sample0;
167  double undistortedLine = distl * ratio + p_line0;
168  p_camera->FocalPlaneMap()->SetDetector(undistortedSample, undistortedLine);
171  return true;
172  }
173 
174 
194  const double uy) {
195 
198 
199  // Test for data outside of image (image bounds plus 10% for y and 20.361224% for x)
200  if(fabs(ux) > 45.79142767 || fabs(uy) > 35.09) return false;
201  if(fabs(ux) > 41.85 || fabs(uy) > 35.09) return false;
202 
203  // Set sRef needed for lo medium distortion algorithm
204  double sRef = 5000.;
205 
206  // The algorithm is applied in the image plane so convert back to sample/line
208  double us = p_camera->FocalPlaneMap()->DetectorSample();
209  double ul = p_camera->FocalPlaneMap()->DetectorLine();
210 
211  // Translate the distorted x/y coordinate to be relative to the
212  // distortion point of symmetry
213  double distus = us - p_sample0;
214  double distul = ul - p_line0;
215 
216  // Compute the distance from the focal plane center and if we are
217  // close to the center then no distortion is required
218  double rp2 = (distus * distus + distul * distul); // pixels squared
219 
220  if(rp2 < 1.0E-6) {
223  return true;
224  }
225 
226  // Add distortion. First compute fractional distortion at rp (r-prime)
227  rp2 = rp2 / sRef / sRef;
228  double drOverR = (p_odk[0] + rp2 * p_odk[1] + rp2 * rp2 * p_odk[2]) / sRef;
229 
230  // Compute the focal plane distorted s/l
231  double ds = p_sample0 + (distus * (1. + drOverR));
232  double dl = p_line0 + (distul * (1. + drOverR));
233 
234  p_camera->FocalPlaneMap()->SetDetector(ds, dl);
237  return true;
238  }
239 }
Isis::LoMediumDistortionMap::SetDistortion
void SetDistortion(const int naifIkCode)
Load LO Medium Resolution Camera perspective & distortion coefficients.
Definition: LoMediumDistortionMap.cpp:74
Isis::CameraDistortionMap::SetDistortion
virtual void SetDistortion(int naifIkCode)
Load distortion coefficients.
Definition: CameraDistortionMap.cpp:58
Isis::CameraFocalPlaneMap::FocalPlaneY
double FocalPlaneY() const
Definition: CameraFocalPlaneMap.cpp:247
Isis::LoMediumDistortionMap::SetUndistortedFocalPlane
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y for Lo Medium Resolution Camera.
Definition: LoMediumDistortionMap.cpp:193
Isis::CameraDistortionMap::p_focalPlaneX
double p_focalPlaneX
Distorted focal plane x.
Definition: CameraDistortionMap.h:65
Isis::CameraDistortionMap::p_undistortedFocalPlaneY
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Definition: CameraDistortionMap.h:68
Isis::LoMediumDistortionMap::p_line0
double p_line0
Center of distortion on line axis.
Definition: LoMediumDistortionMap.h:73
Isis::CameraDistortionMap::p_undistortedFocalPlaneX
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Definition: CameraDistortionMap.h:67
Isis::CameraFocalPlaneMap::DetectorLine
double DetectorLine() const
Definition: CameraFocalPlaneMap.cpp:263
Isis::Camera
Definition: Camera.h:236
Isis::CameraFocalPlaneMap::DetectorSample
double DetectorSample() const
Definition: CameraFocalPlaneMap.cpp:255
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::LoMediumDistortionMap::SetFocalPlane
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y for Lo Medium Resolution Camera.
Definition: LoMediumDistortionMap.cpp:102
Isis::CameraFocalPlaneMap::SetFocalPlane
virtual bool SetFocalPlane(const double dx, const double dy)
Compute detector position (sample,line) from focal plane coordinates.
Definition: CameraFocalPlaneMap.cpp:143
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::Camera::FocalPlaneMap
CameraFocalPlaneMap * FocalPlaneMap()
Returns a pointer to the CameraFocalPlaneMap object.
Definition: Camera.cpp:2836
std
Namespace for the standard library.
Isis::CameraFocalPlaneMap::FocalPlaneX
double FocalPlaneX() const
Definition: CameraFocalPlaneMap.cpp:239
Isis::CameraFocalPlaneMap::SetDetector
virtual bool SetDetector(const double sample, const double line)
Compute distorted focal plane coordinate from detector position (sampel,line)
Definition: CameraFocalPlaneMap.cpp:164
Isis::E
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:39
Isis::LoMediumDistortionMap::p_sample0
double p_sample0
Center of distortion on sample axis.
Definition: LoMediumDistortionMap.h:72
Isis::CameraDistortionMap::p_odk
std::vector< double > p_odk
Vector of distortion coefficients.
Definition: CameraDistortionMap.h:71
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