Isis 3 Programmer Reference
ThemisVisDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <QDebug>
10 #include "ThemisVisDistortionMap.h"
11 
12 
13 using namespace std;
14 
15 namespace Isis {
25  ThemisVisDistortionMap::ThemisVisDistortionMap(Camera *parent) :
26  CameraDistortionMap(parent, 1.0) {
27  // Set necessary constant values
28 
29  // The IR pixel pitch is used by VIS processing because optical distortion corrections are in
30  // terms of IR pixels. Note that the pixel pitch for the instrument currently being processed
31  // is stored in ISIS2's ccd.mmpp.
32  // from IR_PIXEL_PITCH in ISIS2's thm_parameters.def.N
33  p_irPixelPitch = 0.05; // in meters per pixel
34  p_visPixelPitch = 0.009;// in meters per pixel
35 
36  // This value is computed from IR_BAND_FIRST_ROW[5] and
37  // IR_BAND_LAST_ROW[5] in ISIS2's thm_parameters.def.N
38  p_ir_b5_effectiveDetectorLine = (95.0 + 110.0) / 2.0;
39 
40  // from IR_BORESIGHT_LINE in ISIS2's thm_parameters.def.N
41  p_irBoreLine = 109.5;
42  }
43 
44 
45 
46  ThemisVisDistortionMap::~ThemisVisDistortionMap() {
47  }
48 
49 
50 
60 // Optical distortion correction for VIS from lev1u_m01_thm_linesamp_to_pointing() in lev1u_m01_thm_routines.c */
61 
62 // bool ThemisVisDistortionMap::SetFocalPlane(const double dx,
63 // const double dy) {
64 // // first set the distorted x/y, in meters
65 // p_focalPlaneX = dx;
66 // p_focalPlaneY = dy;
67 //
68 //
69 // // Polynomial coefficients for doing optical distortion corrections for the X and Y directions.
70 // // These are for going from pointing to samp/line.
71 // double vis_od_icx[] = { -4.02919e-5, 0.0, 0.0 };// VIS optical distortion inverse coefficients for x
72 // double vis_od_icy[] = { -0.0176112, -0.00718251, 5.52591e-5 };
73 //
74 // // Vertical offset from boresight in IR pixels - positive is DOWN */
75 // double jp = p_focalPlaneY / p_irPixelPitch;
76 //
77 // // IR distortion in vertical direction (pixels) */
78 // // Note that (-jp) is used here because the orientation of positive displacement from the boresight
79 // // in the Y direction assumed for the correction parameters is opposite of the positive direction
80 // // for j.
81 // double deltajp = vis_od_icy[0] + ( vis_od_icy[1] * (-jp)) + ( vis_od_icy[2] * (-jp) * (-jp));
82 //
83 // // Horizontal offset from boresight in IR pixels */
84 // double ip = p_focalPlaneX / p_irPixelPitch;
85 //
86 // // IR stretch factor
87 // double cb1 = vis_od_icx[0] * ((-jp) + p_irBoreLine - ir_b5_effective_detector_line - deltajp);
88 //
89 // // Focal plane horizontal position (in VIS pixels) with the distortion removed
90 // p_undistortedFocalPlaneX = ip * p_irPixelPitch * (1.0 + (cb1 / (1.0 - cb1)));
91 // p_undistortedFocalPlaneY = (jp - deltajp) * p_irPixelPitch;
92 // return true;
93 // }
94 
105  const double uy) {
106  // See the optical distortion correction for VIS section in the
107  // lev1u_m01_thm_vis_pointing_to_linesamp() routine in lev1u_m01_thm_routines.c
108 
109  // Set the focal plane coordinates, in pixels
110  // X direction is perpendicular to the along - track direction;
111  // Y direction is parallel to along-track direction
114 
115  // Constant values
116  // Polynomial coefficients for doing optical distortion corrections for the X and Y directions.
117  // These are for going from samp/line to pointing. Given the X and Y components of the angle
118  // between the boresight and the look vector for a given detector sample/line coordinate,
119  // these factors are used to compute a detector sample coordinate that will give a look
120  // vector corresponding to where the given look vector (detector sample/line) is
121  // really looking on the planet
122  // (values read from VIS_OD_CX and VIS_OD_CY[N] in thm_parameters.def.7.2, last updated 03/2003)
123  double vis_od_cx[] = { -4.02919e-5, 0.0, 0.0 }; // VIS optical distortion coefficients for x
124  double vis_od_cy[] = { -0.0178649, -0.00727843, 5.65278e-5 };
125 
126  // Calculate necessary intermediate values
127 
128  // compute IR pixels(lines) relative to boresight
130 
131  // IR distortion in Y (pixels)
132  // Note that (-j) is used here because the orientation of positive displacement from the boresight in the Y
133  // direction assumed for the correction parameters is opposite of the positive direction for j.
134  double deltaj = vis_od_cy[0] + ( vis_od_cy[1] * (-j)) + ( vis_od_cy[2] * (-j) * (-j));
135 
136  // IR stretch factor in X direction
137  // Note that (-j) is used here because the orientation of positive displacement from the boresight in the Y
138  // direction assumed for the correction parameters is opposite of the positive direction for j.
139  double cb1 = vis_od_cx[0] * ((-j) + p_irBoreLine - p_ir_b5_effectiveDetectorLine);
140 
141  // Corrected X location relative to boresight in focal plane of ideal camera (meters)
142  // Focal plane coordinates, in meters
143  p_focalPlaneX = p_undistortedFocalPlaneX * (1.0 + cb1);
144  p_focalPlaneY = p_irPixelPitch * (j + deltaj);
145 
146  return true;
147  }
148 
149 
150 
161  const double dy) {
162  // VIS optical distortion inverse coefficients for x and y, respectively
163  double vis_od_cx[] = { -4.02919e-5, 0.0, 0.0 };
164  double vis_od_cy[] = { -0.0178649, -0.00727843, 5.65278e-5 };
165  int numAttempts;
166  double delta;
167  bool done = false;
168 
169  // set the focal plane coordinates, in meters relative to boresight
170  p_focalPlaneX = dx;
171  p_focalPlaneY = dy;
172 
173  numAttempts = 1;
174  delta = 0.00001;
175 
176  double dx_guess, dy_guess;
177  double ux_guess, uy_guess;
178 
179  // "solve" undistorted focal plane equations for ux and uy to get beginning offset
180  double xOffset = -dy / p_irPixelPitch * vis_od_cx[0]
181  + vis_od_cx[0] * p_irBoreLine
182  - vis_od_cx[0] * p_ir_b5_effectiveDetectorLine;
183  double yOffset = p_irPixelPitch * vis_od_cy[0] / dy
184  - vis_od_cy[1]
185  + dy / p_irPixelPitch * vis_od_cy[2];
186 
187  while (!done) {
188  // In this loop, we will use the current offset to make a guess at the
189  // undistorted focal plane coordinate that corresponds to the known
190  // distorted focal plane coordinate.
191  //
192  // The offset is updated using the undistored guess.
193  //
194  // Each undistorted guess will be tested by reversing the equation used to
195  // compute the current undistorted guess to get a corresponding distorted
196  // coordinate.
197  //
198  // If this distorted coordinate that corresponds to the current undistorted
199  // guess is close enough to the known distorted coordinate, then we will
200  // accept the corresponding undistorted coordinate as our solution and end
201  // the loop.
202  // guesses are based on the known distorted x/y values and the offset
203  ux_guess = dx / (1.0 + xOffset);
204  uy_guess = dy / (1.0 + yOffset);
205 
206  // offset is updated with each undistored x and y guess
207  xOffset = -uy_guess / p_irPixelPitch * vis_od_cx[0]
208  + vis_od_cx[0] * p_irBoreLine
209  - vis_od_cx[0] * p_ir_b5_effectiveDetectorLine;
210  yOffset = p_irPixelPitch * vis_od_cy[0] / uy_guess
211  - vis_od_cy[1]
212  + uy_guess / p_irPixelPitch * vis_od_cy[2];
213 
214  // find the distorted x/y corresponding to the undistorted x/y guess
215  dx_guess = ux_guess * (1.0 + xOffset);
216  dy_guess = uy_guess * (1.0 + yOffset);
217 
218  // if the distorted (x,y) corresponding to the undistorted (x,y) guesses
219  // are close enough to the known distorted (x,y), then we are done...
220  if ((abs(dy_guess - dy) < delta) && (abs(dx_guess - dx) < delta)) {
221  done = true;
222  }
223 
224  // if we exceed the number of allowed attempts, return that this method failed
225  numAttempts++;
226  if (numAttempts > 20) {
227  return false;
228  }
229  }
230 
231  // use the undistorted x/y whose corresponding distorted x/y are both close enough to the known
232  // distorted x/y
233  p_undistortedFocalPlaneX = ux_guess;
234  p_undistortedFocalPlaneY = uy_guess;
235  return true;
236 
237  }
238 
239 
240 }
241 //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
Isis::ThemisVisDistortionMap::p_irBoreLine
double p_irBoreLine
The bore line for Themis IR instrument.
Definition: ThemisVisDistortionMap.h:53
Isis::ThemisVisDistortionMap::p_irPixelPitch
double p_irPixelPitch
Pixel Pitch for Themis Ir Camera (in meters per pixel).
Definition: ThemisVisDistortionMap.h:46
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::ThemisVisDistortionMap::SetUndistortedFocalPlane
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Sets the focal plane value for the distortion map.
Definition: ThemisVisDistortionMap.cpp:104
Isis::ThemisVisDistortionMap::p_visPixelPitch
double p_visPixelPitch
Pixel Pitch for Themis Vis Camera (in meters per pixel).
Definition: ThemisVisDistortionMap.h:47
Isis::CameraDistortionMap
Distort/undistort focal plane coordinates.
Definition: CameraDistortionMap.h:41
Isis::ThemisVisDistortionMap::SetFocalPlane
virtual bool SetFocalPlane(const double dx, const double dy)
Sets the focal plane value for the distortion map.
Definition: ThemisVisDistortionMap.cpp:160
std
Namespace for the standard library.
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
Isis::ThemisVisDistortionMap::p_ir_b5_effectiveDetectorLine
double p_ir_b5_effectiveDetectorLine
Effective 1-based detector line number used for observing the Band 5, i.e., average of the 16 detecto...
Definition: ThemisVisDistortionMap.h:49