Isis 3 Programmer Reference
CameraDistortionMap.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "IString.h"
8#include "CameraDistortionMap.h"
9
10namespace Isis {
25 p_camera = parent;
27 p_zDirection = zDirection;
28 }
29
30
36
37
59 p_odk.clear();
60 QString odkkey = "INS" + toString(naifIkCode) + "_OD_K";
61 for (int i = 0; i < 3; ++i) {
62 p_odk.push_back(p_camera->Spice::getDouble(odkkey, i));
63 }
64 }
65
66
84 bool CameraDistortionMap::SetFocalPlane(double dx, double dy) {
85 p_focalPlaneX = dx;
86 p_focalPlaneY = dy;
87
88 // No coefficients == no distortion
89 if (p_odk.size() <= 0) {
92 return true;
93 }
94
95 // Get the distance from the focal plane center and if we are close
96 // then skip the distortion
97 double r2 = (dx * dx) + (dy * dy);
98 if (r2 <= 1.0E-6) {
101 return true;
102 }
103
104 // Ok we need to apply distortion correction
105 double drOverR = p_odk[0] + (r2 * (p_odk[1] + (r2 * p_odk[2])));
106 p_undistortedFocalPlaneX = dx - (drOverR * dx);
107 p_undistortedFocalPlaneY = dy - (drOverR * dy);
108 return true;
109 }
110
111
132 const double uy) {
135
136 // No coefficients == nodistortion
137 if (p_odk.size() <= 0) {
138 p_focalPlaneX = ux;
139 p_focalPlaneY = uy;
140 return true;
141 }
142
143 // Compute the distance from the focal plane center and if we are
144 // close to the center then no distortion is required
145 double rp2 = (ux * ux) + (uy * uy);
146 if (rp2 <= 1.0E-6) {
147 p_focalPlaneX = ux;
148 p_focalPlaneY = uy;
149 return true;
150 }
151
152 // Ok make the correction, start by computing
153 // fractional distortion at rp (r-prime)
154 double rp = sqrt(rp2);
155 double drOverR = p_odk[0] + (rp2 * (p_odk[1] + (rp2 * p_odk[2])));
156
157 // Estimate r
158 double r = rp + (drOverR * rp);
159 double r_prev, r2_prev;
160 double tolMilliMeters = p_camera->PixelPitch() / 100.0;
161 int iteration = 0;
162 do {
163 // Don't get in an end-less loop. This algorithm should
164 // converge quickly. If not then we are probably way outside
165 // of the focal plane. Just set the distorted position to the
166 // undistorted position. Also, make sure the focal plane is less
167 // than 1km, it is unreasonable for it to grow larger than that.
168 if (iteration >= 15 || r > 1E9) {
169 drOverR = 0.0;
170 break;
171 }
172
173 r_prev = r;
174 r2_prev = r * r;
175
176 // Compute new fractional distortion:
177 drOverR = p_odk[0] + (r2_prev * (p_odk[1] + (r2_prev * p_odk[2])));
178
179 r = rp + (drOverR * r_prev); // Compute new estimate of r
180 iteration++;
181 }
182 while (fabs(r - r_prev) > tolMilliMeters);
183
184 p_focalPlaneX = ux / (1.0 - drOverR);
185 p_focalPlaneY = uy / (1.0 - drOverR);
186 return true;
187 }
188
189
196 return p_odk;
197 }
198
199
206 return p_zDirection;
207 }
208
209
217 return p_focalPlaneX;
218 }
219
220
228 return p_focalPlaneY;
229 }
230
231
241
242
252
253
264
265}
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
CameraDistortionMap(Camera *parent, double zDirection=1.0)
Camera distortion map constructor.
double p_focalPlaneX
Distorted focal plane x.
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
double p_zDirection
Undistorted focal plane z.
double UndistortedFocalPlaneX() const
Gets the x-value in the undistorted focal plane coordinate system.
std::vector< double > OpticalDistortionCoefficients() const
Retrieve the distortion coefficients used for this model.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
double FocalPlaneX() const
Gets the x-value in the focal plane coordinate system.
double ZDirection() const
Gets the z-direction for this camera.
std::vector< double > p_odk
Vector of distortion coefficients.
virtual ~CameraDistortionMap()
Destructor for the ISIS default camera distortion map.
virtual void SetDistortion(int naifIkCode)
Load 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 UndistortedFocalPlaneZ() const
Gets the z-value in the undistorted focal plane coordinate system.
double UndistortedFocalPlaneY() const
Gets the y-value in the undistorted focal plane coordinate system.
double FocalPlaneY() const
Gets the y-value in the focal plane coordinate system.
double PixelPitch() const
Returns the pixel pitch.
Definition Camera.cpp:2772
double FocalLength() const
Returns the focal length.
Definition Camera.cpp:2762
void SetDistortionMap(CameraDistortionMap *map, bool deleteExisting=true)
Sets the Distortion Map.
Definition Camera.cpp:2372
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