Isis 3 Programmer Reference
ClementineUvvisDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <iomanip>
10 
11 #include "CameraFocalPlaneMap.h"
12 #include "ClementineUvvisDistortionMap.h"
13 
14 using namespace std;
15 
16 namespace Isis {
33  ClementineUvvisDistortionMap::ClementineUvvisDistortionMap(Camera *parent,
34  double xp, double yp,
35  double k1, double k2, double k3,
36  double p1, double p2) :
37  CameraDistortionMap(parent, 1.0) {
38 
39  p_xp = xp;
40  p_yp = yp;
41  p_k1 = k1;
42  p_k2 = k2;
43  p_k3 = k3;
44  p_p1 = p1;
45  p_p2 = p2;
46 
47  }
48 
49 
54  }
55 
56 
69  bool ClementineUvvisDistortionMap::SetFocalPlane(const double dx, const double dy) {
70  p_focalPlaneX = dx;
71  p_focalPlaneY = dy;
72 
73  // reducing to principal point offset (xp,yp)
74  double x = dx - p_xp;
75  double y = dy - p_yp;
76 
77 // std::cout << setprecision(14) << " dx " << dx << " dy " << dy << " p_xp " << p_xp << " p_yp " << p_yp;
78  // r is the distance between the principal point and the measured point on the image
79  double rr = x * x + y * y;
80 // std::cout << " rr " << rr << " r " << sqrt(rr);
81 
82  // dr is the radial distortion contribution
83  double dr = p_k1 + p_k2 * rr + p_k3 * rr * rr;
84 // std::cout << " dr " << dr;
85 
86  // dtx and dty are the decentering distortion contribution in x and y
87  double dtx = p_p1 * (rr + 2.0 * x * x) + 2.0 * p_p2 * x * y;
88  double dty = 2.0 * p_p1 * x * y + p_p2 * (rr + 2 * y * y);
89 // std::cout << " dtx " << dtx << " dty " << dty << std::endl;
90 
91  // image coordinates corrected for principal point, radial and decentering distortion (p1,p2,p3)
92  p_undistortedFocalPlaneX = dx + x * dr + dtx;
93  p_undistortedFocalPlaneY = dy + y * dr + dty;
94 
95  return true;
96  }
97 
98 
111  bool ClementineUvvisDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
112 
113  double xt = ux;
114  double yt = uy;
115 
116  double xx, yy, rr, dr;
117  double xdistortion, ydistortion;
118  double xdistorted, ydistorted;
119  double xprevious, yprevious;
120 
121  // dr is the radial distortion contribution
122  // dtx and dty are the decentering distortion contributions in x and y
123 
124  xprevious = 1000000.0;
125  yprevious = 1000000.0;
126 
127  double tolerance = 0.000001;
128 
129  bool bConverged = false;
130 
131  // iterating to introduce distortion...
132  // we stop when the difference between distorted coordinates
133  // in successive iterations is at or below the given tolerance
134  for (int i = 0; i < 50; i++) {
135  xx = xt * xt;
136  yy = yt * yt;
137  rr = xx + yy;
138 
139  // radial distortion
140  // dr is the radial distortion contribution
141  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
142  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
143  dr = p_k1 + p_k2 * rr + p_k3 * rr * rr;
144 
145  double dtx = p_p1 * (rr + 2.0 * xt * xt) + 2.0 * p_p2 * xt * yt;
146  double dty = 2.0 * p_p1 * xt * yt + p_p2 * (rr + 2 * yt * yt);
147 
148  // distortion at the current point location
149  xdistortion = dr * xt + dtx;
150  ydistortion = dr * yt + dty;
151 
152  // updated image coordinates
153  xt = ux - xdistortion;
154  yt = uy - ydistortion;
155 
156  // distorted point corrected for principal point
157  xdistorted = xt + p_xp;
158  ydistorted = yt + p_yp;
159 
160  // check for convergence
161  if ((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
162  bConverged = true;
163  break;
164  }
165 
166  xprevious = xt;
167  yprevious = yt;
168  }
169 
170  if (bConverged) {
173 
174  p_focalPlaneX = xdistorted;
175  p_focalPlaneY = ydistorted;
176  }
177 
178  return bConverged;
179  }
180 }
Isis::ClementineUvvisDistortionMap::SetFocalPlane
bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
Definition: ClementineUvvisDistortionMap.cpp:69
Isis::CameraDistortionMap::p_focalPlaneX
double p_focalPlaneX
Distorted focal plane x.
Definition: CameraDistortionMap.h:65
Isis::ClementineUvvisDistortionMap::p_yp
double p_yp
Principal point y coordinate.
Definition: ClementineUvvisDistortionMap.h:44
Isis::ClementineUvvisDistortionMap::p_p1
double p_p1
First coefficient of decentering distortion.
Definition: ClementineUvvisDistortionMap.h:48
Isis::CameraDistortionMap::p_undistortedFocalPlaneY
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Definition: CameraDistortionMap.h:68
Isis::CameraDistortionMap::p_undistortedFocalPlaneX
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Definition: CameraDistortionMap.h:67
Isis::Camera
Definition: Camera.h:236
Isis::ClementineUvvisDistortionMap::p_k2
double p_k2
Linear term coefficient of radial distortion.
Definition: ClementineUvvisDistortionMap.h:46
Isis::ClementineUvvisDistortionMap::p_xp
double p_xp
Principal point x coordinate.
Definition: ClementineUvvisDistortionMap.h:43
Isis::ClementineUvvisDistortionMap::SetUndistortedFocalPlane
bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
Definition: ClementineUvvisDistortionMap.cpp:111
Isis::ClementineUvvisDistortionMap::~ClementineUvvisDistortionMap
~ClementineUvvisDistortionMap()
Deconstruct the distortion map for the Clementine UVVIS instrument.
Definition: ClementineUvvisDistortionMap.cpp:53
Isis::CameraDistortionMap
Distort/undistort focal plane coordinates.
Definition: CameraDistortionMap.h:41
std
Namespace for the standard library.
Isis::ClementineUvvisDistortionMap::p_p2
double p_p2
Second coefficient of decentering distortion.
Definition: ClementineUvvisDistortionMap.h:49
Isis::ClementineUvvisDistortionMap::p_k1
double p_k1
Constant term coefficient of radial distortion.
Definition: ClementineUvvisDistortionMap.h:45
Isis::ClementineUvvisDistortionMap::p_k3
double p_k3
Quadratic term coefficient of radial distortion.
Definition: ClementineUvvisDistortionMap.h:47
Isis::CameraDistortionMap::p_focalPlaneY
double p_focalPlaneY
Distorted focal plane y.
Definition: CameraDistortionMap.h:66
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16