Isis 3 Programmer Reference
LroWideAngleCameraDistortionMap.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include <cmath>
10
11#include <sstream>
12#include <iomanip>
13#include <boost/foreach.hpp>
14
15#include "IString.h"
16#include "LroWideAngleCameraDistortionMap.h"
17
18using namespace std;
19
20namespace Isis {
34 int naifIkCode) :
35 CameraDistortionMap(parent) {
36 // Initialize distortion coefficients to 0 to avoid segfaults
37 QString odkkey = "INS" + toString(naifIkCode) + "_OD_K";
38 for (int i = 0; i < 3; ++i) {
39 p_odk.push_back(0);
40 }
41 }
42
43
60 QString odkkey = "INS" + QString::number(naifIkCode) + "_OD_K";
61
62 std::vector<double> v_odk;
63 for(int i = 0; i < 3; i++) {
64 v_odk.push_back(p_camera->getDouble(odkkey, i));
65 }
66
67 m_odkFilters.push_back(v_odk);
68 }
69
70
84 if ( (vband <= 0) || (vband > m_odkFilters.size()) ) {
85 QString mess = "Invalid band (" + QString::number(vband) + " requested " +
86 " Must be <= " + QString::number(m_odkFilters.size());
87 throw IException(IException::Programmer, mess, _FILEINFO_);
88 }
89
90 // Install new parameters
91 p_odk = m_odkFilters[vband-1];
92
93 return;
94
95 }
96
109 bool LroWideAngleCameraDistortionMap::SetFocalPlane(const double dx, const double dy) {
110 p_focalPlaneX = dx;
111 p_focalPlaneY = dy;
112
113 double dk1 = p_odk[0];
114 double dk2 = p_odk[1];
115 double dk3 = p_odk[2];
116
117 double rr = dx * dx + dy * dy;
118
119 double dr = 1.0 + dk1 * rr + dk2 * rr * rr + dk3 * rr * rr * rr;
120
121 // This was in here when the model used to be dx/dr so that the model
122 // would never divide by zero.
123 if ( dr == 0.0 ) return false;
124
125 // Compute the undistorted positions
126 p_undistortedFocalPlaneX = dx * dr;
127 p_undistortedFocalPlaneY = dy * dr;
128
129 return true;
130 }
131
145 bool LroWideAngleCameraDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
146 // image coordinates prior to introducing distortion
149
150 double xt = ux;
151 double yt = uy;
152
153 double rr, dr;
154 double xdistorted, ydistorted;
155 double xprevious, yprevious;
156
157 xprevious = 1000000.0;
158 yprevious = 1000000.0;
159 // Changed this line to 10^-6... it allows the outer pixels to be found
160 // when mapping back to the sensor
161 double tolerance = 1.0e-6;
162
163 bool bConverged = false;
164
165 double dk1 = p_odk[0];
166 double dk2 = p_odk[1];
167 double dk3 = p_odk[2];
168
169 // iterating to introduce distortion...
170 // we stop when the difference between distorted coordinates
171 // in successive iterations is at or below the given tolerance
172 for(int i = 0; i < 50; i++) {
173 rr = xt * xt + yt * yt;
174 // dr is the radial distortion contribution
175 dr = 1.0 + dk1 * rr + dk2 * rr * rr + dk3 * rr * rr * rr;
176
177 // introducing distortion
178 xt = ux / dr;
179 yt = uy / dr;
180
181 // distorted point
182 xdistorted = xt;
183 ydistorted = yt;
184
185 // check for convergence
186 if((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
187 bConverged = true;
188 break;
189 }
190
191 xprevious = xt;
192 yprevious = yt;
193 }
194
195
196 if(bConverged) {
197 p_focalPlaneX = xdistorted;
198 p_focalPlaneY = ydistorted;
199 }
200
201 return bConverged;
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.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
void setBand(int vband)
Implements band-dependant distortion parameters.
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
void addFilter(int naifIkCode)
Add an additional set of parameters for a given LROC/WAC filter.
LroWideAngleCameraDistortionMap(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
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
Namespace for the standard library.