Isis 3 Programmer Reference
ClementineUvvisDistortionMap.cpp
Go to the documentation of this file.
1 
24 #include <iomanip>
25 
26 #include "CameraFocalPlaneMap.h"
28 
29 using namespace std;
30 
31 namespace Isis {
48  ClementineUvvisDistortionMap::ClementineUvvisDistortionMap(Camera *parent,
49  double xp, double yp,
50  double k1, double k2, double k3,
51  double p1, double p2) :
52  CameraDistortionMap(parent, 1.0) {
53 
54  p_xp = xp;
55  p_yp = yp;
56  p_k1 = k1;
57  p_k2 = k2;
58  p_k3 = k3;
59  p_p1 = p1;
60  p_p2 = p2;
61 
62  }
63 
64 
69  }
70 
71 
84  bool ClementineUvvisDistortionMap::SetFocalPlane(const double dx, const double dy) {
85  p_focalPlaneX = dx;
86  p_focalPlaneY = dy;
87 
88  // reducing to principal point offset (xp,yp)
89  double x = dx - p_xp;
90  double y = dy - p_yp;
91 
92 // std::cout << setprecision(14) << " dx " << dx << " dy " << dy << " p_xp " << p_xp << " p_yp " << p_yp;
93  // r is the distance between the principal point and the measured point on the image
94  double rr = x * x + y * y;
95 // std::cout << " rr " << rr << " r " << sqrt(rr);
96 
97  // dr is the radial distortion contribution
98  double dr = p_k1 + p_k2 * rr + p_k3 * rr * rr;
99 // std::cout << " dr " << dr;
100 
101  // dtx and dty are the decentering distortion contribution in x and y
102  double dtx = p_p1 * (rr + 2.0 * x * x) + 2.0 * p_p2 * x * y;
103  double dty = 2.0 * p_p1 * x * y + p_p2 * (rr + 2 * y * y);
104 // std::cout << " dtx " << dtx << " dty " << dty << std::endl;
105 
106  // image coordinates corrected for principal point, radial and decentering distortion (p1,p2,p3)
107  p_undistortedFocalPlaneX = dx + x * dr + dtx;
108  p_undistortedFocalPlaneY = dy + y * dr + dty;
109 
110  return true;
111  }
112 
113 
126  bool ClementineUvvisDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
127 
128  double xt = ux;
129  double yt = uy;
130 
131  double xx, yy, rr, dr;
132  double xdistortion, ydistortion;
133  double xdistorted, ydistorted;
134  double xprevious, yprevious;
135 
136  // dr is the radial distortion contribution
137  // dtx and dty are the decentering distortion contributions in x and y
138 
139  xprevious = 1000000.0;
140  yprevious = 1000000.0;
141 
142  double tolerance = 0.000001;
143 
144  bool bConverged = false;
145 
146  // iterating to introduce distortion...
147  // we stop when the difference between distorted coordinates
148  // in successive iterations is at or below the given tolerance
149  for (int i = 0; i < 50; i++) {
150  xx = xt * xt;
151  yy = yt * yt;
152  rr = xx + yy;
153 
154  // radial distortion
155  // dr is the radial distortion contribution
156  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
157  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
158  dr = p_k1 + p_k2 * rr + p_k3 * rr * rr;
159 
160  double dtx = p_p1 * (rr + 2.0 * xt * xt) + 2.0 * p_p2 * xt * yt;
161  double dty = 2.0 * p_p1 * xt * yt + p_p2 * (rr + 2 * yt * yt);
162 
163  // distortion at the current point location
164  xdistortion = dr * xt + dtx;
165  ydistortion = dr * yt + dty;
166 
167  // updated image coordinates
168  xt = ux - xdistortion;
169  yt = uy - ydistortion;
170 
171  // distorted point corrected for principal point
172  xdistorted = xt + p_xp;
173  ydistorted = yt + p_yp;
174 
175  // check for convergence
176  if ((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
177  bConverged = true;
178  break;
179  }
180 
181  xprevious = xt;
182  yprevious = yt;
183  }
184 
185  if (bConverged) {
188 
189  p_focalPlaneX = xdistorted;
190  p_focalPlaneY = ydistorted;
191  }
192 
193  return bConverged;
194  }
195 }
double p_focalPlaneX
Distorted focal plane x.
double p_p1
First coefficient of decentering distortion.
double p_k2
Linear term coefficient of radial distortion.
Namespace for the standard library.
double p_yp
Principal point y coordinate.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
~ClementineUvvisDistortionMap()
Deconstruct the distortion map for the Clementine UVVIS instrument.
double p_xp
Principal point x coordinate.
Distort/undistort focal plane coordinates.
double p_k1
Constant term coefficient of radial distortion.
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
double p_p2
Second coefficient of decentering distortion.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double p_k3
Quadratic term coefficient of radial distortion.
bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.