diff --git a/src/Distortion.cpp b/src/Distortion.cpp index 5c08ed6b6ee1da0b264d689d91b5087b7591967f..a40ae12d334a26e7036b6267f6b75dbf12995541 100644 --- a/src/Distortion.cpp +++ b/src/Distortion.cpp @@ -204,14 +204,11 @@ void removeDistortion(double dx, double dy, double &ux, double &uy, double r = sqrt(r2); double r3 = r2 * r; - int xPointer = 0; - int yPointer = 5; - double dr_x = odkx[0] + odkx[1] * r + odkx[2] * r2 + odkx[3] * r3; double dr_y = odky[0] + odky[1] * r + odky[2] * r2 + odky[3] * r3; - ux = dx + dr_x + boresightX; - uy = dy + dr_y + boresightY; + ux += dr_x + boresightX; + uy += dr_y + boresightY; } break; // The dawn distortion model is "reversed" from other distortion models so @@ -593,8 +590,8 @@ void applyDistortion(double ux, double uy, double &dx, double &dy, iteration++; } while (fabs(r - r_prev) > desiredPrecision); - dx = ux / (1.0 - drOverR); - dy = uy / (1.0 - drOverR); + dx = shiftedUx / (1.0 - drOverR); + dy = shiftedUy / (1.0 - drOverR); dx += opticalDistCoeffs[3]; dy += opticalDistCoeffs[4]; } diff --git a/tests/DistortionTests.cpp b/tests/DistortionTests.cpp index 7c003584fb2aefa92b6c0e7c60a90848b19ba1a1..1c4443226b2d7d78ff95bfa92d14edea0f813030 100644 --- a/tests/DistortionTests.cpp +++ b/tests/DistortionTests.cpp @@ -324,3 +324,59 @@ TEST(LroLrocNac, testZeroCoeffs) { ASSERT_DOUBLE_EQ(ux, 0.0); ASSERT_DOUBLE_EQ(uy, 0.0); } + +INSTANTIATE_TEST_SUITE_P(CahvorTest, CoeffOffsetParameterizedTest, + ::testing::Values(std::vector<double>(2, 0), + std::vector<double>(2, 1))); + +TEST_P(CoeffOffsetParameterizedTest, RemoveDistortionCahvorTest) +{ + csm::ImageCoord imagePt(0.0, 4.0); + + double ux, uy; + std::vector<double> offsets = GetParam(); + std::vector<double> coeffs = {0, 0, 0}; + coeffs.insert(coeffs.end(), offsets.begin(), offsets.end()); + + removeDistortion(imagePt.samp, imagePt.line, ux, uy, coeffs, + DistortionType::CAHVOR); + + EXPECT_NEAR(ux, 4, 1e-8); + EXPECT_NEAR(uy, 0, 1e-8); +} + +// If coeffs are 0 then this will have the same result as removeDistortion +// with 0 distortion coefficients +TEST_P(CoeffOffsetParameterizedTest, InverseDistortionCahvorTest) +{ + csm::ImageCoord imagePt(0.0, 4.0); + + double dx, dy; + double desiredPrecision = 0.01; + std::vector<double> offsets = GetParam(); + std::vector<double> coeffs = {0, 0, 0}; + coeffs.insert(coeffs.end(), offsets.begin(), offsets.end()); + + applyDistortion(imagePt.samp, imagePt.line, dx, dy, coeffs, + DistortionType::CAHVOR, desiredPrecision); + + EXPECT_NEAR(dx, 4, 1e-8); + EXPECT_NEAR(dy, 0, 1e-8); +} + +TEST_P(CoeffOffsetParameterizedTest, InverseOnesCoeffsCahvorTest) +{ + csm::ImageCoord imagePt(0.0, 4.0); + + double dx, dy; + double desiredPrecision = 0.01; + std::vector<double> offsets = GetParam(); + std::vector<double> coeffs = {1, 1, 1}; + coeffs.insert(coeffs.end(), offsets.begin(), offsets.end()); + + applyDistortion(imagePt.samp, imagePt.line, dx, dy, coeffs, + DistortionType::CAHVOR, desiredPrecision); + + EXPECT_NEAR(dx, 4, 1e-8); + EXPECT_NEAR(dy, 0, 1e-8); +} diff --git a/tests/Fixtures.h b/tests/Fixtures.h index c1a19adb1722b8522b69fed9ee8dc3ff15790698..2b5b053c537467c052dab6d212a1bde8f3c6ed7f 100644 --- a/tests/Fixtures.h +++ b/tests/Fixtures.h @@ -177,6 +177,9 @@ class ConstVelLineScanIsdTest : public ::testing::Test { class ImageCoordParameterizedTest : public ::testing::TestWithParam<csm::ImageCoord> {}; +class CoeffOffsetParameterizedTest + : public ::testing::TestWithParam<std::vector<double>> {}; + class FramerParameterizedTest : public ::testing::TestWithParam<csm::ImageCoord> { protected: