From c97ec71a43df39f1125d7cd3ade18fc3317aee92 Mon Sep 17 00:00:00 2001
From: Jesse Mapel <jam826@nau.edu>
Date: Mon, 18 Mar 2019 07:18:28 -0700
Subject: [PATCH] Fixed reading junk data, also cleaned up groundToImage (#202)

* Fixed reading junk data when interpolating postion and velocity

* Fixed ground to image not using height in checks

* Removed old bisection method check in ground to image
---
 src/UsgsAstroLsSensorModel.cpp | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/UsgsAstroLsSensorModel.cpp b/src/UsgsAstroLsSensorModel.cpp
index e11c513..0fe525b 100644
--- a/src/UsgsAstroLsSensorModel.cpp
+++ b/src/UsgsAstroLsSensorModel.cpp
@@ -479,8 +479,10 @@ csm::ImageCoord UsgsAstroLsSensorModel::groundToImage(
    else {
       --approxNextPoint.line;
    }
-   csm::EcefCoord approxIntersect = imageToGround(approxPoint, 0);
-   csm::EcefCoord approxNextIntersect = imageToGround(approxNextPoint, 0);
+   double height, aPrec;
+   computeElevation(ground_pt.x, ground_pt.y, ground_pt.z, height, aPrec, desired_precision);
+   csm::EcefCoord approxIntersect = imageToGround(approxPoint, height);
+   csm::EcefCoord approxNextIntersect = imageToGround(approxNextPoint, height);
    double lineDX = approxNextIntersect.x - approxIntersect.x;
    double lineDY = approxNextIntersect.y - approxIntersect.y;
    double lineDZ = approxNextIntersect.z - approxIntersect.z;
@@ -495,15 +497,6 @@ csm::ImageCoord UsgsAstroLsSensorModel::groundToImage(
    double firstOffset = computeViewingPixel(firstTime, ground_pt, adj, pixelPrec/2).line - 0.5;
    double lastOffset = computeViewingPixel(lastTime, ground_pt, adj, pixelPrec/2).line - 0.5;
 
-   // Check if both offsets have the same sign.
-   // This means there is not guaranteed to be a zero.
-   if ((firstOffset > 0) != (lastOffset < 0)) {
-        throw csm::Warning(
-           csm::Warning::IMAGE_COORD_OUT_OF_BOUNDS,
-           "The image coordinate is out of bounds of the image size.",
-           "UsgsAstroLsSensorModel::groundToImage");
-   }
-
    // Start secant method search
    for (int it = 0; it < 30; it++) {
       double nextTime = ((firstTime * lastOffset) - (lastTime * firstOffset))
@@ -565,7 +558,7 @@ csm::ImageCoord UsgsAstroLsSensorModel::groundToImage(
    calculatedPixel.line += closestLine;
 
    // Reintersect to ensure the image point actually views the ground point.
-   csm::EcefCoord calculatedPoint = imageToGround(calculatedPixel, 0);
+   csm::EcefCoord calculatedPoint = imageToGround(calculatedPixel, height);
    double dx = ground_pt.x - calculatedPoint.x;
    double dy = ground_pt.y - calculatedPoint.y;
    double dz = ground_pt.z - calculatedPoint.z;
@@ -2111,10 +2104,10 @@ void UsgsAstroLsSensorModel::getAdjSensorPosVel(
    if (m_platformFlag == 0)
       nOrder = 4;
    double sensPosNom[3];
-   lagrangeInterp(m_numPositions, &m_positions[0], m_t0Ephem, m_dtEphem,
+   lagrangeInterp(m_numPositions/3, &m_positions[0], m_t0Ephem, m_dtEphem,
       time, 3, nOrder, sensPosNom);
    double sensVelNom[3];
-   lagrangeInterp(m_numPositions, &m_velocities[0], m_t0Ephem, m_dtEphem,
+   lagrangeInterp(m_numPositions/3, &m_velocities[0], m_t0Ephem, m_dtEphem,
       time, 3, nOrder, sensVelNom);
    // Compute rotation matrix from ICR to ECF
 
-- 
GitLab