Loading [MathJax]/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
LroWideAngleCameraDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <cmath>
10 
11 #include <sstream>
12 #include <iomanip>
13 #include <boost/foreach.hpp>
14 
15 #include "IString.h"
16 #include "LroWideAngleCameraDistortionMap.h"
17 
18 using namespace std;
19 
20 namespace Isis {
33  LroWideAngleCameraDistortionMap::LroWideAngleCameraDistortionMap(Camera *parent,
34  int naifIkCode) :
35  CameraDistortionMap(parent) {
36  SetDistortion(naifIkCode);
37  }
38 
39 
56  QString odkkey = "INS" + QString::number(naifIkCode) + "_OD_K";
57 
58  std::vector<double> v_odk;
59  for(int i = 0; i < 3; i++) {
60  v_odk.push_back(p_camera->getDouble(odkkey, i));
61  }
62 
63  m_odkFilters.push_back(v_odk);
64  }
65 
66 
80  if ( (vband <= 0) || (vband > m_odkFilters.size()) ) {
81  QString mess = "Invalid band (" + QString::number(vband) + " requested " +
82  " Must be <= " + QString::number(m_odkFilters.size());
83  throw IException(IException::Programmer, mess, _FILEINFO_);
84  }
85 
86  // Install new parameters
87  p_odk = m_odkFilters[vband-1];
88 
89  return;
90 
91  }
92 
105  bool LroWideAngleCameraDistortionMap::SetFocalPlane(const double dx, const double dy) {
106  p_focalPlaneX = dx;
107  p_focalPlaneY = dy;
108 
109  double dk1 = p_odk[0];
110  double dk2 = p_odk[1];
111  double dk3 = p_odk[2];
112 
113  double rr = dx * dx + dy * dy;
114 
115  double dr = 1.0 + dk1 * rr + dk2 * rr * rr + dk3 * rr * rr * rr;
116 
117  // This was in here when the model used to be dx/dr so that the model
118  // would never divide by zero.
119  if ( dr == 0.0 ) return false;
120 
121  // Compute the undistorted positions
122  p_undistortedFocalPlaneX = dx * dr;
123  p_undistortedFocalPlaneY = dy * dr;
124 
125  return true;
126  }
127 
141  bool LroWideAngleCameraDistortionMap::SetUndistortedFocalPlane(const double ux, const double uy) {
142  // image coordinates prior to introducing distortion
145 
146  double xt = ux;
147  double yt = uy;
148 
149  double rr, dr;
150  double xdistorted, ydistorted;
151  double xprevious, yprevious;
152 
153  xprevious = 1000000.0;
154  yprevious = 1000000.0;
155  // Changed this line to 10^-6... it allows the outer pixels to be found
156  // when mapping back to the sensor
157  double tolerance = 1.0e-6;
158 
159  bool bConverged = false;
160 
161  double dk1 = p_odk[0];
162  double dk2 = p_odk[1];
163  double dk3 = p_odk[2];
164 
165  // iterating to introduce distortion...
166  // we stop when the difference between distorted coordinates
167  // in successive iterations is at or below the given tolerance
168  for(int i = 0; i < 50; i++) {
169  rr = xt * xt + yt * yt;
170  // dr is the radial distortion contribution
171  dr = 1.0 + dk1 * rr + dk2 * rr * rr + dk3 * rr * rr * rr;
172 
173  // introducing distortion
174  xt = ux / dr;
175  yt = uy / dr;
176 
177  // distorted point
178  xdistorted = xt;
179  ydistorted = yt;
180 
181  // check for convergence
182  if((fabs(xt - xprevious) <= tolerance) && (fabs(yt - yprevious) <= tolerance)) {
183  bConverged = true;
184  break;
185  }
186 
187  xprevious = xt;
188  yprevious = yt;
189  }
190 
191 
192  if(bConverged) {
193  p_focalPlaneX = xdistorted;
194  p_focalPlaneY = ydistorted;
195  }
196 
197  return bConverged;
198  }
199 }
Isis::CameraDistortionMap::SetDistortion
virtual void SetDistortion(int naifIkCode)
Load distortion coefficients.
Definition: CameraDistortionMap.cpp:58
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::Camera
Definition: Camera.h:236
Isis::LroWideAngleCameraDistortionMap::SetUndistortedFocalPlane
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y.
Definition: LroWideAngleCameraDistortionMap.cpp:141
Isis::LroWideAngleCameraDistortionMap::addFilter
void addFilter(int naifIkCode)
Add an additional set of parameters for a given LROC/WAC filter.
Definition: LroWideAngleCameraDistortionMap.cpp:55
Isis::LroWideAngleCameraDistortionMap::setBand
void setBand(int vband)
Implements band-dependant distortion parameters.
Definition: LroWideAngleCameraDistortionMap.cpp:79
Isis::CameraDistortionMap::p_camera
Camera * p_camera
The camera to distort/undistort.
Definition: CameraDistortionMap.h:63
Isis::LroWideAngleCameraDistortionMap::SetFocalPlane
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y.
Definition: LroWideAngleCameraDistortionMap.cpp:105
Isis::CameraDistortionMap
Distort/undistort focal plane coordinates.
Definition: CameraDistortionMap.h:41
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::Spice::getDouble
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition: Spice.cpp:1039
Isis::CameraDistortionMap::p_odk
std::vector< double > p_odk
Vector of distortion coefficients.
Definition: CameraDistortionMap.h:71
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

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:49