Isis 3 Programmer Reference
RadialDistortionMap.cpp
1 #include "RadialDistortionMap.h"
2 #include "CameraFocalPlaneMap.h"
3 
4 using namespace std;
5 
6 namespace Isis {
7  RadialDistortionMap::RadialDistortionMap(Camera *parent, double k1, double zDirection) : CameraDistortionMap(parent, zDirection) {
8  p_k1 = k1;
9  }
10 
11  // Compute undistorted focal plane x/y.
12  bool RadialDistortionMap::SetFocalPlane(const double dx, const double dy) {
13  double offsetSqrd;
14 
15  p_focalPlaneX = dx;
16  p_focalPlaneY = dy;
17 
18  offsetSqrd = dx * dx + dy * dy;
19 
20  p_undistortedFocalPlaneX = dx * (1.0 + p_k1 * offsetSqrd);
21  p_undistortedFocalPlaneY = dy * (1.0 + p_k1 * offsetSqrd);
22 
23  return true;
24  }
25 
26  bool RadialDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
27  double offsetSqrd;
28  int numAttempts;
29  double delta;
30  bool done;
31 
34 
35  /****************************************************************************
36  * Pre-loop intializations
37  ****************************************************************************/
38 
39  numAttempts = 1;
40  delta = 0.00001;
41 
42  offsetSqrd = uy * uy + ux * ux;
43  double guess_dx, guess_dy;
44  double guess_ux, guess_uy;
45 
46  /****************************************************************************
47  * Loop ...
48  ****************************************************************************/
49  do {
50  /* Guess a distorted line/samp */
51  guess_dx = ux / (1.0 + p_k1 * offsetSqrd);
52  guess_dy = uy / (1.0 + p_k1 * offsetSqrd);
53 
54  /* Use the guess to calculate a corrected line/samp */
55  offsetSqrd = guess_dy * guess_dy + guess_dx * guess_dx;
56 
57  guess_ux = guess_dx * (1.0 + p_k1 * offsetSqrd);
58  guess_uy = guess_dy * (1.0 + p_k1 * offsetSqrd);
59 
60  /* If guessed corrected line/samp match the input line/samp we're done*/
61  done = true;
62  if(abs(guess_uy - uy) > delta) {
63  done = false;
64  }
65 
66  if(abs(guess_ux - ux) > delta) {
67  done = false;
68  }
69 
70  /* Not converging so bomb */
71  numAttempts++;
72  if(numAttempts > 20) {
73  return false;
74  }
75  }
76  while(!done);
77 
78  /****************************************************************************
79  * Sucess ...
80  ****************************************************************************/
81 
82  p_focalPlaneX = guess_dx;
83  p_focalPlaneY = guess_dy;
84  return true;
85  }
86 }
double p_focalPlaneX
Distorted focal plane x.
Namespace for the standard library.
bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31