USGS

Isis 3.0 Object Programmers' Reference

Home

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 
71  p_undistortedFocalPlaneX = dx;
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
89  p_undistortedFocalPlaneX = ux;
90  p_undistortedFocalPlaneY = uy;
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.....
109  p_focalPlaneX = p_undistortedFocalPlaneX;
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) {
142  p_focalPlaneX = p_undistortedFocalPlaneX;
143  p_focalPlaneY = ydistorted;
144  }
145 
146  return bConverged;
147  }
148 }