Commit 93bc3c74 authored by Kristin's avatar Kristin Committed by Jesse Mapel
Browse files

UsgsAstroFramePlugin refactor, part one (#117)

* Initial updates for refactoring the UsgsAstroFramePlugin

* Jacobian1 test now passing

* All coefficients test now passing

* More testing passing

* Down to 6 failing tests

* Fixed failing position-offset tests

* Update to strip out full-paths and also we're down to one failing test

* Fixed last failing test by updating canModelBeConstructedFromIsd to load the json ISD into a csm::Isd object if it has not already been loaded

* Updated based on review comments
parent 3714cb61
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ class UsgsAstroFramePlugin : public csm::Plugin {
    // TODO when implementing, add any other necessary members.

private:
    csm::Isd loadImageSupportData(const csm::Isd &imageSupportData) const; 

    static const UsgsAstroFramePlugin m_registeredPlugin;
    static const std::string _PLUGIN_NAME;
    static const std::string _MANUFACTURER_NAME;
+63 −7
Original line number Diff line number Diff line
@@ -3,6 +3,10 @@

#include <cstdlib>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <map> 

#include <csm.h>
#include <Error.h>
@@ -181,7 +185,8 @@ bool UsgsAstroFramePlugin::canModelBeConstructedFromState(const std::string &mod
      modelName != UsgsAstroFrameSensorModel::_SENSOR_MODEL_NAME){
          constructible = false;
      }
  // Check that the necessary keys are there (this does not chek values at all.)

  // Check that the necessary keys are there (this does not check values at all.)
  auto state = json::parse(modelState);
  for(auto &key : _STATE_KEYWORD){
      if (state.find(key) == state.end()){
@@ -273,16 +278,63 @@ return sensor_model;
}


csm::Model *UsgsAstroFramePlugin::constructModelFromISD(const csm::Isd &imageSupportData,
// This function takes a csm::Isd which only has the image filename set. It uses this filename to
// find a metadata json file loacated alongside the image file. It creates and returns new csm::Isd
// with its parameters populated by the metadata file. 
csm::Isd UsgsAstroFramePlugin::loadImageSupportData(const csm::Isd &imageSupportDataOriginal) const{
  // Get image location from the input csm::Isd: 
  std::string imageFilename = imageSupportDataOriginal.filename(); 
  
  // Load 'sidecar' ISD file
  size_t lastIndex = imageFilename.find_last_of("."); 
  std::string baseName = imageFilename.substr(0, lastIndex); 
  std::string isdFilename = baseName.append(".json");

  csm::Isd imageSupportData(isdFilename);
  imageSupportData.clearAllParams();

  try {
    std::ifstream isdFile(isdFilename); 
    json jsonIsd = json::parse(isdFile);
     for (json::iterator it = jsonIsd.begin(); it != jsonIsd.end(); ++it) {
      if (it.value().size() >1 ) {
        std::vector<double> v = it.value();
        for (int j=0;j < v.size(); j++) {
          std::ostringstream val;
          val << std::setprecision(15) << v[j];
          imageSupportData.addParam(it.key(),val.str());
        }
      }
      else {
        imageSupportData.addParam(it.key(), it.value().dump());
      }
    }
    isdFile.close(); 
  } catch (...) {
    std::string errorMessage = "Could not read metadata file associated with image: ";
    errorMessage.append(isdFilename);
    throw csm::Error(csm::Error::FILE_READ, errorMessage, 
                     "UsgsAstroFramePlugin::loadImageSupportData"); 
  }

  return imageSupportData; 
}

csm::Model *UsgsAstroFramePlugin::constructModelFromISD(const csm::Isd &imageSupportDataOriginal,
                                              const std::string &modelName,
                                              csm::WarningList *warnings) const {

  csm::Isd imageSupportData = loadImageSupportData(imageSupportDataOriginal); 

  // FIXME: Check needs to be updated to use new JSON isd spec
  // Check if the sensor model can be constructed from ISD given the model name
  if (!canModelBeConstructedFromISD(imageSupportData, modelName)) {
      throw csm::Error(csm::Error::ISD_NOT_SUPPORTED,
                     "Sensor model support data provided is not supported by this plugin",
                       "UsgsAstroFramePlugin::constructModelFromISD");
  }

  // Create the empty sensorModel
  UsgsAstroFrameSensorModel *sensorModel = new UsgsAstroFrameSensorModel();
  
  // Keep track of necessary keywords that are missing from the ISD.
@@ -375,7 +427,6 @@ csm::Model *UsgsAstroFramePlugin::constructModelFromISD(const csm::Isd &imageSup
  sensorModel->m_odtY[8] = atof(imageSupportData.param("odt_y", 8).c_str());
  sensorModel->m_odtY[9] = atof(imageSupportData.param("odt_y", 9).c_str());


  sensorModel->m_ccdCenter[0] = atof(imageSupportData.param("ccd_center", 0).c_str());
  sensorModel->m_ccdCenter[1] = atof(imageSupportData.param("ccd_center", 1).c_str());

@@ -537,9 +588,14 @@ bool UsgsAstroFramePlugin::canISDBeConvertedToModelState(const csm::Isd &imageSu
      convertible = false;
  }

  csm::Isd localImageSupportData = imageSupportData; 
  if (imageSupportData.parameters().empty()) {
    localImageSupportData = loadImageSupportData(imageSupportData); 
  }

  std::string value;
  for(auto &key : _ISD_KEYWORD){
      value = imageSupportData.param(key);
      value = localImageSupportData.param(key);
      if (value.empty()){
          convertible = false;
      }
+267 −487

File changed.

Preview size limit exceeded, changes collapsed.

+4 −19

File changed.

Preview size limit exceeded, changes collapsed.