Isis 3 Programmer Reference
ApolloMetricDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "ApolloMetricDistortionMap.h"
10 #include "CameraFocalPlaneMap.h"
11 
12 using namespace std;
13 namespace Isis {
32  ApolloMetricDistortionMap::ApolloMetricDistortionMap(Camera *parent,
33  double xp, double yp,
34  double k1, double k2,
35  double k3, double j1,
36  double j2, double t0) :
37  CameraDistortionMap(parent, -1.0) {
38  p_xp = xp;
39  p_yp = yp;
40  p_k1 = k1;
41  p_k2 = k2;
42  p_k3 = k3;
43  p_j1 = j1;
44  p_j2 = j2;
45  p_t0 = t0;
46  }
47 
60  bool ApolloMetricDistortionMap::SetFocalPlane(const double dx, const double dy) {
61  p_focalPlaneX = dx;
62  p_focalPlaneY = dy;
63 
64  // reducing to principal point offset (xp,yp)
65  double x = dx - p_xp;
66  double y = dy - p_yp;
67 
68  // r is the distance between the principal point and the measured point on the image
69  double rr = x * x + y * y;
70  double rrrr = rr * rr;
71 
72  // dr is the radial distortion contribution
73  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
74  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
75  double dr = 1 + p_k1 * rr + p_k2 * rrrr + p_k3 * rr * rrrr;
76  double dt = p_j1 * rr + p_j2 * rrrr;
77 
78  // image coordinates corrected for principal point, radial and decentering distortion
79  p_undistortedFocalPlaneX = dr * x - dt * sin(p_t0);
80  p_undistortedFocalPlaneY = dr * y + dt * cos(p_t0);
81 
82  return true;
83  }
84 
85 
98  bool ApolloMetricDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
99  // image coordinates prior to introducing distortion
102 
103  double xt = ux;
104  double yt = uy;
105 
106  double xx, yy, rr, rrrr, dr;
107  double xdistortion, ydistortion;
108  double xdistorted, ydistorted;
109  double xprevious, yprevious;
110  // dr is the radial distortion contribution
111  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
112  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
113  double dt;
114 
115  xprevious = 1000000.0;
116  yprevious = 1000000.0;
117 
118  double tolerance = 0.000001;
119 
120  bool bConverged = false;
121 
122  // iterating to introduce distortion...
123  // we stop when the difference between distorted coordinates
124  // in successive iterations is at or below the given tolerance
125  for(int i = 0; i < 50; i++) {
126  xx = xt * xt;
127  yy = yt * yt;
128  rr = xx + yy;
129  rrrr = rr * rr;
130 
131  // radial distortion
132  // dr is the radial distortion contribution
133  // -dt*sin(p_t0) is the decentering distortion contribution in the x-direction
134  // dt*cos(p_t0) is the decentering distortion contribution in the y-direction
135  dr = p_k1 * rr + p_k2 * rrrr + p_k3 * rr * rrrr;
136 
137  dt = p_j1 * rr + p_j2 * rrrr;
138 
139  // distortion at the current point location
140  xdistortion = xt * dr - dt * sin(p_t0);
141  ydistortion = yt * dr + dt * cos(p_t0);
142 
143  // updated image coordinates
144  xt = ux - xdistortion;
145  yt = uy - ydistortion;
146 
147  // distorted point corrected for principal point
148  xdistorted = xt + p_xp;
149  ydistorted = yt + p_yp;
150 
151  // check for convergence
152  if((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
153  bConverged = true;
154  break;
155  }
156 
157  xprevious = xt;
158  yprevious = yt;
159  }
160 
161  if(bConverged) {
162  p_focalPlaneX = xdistorted;
163  p_focalPlaneY = ydistorted;
164  }
165 
166  return bConverged;
167  }
168 }
Isis::CameraDistortionMap::p_focalPlaneX
double p_focalPlaneX
Distorted focal plane x.
Definition: CameraDistortionMap.h:65
Isis::CameraDistortionMap::p_undistortedFocalPlaneY
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Definition: CameraDistortionMap.h:68
Isis::ApolloMetricDistortionMap::p_t0
double p_t0
Angle between positive x-axis of image and vector to imaged point.
Definition: ApolloMetricDistortionMap.h:95
Isis::CameraDistortionMap::p_undistortedFocalPlaneX
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Definition: CameraDistortionMap.h:67
Isis::Camera
Definition: Camera.h:236
Isis::ApolloMetricDistortionMap::p_k3
double p_k3
Third coefficient of radial distortion.
Definition: ApolloMetricDistortionMap.h:92
Isis::ApolloMetricDistortionMap::p_k2
double p_k2
Second coefficient of radial distortion.
Definition: ApolloMetricDistortionMap.h:91
Isis::ApolloMetricDistortionMap::SetFocalPlane
bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
Definition: ApolloMetricDistortionMap.cpp:60
Isis::ApolloMetricDistortionMap::p_xp
double p_xp
Principal point x-coordinate.
Definition: ApolloMetricDistortionMap.h:88
Isis::CameraDistortionMap
Distort/undistort focal plane coordinates.
Definition: CameraDistortionMap.h:41
Isis::ApolloMetricDistortionMap::p_j2
double p_j2
Second coefficient of decentering distortion.
Definition: ApolloMetricDistortionMap.h:94
std
Namespace for the standard library.
Isis::ApolloMetricDistortionMap::p_k1
double p_k1
First coefficient of radial distortion.
Definition: ApolloMetricDistortionMap.h:90
Isis::ApolloMetricDistortionMap::p_yp
double p_yp
Principal point y-coordinate.
Definition: ApolloMetricDistortionMap.h:89
Isis::ApolloMetricDistortionMap::p_j1
double p_j1
First coefficient of decentering distortion.
Definition: ApolloMetricDistortionMap.h:93
Isis::ApolloMetricDistortionMap::SetUndistortedFocalPlane
bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
Definition: ApolloMetricDistortionMap.cpp:98
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