Isis 3 Programmer Reference
LoHighDistortionMap.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "LoHighDistortionMap.h"
10 #include "IString.h"
11 
12 using namespace std;
13 
14 namespace Isis {
27  LoHighDistortionMap::LoHighDistortionMap(Camera *parent) :
28  CameraDistortionMap(parent, -1) {
29  }
30 
31 
84  void LoHighDistortionMap::SetDistortion(const int naifIkCode) {
85  // Get the perspective correction factors for x and y and the distortion
86  // center (point of symmetry of distortion)
87  QString perskey = "INS" + toString(naifIkCode) + "_PERSPECTIVE_FACTORS";
88  QString centkey = "INS" + toString(naifIkCode) + "_POINT_OF_SYMMETRY";
89  p_xPerspective = p_camera->Spice::getDouble(perskey, 0);
90  p_yPerspective = p_camera->Spice::getDouble(perskey, 1);
91  p_x0 = p_camera->Spice::getDouble(centkey, 0);
92  p_y0 = p_camera->Spice::getDouble(centkey, 1);
93 
94  // Get the distortion coefficients
96  }
97 
98 
114  const double dy) {
115  p_focalPlaneX = dx;
116  p_focalPlaneY = dy;
117 
118  // Apply perspective correction factors to get perspective corrected x/y
119  double perspectiveFactor = 1. + (p_xPerspective * dx) + (p_yPerspective * dy);
120  double pcx = dx * perspectiveFactor;
121  double pcy = dy * perspectiveFactor;
122 
123  // Translate the perspective-corrected x/y coordinate to be relative to the
124  // distortion point of symmetry
125  double distx = pcx - p_x0;
126  double disty = pcy - p_y0;
127 
128  // Get the distance from the focal plane center and if we are close
129  // skip the distortion
130  double r2 = distx * distx + disty * disty;
131  if(r2 <= 1.0E-6) {
134  return true;
135  }
136 
137  // Otherwise remove distortion
138  double drOverR = p_odk[0] + p_odk[1] * r2;
139  p_undistortedFocalPlaneX = pcx - (drOverR * distx);
140  p_undistortedFocalPlaneY = pcy - (drOverR * disty);
141  return true;
142  }
143 
144 
164  const double uy) {
165 
168 
169  // Translate the distorted x/y coordinate to be relative to the
170  // distortion point of symmetry
171  double distux = p_undistortedFocalPlaneX - p_x0;
172  double distuy = p_undistortedFocalPlaneY - p_y0;
173 
174  // Compute the distance from the focal plane center and if we are
175  // close to the center then no distortion is required
176  double rp2 = distux * distux + distuy * distuy;
177 
178  double pcx, pcy;
179 
180  if(rp2 > 1.0E-6) {
181 
182  // Add distortion. First compute fractional distortion at rp (r-prime)
183  double drOverR = p_odk[0] + rp2 * p_odk[1];
184 
185  // Compute the perspective corrected x/y
186  pcx = p_undistortedFocalPlaneX + (distux * drOverR);
187  pcy = p_undistortedFocalPlaneY + (distuy * drOverR);
188  }
189  else {
192  }
193 
194  // Add the perspective error
195  double perspectiveCorrection = 1. - (p_xPerspective * pcx) - (p_yPerspective * pcy);
196  p_focalPlaneX = pcx * perspectiveCorrection;
197  p_focalPlaneY = pcy * perspectiveCorrection;
198  return true;
199  }
200 }
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::LoHighDistortionMap::p_yPerspective
double p_yPerspective
Perspective correction factor in y.
Definition: LoHighDistortionMap.h:63
Isis::CameraDistortionMap::p_undistortedFocalPlaneX
double p_undistortedFocalPlaneX
Undistorted focal plane x.
Definition: CameraDistortionMap.h:67
Isis::LoHighDistortionMap::SetFocalPlane
virtual bool SetFocalPlane(const double dx, const double dy)
Compute undistorted focal plane x/y for Lo High Resolution Camera.
Definition: LoHighDistortionMap.cpp:113
Isis::Camera
Definition: Camera.h:236
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::LoHighDistortionMap::p_y0
double p_y0
Center of distortion on y axis.
Definition: LoHighDistortionMap.h:65
Isis::CameraDistortionMap::p_camera
Camera * p_camera
The camera to distort/undistort.
Definition: CameraDistortionMap.h:63
Isis::CameraDistortionMap
Distort/undistort focal plane coordinates.
Definition: CameraDistortionMap.h:41
Isis::LoHighDistortionMap::p_x0
double p_x0
Center of distortion on x axis.
Definition: LoHighDistortionMap.h:64
std
Namespace for the standard library.
Isis::E
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:39
Isis::LoHighDistortionMap::SetUndistortedFocalPlane
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Compute distorted focal plane x/y for Lo High Resolution Camera.
Definition: LoHighDistortionMap.cpp:163
Isis::LoHighDistortionMap::p_xPerspective
double p_xPerspective
Perspective correction factor in x.
Definition: LoHighDistortionMap.h:62
Isis::LoHighDistortionMap::SetDistortion
void SetDistortion(const int naifIkCode)
Load LO High Resolution Camera perspective & distortion coefficients.
Definition: LoHighDistortionMap.cpp:84
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