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