Commit 64481685 authored by acpaquette's avatar acpaquette Committed by Jesse Mapel
Browse files

Dawn Distortion (#231)

* Added more logging to various functions

* Updated distortion and warning parseing

* Removed duplicate distortion models for kaguya

* Adds the dawn radial distortion model

* Updated comments in distortion and the line scanner

* Updated dawn distortion logic

* Removed duplicate logging statement in the frame sensor

* Updated dawn distortion model and added tests
parent 6d331383
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -9,7 +9,8 @@
enum DistortionType {
  RADIAL,
  TRANSVERSE,
  KAGUYATC
  KAGUYATC,
  DAWNFC
};

// Transverse Distortion
+64 −0
Original line number Diff line number Diff line
@@ -200,6 +200,58 @@ void removeDistortion(double dx, double dy, double &ux, double &uy,
      ux = dx + dr_x;
      uy = dy + dr_y;
    }
    break;
    // The dawn distortion model is "reversed" from other distortion models so
    // the remove function iteratively computes undistorted coordinates based on
    // the distorted coordinates, rather than iteratively computing distorted coordinates
    // to undistorted coordinates.
    case DAWNFC: {
      double r2;
      int    numAttempts = 1;
      bool    done;

      /****************************************************************************
      * Pre-loop intializations
      ****************************************************************************/

      r2 = dy * dy + dx * dx;
      double guess_dx, guess_dy;
      double guess_ux, guess_uy;

      /****************************************************************************
      * Loop ...
      ****************************************************************************/
      do {
        guess_ux = dx / (1.0 + opticalDistCoeffs[0] * r2);
        guess_uy = dy / (1.0 + opticalDistCoeffs[0] * r2);

        r2 = guess_uy * guess_uy + guess_ux * guess_ux;

        guess_dx = guess_ux * (1.0 + opticalDistCoeffs[0] * r2);
        guess_dy = guess_uy * (1.0 + opticalDistCoeffs[0] * r2);

        done = false;

        if (abs(guess_dx - dx) < tolerance && abs(guess_dy - dy) < tolerance) {
          done = true;
        }

        /* Not converging so bomb */
        numAttempts++;
        if(numAttempts > 20) {
          std::cout << "Didn't converge" << std::endl;
          return;
        }
      }
      while(!done);

      /****************************************************************************
      * Sucess ...
      ****************************************************************************/

      ux = guess_ux;
      uy = guess_uy;
    }
  }
}

@@ -324,5 +376,17 @@ void applyDistortion(double ux, double uy, double &dx, double &dy,
        dy = ydistorted;
      }
    }
    break;
    // The dawn distortion model is "reversed" from other distortion models so
    // the apply function computes distorted coordinates as a
    // fn(undistorted coordinates)
    case DAWNFC: {
      double r2;

      r2 = ux * ux + uy * uy;

      dx = ux * (1.0 + opticalDistCoeffs[0] * r2);
      dy = uy * (1.0 + opticalDistCoeffs[0] * r2);
    }
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -941,8 +941,8 @@ std::string UsgsAstroFrameSensorModel::constructStateFromIsd(const std::string&
    }

    // get optical_distortion
    state["m_distortionType"] = getDistortionModel(isd);
    state["m_opticalDistCoeffs"] = getDistortionCoeffs(isd);
    state["m_distortionType"] = getDistortionModel(isd, warnings);
    state["m_opticalDistCoeffs"] = getDistortionCoeffs(isd, warnings);

    // get detector_center
    state["m_ccdCenter"][0] = getDetectorCenterLine(isd, parsingWarnings);
+18 −4
Original line number Diff line number Diff line
@@ -2865,7 +2865,21 @@ std::string UsgsAstroLsSensorModel::constructStateFromIsd(const std::string imag
  }

  // Get the optional logging file
  state["m_logFile"] = getLogFile(isd);
  state["m_logFile"] = getLogFile(isd, warnings);

  if (!parsingWarnings->empty()) {
    if (warnings) {
      warnings->insert(warnings->end(), parsingWarnings->begin(), parsingWarnings->end());
    }
    delete parsingWarnings;
    parsingWarnings = nullptr;
    throw csm::Error(csm::Error::SENSOR_MODEL_NOT_CONSTRUCTIBLE,
                     "ISD is invalid for creating the sensor model.",
                     "UsgsAstroFrameSensorModel::constructStateFromIsd");
  }

  delete parsingWarnings;
  parsingWarnings = nullptr;

  // The state data will still be updated when a sensor model is created since
  // some state data is not in the ISD and requires a SM to compute them.
+21 −0
Original line number Diff line number Diff line
@@ -766,6 +766,9 @@ DistortionType getDistortionModel(json isd, csm::WarningList *list) {
    else if (distortion.compare("kaguyatc") == 0) {
      return DistortionType::KAGUYATC;
    }
    else if (distortion.compare("dawnfc") == 0) {
      return DistortionType::DAWNFC;
    }
  }
  catch (...) {
    if (list) {
@@ -855,7 +858,25 @@ std::vector<double> getDistortionCoeffs(json isd, csm::WarningList *list) {
        coefficients = std::vector<double>(8, 0.0);
      }
    }
    break;
    case DistortionType::DAWNFC: {
      try {
        coefficients = isd.at("optical_distortion").at("dawnfc").at("coefficients").get<std::vector<double>>();

        return coefficients;
      }
      catch (...) {
        if (list) {
          list->push_back(
            csm::Warning(
              csm::Warning::DATA_NOT_AVAILABLE,
              "Could not parse the dawn radial distortion model coefficients.",
              "Utilities::getDistortion()"));
        }
        coefficients = std::vector<double>(1, 0.0);
      }
    }
    break;
  }
  if (list) {
    list->push_back(
Loading