Isis 3 Programmer Reference
ThemisVisDistortionMap.cpp
Go to the documentation of this file.
1 
20 #include <QDebug>
21 #include "ThemisVisDistortionMap.h"
22 
23 
24 using namespace std;
25 
26 namespace Isis {
36  ThemisVisDistortionMap::ThemisVisDistortionMap(Camera *parent) :
37  CameraDistortionMap(parent, 1.0) {
38  // Set necessary constant values
39 
40  // The IR pixel pitch is used by VIS processing because optical distortion corrections are in
41  // terms of IR pixels. Note that the pixel pitch for the instrument currently being processed
42  // is stored in ISIS2's ccd.mmpp.
43  // from IR_PIXEL_PITCH in ISIS2's thm_parameters.def.N
44  p_irPixelPitch = 0.05; // in meters per pixel
45  p_visPixelPitch = 0.009;// in meters per pixel
46 
47  // This value is computed from IR_BAND_FIRST_ROW[5] and
48  // IR_BAND_LAST_ROW[5] in ISIS2's thm_parameters.def.N
49  p_ir_b5_effectiveDetectorLine = (95.0 + 110.0) / 2.0;
50 
51  // from IR_BORESIGHT_LINE in ISIS2's thm_parameters.def.N
52  p_irBoreLine = 109.5;
53  }
54 
55 
56 
57  ThemisVisDistortionMap::~ThemisVisDistortionMap() {
58  }
59 
60 
61 
71 // Optical distortion correction for VIS from lev1u_m01_thm_linesamp_to_pointing() in lev1u_m01_thm_routines.c */
72 
73 // bool ThemisVisDistortionMap::SetFocalPlane(const double dx,
74 // const double dy) {
75 // // first set the distorted x/y, in meters
76 // p_focalPlaneX = dx;
77 // p_focalPlaneY = dy;
78 //
79 //
80 // // Polynomial coefficients for doing optical distortion corrections for the X and Y directions.
81 // // These are for going from pointing to samp/line.
82 // double vis_od_icx[] = { -4.02919e-5, 0.0, 0.0 };// VIS optical distortion inverse coefficients for x
83 // double vis_od_icy[] = { -0.0176112, -0.00718251, 5.52591e-5 };
84 //
85 // // Vertical offset from boresight in IR pixels - positive is DOWN */
86 // double jp = p_focalPlaneY / p_irPixelPitch;
87 //
88 // // IR distortion in vertical direction (pixels) */
89 // // Note that (-jp) is used here because the orientation of positive displacement from the boresight
90 // // in the Y direction assumed for the correction parameters is opposite of the positive direction
91 // // for j.
92 // double deltajp = vis_od_icy[0] + ( vis_od_icy[1] * (-jp)) + ( vis_od_icy[2] * (-jp) * (-jp));
93 //
94 // // Horizontal offset from boresight in IR pixels */
95 // double ip = p_focalPlaneX / p_irPixelPitch;
96 //
97 // // IR stretch factor
98 // double cb1 = vis_od_icx[0] * ((-jp) + p_irBoreLine - ir_b5_effective_detector_line - deltajp);
99 //
100 // // Focal plane horizontal position (in VIS pixels) with the distortion removed
101 // p_undistortedFocalPlaneX = ip * p_irPixelPitch * (1.0 + (cb1 / (1.0 - cb1)));
102 // p_undistortedFocalPlaneY = (jp - deltajp) * p_irPixelPitch;
103 // return true;
104 // }
105 
116  const double uy) {
117  // See the optical distortion correction for VIS section in the
118  // lev1u_m01_thm_vis_pointing_to_linesamp() routine in lev1u_m01_thm_routines.c
119 
120  // Set the focal plane coordinates, in pixels
121  // X direction is perpendicular to the along - track direction;
122  // Y direction is parallel to along-track direction
125 
126  // Constant values
127  // Polynomial coefficients for doing optical distortion corrections for the X and Y directions.
128  // These are for going from samp/line to pointing. Given the X and Y components of the angle
129  // between the boresight and the look vector for a given detector sample/line coordinate,
130  // these factors are used to compute a detector sample coordinate that will give a look
131  // vector corresponding to where the given look vector (detector sample/line) is
132  // really looking on the planet
133  // (values read from VIS_OD_CX and VIS_OD_CY[N] in thm_parameters.def.7.2, last updated 03/2003)
134  double vis_od_cx[] = { -4.02919e-5, 0.0, 0.0 }; // VIS optical distortion coefficients for x
135  double vis_od_cy[] = { -0.0178649, -0.00727843, 5.65278e-5 };
136 
137  // Calculate necessary intermediate values
138 
139  // compute IR pixels(lines) relative to boresight
141 
142  // IR distortion in Y (pixels)
143  // Note that (-j) is used here because the orientation of positive displacement from the boresight in the Y
144  // direction assumed for the correction parameters is opposite of the positive direction for j.
145  double deltaj = vis_od_cy[0] + ( vis_od_cy[1] * (-j)) + ( vis_od_cy[2] * (-j) * (-j));
146 
147  // IR stretch factor in X direction
148  // Note that (-j) is used here because the orientation of positive displacement from the boresight in the Y
149  // direction assumed for the correction parameters is opposite of the positive direction for j.
150  double cb1 = vis_od_cx[0] * ((-j) + p_irBoreLine - p_ir_b5_effectiveDetectorLine);
151 
152  // Corrected X location relative to boresight in focal plane of ideal camera (meters)
153  // Focal plane coordinates, in meters
154  p_focalPlaneX = p_undistortedFocalPlaneX * (1.0 + cb1);
155  p_focalPlaneY = p_irPixelPitch * (j + deltaj);
156 
157  return true;
158  }
159 
160 
161 
172  const double dy) {
173  // VIS optical distortion inverse coefficients for x and y, respectively
174  double vis_od_cx[] = { -4.02919e-5, 0.0, 0.0 };
175  double vis_od_cy[] = { -0.0178649, -0.00727843, 5.65278e-5 };
176  int numAttempts;
177  double delta;
178  bool done = false;
179 
180  // set the focal plane coordinates, in meters relative to boresight
181  p_focalPlaneX = dx;
182  p_focalPlaneY = dy;
183 
184  numAttempts = 1;
185  delta = 0.00001;
186 
187  double dx_guess, dy_guess;
188  double ux_guess, uy_guess;
189 
190  // "solve" undistorted focal plane equations for ux and uy to get beginning offset
191  double xOffset = -dy / p_irPixelPitch * vis_od_cx[0]
192  + vis_od_cx[0] * p_irBoreLine
193  - vis_od_cx[0] * p_ir_b5_effectiveDetectorLine;
194  double yOffset = p_irPixelPitch * vis_od_cy[0] / dy
195  - vis_od_cy[1]
196  + dy / p_irPixelPitch * vis_od_cy[2];
197 
198  while (!done) {
199  // In this loop, we will use the current offset to make a guess at the
200  // undistorted focal plane coordinate that corresponds to the known
201  // distorted focal plane coordinate.
202  //
203  // The offset is updated using the undistored guess.
204  //
205  // Each undistorted guess will be tested by reversing the equation used to
206  // compute the current undistorted guess to get a corresponding distorted
207  // coordinate.
208  //
209  // If this distorted coordinate that corresponds to the current undistorted
210  // guess is close enough to the known distorted coordinate, then we will
211  // accept the corresponding undistorted coordinate as our solution and end
212  // the loop.
213  // guesses are based on the known distorted x/y values and the offset
214  ux_guess = dx / (1.0 + xOffset);
215  uy_guess = dy / (1.0 + yOffset);
216 
217  // offset is updated with each undistored x and y guess
218  xOffset = -uy_guess / p_irPixelPitch * vis_od_cx[0]
219  + vis_od_cx[0] * p_irBoreLine
220  - vis_od_cx[0] * p_ir_b5_effectiveDetectorLine;
221  yOffset = p_irPixelPitch * vis_od_cy[0] / uy_guess
222  - vis_od_cy[1]
223  + uy_guess / p_irPixelPitch * vis_od_cy[2];
224 
225  // find the distorted x/y corresponding to the undistorted x/y guess
226  dx_guess = ux_guess * (1.0 + xOffset);
227  dy_guess = uy_guess * (1.0 + yOffset);
228 
229  // if the distorted (x,y) corresponding to the undistorted (x,y) guesses
230  // are close enough to the known distorted (x,y), then we are done...
231  if ((abs(dy_guess - dy) < delta) && (abs(dx_guess - dx) < delta)) {
232  done = true;
233  }
234 
235  // if we exceed the number of allowed attempts, return that this method failed
236  numAttempts++;
237  if (numAttempts > 20) {
238  return false;
239  }
240  }
241 
242  // use the undistorted x/y whose corresponding distorted x/y are both close enough to the known
243  // distorted x/y
244  p_undistortedFocalPlaneX = ux_guess;
245  p_undistortedFocalPlaneY = uy_guess;
246  return true;
247 
248  }
249 
250 
251 }
252 //svn commit -m "PROG: Documented existing optical distortion algorithms in ThemisVisDistortionMap using information from ISIS2 lev1u_m01_thm_routines.c." src/odyssey/objs/ThemisVisCamera/ThemisVisDistortionMap.cpp src/odyssey/objs/ThemisVisCamera/ThemisVisDistortionMap.h
double p_focalPlaneX
Distorted focal plane x.
double p_visPixelPitch
Pixel Pitch for Themis Vis Camera (in meters per pixel).
Namespace for the standard library.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
double p_irBoreLine
The bore line for Themis IR instrument.
Distort/undistort focal plane coordinates.
double p_ir_b5_effectiveDetectorLine
Effective 1-based detector line number used for observing the Band 5, i.e., average of the 16 detecto...
double p_focalPlaneY
Distorted focal plane y.
double p_irPixelPitch
Pixel Pitch for Themis Ir Camera (in meters per pixel).
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Sets the focal plane value for the distortion map.
virtual bool SetFocalPlane(const double dx, const double dy)
Sets the focal plane value for the distortion map.