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
CameraDistortionMap.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "IString.h"
8#include "CameraDistortionMap.h"
9
10namespace Isis {
25 p_camera = parent;
26 p_camera->SetDistortionMap(this);
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
96 double r2 = (dx * dx) + (dy * dy);
97
98 // Ok we need to apply distortion correction
99 double drOverR = p_odk[0] + (r2 * (p_odk[1] + (r2 * p_odk[2])));
100 p_undistortedFocalPlaneX = dx - (drOverR * dx);
101 p_undistortedFocalPlaneY = dy - (drOverR * dy);
102 return true;
103 }
104
105
126 const double uy) {
129
130 // No coefficients == nodistortion
131 if (p_odk.size() <= 0) {
132 p_focalPlaneX = ux;
133 p_focalPlaneY = uy;
134 return true;
135 }
136
137 // Compute the distance from the focal plane center
138 double rp2 = (ux * ux) + (uy * uy);
139
140 // Ok make the correction, start by computing
141 // fractional distortion at rp (r-prime)
142 double rp = sqrt(rp2);
143 double drOverR = p_odk[0] + (rp2 * (p_odk[1] + (rp2 * p_odk[2])));
144
145 // Estimate r
146 double r = rp + (drOverR * rp);
147 double r_prev, r2_prev;
148 double tolMilliMeters = p_camera->PixelPitch() / 100.0;
149 int iteration = 0;
150 do {
151 // Don't get in an end-less loop. This algorithm should
152 // converge quickly. If not then we are probably way outside
153 // of the focal plane. Just set the distorted position to the
154 // undistorted position. Also, make sure the focal plane is less
155 // than 1km, it is unreasonable for it to grow larger than that.
156 if (iteration >= 15 || r > 1E9) {
157 drOverR = 0.0;
158 break;
159 }
160
161 r_prev = r;
162 r2_prev = r * r;
163
164 // Compute new fractional distortion:
165 drOverR = p_odk[0] + (r2_prev * (p_odk[1] + (r2_prev * p_odk[2])));
166
167 r = rp + (drOverR * r_prev); // Compute new estimate of r
168 iteration++;
169 }
170 while (fabs(r - r_prev) > tolMilliMeters);
171
172 p_focalPlaneX = ux / (1.0 - drOverR);
173 p_focalPlaneY = uy / (1.0 - drOverR);
174 return true;
175 }
176
177
184 return p_odk;
185 }
186
187
194 return p_zDirection;
195 }
196
197
205 return p_focalPlaneX;
206 }
207
208
216 return p_focalPlaneY;
217 }
218
219
229
230
240
241
250 return p_zDirection *p_camera->FocalLength();
251 }
252
253}
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.
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.