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

Cahvor fix #490

Merged
merged 2 commits into from
Feb 25, 2025
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ release.

## [Unreleased]

### Fixed
- Fixed CAHVOR model optical shifts by removing tolerance check [#488](https://github.com/DOI-USGS/usgscsm/issues/488)

## [2.0.1] - 2024-01-23

### Changed
Expand All @@ -51,4 +54,4 @@ release.
- Updated ALE submodule [#470](https://github.com/DOI-USGS/usgscsm/pull/470)

### Fixed
- Fixed issue with radial distortion computation [#464](https://github.com/DOI-USGS/usgscsm/pull/464)
- Fixed issue with radial distortion computation [#464](https://github.com/DOI-USGS/usgscsm/pull/464)
96 changes: 45 additions & 51 deletions src/Distortion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,13 @@ void removeDistortion(double dx, double dy, double &ux, double &uy,
double shiftedDy = dy - opticalDistCoeffs[4];
double rr = shiftedDx * shiftedDx + shiftedDy * shiftedDy;

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

ux = shiftedDx * (1.0 - dr);
uy = shiftedDy * (1.0 - dr);
ux += opticalDistCoeffs[3];
uy += opticalDistCoeffs[4];
}
ux = shiftedDx * (1.0 - dr);
uy = shiftedDy * (1.0 - dr);
ux += opticalDistCoeffs[3];
uy += opticalDistCoeffs[4];
}
break;

Expand Down Expand Up @@ -587,51 +584,48 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
double shiftedUx = ux - opticalDistCoeffs[3];
double shiftedUy = uy - opticalDistCoeffs[4];
double rp2 = (ux * ux) + (uy * uy);
double rp = sqrt(rp2);
// Compute first fractional distortion using rp
double drOverR =
opticalDistCoeffs[0] +
(rp2 * (opticalDistCoeffs[1] + (rp2 * opticalDistCoeffs[2])));

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

do
{
double rp = sqrt(rp2);
// 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 >= 20 || r > 1E9)
{
// 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 >= 20 || r > 1E9)
{
drOverR = 0.0;
break;
}

r_prev = r;
r2_prev = r * r;

// Compute new fractional distortion:
drOverR = opticalDistCoeffs[0] +
(r2_prev *
(opticalDistCoeffs[1] + (r2_prev * opticalDistCoeffs[2])));

// Compute new estimate of r
r = rp + (drOverR * r_prev);
iteration++;
} while (fabs(r - r_prev) > desiredPrecision);

dx = shiftedUx / (1.0 - drOverR);
dy = shiftedUy / (1.0 - drOverR);
dx += opticalDistCoeffs[3];
dy += opticalDistCoeffs[4];
}
drOverR = 0.0;
break;
}

r_prev = r;
r2_prev = r * r;

// Compute new fractional distortion:
drOverR = opticalDistCoeffs[0] +
(r2_prev *
(opticalDistCoeffs[1] + (r2_prev * opticalDistCoeffs[2])));

// Compute new estimate of r
r = rp + (drOverR * r_prev);
iteration++;
} while (fabs(r - r_prev) > desiredPrecision);

dx = shiftedUx / (1.0 - drOverR);
dy = shiftedUy / (1.0 - drOverR);
dx += opticalDistCoeffs[3];
dy += opticalDistCoeffs[4];

}
break;

Expand Down
Loading