Commit 0b613205 authored by Kristin Berry's avatar Kristin Berry Committed by Makayla Shepherd
Browse files

Re-added toPvl and gitignore

parent 44ea7853
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
*
!/**/
!*.*
*.o
moc_*
print.prt
@@ -6,3 +9,7 @@ object_script.*.Debug
*_plugin_import.cpp
*.moc
ui_*.h
*.so
*.so.*
*.pb.cc
*.pb.h
+347 −1
Original line number Diff line number Diff line
@@ -85,8 +85,354 @@ namespace Isis {



  /**
   * Generates a Pvl file from the currently stored control points and header.
   *  
   * @return Pvl& The Pvl version of the network
   */
  Pvl &ControlNetVersioner::toPvl(){
    Pvl pvl;
    pvl.addObject(PvlObject("ControlNetwork"));
    PvlObject &network = pvl.findObject("ControlNetwork");

    network += PvlKeyword("NetworkId", m_header.networkid().c_str());
    network += PvlKeyword("TargetName", m_header.targetname().c_str());
    network += PvlKeyword("UserName", m_header.username().c_str());
    network += PvlKeyword("Created", m_header.created().c_str());
    network += PvlKeyword("LastModified", m_header.lastmodified().c_str());
    network += PvlKeyword("Description", m_header.description().c_str());
    // optionally add username to output? 

    // This is the Pvl version we're converting to
    network += PvlKeyword("Version", "5");

    //  Get Target Radii from naif kernel
    PvlGroup pvlRadii;
    QString target = (QString)network.findKeyword("TargetName",Pvl::Traverse);
    if (target != "") {
      try {
        NaifStatus::CheckErrors();
        pvlRadii = Target::radiiGroup(target);
      }
      catch (IException) {
        // leave pvlRadii empty if target is not recognized by NAIF 
      }
    }

    ControlPoint controlPoint;
    foreach(controlPoint, *m_points) {
      PvlObject pvlPoint("ControlPoint");

      if (controlPoint.GetType() == ControlPoint::Fixed) {
        pvlPoint += PvlKeyword("PointType", "Fixed");
      }
      else if (controlPoint.GetType() == ControlPoint::Constrained) {
        pvlPoint += PvlKeyword("PointType", "Constrained");
      }
      else {
        pvlPoint += PvlKeyword("PointType", "Free");
      }

      pvlPoint += PvlKeyword("PointId", controlPoint.GetId());
      pvlPoint += PvlKeyword("ChooserName", controlPoint.GetChooserName());
      pvlPoint += PvlKeyword("DateTime", controlPoint.GetDateTime()); 

      if (controlPoint.IsEditLocked()) {
        pvlPoint += PvlKeyword("EditLock", "True");
      }
      if (controlPoint.IsIgnored()) {
        pvlPoint += PvlKeyword("Ignore", "True");
      }

      switch (controlPoint.GetAprioriSurfPointSource()) {
        case ControlPoint::SurfacePointSouce::None:
          break;
        case ControlPoint::SurfacePointSouce::User:
          pvlPoint += PvlKeyword("AprioriXYZSource", "User");
          break;
        case ControlPoint::SurfacePointSouce::AverageOfMeasures:
          pvlPoint += PvlKeyword("AprioriXYZSource", "AverageOfMeasures");
          break;
        case ControlPoint::SurfacePointSouce::Reference:
          pvlPoint += PvlKeyword("AprioriXYZSource", "Reference");
          break;
        case ControlPoint::SurfacePointSouce::Basemap:
          pvlPoint += PvlKeyword("AprioriXYZSource", "Basemap");
          break;
        case ControlPoint::SurfacePointSouce::BundleSolution:
          pvlPoint += PvlKeyword("AprioriXYZSource", "BundleSolution");
          break;
        case ControlPoint::RadiusSource::Ellipsoid: // these enum vals
        case ControlPoint::RadiusSource::DEM:       // DNE for Surface Pt
          break;
      }

      if (controlPoint.HasAprioriSurfacePointSourceFile()) { //DNE right now
        pvlPoint += PvlKeyword("AprioriXYZSourceFile",
                        controlPoint.GetAprioriSurfacePointSourceFile());
      }

      switch (controlPoint.GetAprioriRadiusSource()) {
        case ControlPoint::RadiusSource::None:
          break;
        case ControlPoint::RadiusSource::User:
          pvlPoint += PvlKeyword("AprioriRadiusSource", "User");
          break;
        case ControlPoint::RadiusSource::AverageOfMeasures:
          pvlPoint += PvlKeyword("AprioriRadiusSource", "AverageOfMeasures");
          break;
        case ControlPoint::RadiusSource::Reference:
          pvlPoint += PvlKeyword("AprioriRadiusSource", "Reference");
          break;
        case ControlPoint::RadiusSource::Basemap:
          pvlPoint += PvlKeyword("AprioriRadiusSource", "Basemap");
          break;
        case ControlPoint::RadiusSource::BundleSolution:
          pvlPoint += PvlKeyword("AprioriRadiusSource", "BundleSolution");
          break;
        case ControlPoint::RadiusSource::Ellipsoid:
          pvlPoint += PvlKeyword("AprioriRadiusSource", "Ellipsoid");
          break;
        case ControlPoint::RadiusSource::DEM:
          pvlPoint += PvlKeyword("AprioriRadiusSource", "DEM");
          break;
      }

      // FIXME: None of Apriori(X,Y,Z) is available directly from ControlPoint in the API
      if (controlPoint.HasAprioriRadiusSourcefile()) { // DNE
        pvlPoint += PvlKeyword("AprioriRadiusSourceFile",
                        protobufPoint.GetAprioriRadiusSourceFile());
        }

      if (controlPoint.HasApriorix()) { // DNE
        pvlPoint += PvlKeyword("AprioriX", toString(controlPoint.AprioriX()), "meters");
        pvlPoint += PvlKeyword("AprioriY", toString(controlPoint.AprioriY()), "meters");
        pvlPoint += PvlKeyword("AprioriZ", toString(controlPoint.AprioriZ()), "meters");

        // Get surface point, convert to lat,lon,radius and output as comment
        SurfacePoint apriori;
        apriori.SetRectangular(
                Displacement(controlPoint.AprioriX(),Displacement::Meters),
                Displacement(controlPoint.AprioriY(),Displacement::Meters),
                Displacement(controlPoint.AprioriZ(),Displacement::Meters));
        pvlPoint.findKeyword("AprioriX").addComment("AprioriLatitude = " +
                                 toString(apriori.GetLatitude().degrees()) +
                                 " <degrees>");
        pvlPoint.findKeyword("AprioriY").addComment("AprioriLongitude = " +
                                 toString(apriori.GetLongitude().degrees()) +
                                 " <degrees>");
        pvlPoint.findKeyword("AprioriZ").addComment("AprioriRadius = " +
                                 toString(apriori.GetLocalRadius().meters()) +
                                 " <meters>");

        // FIXME: None of Covariance matrix information is available directly from ControlPoint in the API
        if (controlPoint.aprioricovar_size()) { // DNE
          PvlKeyword matrix("AprioriCovarianceMatrix");
          matrix += toString(controlPoint.aprioricovar(0)); // DNE
          matrix += toString(controlPoint.aprioricovar(1)); // DNE
          matrix += toString(controlPoint.aprioricovar(2)); // DNE
          matrix += toString(controlPoint.aprioricovar(3)); // DNE
          matrix += toString(controlPoint.aprioricovar(4)); // DNE 
          matrix += toString(controlPoint.aprioricovar(5)); // DNE
          pvlPoint += matrix;

          if (pvlRadii.hasKeyword("EquatorialRadius")) {
            apriori.SetRadii(
                         Distance(pvlRadii["EquatorialRadius"],Distance::Meters),
                         Distance(pvlRadii["EquatorialRadius"],Distance::Meters),
                         Distance(pvlRadii["PolarRadius"],Distance::Meters));
            symmetric_matrix<double, upper> covar;
            covar.resize(3);
            covar.clear();
            covar(0, 0) = controlPoint.aprioricovar(0); // DNE
            covar(0, 1) = controlPoint.aprioricovar(1); // DNE
            covar(0, 2) = controlPoint.aprioricovar(2); // DNE
            covar(1, 1) = controlPoint.aprioricovar(3); // DNE
            covar(1, 2) = controlPoint.aprioricovar(4); // ""
            covar(2, 2) = controlPoint.aprioricovar(5); // ""
            apriori.SetRectangularMatrix(covar);
            QString sigmas = "AprioriLatitudeSigma = " +
                             toString(apriori.GetLatSigmaDistance().meters()) +
                             " <meters>  AprioriLongitudeSigma = " +
                             toString(apriori.GetLonSigmaDistance().meters()) +
                             " <meters>  AprioriRadiusSigma = " +
                             toString(apriori.GetLocalRadiusSigma().meters()) +
                             " <meters>";
            pvlPoint.findKeyword("AprioriCovarianceMatrix").addComment(sigmas);
          }
        }
      }

      if (controlPoint.IsLatitudeConstrained()) {
        pvlPoint += PvlKeyword("LatitudeConstrained", "True");
      }

      if (controlPoint.IsLongitudeConstrained()) {
        pvlPoint += PvlKeyword("LongitudeConstrained", "True");
      }

      if (controlPoint.IsRadiusConstrained()) {
        pvlPoint += PvlKeyword("RadiusConstrained", "True");
      }

      if (controlPoint.HasAdjustedX()) {
        pvlPoint += PvlKeyword("AdjustedX", toString(controlPoint.AdjustedX()), "meters");
        pvlPoint += PvlKeyword("AdjustedY", toString(controlPoint.AdjustedY()), "meters");
        pvlPoint += PvlKeyword("AdjustedZ", toString(controlPoint.AdjustedZ()), "meters");

        // Get surface point, convert to lat,lon,radius and output as comment
        SurfacePoint adjusted;
        adjusted.SetRectangular(
                Displacement(controlPoint.AdjustedX(),Displacement::Meters),
                Displacement(controlPoint.adjustedY(),Displacement::Meters),
                Displacement(controlPoint.adjustedZ(),Displacement::Meters));
        pvlPoint.findKeyword("AdjustedX").addComment("AdjustedLatitude = " +
                                 toString(adjusted.GetLatitude().degrees()) +
                                 " <degrees>");
        pvlPoint.findKeyword("AdjustedY").addComment("AdjustedLongitude = " +
                                 toString(adjusted.GetLongitude().degrees()) +
                                 " <degrees>");
        pvlPoint.findKeyword("AdjustedZ").addComment("AdjustedRadius = " +
                                 toString(adjusted.GetLocalRadius().meters()) +
                                 " <meters>");

        if (controlPoint.AdjustedCovarSize()) { // DNE
          PvlKeyword matrix("AdjustedCovarianceMatrix");
          matrix += toString(controlPoint.AdjustedCovar(0));
          matrix += toString(controlPoint.AdjustedCovar(1));
          matrix += toString(controlPoint.AdjustedCovar(2));
          matrix += toString(controlPoint.AdjustedCovar(3));
          matrix += toString(controlPoint.AdjustedCovar(4));
          matrix += toString(controlPoint.AdjustedCovar(5));
          pvlPoint += matrix;

          if (pvlRadii.hasKeyword("EquatorialRadius")) {
            adjusted.SetRadii(
                         Distance(pvlRadii["EquatorialRadius"],Distance::Meters),
                         Distance(pvlRadii["EquatorialRadius"],Distance::Meters),
                         Distance(pvlRadii["PolarRadius"],Distance::Meters));
            symmetric_matrix<double, upper> covar;
            covar.resize(3);
            covar.clear();
            covar(0, 0) = controlPoint.AdjustedCovar(0);
            covar(0, 1) = controlPoint.AdjustedCovar(1);
            covar(0, 2) = controlPoint.AdjustedCovar(2);
            covar(1, 1) = controlPoint.AdjustedCovar(3);
            covar(1, 2) = controlPoint.AdjustedCovar(4);
            covar(2, 2) = controlPoint.AdjustedCovar(5);
            adjusted.SetRectangularMatrix(covar);
            QString sigmas = "AdjustedLatitudeSigma = " +
                             toString(adjusted.GetLatSigmaDistance().meters()) +
                             " <meters>  AdjustedLongitudeSigma = " +
                             toString(adjusted.GetLonSigmaDistance().meters()) +
                             " <meters>  AdjustedRadiusSigma = " +
                             toString(adjusted.GetLocalRadiusSigma().meters()) +
                             " <meters>";
            pvlPoint.findKeyword("AdjustedCovarianceMatrix").addComment(sigmas);
          }
        }
      }

      for (int j = 0; j < controlPoint.GetNumMeasures(); j++) {
        PvlGroup pvlMeasure("ControlMeasure");
        const ControlMeasure &
            controlMeasure = controlPoint.GetMeasures(j);
        pvlMeasure += PvlKeyword("SerialNumber", controlMeasure.GetCubeSerialNumber()); 

        switch(controlMeasure.GetType()) {
          case ControlMeasure::Candidate:
            pvlMeasure += PvlKeyword("MeasureType", "Candidate");
            break;
          case ControlMeasure::Manual:
            pvlMeasure += PvlKeyword("MeasureType", "Manual");
            break;
          case ControlMeasure::RegisteredPixel:
            pvlMeasure += PvlKeyword("MeasureType", "RegisteredPixel");
            break;
          case ControlMeasure::RegisteredSubPixel:
            pvlMeasure += PvlKeyword("MeasureType", "RegisteredSubPixel");
            break;
        }

        if (controlMeasure.HasChooserName()) { // DNE
          pvlMeasure += PvlKeyword("ChooserName", controlMeasure.GetChooserName()); 
        }

        if (controlMeasure.HasDateTime()) { // DNE
          pvlMeasure += PvlKeyword("DateTime", controlMeasure.GetDateTime());
        }

        if (controlMeasure.IsEditLocked()) {
          pvlMeasure += PvlKeyword("EditLock", "True");
        }

        if (controlMeasure.IsIgnored()) {
          pvlMeasure += PvlKeyword("Ignore", "True");
        }

        if (controlMeasure.HasSample()) { // DNE
          pvlMeasure += PvlKeyword("Sample", toString(controlMeasure.GetSample());
        }

        if (controlMeasure.HasLine()) { // DNE
          pvlMeasure += PvlKeyword("Line", toString(controlMeasure.GetLine()));
        }

        if (controlMeasure.HasDiameter()) { // DNE
          pvlMeasure += PvlKeyword("Diameter", toString(controlMeasure.GetDiameter()));
        }

        if (controlMeasure.HasAprioriSample()) { // DNE
          pvlMeasure += PvlKeyword("AprioriSample", toString(controlMeasure.GetAprioriSample()));
        }

        if (controlMeasure.HasAprioriLine()) { // DNE
          pvlMeasure += PvlKeyword("AprioriLine", toString(controlMeasure.GetAprioriLine()));
        }

        if (controlMeasure.HasSampleSigma()) { // DNE
          pvlMeasure += PvlKeyword("SampleSigma", toString(controlMeasure.GetSampleSigma()),
                                   "pixels");
        }

        if (controlMeasure.HasLineSigma()) { // BUG IN ORIGINAL CODE (had samplesigma) and DNE
          pvlMeasure += PvlKeyword("LineSigma", toString(controlMeasure.GetLineSigma()),
                                   "pixels");
        }

        if (controlMeasure.HasSampleResidual()) { // DNE
          pvlMeasure += PvlKeyword("SampleResidual", toString(controlMeasure.GetSampleResidual())
                                   "pixels");
        }

        if (controlMeasure.HasLineResidual()) { // DNE
          pvlMeasure += PvlKeyword("LineResidual", toString(controlMeasure.GetLineResidual()),
                                   "pixels");
        }

        if (controlMeasure.HasJigsawRejected()) { // DNE
         pvlMeasure += PvlKeyword("JigsawRejected", toString(controlMeasure.GetJigsawRejected())); // DNE
        }

        for (int logEntry = 0;
            logEntry < controlMeasure.LogSize(); // DNE? 
            logEntry ++) {
          const ControlMeasureLogData &log = 
                controlMeasure.GetLogData(logEntry); // Not sure this is right.

          ControlMeasureLogData interpreter(log);
          pvlMeasure += interpreter.ToKeyword();
        }

        if (controlPoint.HasReferenceIndex() && // DNE or covered by different function? 
           controlPoint.IndexOfRefMeasure() == j) {
          pvlMeasure += PvlKeyword("Reference", "True");
        }
        pvlPoint.addGroup(pvlMeasure);
      }
      network.addObject(pvlPoint);
    }
    return pvl;
  }


+1 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ namespace Isis {
   *                           to which it is appended. References #3892
   *  @history 2017-12-11 Jeannie Backer & Jesse Mapel - Created class skeleton for refactor.
   *  @history 2017-12-11 Jesse Mapel - Added VersionedControlNetHeaders.
   *  @history 2017-12-12 Kristin Berry - Added initial toPvl for refactor. 
   *  @history 2017-12-12 Jeannie Backer - Added VersionedControlPoints.
   *  @history 2017-12-12 Jeannie Backer - Implemented createPoint() methods.
   *  @history 2017-12-13 Jeannie Backer - Added target radii to createPoint(V0006).