Commit 1387e61c authored by John Bonn's avatar John Bonn
Browse files

Fixed XML serialzation and code cleanup. #4835

parent 21bacdfd
Loading
Loading
Loading
Loading
+9 −80
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ namespace Isis {

    m_statisticsResults = new BundleResults(outputStatistics);

    m_images = NULL;
    m_images = new QList<ImageList *>(imgList);
  }

@@ -80,19 +79,12 @@ namespace Isis {
   * @param src BundleSolutionInfo where the settings and BundleResults are read from.
   */
  BundleSolutionInfo::BundleSolutionInfo(const BundleSolutionInfo &src)
      : m_id(new QUuid(src.m_id->toString())),
      : m_id(new QUuid(QUuid::createUuid())),
        m_runTime(src.m_runTime),
        m_controlNetworkFileName(new FileName(src.m_controlNetworkFileName->expanded())),
        m_settings(new BundleSettings(*src.m_settings)),
        m_statisticsResults(new BundleResults(*src.m_statisticsResults)),
        m_images(new QList<ImageList *>(*src.m_images)) { // is this correct???

    // m_images = NULL;
    // m_images = new QList<ImageList *>;
    // for (int i = 0; i < src.m_images->size(); i++) {
    //   m_images->append(src.m_images->at(i));
    // }

        m_images(new QList<ImageList *>(*src.m_images)) { 
  }


@@ -101,7 +93,6 @@ namespace Isis {
   */
  BundleSolutionInfo::~BundleSolutionInfo() {
    delete m_id;
    m_id = NULL;

    delete m_controlNetworkFileName;
    m_controlNetworkFileName = NULL;
@@ -128,7 +119,7 @@ namespace Isis {
    if (&src != this) {

      delete m_id;
      m_id = new QUuid(src.m_id->toString());
      m_id = new QUuid(QUuid::createUuid());

      m_runTime = src.m_runTime;

@@ -159,55 +150,6 @@ namespace Isis {
  }


  /**
   * Saves the BundleSolutionInfo to the project
   *
   * Output format:
   *
   *
   * <image id="..." fileName="...">
   *   ...
   * </image>
   *
   * (fileName attribute is just the base name)
   *
   * @param stream The stream to which the BundleSolutionInfo will be saved
   * @param project The project to which this BundleSolutionInfo will be saved
   * @param newProjectRoot The location of the project root directory. This is not used.
   */
  void BundleSolutionInfo::save(QXmlStreamWriter &stream, const Project *project,
                                FileName newProjectRoot) const {

    stream.writeStartElement("bundleSolutionInfo");
    // save ID, cnet file name, and run time to stream
    stream.writeStartElement("generalAttributes");
    stream.writeTextElement("id", m_id->toString());
    stream.writeTextElement("runTime", runTime());
    stream.writeTextElement("fileName", m_controlNetworkFileName->expanded());
    stream.writeEndElement(); // end general attributes

    // save settings to stream
    m_settings->save(stream, project);

    // save statistics to stream
    m_statisticsResults->save(stream, project);

    // save image lists to stream
    std::cout << "\nm_images->isEmpty() ? " << (m_images->isEmpty() ? "EMPTY" : "NOT EMPTY") << "\n\n";
    if ( !m_images->isEmpty() ) {
      stream.writeStartElement("imageLists");

      std::cout << "m_images->count() " << m_images->count() << "\n\n";
      for (int i = 0; i < m_images->count(); i++) {
        m_images->at(i)->save(stream, project, "");
      }

      stream.writeEndElement();
    }
    stream.writeEndElement(); //end bundleSolutionInfo
  }


  /**
   * Saves the BundleSolutionInfo to the project
   *
@@ -277,7 +219,6 @@ namespace Isis {
    m_xmlHandlerBundleSolutionInfo = bundleSolutionInfo;
    m_xmlHandlerProject = project;
    m_xmlHandlerCharacters = "";
    m_xmlHandlerBundleResults = NULL;
  }


@@ -285,9 +226,6 @@ namespace Isis {
   * Destructor
   */
  BundleSolutionInfo::XmlHandler::~XmlHandler() {
    if (m_xmlHandlerBundleResults) {
      delete m_xmlHandlerBundleResults;
    }
  }


@@ -310,11 +248,11 @@ namespace Isis {
    if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {

      if (localName == "bundleSettings") {
        m_xmlHandlerBundleSettings =
        m_xmlHandlerBundleSolutionInfo->m_settings =
            BundleSettingsQsp(new BundleSettings(m_xmlHandlerProject, reader()));
      }
      else if (localName == "bundleResults") {
        m_xmlHandlerBundleResults = new BundleResults(m_xmlHandlerProject, reader());
        m_xmlHandlerBundleSolutionInfo->m_statisticsResults = new BundleResults(m_xmlHandlerProject, reader());
      }
      else if (localName == "imageList") {
        m_xmlHandlerBundleSolutionInfo->m_images->append(new ImageList(m_xmlHandlerProject, reader()));
@@ -350,27 +288,18 @@ namespace Isis {
                                                  const QString &localName,
                                                  const QString &qName) {
    if (localName == "id") {
      m_xmlHandlerBundleSolutionInfo->m_id = NULL;
      // all constructors assign a Uuid - we need to give it a one from the XML
      assert(m_xmlHandlerBundleSolutionInfo->m_id);
      delete m_xmlHandlerBundleSolutionInfo->m_id;
      m_xmlHandlerBundleSolutionInfo->m_id = new QUuid(m_xmlHandlerCharacters);
    }
    else if (localName == "runTime") {
      m_xmlHandlerBundleSolutionInfo->m_runTime = m_xmlHandlerCharacters;
    }
    else if (localName == "fileName") {
      m_xmlHandlerBundleSolutionInfo->m_controlNetworkFileName = NULL;
      assert(m_xmlHandlerBundleSolutionInfo->m_controlNetworkFileName == NULL);
      m_xmlHandlerBundleSolutionInfo->m_controlNetworkFileName = new FileName(m_xmlHandlerCharacters);
    }
    else if (localName == "bundleSettings") {
      m_xmlHandlerBundleSolutionInfo->m_settings =
          BundleSettingsQsp(new BundleSettings(*m_xmlHandlerBundleSettings));
    }
    else if (localName == "bundleResults") {
      m_xmlHandlerBundleSolutionInfo->m_statisticsResults = new BundleResults(*m_xmlHandlerBundleResults);
      delete m_xmlHandlerBundleResults;
      m_xmlHandlerBundleResults = NULL;
    }
    else if (localName == "imageLists") {
    }
    m_xmlHandlerCharacters = "";
    return XmlStackedHandler::endElement(namespaceURI, localName, qName);
  }
+2 −4
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ namespace Isis {
   *                           in the bundle adjustment. These images will be displayed on the
   *                           project tree under results/bundle/<runtime> and will keep the same
   *                           structure as the input on the project tree. Fixes #4818.
   *   @history 2017-05-02 J Bonn - Fixed XML serialzation and code cleanup.  #4835
   */
  class BundleSolutionInfo : public QObject {
    Q_OBJECT
@@ -131,7 +132,7 @@ namespace Isis {
      bool outputPointsCSV();
      bool outputResiduals();

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

    public slots:
@@ -166,9 +167,6 @@ namespace Isis {
          BundleSolutionInfo *m_xmlHandlerBundleSolutionInfo; //!< The bundleSolutionInfo object
          Project *m_xmlHandlerProject;  //TODO does xml stuff need project???
          QString m_xmlHandlerCharacters; //!< List of characters that have been handled
          QList<ImageList *> *m_xmlHandlerImages; //!< List of pointers to images
          BundleSettingsQsp m_xmlHandlerBundleSettings; //!< Settings used to run the bundle adjust
          BundleResults *m_xmlHandlerBundleResults; //!< Results from the bundle adjust
      };

    private:
+202 −7
Original line number Diff line number Diff line
Unit test for BundleSolutionInfo...
Printing PVL group with results from the settings/cnet/statistics constructor...
Serializing results from the settings/cnet/statistics constructor...

<bundleSolutionInfo>
    <generalAttributes>
@@ -9,7 +9,6 @@ Printing PVL group with results from the settings/cnet/statistics constructor...
    </generalAttributes>
    <bundleSettings>
        <globalSettings>
            
            <validateNetwork>Yes</validateNetwork>
            <solveOptions solveObservationMode="No" solveRadius="No" updateCubeLabel="No" errorPropagation="No" createInverseMatrix="No"/>
            <aprioriSigmas latitude="N/A" longitude="N/A" radius="N/A"/>
@@ -97,7 +96,6 @@ Testing copy constructor...
    </generalAttributes>
    <bundleSettings>
        <globalSettings>
            
            <validateNetwork>Yes</validateNetwork>
            <solveOptions solveObservationMode="No" solveRadius="No" updateCubeLabel="No" errorPropagation="No" createInverseMatrix="No"/>
            <aprioriSigmas latitude="N/A" longitude="N/A" radius="N/A"/>
@@ -185,7 +183,6 @@ Testing assignment operator to set this equal to itself...
    </generalAttributes>
    <bundleSettings>
        <globalSettings>
            
            <validateNetwork>Yes</validateNetwork>
            <solveOptions solveObservationMode="No" solveRadius="No" updateCubeLabel="No" errorPropagation="No" createInverseMatrix="No"/>
            <aprioriSigmas latitude="N/A" longitude="N/A" radius="N/A"/>
@@ -273,7 +270,6 @@ Testing assignment operator to create a new results object...
    </generalAttributes>
    <bundleSettings>
        <globalSettings>
            
            <validateNetwork>Yes</validateNetwork>
            <solveOptions solveObservationMode="No" solveRadius="No" updateCubeLabel="No" errorPropagation="No" createInverseMatrix="No"/>
            <aprioriSigmas latitude="N/A" longitude="N/A" radius="N/A"/>
@@ -361,7 +357,6 @@ Testing mutator methods...
    </generalAttributes>
    <bundleSettings>
        <globalSettings>
            
            <validateNetwork>Yes</validateNetwork>
            <solveOptions solveObservationMode="No" solveRadius="No" updateCubeLabel="No" errorPropagation="No" createInverseMatrix="No"/>
            <aprioriSigmas latitude="N/A" longitude="N/A" radius="N/A"/>
@@ -448,5 +443,205 @@ we cannot test updateFileName().
Testing error throws...

Testing output methods
Testing XML write/read...

Testing XML serialization 1: round trip serialization of fully populated BundleSolution object...
Serializing test XML object to file...

<bundleSolutionInfo>
    <generalAttributes>
        
        <runTime>xxx</runTime>
        <fileName>cnetfile.net</fileName>
    </generalAttributes>
    <bundleSettings>
        <globalSettings>
            <validateNetwork>Yes</validateNetwork>
            <solveOptions solveObservationMode="No" solveRadius="No" updateCubeLabel="No" errorPropagation="No" createInverseMatrix="No"/>
            <aprioriSigmas latitude="N/A" longitude="N/A" radius="N/A"/>
            <outlierRejectionOptions rejection="No" multiplier="N/A"/>
            <convergenceCriteriaOptions convergenceCriteria="Sigma0" threshold="1.0e-10" maximumIterations="50"/>
            <maximumLikelihoodEstimation/>
            <outputFileOptions fileNamePrefix=""/>
        </globalSettings>
        <observationSolveSettingsList>
            <bundleObservationSolveSettings>
                
                <instrumentId></instrumentId>
                <instrumentPointingOptions solveOption="AnglesOnly" numberCoefSolved="1" degree="2" solveDegree="2" solveTwist="Yes" solveOverExisting="No" interpolationType="3">
                    <aprioriPointingSigmas>
                        <sigma>N/A</sigma>
                    </aprioriPointingSigmas>
                </instrumentPointingOptions>
                <instrumentPositionOptions solveOption="None" numberCoefSolved="0" degree="2" solveDegree="2" solveOverHermiteSpline="No" interpolationType="3">
                    <aprioriPositionSigmas/>
                </instrumentPositionOptions>
            </bundleObservationSolveSettings>
        </observationSolveSettingsList>
    </bundleSettings>
    <bundleResults>
        <correlationMatrix correlationFileName="" covarianceFileName="">
            <imagesAndParameters>
                <image id="TestImageFileName">
                    <parameter>  X  (t0)</parameter>
                    <parameter>  Y  (t0)</parameter>
                    <parameter>  Z  (t0)</parameter>
                    <parameter> RA  (t0)</parameter>
                    <parameter>DEC  (t0)</parameter>
                    <parameter>TWI  (t0)</parameter>
                </image>
            </imagesAndParameters>
        </correlationMatrix>
        <generalStatisticsValues>
            <numberFixedPoints>0</numberFixedPoints>
            <numberIgnoredPoints>0</numberIgnoredPoints>
            <numberHeldImages>0</numberHeldImages>
            <rejectionLimit>0.5</rejectionLimit>
            <numberRejectedObservations>0</numberRejectedObservations>
            <numberObservations>0</numberObservations>
            <numberImageParameters>0</numberImageParameters>
            <numberConstrainedPointParameters>0</numberConstrainedPointParameters>
            <numberConstrainedImageParameters>0</numberConstrainedImageParameters>
            <numberConstrainedTargetParameters>0</numberConstrainedTargetParameters>
            <numberUnknownParameters>0</numberUnknownParameters>
            <degreesOfFreedom>-1</degreesOfFreedom>
            <sigma0>0.0</sigma0>
            <converged>No</converged>
        </generalStatisticsValues>
        <rms>
            <residuals x="0.0" y="0.0" xy="0.0"/>
            <sigmas lat="0.0" lon="0.0" rad="0.0"/>
            <imageResidualsLists>
                <residualsList listSize="3">
                    <statisticsItem>
                        
                    </statisticsItem>
                </lineList>
            </imageResidualsLists>
            <imageSigmasLists>
                <xSigmas listSize="0"/>
                <ySigmas listSize="0"/>
                <zSigmas listSize="0"/>
                <raSigmas listSize="0"/>
                <decSigmas listSize="0"/>
                <twistSigmas listSize="0"/>
            </imageSigmasLists>
        </rms>
        <elapsedTime time="0.0" errorProp="0.0"/>
        <minMaxSigmas>
            <minLat value="1000000000000.0" pointId=""/>
            <maxLat value="0.0" pointId=""/>
            <minLon value="1000000000000.0" pointId=""/>
            <maxLon value="0.0" pointId=""/>
            <minRad value="1000000000000.0" pointId=""/>
            <maxRad value="0.0" pointId=""/>
        </minMaxSigmas>
        <maximumLikelihoodEstimation numberModels="0" maximumLikelihoodIndex="0" maximumLikelihoodMedianR2Residuals="0.0">
            <cumulativeProbabilityCalculator/>
            <residualsCumulativeProbabilityCalculator/>
        </maximumLikelihoodEstimation>
    </bundleResults>
</bundleSolutionInfo> 


Testing XML: reading serialized BundleResults back in...
Testing XML: Object deserialized as (should match object above):

<bundleSolutionInfo>
    <generalAttributes>
        
        <runTime>xxx</runTime>
        <fileName>cnetfile.net</fileName>
    </generalAttributes>
    <bundleSettings>
        <globalSettings>
            <validateNetwork>Yes</validateNetwork>
            <solveOptions solveObservationMode="No" solveRadius="No" updateCubeLabel="No" errorPropagation="No" createInverseMatrix="No"/>
            <aprioriSigmas latitude="N/A" longitude="N/A" radius="N/A"/>
            <outlierRejectionOptions rejection="No" multiplier="N/A"/>
            <convergenceCriteriaOptions convergenceCriteria="Sigma0" threshold="1.0e-10" maximumIterations="50"/>
            <maximumLikelihoodEstimation/>
            <outputFileOptions fileNamePrefix=""/>
        </globalSettings>
        <observationSolveSettingsList>
            <bundleObservationSolveSettings>
                
                <instrumentId></instrumentId>
                <instrumentPointingOptions solveOption="AnglesOnly" numberCoefSolved="1" degree="2" solveDegree="2" solveTwist="Yes" solveOverExisting="No" interpolationType="3">
                    <aprioriPointingSigmas>
                        <sigma>N/A</sigma>
                    </aprioriPointingSigmas>
                </instrumentPointingOptions>
                <instrumentPositionOptions solveOption="None" numberCoefSolved="0" degree="2" solveDegree="2" solveOverHermiteSpline="No" interpolationType="3">
                    <aprioriPositionSigmas/>
                </instrumentPositionOptions>
            </bundleObservationSolveSettings>
        </observationSolveSettingsList>
    </bundleSettings>
    <bundleResults>
        <correlationMatrix correlationFileName="" covarianceFileName="">
            <imagesAndParameters>
                <image id="TestImageFileName">
                    <parameter>  X  (t0)</parameter>
                    <parameter>  Y  (t0)</parameter>
                    <parameter>  Z  (t0)</parameter>
                    <parameter> RA  (t0)</parameter>
                    <parameter>DEC  (t0)</parameter>
                    <parameter>TWI  (t0)</parameter>
                </image>
            </imagesAndParameters>
        </correlationMatrix>
        <generalStatisticsValues>
            <numberFixedPoints>0</numberFixedPoints>
            <numberIgnoredPoints>0</numberIgnoredPoints>
            <numberHeldImages>0</numberHeldImages>
            <rejectionLimit>0.5</rejectionLimit>
            <numberRejectedObservations>0</numberRejectedObservations>
            <numberObservations>0</numberObservations>
            <numberImageParameters>0</numberImageParameters>
            <numberConstrainedPointParameters>0</numberConstrainedPointParameters>
            <numberConstrainedImageParameters>0</numberConstrainedImageParameters>
            <numberConstrainedTargetParameters>0</numberConstrainedTargetParameters>
            <numberUnknownParameters>0</numberUnknownParameters>
            <degreesOfFreedom>-1</degreesOfFreedom>
            <sigma0>0.0</sigma0>
            <converged>No</converged>
        </generalStatisticsValues>
        <rms>
            <residuals x="0.0" y="0.0" xy="0.0"/>
            <sigmas lat="0.0" lon="0.0" rad="0.0"/>
            <imageResidualsLists>
                <residualsList listSize="3">
                    <statisticsItem>
                        
                    </statisticsItem>
                </lineList>
            </imageResidualsLists>
            <imageSigmasLists>
                <xSigmas listSize="0"/>
                <ySigmas listSize="0"/>
                <zSigmas listSize="0"/>
                <raSigmas listSize="0"/>
                <decSigmas listSize="0"/>
                <twistSigmas listSize="0"/>
            </imageSigmasLists>
        </rms>
        <elapsedTime time="0.0" errorProp="0.0"/>
        <minMaxSigmas>
            <minLat value="1000000000000.0" pointId=""/>
            <maxLat value="0.0" pointId=""/>
            <minLon value="1000000000000.0" pointId=""/>
            <maxLon value="0.0" pointId=""/>
            <minRad value="1000000000000.0" pointId=""/>
            <maxRad value="0.0" pointId=""/>
        </minMaxSigmas>
        <maximumLikelihoodEstimation numberModels="0" maximumLikelihoodIndex="0" maximumLikelihoodMedianR2Residuals="0.0">
            <cumulativeProbabilityCalculator/>
            <residualsCumulativeProbabilityCalculator/>
        </maximumLikelihoodEstimation>
    </bundleResults>
</bundleSolutionInfo> 



Writing text ouput file...
Writing csv ouput files...
+2 −0
Original line number Diff line number Diff line
@@ -322,6 +322,8 @@ void printXml(const BundleSolutionInfo &printable) {
  QXmlStreamWriter writer(&output);
  writer.setAutoFormatting(true);
  printable.save(writer, NULL);
  // Note Statistics class does not serialize/restore properly as of 2017-04-27
  output.remove(QRegExp("<statistics>.*</statistics>"));
  output.remove(QRegExp("<id>[^<]*</id>"));
  qDebug().noquote() << output << endl << endl;
}