Isis 3 Programmer Reference
Chandrayaan1M3DistortionMap.cpp
Go to the documentation of this file.
1 
24 #include <iomanip>
25 
27 #include "CameraFocalPlaneMap.h"
28 
29 using namespace std;
30 
31 namespace Isis {
32  Chandrayaan1M3DistortionMap::Chandrayaan1M3DistortionMap(Camera *parent,
33  double xp, double yp,
34  double k1, double k2, double k3,
35  double p1, double p2) :
36  CameraDistortionMap(parent, 1.0) {
37 
38  p_xp = xp;
39  p_yp = yp;
40  p_k1 = k1;
41  p_k2 = k2;
42  p_k3 = k3;
43  p_p1 = p1;
44  p_p2 = p2;
45  }
46 
59  bool Chandrayaan1M3DistortionMap::SetFocalPlane(const double dx, const double dy) {
60  p_focalPlaneX = dx;
61  p_focalPlaneY = dy;
62 
63  // reducing to principal point offset (xp,yp)
64  double x = dx - p_xp;
65  double y = dy - p_yp;
66 
67 // std::cout << setprecision(14) << " dx " << dx << " dy " << dy << " p_xp " << p_xp << " p_yp " << p_yp;
68  // r is the distance between the principal point and the measured point on the image
69  double rr = x * x + y * y;
70 // std::cout << " rr " << rr << " r " << sqrt(rr);
71 
72  // dr is the radial distortion contribution
73  double dr = p_k1 + p_k2 * rr + p_k3 * rr * rr;
74 // std::cout << " dr " << dr;
75 
76  // dtx and dty are the decentering distortion contribution in x and y
77  double dtx = p_p1 * (rr + 2.0 * x * x) + 2.0 * p_p2 * x * y;
78  double dty = 2.0 * p_p1 * x * y + p_p2 * (rr + 2 * y * y);
79 // std::cout << " dtx " << dtx << " dty " << dty << std::endl;
80 
81  // image coordinates corrected for principal point, radial and decentering distortion (p1,p2,p3)
82  p_undistortedFocalPlaneX = dx + x * dr + dtx;
83  p_undistortedFocalPlaneY = dy + y * dr + dty;
84 
85  return true;
86  }
87 
88 
101  bool Chandrayaan1M3DistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
102 
103  double xt = ux;
104  double yt = uy;
105 
106  double xx, yy, rr, dr;
107  double xdistortion, ydistortion;
108  double xdistorted, ydistorted;
109  double xprevious, yprevious;
110 
111  // dr is the radial distortion contribution
112  // dtx and dty are the decentering distortion contributions in x and y
113 
114  xprevious = 1000000.0;
115  yprevious = 1000000.0;
116 
117  double tolerance = 0.000001;
118 
119  bool bConverged = false;
120 
121  // iterating to introduce distortion...
122  // we stop when the difference between distorted coordinates
123  // in successive iterations is at or below the given tolerance
124  for (int i = 0; i < 50; i++) {
125  xx = xt * xt;
126  yy = yt * yt;
127  rr = xx + yy;
128 
129  // radial distortion
130  // dr is the radial distortion contribution
131  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
132  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
133  dr = p_k1 + p_k2 * rr + p_k3 * rr * rr;
134 
135  double dtx = p_p1 * (rr + 2.0 * xt * xt) + 2.0 * p_p2 * xt * yt;
136  double dty = 2.0 * p_p1 * xt * yt + p_p2 * (rr + 2 * yt * yt);
137 
138  // distortion at the current point location
139  xdistortion = dr * xt + dtx;
140  ydistortion = dr * yt + dty;
141 
142  // updated image coordinates
143  xt = ux - xdistortion;
144  yt = uy - ydistortion;
145 
146  // distorted point corrected for principal point
147  xdistorted = xt + p_xp;
148  ydistorted = yt + p_yp;
149 
150  // check for convergence
151  if ((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
152  bConverged = true;
153  break;
154  }
155 
156  xprevious = xt;
157  yprevious = yt;
158  }
159 
160  if (bConverged) {
163 
164  p_focalPlaneX = xdistorted;
165  p_focalPlaneY = ydistorted;
166  }
167 
168  return bConverged;
169  }
170 }
double p_focalPlaneX
Distorted focal plane x.
Namespace for the standard library.
double p_yp
principal point coordinates
double p_undistortedFocalPlaneX
Undistorted focal plane x.
double p_p2
coefficients of decentering distortion
bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
double p_k3
coefficients of radial distortion
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31