Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated distortion to closer match ISIS #243

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/usgscsm/Distortion.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ void removeDistortion(double dx, double dy, double &ux, double &uy,
void applyDistortion(double ux, double uy, double &dx, double &dy,
const std::vector<double> opticalDistCoeffs,
DistortionType distortionType,
const double desiredPrecision = 0, const double tolerance = 1.0E-6);
const double desiredPrecision = 1.0E-6, const double tolerance = 1.0E-6);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this one argument, the tolerance. The desired precision should be handled by the model that calls this and converted into a convergence tolerance.

#endif
11 changes: 7 additions & 4 deletions src/Distortion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ void removeDistortion(double dx, double dy, double &ux, double &uy,
case RADIAL: {
double rr = dx * dx + dy * dy;

if (rr > tolerance)
{
if (rr > tolerance) {
double dr = opticalDistCoeffs[0] + (rr * (opticalDistCoeffs[1] + rr * opticalDistCoeffs[2]));

ux = dx * (1.0 - dr);
uy = dy * (1.0 - dr);
}
Expand Down Expand Up @@ -306,17 +306,19 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
// Compute first fractional distortion using rp
double drOverR = opticalDistCoeffs[0]
+ (rp2 * (opticalDistCoeffs[1] + (rp2 * opticalDistCoeffs[2])));

// Compute first distorted point estimate, r
double r = rp + (drOverR * rp);
double r_prev, r2_prev;
int iteration = 0;

do {
// Don't get in an end-less loop. This algorithm should
// converge quickly. If not then we are probably way outside
// of the focal plane. Just set the distorted position to the
// undistorted position. Also, make sure the focal plane is less
// than 1km, it is unreasonable for it to grow larger than that.
if (iteration >= 15 || r > 1E9) {
if (iteration >= 20 || r > 1E9) {
drOverR = 0.0;
break;
}
Expand All @@ -332,7 +334,8 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
r = rp + (drOverR * r_prev);
iteration++;
}
while (fabs(r * (1 - drOverR) - rp) > desiredPrecision);
while (fabs(r - r_prev) > desiredPrecision);

dx = ux / (1.0 - drOverR);
dy = uy / (1.0 - drOverR);
}
Expand Down