Isis 3 Programmer Reference
LroNarrowAngleDistortionMap.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include <cmath>
10
11#include "IString.h"
12#include "LroNarrowAngleDistortionMap.h"
13
14namespace Isis {
29
33 void LroNarrowAngleDistortionMap::SetDistortion(const int naifIkCode) {
34 QString odkkey = "INS" + toString(naifIkCode) + "_OD_K";
35 p_odk.clear();
36 p_odk.push_back(p_camera->getDouble(odkkey, 0));
37 }
38
50 bool LroNarrowAngleDistortionMap::SetFocalPlane(const double dx, const double dy) {
51 p_focalPlaneX = dx;
52 p_focalPlaneY = dy;
53
54 double dk1 = p_odk[0];
55
56 double den = 1 + dk1 * dy * dy; // r = dy*dy = distance from the focal plane center
57 if(den == 0.0)
58 return false;
59
61 p_undistortedFocalPlaneY = dy / den;
62
63 return true;
64 }
65
76 bool LroNarrowAngleDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
77 // image coordinates prior to introducing distortion
80
81 double yt = uy;
82
83 double rr, dr;
84 double ydistorted;
85 double yprevious = 1000000.0;
86 double tolerance = 1.0e-10;
87
88 bool bConverged = false;
89
90 double dk1 = p_odk[0];
91
92 // Owing to the odd distotion model employed in this senser if |y| is > 116.881145553046
93 // then there is no root to find. Further, the greatest y that any measure on the sensor
94 // will acutally distort to is less than 20. Thus, if any distorted measure is greater
95 // that that skip the iterations. The points isn't in the cube, and exactly how far outside
96 // the cube is irrelevant. Just let the camera model know its not in the cube....
97 if (fabs(uy) > 40) { //if the point is way off the image.....
99 p_focalPlaneY = 100.0; //100.0 is >> 20.0, and clearly outside the cube
100 return true;
101 }
102
103 // iterating to introduce distortion (in sample only)...
104 // we stop when the difference between distorted coordinate
105 // in successive iterations is at or below the given tolerance
106 for(int i = 0; i < 50; i++) {
107 rr = yt * yt;
108
109 // dr is the radial distortion contribution
110 dr = 1.0 + dk1 * rr;
111
112 // distortion at the current sample location
113 yt = uy * dr;
114
115 // distorted sample
116 ydistorted = yt;
117
118 if (yt < -1e121) //debug
119 break; //debug
120
121 // check for convergence
122 if(fabs(yt - yprevious) <= tolerance) {
123 bConverged = true;
124 break;
125 }
126
127 yprevious = yt;
128 }
129
130 if(bConverged) {
132 p_focalPlaneY = ydistorted;
133 }
134
135 return bConverged;
136 }
137}
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.
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
LroNarrowAngleDistortionMap(Camera *parent)
Camera distortion map constructor.
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted 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
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