Isis 3 Programmer Reference
Hyb2OncDistortionMap.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include <QDebug>
10#include <QtGlobal>
11#include <QtMath>
12
13#include "Hyb2OncDistortionMap.h"
14
15namespace Isis {
31 : CameraDistortionMap(parent, zDirection) {
32 }
33
34
40
41
59 bool Hyb2OncDistortionMap::SetFocalPlane(double dx, double dy) {
60 p_focalPlaneX = dx;
61 p_focalPlaneY = dy;
62
63 // reducing to principal point offset (xp,yp)
64 double x = dx;// - p_xp;
65 double y = dy;// - p_yp;
66 //
67 // Get the distance from the focal plane center and if we are close
68 // then skip the distortion (this prevents division by zero)
69 double r = (x * x) + (y * y);
70 double r2 = r*r;
71 double r4 = r2*r2;
72 if (r <= 1.0E-6) {
75 return true;
76 }
77
78 // apply distortion correction
79 // r = x^2 + y^2
80 // rprime = L0*r + L1*r^3 + L2*r^5, where Li are distortion coeffs
81 // "dr" is rprime divided by r, used to reduce operations
82 double dr = p_odk[0] + p_odk[1] * r2 + p_odk[2] * r4;
85 return true;
86 }
87
88
109 const double uy) {
112
113 // Compute the distance from the focal plane center and if we are
114 // close to the center then no distortion is required
115
116 bool converged = false;
117 int iteration = 0;
118 double tolMilliMeters = p_camera->PixelPitch() / 100.0;
119 double x = ux;
120 double y = uy;
121 double r = (x * x) + (y * y);
122 if (r <= 1.0E-6) {
123 p_focalPlaneX = ux;
124 p_focalPlaneY = uy;
125 return true;
126 }
127 double rPrevious = r;
128
129 while (!converged && qAbs(r - rPrevious) > tolMilliMeters) {
130 double r2 = r*r;
131 double r4 = r2*r2;
132 double dr = p_odk[0] + p_odk[1] * r2 + p_odk[2] * r4;
133 rPrevious = r;
134 x = dr * x;
135 y = dr * y;
136 r = x*x + y*y;
137
138 iteration++;
139 if (iteration > 50) {
140 converged = false;
141 break;
142 }
143 }
144
145 converged = true;
146 p_focalPlaneX = x;
147 p_focalPlaneY = y;
148
149 return converged;
150 }
151
152}
Distort/undistort focal plane coordinates.
double p_focalPlaneX
Distorted focal plane x.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
std::vector< double > p_odk
Vector of distortion coefficients.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Camera * p_camera
The camera to distort/undistort.
double p_focalPlaneY
Distorted focal plane y.
double PixelPitch() const
Returns the pixel pitch.
Definition Camera.cpp:2772
virtual bool SetFocalPlane(double dx, double dy)
Compute undistorted focal plane x/y.
Hyb2OncDistortionMap(Camera *parent, double zDirection=1.0)
Hayabusa 2 ONC Camera distortion map constructor.
virtual ~Hyb2OncDistortionMap()
Destructor.
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16