Isis 3 Programmer Reference
JunoDistortionMap.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "IString.h"
10#include "JunoDistortionMap.h"
11
12namespace Isis {
28
29
35
36
64 void JunoDistortionMap::SetDistortion(int naifIkCode) {
65
66 // Use the pixel pitch to scale k1 and k2 coefficients to operate in focal
67 // plane coordinates (millimeters). The coefficients found in the kernels
68 // are based on detector coordinates (pixels).
69
70 double pp = p_camera->PixelPitch();
71 double p2 = pp * pp;
72
73 // Currently k0 is non-existant in kernels (i.e equals zero). The try is
74 // here in case this coefficient is needed for future distortion models.
75 try {
76 QString odk0 = "INS" + toString(naifIkCode) + "_DISTORTION_K0";
77 p_odk.push_back(p_camera->Spice::getDouble(odk0));
78
79 }
80 catch (IException &e) {
81 p_odk.push_back(0.0);
82 }
83
84 QString odk1 = "INS" + toString(naifIkCode) + "_DISTORTION_K1";
85 p_odk.push_back(p_camera->Spice::getDouble(odk1) / p2);
86 QString odk2 = "INS" + toString(naifIkCode) + "_DISTORTION_K2";
87 p_odk.push_back(p_camera->Spice::getDouble(odk2) / (p2 * p2));
88 }
89
90
110 const double uy) {
111
114
115 // Compute the distance from the focal plane center and if we are
116 // close to the center then assume no distortion
117 double r2 = (ux * ux) + (uy * uy);
118 if (r2 <= 1.0E-6) {
119 p_focalPlaneX = ux;
120 p_focalPlaneY = uy;
121 return true;
122 }
123
124 // The equation given in the IK computes the undistorted focal plane
125 // ux = dx * (1 + k1*r^2), r^2 = dx^2 + dy^2
126 double dr = 1 + p_odk[0] + p_odk[1]*r2 + p_odk[2]*r2*r2;
127 p_focalPlaneX = ux * dr;
128 p_focalPlaneY = uy * dr;
129
130 return true;
131
132 }
133
134
153 double dy) {
154 p_focalPlaneX = dx;
155 p_focalPlaneY = dy;
156
157 // Get the distance from the focal plane center and if we are close
158 // then skip the distortion
159 double r2 = (dx * dx) + (dy * dy);
160 if (r2 <= 1.0E-6) {
163 return true;
164 }
165
166 bool converged = false;
167 int i = 0;
168 int maximumIterations = 15;
169 double tolerance = p_camera->PixelPitch() / 100.0;
170 double uxEstimate = dx;
171 double uyEstimate = dy;
172 double uxPrev = dx;
173 double uyPrev = dy;
174 double xDistortion = 0.0;
175 double yDistortion = 0.0;
176 double dr = 0.0;
177 while (!converged) {
178 dr = p_odk[0] + p_odk[1]*r2 + p_odk[2]*r2*r2;
179 xDistortion = uxEstimate * dr;
180 yDistortion = uyEstimate * dr;
181 uxEstimate = dx - xDistortion;
182 uyEstimate = dy - yDistortion;
183 i++;
184 if (fabs(uxEstimate - uxPrev) < tolerance &&
185 fabs(uyEstimate - uyPrev) < tolerance ) {
186 converged = true;
187 }
188 // If doesn't converge, don't do correction
189 if (i > maximumIterations) {
192 break;
193 }
194 r2 = (uxEstimate * uxEstimate) + (uyEstimate * uyEstimate);
195 uxPrev = uxEstimate;
196 uyPrev = uyEstimate;
197 }
198 p_undistortedFocalPlaneX = uxEstimate;
199 p_undistortedFocalPlaneY = uyEstimate;
200 return true;
201 }
202
203}
Distort/undistort focal plane coordinates.
double p_focalPlaneX
Distorted focal plane x.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
std::vector< double > p_odk
Vector of distortion coefficients.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Camera * p_camera
The camera to distort/undistort.
double p_focalPlaneY
Distorted focal plane y.
double PixelPitch() const
Returns the pixel pitch.
Definition Camera.cpp:2772
Isis exception class.
Definition IException.h:91
virtual void SetDistortion(int naifIkCode)
Load distortion coefficients for JunoCam.
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
virtual ~JunoDistortionMap()
Destructor.
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
JunoDistortionMap(Camera *parent)
Juno JunoCam distortion map constructor.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211