Commit 15404ea5 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Removed pvlObject() from BundleResults, BundleSettings, BundleSolutionInfo,...

Removed pvlObject() from BundleResults, BundleSettings, BundleSolutionInfo, BundleObservationSolveSettings. Updated unit tests to use the save() (XML) methods. Fixes #4797.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce_FY17-Sprint1@7603 41f8697f-d340-4b68-9986-7bafba869bb8
parent 906de12b
Loading
Loading
Loading
Loading
+182 −276
Original line number Original line Diff line number Diff line
@@ -1420,96 +1420,6 @@ namespace Isis {
//  }
//  }




  /**
   * Saves the BundleResults object as a PvlObject.
   * 
   * @param name The name of the PvlObject to save to.
   * 
   * @return @b PvlObject A PvlObject containing the BundleResults object's information.
   */
  PvlObject BundleResults::pvlObject(QString name) const {

    PvlObject pvl(name);

    pvl += PvlKeyword("NumberFixedPoints", toString(numberFixedPoints()));
    pvl += PvlKeyword("NumberIgnoredPoints", toString(numberIgnoredPoints()));
    pvl += PvlKeyword("NumberHeldImages", toString(numberHeldImages()));
    pvl += PvlKeyword("RMSResidualX", toString(rmsRx()));
    pvl += PvlKeyword("RMSResidualY", toString(rmsRy()));
    pvl += PvlKeyword("RMSResidualXY", toString(rmsRxy()));
    pvl += PvlKeyword("RejectionLimit", toString(rejectionLimit()));
    pvl += PvlKeyword("RadiansToMeters", toString(radiansToMeters()));
    pvl += PvlKeyword("NumberRejectedObservations", toString(numberRejectedObservations()));
    pvl += PvlKeyword("NumberObservations", toString(numberObservations()));
    pvl += PvlKeyword("NumberImageParameters", toString(numberImageParameters()));
    pvl += PvlKeyword("NumberConstrainedPointParameters",
                      toString(numberConstrainedPointParameters()));
    pvl += PvlKeyword("NumberConstrainedImageParameters",
                      toString(numberConstrainedImageParameters()));
    pvl += PvlKeyword("NumberConstrainedTargetParameters",
                      toString(numberConstrainedTargetParameters()));
    pvl += PvlKeyword("NumberUnknownParameters", toString(numberUnknownParameters()));
    pvl += PvlKeyword("DegreesOfFreedom", toString(degreesOfFreedom()));
    pvl += PvlKeyword("Sigma0", toString(sigma0()));
    pvl += PvlKeyword("ElapsedTime", toString(elapsedTime()));
    pvl += PvlKeyword("ElapsedTimeErrorProp", toString(elapsedTimeErrorProp()));
    pvl += PvlKeyword("Iterations", toString(iterations()));
    pvl += PvlKeyword("Converged", toString(converged()));
#if 0
    // loop through these ??? what value to store???
    pvl += PvlKeyword("RmsImageSampleResidualsSize", toString(m_rmsImageSampleResiduals.size());
    pvl += PvlKeyword("RmsImageLineResidualsSize",   toString(m_rmsImageLineResiduals.size());
    pvl += PvlKeyword("RmsImageResidualsSize",       toString(m_rmsImageResiduals.size());
    pvl += PvlKeyword("RmsImageXSigmasSize",         toString(m_rmsImageXSigmas.size());
    pvl += PvlKeyword("RmsImageYSigmasSize",         toString(m_rmsImageYSigmas.size());
    pvl += PvlKeyword("RmsImageZSigmasSize",         toString(m_rmsImageZSigmas.size());
    pvl += PvlKeyword("RmsImageRASigmasSize",        toString(m_rmsImageRASigmas.size());
    pvl += PvlKeyword("RmsImageDECSigmasSize",       toString(m_rmsImageDECSigmas.size());
    pvl += PvlKeyword("RmsImageTWISTSigmasSize",     toString(m_rmsImageTWISTSigmas.size());
#endif 
    pvl += PvlKeyword("MinSigmaLatitude", toString(minSigmaLatitudeDistance().meters()));
    pvl += PvlKeyword("MinSigmaLatitudePointId", minSigmaLatitudePointId());
    pvl += PvlKeyword("MaxSigmaLatitude", toString(maxSigmaLatitudeDistance().meters()));
    pvl += PvlKeyword("MaxSigmaLatitudePointId", maxSigmaLatitudePointId());
    pvl += PvlKeyword("MinSigmaLongitude", toString(minSigmaLongitudeDistance().meters()));
    pvl += PvlKeyword("MinSigmaLongitudePointId", minSigmaLongitudePointId());
    pvl += PvlKeyword("MaxSigmaLongitude", toString(maxSigmaLongitudeDistance().meters()));
    pvl += PvlKeyword("MaxSigmaLongitudePointId", maxSigmaLongitudePointId());
    pvl += PvlKeyword("MinSigmaRadius", toString(minSigmaRadiusDistance().meters()));
    pvl += PvlKeyword("MinSigmaRadiusPointId", minSigmaRadiusPointId());
    pvl += PvlKeyword("MaxSigmaRadius", toString(maxSigmaRadiusDistance().meters()));
    pvl += PvlKeyword("MaxSigmaRadiusPointId", maxSigmaRadiusPointId());
    pvl += PvlKeyword("RmsSigmaLat", toString(sigmaLatitudeStatisticsRms()));
    pvl += PvlKeyword("RmsSigmaLon", toString(sigmaLongitudeStatisticsRms()));
    pvl += PvlKeyword("RmsSigmaRad", toString(sigmaRadiusStatisticsRms()));
    pvl += PvlKeyword("NumberMaximumLikelihoodModels", toString(numberMaximumLikelihoodModels()));
    if (numberMaximumLikelihoodModels() > 0) {

      PvlKeyword models("MaximumLikelihoodModels");
      PvlKeyword quantiles("MaximumLikelihoodQuantiles"); 
      
      for (int i = 0; i < m_maximumLikelihoodFunctions.size(); i++) {
        models.addValue(MaximumLikelihoodWFunctions::modelToString(
                            m_maximumLikelihoodFunctions[i].first.model()));
        quantiles.addValue(toString(m_maximumLikelihoodFunctions[i].second));
      }
      pvl += models;
      pvl += quantiles;
      pvl += PvlKeyword("MaximumLikelihoodMedianR2Residuals", 
                          toString(m_maximumLikelihoodMedianR2Residuals));
    }

    if (m_correlationMatrix) {
      pvl += correlationMatrix().pvlObject();
    }
    else {
      pvl += PvlKeyword("CorrelationMatrix", "None");
    }

    return pvl;
  }


  /**
  /**
   * Returns the Correlation Matrix.
   * Returns the Correlation Matrix.
   *
   *
@@ -1561,7 +1471,7 @@ namespace Isis {
    // TODO: does xml stuff need project???
    // TODO: does xml stuff need project???


    stream.writeStartElement("bundleResults");
    stream.writeStartElement("bundleResults");
    stream.writeTextElement("id", m_id->toString());
    // stream.writeTextElement("id", m_id->toString());


//    stream.writeTextElement("instrumentId", m_instrumentId);
//    stream.writeTextElement("instrumentId", m_instrumentId);


@@ -1744,11 +1654,11 @@ namespace Isis {
                          toString(maximumLikelihoodMedianR2Residuals()));
                          toString(maximumLikelihoodMedianR2Residuals()));


    stream.writeStartElement("cumulativeProbabilityCalculator");
    stream.writeStartElement("cumulativeProbabilityCalculator");
    cumulativeProbabilityDistribution().save(stream, project);
    // cumulativeProbabilityDistribution().save(stream, project);
    stream.writeEndElement(); // end cumulativeProbabilityCalculator
    stream.writeEndElement(); // end cumulativeProbabilityCalculator


    stream.writeStartElement("residualsCumulativeProbabilityCalculator");
    stream.writeStartElement("residualsCumulativeProbabilityCalculator");
    residualsCumulativeProbabilityDistribution().save(stream, project);
    // residualsCumulativeProbabilityDistribution().save(stream, project);
    stream.writeEndElement(); // end residualsCumulativeProbabilityCalculator
    stream.writeEndElement(); // end residualsCumulativeProbabilityCalculator


    for (int i = 0; i < numberMaximumLikelihoodModels(); i++) {
    for (int i = 0; i < numberMaximumLikelihoodModels(); i++) {
@@ -2305,8 +2215,4 @@ namespace Isis {
    m_xmlHandlerCharacters = "";
    m_xmlHandlerCharacters = "";
    return XmlStackedHandler::endElement(namespaceURI, localName, qName);
    return XmlStackedHandler::endElement(namespaceURI, localName, qName);
  }
  }



  
}
}
+28 −28
Original line number Original line Diff line number Diff line
@@ -81,6 +81,8 @@ namespace Isis {
   *   @history 2016-08-15 Jesse Mapel - Added iteration count, radians to meters conversion,
   *   @history 2016-08-15 Jesse Mapel - Added iteration count, radians to meters conversion,
   *                           observation vector, bundle control point vector, and output control
   *                           observation vector, bundle control point vector, and output control
   *                           network for write methods in BundleSolutionInfo.  Fixes #4159.
   *                           network for write methods in BundleSolutionInfo.  Fixes #4159.
   *   @history 2017-04-24 Ian Humphrey - Removed pvlObject() method. Commented out m_id serialization
   *                           for save() (causes segfault in unit test for empty xml). Fixes #4797.
   */
   */
  class BundleResults : public QObject {
  class BundleResults : public QObject {
    Q_OBJECT
    Q_OBJECT
@@ -230,8 +232,6 @@ namespace Isis {
      bool setNumberHeldImages(SerialNumberList pHeldSnList,
      bool setNumberHeldImages(SerialNumberList pHeldSnList,
                               SerialNumberList *pSnList);
                               SerialNumberList *pSnList);


      PvlObject pvlObject(QString name = "BundleResults") const;

      // Correlation Matrix accessors for cnetsuite and mutators for bundle adjust.
      // Correlation Matrix accessors for cnetsuite and mutators for bundle adjust.
      CorrelationMatrix correlationMatrix() const;
      CorrelationMatrix correlationMatrix() const;
      void setCorrMatCovFileName(FileName name);
      void setCorrMatCovFileName(FileName name);
+45 −35
Original line number Original line Diff line number Diff line
@@ -27,6 +27,8 @@
using namespace std;
using namespace std;
using namespace Isis;
using namespace Isis;


void printXml(const BundleResults &);

namespace Isis {
namespace Isis {
  /**
  /**
   * This class is used to test BundleResults' XmlHandler class.
   * This class is used to test BundleResults' XmlHandler class.
@@ -77,13 +79,15 @@ namespace Isis {
}
}





/**
/**
 * Unit test for BundleResults.
 * Unit test for BundleResults.
 *
 *
 * @internal
 * @internal
 *   @history 2016-07-01 Jesse Mapel - Added TargetBody tests.
 *   @history 2016-07-01 Jesse Mapel - Added TargetBody tests.
 *   @history 2016-10-13 Ian Humphrey - Changed call from addnew to addNew(). References #4293.
 *   @history 2016-10-13 Ian Humphrey - Changed call from addnew to addNew(). References #4293.
 *   @history 2017-04-24 Ian Humphrey - Removed pvlObject serialization, replaced with XML
 *                           serialization for checking the state of the bundle results during the
 *                           unit test. Fixes #4797.
 */
 */
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
  try {
  try {
@@ -95,13 +99,11 @@ int main(int argc, char *argv[]) {
    qDebug() << "Printing PVL group with results from the default constructor...";
    qDebug() << "Printing PVL group with results from the default constructor...";
    QObject *parent = NULL;
    QObject *parent = NULL;
    BundleResults results(parent);
    BundleResults results(parent);
    PvlObject pvl = results.pvlObject("DefaultResultsObject");
    printXml(results);
    cout << pvl << endl << endl;


    qDebug() << "Testing copy constructor...";
    qDebug() << "Testing copy constructor...";
    BundleResults copyResults(results);
    BundleResults copyResults(results);
    pvl = copyResults.pvlObject("CopyResultsObject");
    printXml(copyResults);
    cout << pvl << endl << endl;


    qDebug() << "Add maximum likelihood models, then test the assignment operator...";
    qDebug() << "Add maximum likelihood models, then test the assignment operator...";
    QList< QPair< MaximumLikelihoodWFunctions::Model, double > > modelsWithQuantiles;
    QList< QPair< MaximumLikelihoodWFunctions::Model, double > > modelsWithQuantiles;
@@ -125,13 +127,11 @@ int main(int argc, char *argv[]) {


    qDebug() << "Testing assignment operator=...";
    qDebug() << "Testing assignment operator=...";
    results = results;
    results = results;
    pvl = results.pvlObject("SelfAssignedResultsObject");
    printXml(results);
    cout << endl << pvl << endl << endl;


    BundleResults assignmentOpResults;
    BundleResults assignmentOpResults;
    assignmentOpResults = results;
    assignmentOpResults = results;
    pvl = assignmentOpResults.pvlObject("AssignedNewResultsObject");
    printXml(assignmentOpResults);
    cout << pvl << endl << endl;


    qDebug() << "Testing mutator methods...";
    qDebug() << "Testing mutator methods...";
    results.resizeSigmaStatisticsVectors(1);
    results.resizeSigmaStatisticsVectors(1);
@@ -188,8 +188,7 @@ int main(int argc, char *argv[]) {
    results.incrementIgnoredPoints();
    results.incrementIgnoredPoints();
    results.setRadiansToMeters(23.68);
    results.setRadiansToMeters(23.68);
    results.setIterations(6);
    results.setIterations(6);
    pvl = results.pvlObject("MutatedResultsObject");
    printXml(results);
    cout << pvl << endl << endl;
    qDebug() << "";
    qDebug() << "";


    qDebug() << "Testing more computation methods...";
    qDebug() << "Testing more computation methods...";
@@ -292,8 +291,6 @@ int main(int argc, char *argv[]) {
    QDataStream inputData(byteArray);
    QDataStream inputData(byteArray);
    BundleResults newResults;
    BundleResults newResults;
    inputData >> newResults;
    inputData >> newResults;
    pvl = newResults.pvlObject();
    cout << pvl << endl;
    qDebug() << "";
    qDebug() << "";


    qDebug() << "Testing XML write/read...";
    qDebug() << "Testing XML write/read...";
@@ -316,14 +313,12 @@ int main(int argc, char *argv[]) {
    // read xml
    // read xml
    XmlStackedHandlerReader reader;
    XmlStackedHandlerReader reader;
    BundleResultsXmlHandlerTester bsFromXml(project, &reader, xmlFile);
    BundleResultsXmlHandlerTester bsFromXml(project, &reader, xmlFile);
    pvl = bsFromXml.pvlObject("BundleResultsFromXml");
    printXml(bsFromXml);
    cout << pvl << endl << endl;


    // read xml with no attributes or values
    // read xml with no attributes or values
    FileName emptyXmlFile("./unitTest_NoElementValues.xml");
    FileName emptyXmlFile("./unitTest_NoElementValues.xml");
    BundleResultsXmlHandlerTester bsFromEmptyXml(project, &reader, emptyXmlFile);
    BundleResultsXmlHandlerTester bsFromEmptyXml(project, &reader, emptyXmlFile);
    pvl = bsFromEmptyXml.pvlObject("BundleResultsFromEmptyXml");
    printXml(bsFromEmptyXml);
    cout << pvl << endl << endl;


    qDebug() << "Testing error throws...";
    qDebug() << "Testing error throws...";
    try {
    try {
@@ -366,3 +361,18 @@ int main(int argc, char *argv[]) {
    e.print();
    e.print();
  }
  }
}
}


/**
 * Prints the serialized BundleResults as XML.
 *
 * @param const BundleResults &printable The bundle results to print.
 */
void printXml(const BundleResults &printable) {
  QString output;
  QXmlStreamWriter writer(&output);
  writer.setAutoFormatting(true);
  printable.save(writer, NULL);
  output.remove(QRegExp("<id>[^<]*</id>"));
  qDebug().noquote() << output << endl << endl;
}
+249 −356
Original line number Original line Diff line number Diff line
@@ -1011,105 +1011,6 @@ namespace Isis {
  }
  }




  /**
   * Create PvlObject with the given name containing the BundleSettings 
   * information. 
   * 
   * @param name The name of the output PvlObject. Defaults to "BundleSettings".
   * 
   * @return @b PvlObject A PVL containing all of the BundleSettings 
   *                      information for this bundle adjustment.
   */
  PvlObject BundleSettings::pvlObject(QString name) const {

    PvlObject pvl(name);

    // General Solve Options
    pvl += PvlKeyword("NetworkValidated", toString(validateNetwork()));
    pvl += PvlKeyword("SolveObservationMode", toString(solveObservationMode()));
    pvl += PvlKeyword("SolveRadius", toString(solveRadius()));
    pvl += PvlKeyword("UpdateCubeLabel", toString(updateCubeLabel()));
    pvl += PvlKeyword("ErrorPropagation", toString(errorPropagation()));
    pvl += PvlKeyword("CreateInverseMatrix", toString(createInverseMatrix()));
    pvl += PvlKeyword("OutlierRejection", toString(outlierRejection()));
    if (m_outlierRejection) {
      pvl += PvlKeyword("OutlierMultiplier", toString(outlierRejectionMultiplier()));
    }
    if ( !IsSpecial(globalLatitudeAprioriSigma()) ) {
      pvl += PvlKeyword("GlobalLatitudeAprioriSigma", toString(globalLatitudeAprioriSigma()));
    }
    else {
      pvl += PvlKeyword("GlobalLatitudeAprioriSigma", "None");
    }
    if (!IsSpecial(globalLongitudeAprioriSigma())) {
      pvl += PvlKeyword("GlobalLongitudeAprioriSigma", toString(globalLongitudeAprioriSigma()));
    }
    else {
      pvl += PvlKeyword("GlobalLongitudeAprioriSigma", "None");
    }
    if (m_solveRadius) {
      if ( !IsSpecial(globalLongitudeAprioriSigma()) ) {
      pvl += PvlKeyword("GlobalRadiiAprioriSigma", toString(globalRadiusAprioriSigma()));
      }
      else {
        pvl += PvlKeyword("GlobalRadiiAprioriSigma", "None");
      }
    }

    // Convergence Criteria
    pvl += PvlKeyword("ConvergenceCriteria", convergenceCriteriaToString(convergenceCriteria()));
    pvl += PvlKeyword("ConvergenceCriteriaThreshold", toString(convergenceCriteriaThreshold()));
    pvl += PvlKeyword("ConvergenceCriteriaMaximumIterations",
                        toString(convergenceCriteriaMaximumIterations()));

    // Target body
    pvl += PvlKeyword("SolveTargetBody", toString(solveTargetBody()));
    pvl += PvlKeyword("NumberTargetBodyParameters", toString(numberTargetBodyParameters()));
    pvl += PvlKeyword("SolvePoleRightAscension", toString(solvePoleRA()));
    pvl += PvlKeyword("SolvePoleRightAscensionVelocity", toString(solvePoleRAVelocity()));
    pvl += PvlKeyword("SolvePoleDeclination", toString(solvePoleDec()));
    pvl += PvlKeyword("SolvePoleDeclinationVelocity", toString(solvePoleDecVelocity()));
    pvl += PvlKeyword("SolvePolePrimeMeridian", toString(solvePM()));
    pvl += PvlKeyword("SolvePolePrimeMeridianVelocity", toString(solvePMVelocity()));
    pvl += PvlKeyword("SolvePolePrimeMeridianAcceleration", toString(solvePMAcceleration()));
    pvl += PvlKeyword("solveTriaxialRadii", toString(solveTriaxialRadii()));
    pvl += PvlKeyword("solveMeanRadius", toString(solveMeanRadius()));

    // Output Options
    pvl += PvlKeyword("FilePrefix", outputFilePrefix());

    // Maximum Likelihood Options
    PvlKeyword models("MaximumLikelihoodModels"); 
    if (m_maximumLikelihood.size() > 0) {

      models.addValue(MaximumLikelihoodWFunctions::modelToString(m_maximumLikelihood[0].first));

      PvlKeyword quantiles("MaximumLikelihoodQuantiles", 
                           toString(m_maximumLikelihood[0].second));

      for (int i = 1; i < m_maximumLikelihood.size(); i++) {
        models.addValue(MaximumLikelihoodWFunctions::modelToString(m_maximumLikelihood[i].first));
        quantiles.addValue(toString(m_maximumLikelihood[i].second));
      }
      pvl += models;
      pvl += quantiles;
    }
    else {
      models.addValue("None");
    }

    pvl += PvlKeyword("NumberObservationSolveSettings", toString(numberSolveSettings()));

    for (int i = 0; i < numberSolveSettings(); i++) {
      BundleObservationSolveSettings boss = observationSolveSettings(i);
      PvlObject bundleObsSolveSettingsPvl = boss.pvlObject();
      pvl += bundleObsSolveSettingsPvl;
    }

    return pvl;
  }


  /**
  /**
   * This method is used to write a BundleSettings object to an XML format
   * This method is used to write a BundleSettings object to an XML format
   *
   *
@@ -1118,7 +1019,6 @@ namespace Isis {
   * also.
   * also.
   */
   */
  void BundleSettings::save(QXmlStreamWriter &stream, const Project *project) const {
  void BundleSettings::save(QXmlStreamWriter &stream, const Project *project) const {
    // option 2
    stream.writeStartElement("bundleSettings");
    stream.writeStartElement("bundleSettings");


    stream.writeStartElement("globalSettings");
    stream.writeStartElement("globalSettings");
@@ -1200,7 +1100,6 @@ namespace Isis {
    else {
    else {
      // throw error??? should not write if no observation settings...
      // throw error??? should not write if no observation settings...
    }
    }

    stream.writeEndElement();
    stream.writeEndElement();
  }
  }


@@ -1451,10 +1350,4 @@ namespace Isis {
             << qPrintable(exception.message());
             << qPrintable(exception.message());
    return false;
    return false;
  }
  }


}
}



+55 −58
Original line number Original line Diff line number Diff line
@@ -100,6 +100,7 @@ namespace Isis {
   *                           are acquired by an associated observation number. References #4293.
   *                           are acquired by an associated observation number. References #4293.
   *   @history 2016-10-17 Jesse Mapel - Removed m_SCPVLFilename parameter in accordance with
   *   @history 2016-10-17 Jesse Mapel - Removed m_SCPVLFilename parameter in accordance with
   *                           USEPVL being removed from jigsaw.  References #4316.
   *                           USEPVL being removed from jigsaw.  References #4316.
   *   @history 2017-04-24 Ian Humphrey - Removed pvlObject(). Fixes #4797.
   *
   *
   *   @todo Determine which XmlStackedHandlerReader constructor is preferred
   *   @todo Determine which XmlStackedHandlerReader constructor is preferred
   *   @todo Determine which XmlStackedHandler needs a Project pointer (see constructors)
   *   @todo Determine which XmlStackedHandler needs a Project pointer (see constructors)
@@ -269,11 +270,8 @@ namespace Isis {
      QString outputFilePrefix() const;
      QString outputFilePrefix() const;
      QString SCPVLFilename() const;
      QString SCPVLFilename() const;


      PvlObject pvlObject(QString name = "BundleSettings") const;

      void save(QXmlStreamWriter &stream, const Project *project) const;
      void save(QXmlStreamWriter &stream, const Project *project) const;



    private:
    private:


      //=====================================================================//
      //=====================================================================//
@@ -390,4 +388,3 @@ namespace Isis {
Q_DECLARE_METATYPE(Isis::BundleSettingsQsp);
Q_DECLARE_METATYPE(Isis::BundleSettingsQsp);


#endif
#endif
Loading