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
14namespace 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}
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
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
MarciDistortionMap(Camera *parent, int naifIkCode)
Camera distortion map constructor.
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition Spice.cpp:1046
const double E
Sets some basic constants for use in ISIS programming.
Definition Constants.h:39
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