Isis 3 Programmer Reference
LroNarrowAngleDistortionMap.cpp
Go to the documentation of this file.
1 
20 #include <cmath>
21 
22 #include "IString.h"
24 
25 namespace Isis {
39  }
40 
44  void LroNarrowAngleDistortionMap::SetDistortion(const int naifIkCode) {
45  QString odkkey = "INS" + toString(naifIkCode) + "_OD_K";
46  p_odk.clear();
47  p_odk.push_back(p_camera->getDouble(odkkey, 0));
48  }
49 
61  bool LroNarrowAngleDistortionMap::SetFocalPlane(const double dx, const double dy) {
62  p_focalPlaneX = dx;
63  p_focalPlaneY = dy;
64 
65  double dk1 = p_odk[0];
66 
67  double den = 1 + dk1 * dy * dy; // r = dy*dy = distance from the focal plane center
68  if(den == 0.0)
69  return false;
70 
72  p_undistortedFocalPlaneY = dy / den;
73 
74  return true;
75  }
76 
87  bool LroNarrowAngleDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
88  // image coordinates prior to introducing distortion
91 
92  double yt = uy;
93 
94  double rr, dr;
95  double ydistorted;
96  double yprevious = 1000000.0;
97  double tolerance = 1.0e-10;
98 
99  bool bConverged = false;
100 
101  double dk1 = p_odk[0];
102 
103  // Owing to the odd distotion model employed in this senser if |y| is > 116.881145553046
104  // then there is no root to find. Further, the greatest y that any measure on the sensor
105  // will acutally distort to is less than 20. Thus, if any distorted measure is greater
106  // that that skip the iterations. The points isn't in the cube, and exactly how far outside
107  // the cube is irrelevant. Just let the camera model know its not in the cube....
108  if (fabs(uy) > 40) { //if the point is way off the image.....
110  p_focalPlaneY = 100.0; //100.0 is >> 20.0, and clearly outside the cube
111  return true;
112  }
113 
114  // iterating to introduce distortion (in sample only)...
115  // we stop when the difference between distorted coordinate
116  // in successive iterations is at or below the given tolerance
117  for(int i = 0; i < 50; i++) {
118  rr = yt * yt;
119 
120  // dr is the radial distortion contribution
121  dr = 1.0 + dk1 * rr;
122 
123  // distortion at the current sample location
124  yt = uy * dr;
125 
126  // distorted sample
127  ydistorted = yt;
128 
129  if (yt < -1e121) //debug
130  break; //debug
131 
132  // check for convergence
133  if(fabs(yt - yprevious) <= tolerance) {
134  bConverged = true;
135  break;
136  }
137 
138  yprevious = yt;
139  }
140 
141  if(bConverged) {
143  p_focalPlaneY = ydistorted;
144  }
145 
146  return bConverged;
147  }
148 }
double p_focalPlaneX
Distorted focal plane x.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Camera * p_camera
The camera to distort/undistort.
Distort/undistort focal plane coordinates.
LroNarrowAngleDistortionMap(Camera *parent)
Camera distortion map constructor.
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
std::vector< double > p_odk
Vector of distortion coefficients.
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition: Spice.cpp:963