Isis 3 Programmer Reference
LroWideAngleCameraDistortionMap.cpp
Go to the documentation of this file.
1 
23 #include <cmath>
24 
25 #include <sstream>
26 #include <iomanip>
27 #include <boost/foreach.hpp>
28 
29 #include "IString.h"
31 
32 using namespace std;
33 
34 namespace Isis {
47  LroWideAngleCameraDistortionMap::LroWideAngleCameraDistortionMap(Camera *parent,
48  int naifIkCode) :
49  CameraDistortionMap(parent) {
50  SetDistortion(naifIkCode);
51  }
52 
53 
70  QString odkkey = "INS" + QString::number(naifIkCode) + "_OD_K";
71 
72  std::vector<double> v_odk;
73  for(int i = 0; i < 3; i++) {
74  v_odk.push_back(p_camera->getDouble(odkkey, i));
75  }
76 
77  m_odkFilters.push_back(v_odk);
78  }
79 
80 
94  if ( (vband <= 0) || (vband > m_odkFilters.size()) ) {
95  QString mess = "Invalid band (" + QString::number(vband) + " requested " +
96  " Must be <= " + QString::number(m_odkFilters.size());
98  }
99 
100  // Install new parameters
101  p_odk = m_odkFilters[vband-1];
102 
103  return;
104 
105  }
106 
119  bool LroWideAngleCameraDistortionMap::SetFocalPlane(const double dx, const double dy) {
120  p_focalPlaneX = dx;
121  p_focalPlaneY = dy;
122 
123  double dk1 = p_odk[0];
124  double dk2 = p_odk[1];
125  double dk3 = p_odk[2];
126 
127  double rr = dx * dx + dy * dy;
128 
129  double dr = 1.0 + dk1 * rr + dk2 * rr * rr + dk3 * rr * rr * rr;
130 
131  // This was in here when the model used to be dx/dr so that the model
132  // would never divide by zero.
133  if ( dr == 0.0 ) return false;
134 
135  // Compute the undistorted positions
136  p_undistortedFocalPlaneX = dx * dr;
137  p_undistortedFocalPlaneY = dy * dr;
138 
139  return true;
140  }
141 
155  bool LroWideAngleCameraDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
156  // image coordinates prior to introducing distortion
159 
160  double xt = ux;
161  double yt = uy;
162 
163  double rr, dr;
164  double xdistorted, ydistorted;
165  double xprevious, yprevious;
166 
167  xprevious = 1000000.0;
168  yprevious = 1000000.0;
169  // Changed this line to 10^-6... it allows the outer pixels to be found
170  // when mapping back to the sensor
171  double tolerance = 1.0e-6;
172 
173  bool bConverged = false;
174 
175  double dk1 = p_odk[0];
176  double dk2 = p_odk[1];
177  double dk3 = p_odk[2];
178 
179  // iterating to introduce distortion...
180  // we stop when the difference between distorted coordinates
181  // in successive iterations is at or below the given tolerance
182  for(int i = 0; i < 50; i++) {
183  rr = xt * xt + yt * yt;
184  // dr is the radial distortion contribution
185  dr = 1.0 + dk1 * rr + dk2 * rr * rr + dk3 * rr * rr * rr;
186 
187  // introducing distortion
188  xt = ux / dr;
189  yt = uy / dr;
190 
191  // distorted point
192  xdistorted = xt;
193  ydistorted = yt;
194 
195  // check for convergence
196  if((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
197  bConverged = true;
198  break;
199  }
200 
201  xprevious = xt;
202  yprevious = yt;
203  }
204 
205 
206  if(bConverged) {
207  p_focalPlaneX = xdistorted;
208  p_focalPlaneY = ydistorted;
209  }
210 
211  return bConverged;
212  }
213 }
double p_focalPlaneX
Distorted focal plane x.
Namespace for the standard library.
virtual void SetDistortion(int naifIkCode)
Load distortion coefficients.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
void setBand(int vband)
Implements band-dependant distortion parameters.
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Camera * p_camera
The camera to distort/undistort.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Distort/undistort focal plane coordinates.
double p_focalPlaneY
Distorted focal plane y.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
std::vector< double > p_odk
Vector of distortion coefficients.
void addFilter(int naifIkCode)
Add an additional set of parameters for a given LROC/WAC filter.
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition: Spice.cpp:963