File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
MarciDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <cmath>
10 
11 #include "IString.h"
12 #include "MarciDistortionMap.h"
13 
14 namespace Isis {
28  QString odkkey = "INS" + toString(naifIkCode) + "_DISTORTION_COEFFS";
29 
30  for(int i = 0; i < 4; i++) {
31  p_odk.push_back(p_camera->getDouble(odkkey, i));
32  }
33  }
34 
46  bool MarciDistortionMap::SetFocalPlane(const double dx, const double dy) {
47  p_focalPlaneX = dx;
48  p_focalPlaneY = dy;
49 
50  double dxPix = p_focalPlaneX / p_camera->PixelPitch();
51  double dyPix = p_focalPlaneY / p_camera->PixelPitch();
52 
53  // Get the distance from the focal plane center and if we are close
54  // then skip the distortion
55  double radialDist2 = (dxPix * dxPix) + (dyPix * dyPix);
56 
57  if(radialDist2 <= 1.0E-3) {
60  return true;
61  }
62 
63  // Ok we need to apply distortion correction
64  double radialDist4 = radialDist2 * radialDist2;
65  double radialDist6 = radialDist4 * radialDist2;
66 
67  double uRadialDist = p_odk[0] + radialDist2 * p_odk[1] +
68  radialDist4 * p_odk[2] +
69  radialDist6 * p_odk[3];
70 
71  // double radialDist = sqrt(radialDist2);
72  double uxPix = dxPix * uRadialDist;
73  double uyPix = dyPix * uRadialDist;
74 
75 
78 
79  return true;
80  }
81 
95  const double uy) {
98 
99  double uxPix = ux / p_camera->PixelPitch();
100  double uyPix = uy / p_camera->PixelPitch();
101 
102  double dxPix = GuessDx(uxPix);
103  double dyPix = uyPix;
104 
105  // Get the distance from the focal plane center and if we are close
106  // then skip the distortion
107  double Ru = sqrt((uxPix * uxPix) + (uyPix * uyPix));
108 
109  if(Ru <= 1.0E-6) {
110  p_focalPlaneX = ux;
111  p_focalPlaneY = uy;
112  return true;
113  }
114 
115  double delta = 1.0;
116  int iter = 0;
117 
118  double Rd = sqrt((dxPix * dxPix) + (dyPix * dyPix));
119 
120  while(fabs(delta) > 1E-9) {
121  if(fabs(delta) > 1E30 || iter > 50) {
122  return false;
123  }
124 
125  double Rd2 = Rd * Rd;
126  double Rd3 = Rd2 * Rd;
127  double Rd4 = Rd3 * Rd;
128  double Rd5 = Rd4 * Rd;
129  double Rd6 = Rd5 * Rd;
130 
131  double fRd = p_odk[0] + Rd2 * p_odk[1] +
132  Rd4 * p_odk[2] +
133  Rd6 * p_odk[3] - Ru * (1.0 / Rd);
134 
135  double fRd2 = 2 * p_odk[1] * Rd +
136  4 * p_odk[2] * Rd3 +
137  6 * p_odk[3] * Rd5 +
138  Ru * (1.0 / Rd2);
139 
140  delta = fRd / fRd2;
141 
142  Rd = Rd - delta;
143 
144  iter ++;
145  }
146 
147  dxPix = uxPix * (Rd / Ru);
148  dyPix = uyPix * (Rd / Ru);
149 
150  p_focalPlaneX = dxPix * p_camera->PixelPitch();
151  p_focalPlaneY = dyPix * p_camera->PixelPitch();
152 
153  return true;
154  }
155 
156  double MarciDistortionMap::GuessDx(double uX) {
157  // We're using natural log fits, but if uX < 1 the fit doesnt work
158  if(fabs(uX) < 1) return uX;
159 
160  if(p_filter == 0) { // BLUE FILTER
161  return (1.4101 * log(fabs(uX)));
162  }
163 
164  else if(p_filter == 1) { // GREEN FILTER
165  return (1.1039 * log(fabs(uX)));
166  }
167 
168  else if(p_filter == 2) { // ORANGE FILTER
169  return (0.8963 * log(fabs(uX)) + 2.1644);
170  }
171 
172  else if(p_filter == 3) { // RED FILTER
173  return (1.1039 * log(fabs(uX)));
174  }
175 
176  else if(p_filter == 4) { // NIR FILTER
177  return (1.4101 * log(fabs(uX)));
178  }
179 
180  return uX;
181  }
182 }
Isis::MarciDistortionMap::SetUndistortedFocalPlane
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
Definition: MarciDistortionMap.cpp:94
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::CameraDistortionMap::p_undistortedFocalPlaneX
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Definition: CameraDistortionMap.h:67
Isis::Camera
Definition: Camera.h:236
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::MarciDistortionMap::MarciDistortionMap
MarciDistortionMap(Camera *parent, int naifIkCode)
Camera distortion map constructor.
Definition: MarciDistortionMap.cpp:27
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::MarciDistortionMap::SetFocalPlane
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
Definition: MarciDistortionMap.cpp:46
Isis::Camera::PixelPitch
double PixelPitch() const
Returns the pixel pitch.
Definition: Camera.cpp:2742
Isis::E
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:39
Isis::Spice::getDouble
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition: Spice.cpp:1039
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

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:49