Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
MarciDistortionMap.cpp
1
6
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
54 double radialDist2 = (dxPix * dxPix) + (dyPix * dyPix);
55
56 // Ok we need to apply distortion correction
57 double radialDist4 = radialDist2 * radialDist2;
58 double radialDist6 = radialDist4 * radialDist2;
59
60 double uRadialDist = p_odk[0] + radialDist2 * p_odk[1] +
61 radialDist4 * p_odk[2] +
62 radialDist6 * p_odk[3];
63
64 // double radialDist = sqrt(radialDist2);
65 double uxPix = dxPix * uRadialDist;
66 double uyPix = dyPix * uRadialDist;
67
68
69 p_undistortedFocalPlaneX = uxPix * p_camera->PixelPitch();
70 p_undistortedFocalPlaneY = uyPix * p_camera->PixelPitch();
71
72 return true;
73 }
74
88 const double uy) {
91
92 double uxPix = ux / p_camera->PixelPitch();
93 double uyPix = uy / p_camera->PixelPitch();
94
95 double dxPix = GuessDx(uxPix);
96 double dyPix = uyPix;
97
98 // Get the distance from the focal plane center
99 double Ru = sqrt((uxPix * uxPix) + (uyPix * uyPix));
100
101 double delta = 1.0;
102 int iter = 0;
103
104 double Rd = sqrt((dxPix * dxPix) + (dyPix * dyPix));
105
106 while(fabs(delta) > 1E-9) {
107 if(fabs(delta) > 1E30 || iter > 50) {
108 return false;
109 }
110
111 double Rd2 = Rd * Rd;
112 double Rd3 = Rd2 * Rd;
113 double Rd4 = Rd3 * Rd;
114 double Rd5 = Rd4 * Rd;
115 double Rd6 = Rd5 * Rd;
116
117 double fRd = p_odk[0] + Rd2 * p_odk[1] +
118 Rd4 * p_odk[2] +
119 Rd6 * p_odk[3] - Ru * (1.0 / Rd);
120
121 double fRd2 = 2 * p_odk[1] * Rd +
122 4 * p_odk[2] * Rd3 +
123 6 * p_odk[3] * Rd5 +
124 Ru * (1.0 / Rd2);
125
126 delta = fRd / fRd2;
127
128 Rd = Rd - delta;
129
130 iter ++;
131 }
132
133 dxPix = uxPix * (Rd / Ru);
134 dyPix = uyPix * (Rd / Ru);
135
136 p_focalPlaneX = dxPix * p_camera->PixelPitch();
137 p_focalPlaneY = dyPix * p_camera->PixelPitch();
138
139 return true;
140 }
141
142 double MarciDistortionMap::GuessDx(double uX) {
143 // We're using natural log fits, but if uX < 1 the fit doesnt work
144 if(fabs(uX) < 1) return uX;
145
146 if(p_filter == 0) { // BLUE FILTER
147 return (1.4101 * log(fabs(uX)));
148 }
149
150 else if(p_filter == 1) { // GREEN FILTER
151 return (1.1039 * log(fabs(uX)));
152 }
153
154 else if(p_filter == 2) { // ORANGE FILTER
155 return (0.8963 * log(fabs(uX)) + 2.1644);
156 }
157
158 else if(p_filter == 3) { // RED FILTER
159 return (1.1039 * log(fabs(uX)));
160 }
161
162 else if(p_filter == 4) { // NIR FILTER
163 return (1.4101 * log(fabs(uX)));
164 }
165
166 return uX;
167 }
168}
CameraDistortionMap(Camera *parent, double zDirection=1.0)
Camera distortion map constructor.
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.
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.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.