Isis 3 Programmer Reference
ApolloMetricDistortionMap.cpp
Go to the documentation of this file.
1 
21 #include "CameraFocalPlaneMap.h"
22 
23 using namespace std;
24 namespace Isis {
43  ApolloMetricDistortionMap::ApolloMetricDistortionMap(Camera *parent,
44  double xp, double yp,
45  double k1, double k2,
46  double k3, double j1,
47  double j2, double t0) :
48  CameraDistortionMap(parent, -1.0) {
49  p_xp = xp;
50  p_yp = yp;
51  p_k1 = k1;
52  p_k2 = k2;
53  p_k3 = k3;
54  p_j1 = j1;
55  p_j2 = j2;
56  p_t0 = t0;
57  }
58 
71  bool ApolloMetricDistortionMap::SetFocalPlane(const double dx, const double dy) {
72  p_focalPlaneX = dx;
73  p_focalPlaneY = dy;
74 
75  // reducing to principal point offset (xp,yp)
76  double x = dx - p_xp;
77  double y = dy - p_yp;
78 
79  // r is the distance between the principal point and the measured point on the image
80  double rr = x * x + y * y;
81  double rrrr = rr * rr;
82 
83  // dr is the radial distortion contribution
84  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
85  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
86  double dr = 1 + p_k1 * rr + p_k2 * rrrr + p_k3 * rr * rrrr;
87  double dt = p_j1 * rr + p_j2 * rrrr;
88 
89  // image coordinates corrected for principal point, radial and decentering distortion
90  p_undistortedFocalPlaneX = dr * x - dt * sin(p_t0);
91  p_undistortedFocalPlaneY = dr * y + dt * cos(p_t0);
92 
93  return true;
94  }
95 
96 
109  bool ApolloMetricDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
110  // image coordinates prior to introducing distortion
113 
114  double xt = ux;
115  double yt = uy;
116 
117  double xx, yy, rr, rrrr, dr;
118  double xdistortion, ydistortion;
119  double xdistorted, ydistorted;
120  double xprevious, yprevious;
121  // dr is the radial distortion contribution
122  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
123  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
124  double dt;
125 
126  xprevious = 1000000.0;
127  yprevious = 1000000.0;
128 
129  double tolerance = 0.000001;
130 
131  bool bConverged = false;
132 
133  // iterating to introduce distortion...
134  // we stop when the difference between distorted coordinates
135  // in successive iterations is at or below the given tolerance
136  for(int i = 0; i < 50; i++) {
137  xx = xt * xt;
138  yy = yt * yt;
139  rr = xx + yy;
140  rrrr = rr * rr;
141 
142  // radial distortion
143  // dr is the radial distortion contribution
144  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
145  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
146  dr = p_k1 * rr + p_k2 * rrrr + p_k3 * rr * rrrr;
147 
148  dt = p_j1 * rr + p_j2 * rrrr;
149 
150  // distortion at the current point location
151  xdistortion = xt * dr - dt * sin(p_t0);
152  ydistortion = yt * dr + dt * cos(p_t0);
153 
154  // updated image coordinates
155  xt = ux - xdistortion;
156  yt = uy - ydistortion;
157 
158  // distorted point corrected for principal point
159  xdistorted = xt + p_xp;
160  ydistorted = yt + p_yp;
161 
162  // check for convergence
163  if((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
164  bConverged = true;
165  break;
166  }
167 
168  xprevious = xt;
169  yprevious = yt;
170  }
171 
172  if(bConverged) {
173  p_focalPlaneX = xdistorted;
174  p_focalPlaneY = ydistorted;
175  }
176 
177  return bConverged;
178  }
179 }
double p_focalPlaneX
Distorted focal plane x.
double p_k2
Second coefficient of radial distortion.
Namespace for the standard library.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
double p_j2
Second coefficient of decentering distortion.
bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
double p_k3
Third coefficient of radial distortion.
Distort/undistort focal plane coordinates.
double p_yp
Principal point y-coordinate.
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
double p_k1
First coefficient of radial distortion.
double p_j1
First coefficient of decentering distortion.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
double p_t0
Angle between positive x-axis of image and vector to imaged point.
double p_xp
Principal point x-coordinate.