Isis 3 Programmer Reference
TgoCassisDistortionMap.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include <cmath>
10
11#include <QDebug>
12
13#include "IString.h"
14#include "TgoCassisDistortionMap.h"
15
16namespace Isis {
30 int naifIkCode)
31 : CameraDistortionMap(parent) {
32
33 QString od = "INS" + toString(naifIkCode) + "_OD_";
34
35 for(int i = 0; i < 6; i++) {
36 m_A1_corr.push_back(p_camera->getDouble(od + "A1_CORR", i));
37 m_A2_corr.push_back(p_camera->getDouble(od + "A2_CORR", i));
38 m_A3_corr.push_back(p_camera->getDouble(od + "A3_CORR", i));
39 m_A1_dist.push_back(p_camera->getDouble(od + "A1_DIST", i));
40 m_A2_dist.push_back(p_camera->getDouble(od + "A2_DIST", i));
41 m_A3_dist.push_back(p_camera->getDouble(od + "A3_DIST", i));
42 }
43 m_pixelPitch = p_camera->getDouble("INS" + toString(naifIkCode) + "_PIXEL_PITCH");
44 m_width = p_camera->getDouble("INS" + toString(naifIkCode) + "_FILTER_SAMPLES");
45 m_height = p_camera->getDouble("INS" + toString(naifIkCode) + "_FILTER_LINES");
46 }
47
48
54
55
86 const double dy) {
87
88 p_focalPlaneX = dx;
89 p_focalPlaneY = dy;
90
91 // calculate divisor using A3_corr coeffiecients
92 double divider = chiDotA(dx, dy, m_A3_corr);
93 // This distortion model is only valid for values on the CCD:
94 // -1/2 * pixel pitch * CCD width = -10.24 < x < 10.24 = 1/2 * pixel pitch * CCD width
95 // -1/2 * pixel pitch * CCD height = -10.24 < y < 10.24 = 1/2 * pixel pitch * CCD height
96 //
97 // Also, the zeros for the divider variable fall well outside the boundary
98 // of the CCD. (See $ISISDATA/tgo/assets/distortion/DistortionModelA3CorrRoots.jpg).
99 //
100 // So, whenever x or y are too far from center or divider is near zero,
101 // return the given inputs
102
103 if ( dx < -0.5*m_pixelPitch*m_width - 0.2 ||
104 dx > 0.5*m_pixelPitch*m_width + 0.2 ||
105 dy < -0.5*m_pixelPitch*m_height - 0.2 ||
106 dy > 0.5*m_pixelPitch*m_height + 0.2 ) {
109
110 return true;
111 }
112
113 // get undistorted ideal (x,y) coordinates
114 double ux = chiDotA(dx, dy, m_A1_corr) / divider;
115 double uy = chiDotA(dx, dy, m_A2_corr) / divider;
116
119
120 return true;
121 }
122
123
154 const double uy) {
157
158 // calculate divisor using A3_dist coeffiecients
159 double divider = chiDotA(ux, uy, m_A3_dist);
160 // This distortion model is only valid for values on the CCD:
161 // -1/2 * pixel pitch * CCD width = -10.24 < x < 10.24 = 1/2 * pixel pitch * CCD width
162 // -1/2 * pixel pitch * CCD height = -10.24 < y < 10.24 = 1/2 * pixel pitch * CCD height
163 //
164 // Also, the zeros for the divider variable fall well outside the boundary
165 // of the CCD. (See $ISISDATA/tgo/assets/distortion/DistortionModelA3DistRoots.jpg).
166 //
167 // So, whenever x or y are too far from center or divider is near zero,
168 // return the given inputs
169
170 if ( ux < -0.5*m_pixelPitch*m_width - 0.2 ||
171 ux > 0.5*m_pixelPitch*m_width + 0.2 ||
172 uy < -0.5*m_pixelPitch*m_height - 0.2 ||
173 uy > 0.5*m_pixelPitch*m_height + 0.2 ) {
174 p_focalPlaneX = ux;
175 p_focalPlaneY = uy;
176
177 return true;
178 }
179
180 // get undistorted ideal (x,y) coordinates
181 double dx = chiDotA(ux, uy, m_A1_dist) / divider;
182 double dy = chiDotA(ux, uy, m_A2_dist) / divider;
183
184 p_focalPlaneX = dx;
185 p_focalPlaneY = dy;
186 return true;
187 }
188
189
209 double y,
210 QList<double> A) {
211 double x2 = x*x;
212 double y2 = y*y;
213 double xy = x*y;
214
215 return A[0] * x2
216 + A[1] * xy
217 + A[2] * y2
218 + A[3] * x
219 + A[4] * y
220 + A[5];
221 }
222}
Distort/undistort focal plane coordinates.
double p_focalPlaneX
Distorted focal plane x.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Camera * p_camera
The camera to distort/undistort.
double p_focalPlaneY
Distorted focal plane y.
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition Spice.cpp:1046
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane (x,y) given an undistorted focal plane (x,y).
QList< double > m_A1_dist
Coefficients for rational distortion model used to compute distorted x from ideal x.
QList< double > m_A3_dist
Coefficients for rational distortion model used to find scaling factor used when computing distorted ...
double m_width
The width of the ccd in pixels.
QList< double > m_A3_corr
Coefficients for rational distortion model used to find scaling factor used when computing ideal coor...
TgoCassisDistortionMap(Camera *parent, int naifIkCode)
Exomars TGO CaSSIS distortion map constructor.
virtual ~TgoCassisDistortionMap()
Exomars TGO CaSSIS distortion map destructor.
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane (x,y) coordinate given the distorted (x,y).
double chiDotA(double x, double y, QList< double > A)
Evaluate the value for the multi-variate polynomial, given the list of 6 coefficients.
QList< double > m_A2_corr
Coefficients for rational distortion model used to compute ideal y from distorted y.
QList< double > m_A1_corr
Coefficients for rational distortion model used to compute ideal x from distorted x.
double m_height
The height of the ccd in pixels.
QList< double > m_A2_dist
Coefficients for rational distortion model used to compute distorted y from ideal y.
double m_pixelPitch
The pixel pitch of the camera.
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