Commit aec954d3 authored by dcookastro's avatar dcookastro Committed by kledmundson
Browse files

Added an option in lrolola2isis to sort the output file so order of points...

Added an option in lrolola2isis to sort the output file so order of points will be consistent for testing (#2749)

* Added option to sort the output for consistent order in testing and added a test case

* Cleaned up commented out lines in LidarData.h and .cpp

* Added additional documentation for LidarData, LidarControlPoint, and lrolola2isis

* Removed debug lines from LidarData.cpp and old comments from the lrolola2isis twoImage test

* Added an additional comment about the Test format to LidarData.cpp
parent d11b3abb
Loading
Loading
Loading
Loading
+31 −6
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@
#include "IException.h"
#include "iTime.h"
#include "Latitude.h"
#include "LidarControlPoint.h"
#include "Longitude.h"
#include "Progress.h"
#include "SerialNumberList.h"
@@ -50,13 +49,31 @@ namespace Isis {


  /**
   * Gets the list of Lidar data points.
   * Gets the list of Lidar data points optionally sorted . 
   *
   * @param sort An option to sort the list.  The default is false (no sort).
   * @return @b QList<QSharedPointer<LidarControlPoint>> Returns list of Lidar control points.
   * @internal
   *   @history 2019-02-23 Debbie A Cook - Added optional argument to the points
   *                           method to sort the list.  See LidarControlPoint for the sorting
   *                           functor. The default behavior has not changed for backward
   *                           compatability. References #5343.
   */
  QList< QSharedPointer<LidarControlPoint> > LidarData::points() const {
  QList< QSharedPointer<LidarControlPoint> > LidarData::points(bool sort) const {
    if (!sort) {
      // This is the default behavior.  The list is coming from a QHash so the point order
      // will vary.
      return m_points.values();
    }
    else {
      // Sort the points as recommended by QT with std::sort since qsort is deprecated 
      QList< QSharedPointer<LidarControlPoint> > pointlist = points();
      std::sort(pointlist.begin(), pointlist.end(),
                LidarControlPoint::LidarControlPointLessThanFunctor());
      return pointlist;
    }
  }

  
  /**
   * Creates the ControlNet's image camera's based on the list of Serial Numbers
@@ -344,10 +361,18 @@ namespace Isis {
   * @throws IException::User Throws User exception if it cannot open the file for writing.
   */
  void LidarData::write(FileName outputFile, LidarData::Format format) {
    bool sort = false;  // Default behavior
    
    // Set up the output file
    if (format == Json) {
      outputFile = outputFile.setExtension("json");
    }
    else if (format == Test) {
      // Format is same as Json, but points are sorted instead of random so that
      // output can be compared to truth data
      outputFile = outputFile.setExtension("json");
      sort = true;
    }
    else {
      outputFile = outputFile.setExtension("dat");
    }
@@ -362,7 +387,7 @@ namespace Isis {
    QJsonObject lidarDataObject;
    QJsonArray pointArray;
    // Serialize the LidarControlPoints it contains
    foreach (QSharedPointer<LidarControlPoint> lcp, points()) {
    foreach (QSharedPointer<LidarControlPoint> lcp, points(sort)) {
      // Serialize LidarControlPoint
      QJsonObject pointObject;
      pointObject["id"] = lcp->GetId();
@@ -458,7 +483,7 @@ namespace Isis {

    // Write the JSON to the file
    QJsonDocument lidarDataDoc(lidarDataObject);
    if (format == Json) {
    if (format == Json || format == Test) {
      saveFile.write(lidarDataDoc.toJson());
    }
    else {
+11 −6
Original line number Diff line number Diff line
@@ -11,12 +11,13 @@
#include "boost/numeric/ublas/symmetric.hpp"
#include "boost/numeric/ublas/io.hpp"

#include "LidarControlPoint.h"

class QJsonObject;

namespace Isis {
  class Camera;
  class FileName;
  class LidarControlPoint;
  class Progress;
  class SerialNumberList;

@@ -39,6 +40,8 @@ namespace Isis {
   *                           and adjusted variance/covariance matrix to the read and
   *                           write methods. Ref #5343.
   *   @history 2018-06-14 Ken Edmundson - Added typedef for QSharedPointer to LidarData object.
   *   @history 2019-02-23 Debbie A. Cook - Added sorting option to points() method with default 
   *                           being to not sort. References #5343.
   *
   */
  class LidarData {
@@ -47,17 +50,19 @@ namespace Isis {
      /** Enumerates the file formats for serializing the LidarData class. */
      enum Format {
        Binary, /**< Serializes to a binary (QByteArray) .dat file. */
        Json    /**< Serializes to a JSON .json file. */
        Json,    /**< Serializes to a JSON .json file. */
        Test    /**< Serializes to an ordered JSON .json file for comparing to truth data. */
      };

      LidarData();

      void insert(QSharedPointer<LidarControlPoint> point);
      QList< QSharedPointer<LidarControlPoint> > points() const;

      QList< QSharedPointer<LidarControlPoint> > points(bool sort = false) const;

      void SetImages(SerialNumberList &list, Progress *progress = 0);

      // Serialization methods or LidarData
      // Serialization methods for LidarData
      void read(FileName);
      void write(FileName, Format);
    
+20 −0
Original line number Diff line number Diff line
@@ -24,6 +24,12 @@
 *   http://www.usgs.gov/privacy.html.
 */

#include <algorithm>
#include <functional>

#include <QPointer>
#include <QSharedPointer>

#include "ControlMeasure.h"
#include "ControlPoint.h"
#include "Cube.h"
@@ -43,6 +49,9 @@ namespace Isis {
   *   @history 2018-01-29 Makayla Shepherd Original version
   *   @history 2018-02-09 Ken Edmundson Added typedef forLidarControlPointQsp
   *   @history 2018-03-18 Debbie A. Cook Added Simultaneous measures 
   *   @history 2019-02-23 Debbie A. Cook Added Functor Predicate struct to sort
   *                                        based on Id.  This is needed for getting consistent 
   *                                        output for comparing test data. References #5343.
   */
  
  class LidarControlPoint : public ControlPoint {
@@ -58,6 +67,17 @@ namespace Isis {
    ControlPoint::Status setTime(iTime time);
    ControlPoint::Status addSimultaneous(QString newSerial);

    //  Functor predicate for sorting LidarControlPoints
    struct LidarControlPointLessThanFunctor :
      public std::binary_function<QSharedPointer<LidarControlPoint>,
                                                      QSharedPointer<LidarControlPoint>,
                                                      bool> {
      bool operator() ( QSharedPointer<LidarControlPoint> lcp1,
                                    QSharedPointer<LidarControlPoint> lcp2)
          {
           return (lcp1->GetId() < lcp2->GetId());
          }
    };
    double range();
    double sigmaRange();
    iTime time();
+7 −0
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@
      Changed internal default for lidar coordinate a priori uncertainties to "none", allowing FREE
      lidar points.
      </change>
    <change name="Debbie A Cook" date="2019-02-23">
      Added new file OUTPUTTYPE=TEST, to be used strictly for testing.
      This option does a SLOW sort on the output data. References #5343.
      </change>
  </history>

  <category>
@@ -93,6 +97,9 @@
            <option value="JSON">
              <brief> JSON output file (.json)</brief>
            </option>
            <option value="TEST">
              <brief> DO NOT USE (only for tests) ordered JSON output file (.json) </brief>
            </option>
          </list>
        </parameter>
    </group>
+3 −0
Original line number Diff line number Diff line
@@ -193,6 +193,9 @@ void IsisMain() {
  if (ui.GetString("OUTPUTTYPE") == "JSON") {
    lidarDataSet.write(ui.GetFileName("TO"), LidarData::Format::Json);
  }
  else if (ui.GetString("OUTPUTTYPE") == "TEST") {
    lidarDataSet.write(ui.GetFileName("TO"), LidarData::Format::Test);
  }
  else {
    lidarDataSet.write(ui.GetFileName("TO"), LidarData::Format::Binary);
  }
Loading