Commit 09c09382 authored by Jesse Mapel's avatar Jesse Mapel
Browse files

General code cleanup and coding standards in ControlnetVersioner

parent 1b148e0f
Loading
Loading
Loading
Loading
+99 −76
Original line number Diff line number Diff line
@@ -172,7 +172,8 @@ namespace Isis {
   * of the point to the caller who is expected to delete it when done with it.
   *
   * @return @b ControlPoint* A pointer to the control point. The caller assumes ownership of the
   *                          ControlPoint and is expected to delete it when done.
   *                          ControlPoint and is expected to delete it when done. If there are no
   *                          points to return, a NULL pointer is returned.
   */
  ControlPoint *ControlNetVersioner::takeFirstPoint() {
    ControlPoint *point = NULL;
@@ -187,7 +188,7 @@ namespace Isis {
  /**
   * Generates a Pvl file from the currently stored control points and header.
   *
   * @return Pvl& The Pvl version of the network
   * @return Pvl The Pvl version of the network
   */
  Pvl ControlNetVersioner::toPvl(){
    Pvl pvl;
@@ -326,7 +327,8 @@ namespace Isis {
        pvlPoint += aprioriY;
        pvlPoint += aprioriZ;

        symmetric_matrix<double, upper> aprioriCovarianceMatrix = aprioriSurfacePoint.GetRectangularMatrix();
        symmetric_matrix<double, upper> aprioriCovarianceMatrix =
              aprioriSurfacePoint.GetRectangularMatrix();

        if ( aprioriCovarianceMatrix.size1() > 0 ) {

@@ -387,9 +389,12 @@ namespace Isis {
      // adj surface point, convert to lat,lon,radius and output as comment
      SurfacePoint adjustedSurfacePoint = controlPoint->GetAdjustedSurfacePoint();
      if ( adjustedSurfacePoint.Valid() ) {
        PvlKeyword adjustedX("AdjustedX", toString(adjustedSurfacePoint.GetX().meters()), "meters");
        PvlKeyword adjustedY("AdjustedY", toString(adjustedSurfacePoint.GetY().meters()), "meters");
        PvlKeyword adjustedZ("AdjustedZ", toString(adjustedSurfacePoint.GetZ().meters()), "meters");
        PvlKeyword adjustedX("AdjustedX",
                             toString(adjustedSurfacePoint.GetX().meters()), "meters");
        PvlKeyword adjustedY("AdjustedY",
                             toString(adjustedSurfacePoint.GetY().meters()), "meters");
        PvlKeyword adjustedZ("AdjustedZ",
                             toString(adjustedSurfacePoint.GetZ().meters()), "meters");

        adjustedX.addComment("AdjustedLatitude = "
                             + toString(adjustedSurfacePoint.GetLatitude().degrees())
@@ -405,7 +410,8 @@ namespace Isis {
        pvlPoint += adjustedY;
        pvlPoint += adjustedZ;

        symmetric_matrix<double, upper> adjustedCovarianceMatrix = adjustedSurfacePoint.GetRectangularMatrix();
        symmetric_matrix<double, upper> adjustedCovarianceMatrix =
              adjustedSurfacePoint.GetRectangularMatrix();

        if ( adjustedCovarianceMatrix.size1() > 0 ) {

@@ -453,8 +459,7 @@ namespace Isis {

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

        switch ( controlMeasure.GetType() ) {
@@ -520,7 +525,8 @@ namespace Isis {

        if ( controlMeasure.GetSampleResidual() != Isis::Null
             && controlMeasure.GetSampleResidual() != 0. ) {
          pvlMeasure += PvlKeyword("SampleResidual", toString(controlMeasure.GetSampleResidual()),
          pvlMeasure += PvlKeyword("SampleResidual",
                                   toString(controlMeasure.GetSampleResidual()),
                                   "pixels");
        }

@@ -538,9 +544,9 @@ namespace Isis {
          pvlMeasure += log.ToKeyword();
        }

        if ( controlPoint->HasRefMeasure() &&
           controlPoint->IndexOfRefMeasure() == j &&
           controlPoint->IsReferenceExplicit() ) {
        if ( controlPoint->HasRefMeasure()
             && controlPoint->IndexOfRefMeasure() == j
             && controlPoint->IsReferenceExplicit() ) {
          pvlMeasure += PvlKeyword("Reference", "True");
        }
        pvlPoint.addGroup(pvlMeasure);
@@ -881,7 +887,9 @@ namespace Isis {
   * @param netFile The filename of the control network file.
   * @param progress The progress object to track reading points.
   */
  void ControlNetVersioner::readProtobuf(const Pvl &header, const FileName netFile, Progress *progress) {
  void ControlNetVersioner::readProtobuf(const Pvl &header,
                                         const FileName netFile,
                                         Progress *progress) {
    int version = 1;

    const PvlObject &protoBuf = header.findObject("ProtoBuffer");
@@ -916,7 +924,9 @@ namespace Isis {
   * @param netFile The filename of the control network file.
   * @param progress The progress object to track reading points.
   */
  void ControlNetVersioner::readProtobufV0001(const Pvl &header, const FileName netFile, Progress *progress) {
  void ControlNetVersioner::readProtobufV0001(const Pvl &header,
                                              const FileName netFile,
                                              Progress *progress) {
    const PvlObject &protoBufferInfo = header.findObject("ProtoBuffer");
    const PvlObject &protoBufferCore = protoBufferInfo.findObject("Core");

@@ -1037,7 +1047,9 @@ namespace Isis {
   * @param netFile The filename of the control network file.
   * @param progress The progress object to track reading points.
   */
  void ControlNetVersioner::readProtobufV0002(const Pvl &header, const FileName netFile, Progress *progress) {
  void ControlNetVersioner::readProtobufV0002(const Pvl &header,
                                              const FileName netFile,
                                              Progress *progress) {
    // read the header protobuf object
    const PvlObject &protoBufferInfo = header.findObject("ProtoBuffer");
    const PvlObject &protoBufferCore = protoBufferInfo.findObject("Core");
@@ -1154,7 +1166,9 @@ namespace Isis {
   * @param netFile The filename of the control network file.
   * @param progress The progress object to track reading points.
   */
  void ControlNetVersioner::readProtobufV0005(const Pvl &header, const FileName netFile, Progress *progress) {
  void ControlNetVersioner::readProtobufV0005(const Pvl &header,
                                              const FileName netFile,
                                              Progress *progress) {
    // read the header protobuf object
    const PvlObject &protoBufferInfo = header.findObject("ProtoBuffer");
    const PvlObject &protoBufferCore = protoBufferInfo.findObject("Core");
@@ -1300,8 +1314,7 @@ namespace Isis {
   *
   * @param point The versioned control point to be updated.
   *
   * @return The latest version ControlPoint constructed from the
   *         given point.
   * @return @b ControlPoint* The ControlPoint constructed from the given point.
   */
  ControlPoint *ControlNetVersioner::createPoint(ControlPointV0001 &point) {
    ControlPointV0002 newPoint(point);
@@ -1318,8 +1331,7 @@ namespace Isis {
   *
   * @param point The versioned control point to be updated.
   *
   * @return The latest version ControlPoint constructed from the
   *         given point.
   * @return @b ControlPoint* The ControlPoint constructed from the given point.
   */
  ControlPoint *ControlNetVersioner::createPoint(ControlPointV0002 &point) {

@@ -1338,8 +1350,7 @@ namespace Isis {
   *
   * @param point The versioned control point to be updated.
   *
   * @return The latest version ControlPoint constructed from the
   *         given point.
   * @return @b ControlPoint* The ControlPoint constructed from the given point.
   */
  ControlPoint *ControlNetVersioner::createPoint(ControlPointV0003 &point) {
    ControlPointFileEntryV0002 protoPoint = point.pointData();
@@ -1367,8 +1378,9 @@ namespace Isis {
        pointType = ControlPoint::PointType::Fixed;
        break;
      default:
        QString msg = "Unable to create ControlPoint [" + toString(protoPoint.id().c_str()) + "] from file. "
                      "Type enumeration [" + toString((int)(protoPoint.type())) + "] is invalid.";
        QString msg = "Unable to create ControlPoint [" + toString(protoPoint.id().c_str())
                      + "] from file. Type enumeration [" + toString((int)(protoPoint.type()))
                      + "] is invalid.";
        throw IException(IException::Programmer, msg, _FILEINFO_);
        break;
    }
@@ -1427,7 +1439,8 @@ namespace Isis {
          break;

        case ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures:
          controlPoint->SetAprioriSurfacePointSource(ControlPoint::SurfacePointSource::AverageOfMeasures);
          controlPoint->SetAprioriSurfacePointSource(
                              ControlPoint::SurfacePointSource::AverageOfMeasures);
          break;

        case ControlPointFileEntryV0002_AprioriSource_Reference:
@@ -1439,7 +1452,8 @@ namespace Isis {
          break;

        case ControlPointFileEntryV0002_AprioriSource_BundleSolution:
          controlPoint->SetAprioriSurfacePointSource(ControlPoint::SurfacePointSource::BundleSolution);
          controlPoint->SetAprioriSurfacePointSource(
                              ControlPoint::SurfacePointSource::BundleSolution);
          break;

        default:
@@ -1450,7 +1464,8 @@ namespace Isis {
    }

    if ( protoPoint.has_apriorisurfpointsourcefile() ) {
      controlPoint->SetAprioriSurfacePointSourceFile(protoPoint.apriorisurfpointsourcefile().c_str());
      controlPoint->SetAprioriSurfacePointSourceFile(
                          protoPoint.apriorisurfpointsourcefile().c_str());
    }

    if ( protoPoint.has_apriorix()
@@ -1506,8 +1521,12 @@ namespace Isis {
    if ( m_header.equatorialRadius.isValid() && m_header.polarRadius.isValid() ) {
      SurfacePoint aprioriSurfacePoint = controlPoint->GetAprioriSurfacePoint();
      SurfacePoint adjustedSurfacePoint = controlPoint->GetAdjustedSurfacePoint();
      aprioriSurfacePoint.SetRadii(m_header.equatorialRadius, m_header.equatorialRadius, m_header.polarRadius);
      adjustedSurfacePoint.SetRadii(m_header.equatorialRadius, m_header.equatorialRadius, m_header.polarRadius);
      aprioriSurfacePoint.SetRadii(m_header.equatorialRadius,
                                   m_header.equatorialRadius,
                                   m_header.polarRadius);
      adjustedSurfacePoint.SetRadii(m_header.equatorialRadius,
                                    m_header.equatorialRadius,
                                    m_header.polarRadius);
      controlPoint->SetAdjustedSurfacePoint(adjustedSurfacePoint);
      controlPoint->SetAprioriSurfacePoint(aprioriSurfacePoint);
    }
@@ -1543,7 +1562,8 @@ namespace Isis {
   * @return The ControlMeasure constructed from the V0006 version
   *         file.
   */
  ControlMeasure *ControlNetVersioner::createMeasure(const ControlPointFileEntryV0002_Measure &measure) {
  ControlMeasure *ControlNetVersioner::createMeasure(
                                             const ControlPointFileEntryV0002_Measure &measure) {

    ControlMeasure *newMeasure = new ControlMeasure;

@@ -1677,10 +1697,9 @@ namespace Isis {
      delete [] blankLabel;

      int numMeasures = 0;
      int numPoints = 0;
      int numPoints = m_points.size();
      foreach (ControlPoint *point, m_points) {
        numMeasures += point->GetNumMeasures();
        numPoints += 1;
      }

      streampos startCoreHeaderPos = output.tellp();
@@ -1775,8 +1794,8 @@ namespace Isis {


 /**
  * This will write the first control point to a ZeroCopyOutputStream.
  * The written point will be removed from the versioner and deleted if the versioner
  * This will write the first control point to a file stream.
  * The written point will be removed from the versioner and then deleted if the versioner
  * has ownership of it.
  *
  * @param output A pointer to the fileStream that we are writing the point to.
@@ -1821,8 +1840,9 @@ namespace Isis {
          pointType = ControlPointFileEntryV0002_PointType_Fixed;
          break;
        default:
          QString msg = "Unable to create ProtoPoint [" + toString(protoPoint.id().c_str()) + "] from file. "
                        "Type enumeration [" + toString((int)(controlPoint->GetType())) + "] is invalid.";
          QString msg = "Unable to create ProtoPoint [" + toString(protoPoint.id().c_str())
                        + "] from file. Type enumeration ["
                        + toString((int)(controlPoint->GetType())) + "] is invalid.";
          throw IException(IException::Programmer, msg, _FILEINFO_);
          break;
      }
@@ -1854,20 +1874,25 @@ namespace Isis {
          protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_User);
          break;
        case ControlPoint::SurfacePointSource::AverageOfMeasures:
          protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures);
          protoPoint.set_apriorisurfpointsource(
                           ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures);
          break;
        case ControlPoint::SurfacePointSource::Reference:
          protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_Reference);
          protoPoint.set_apriorisurfpointsource(
                           ControlPointFileEntryV0002_AprioriSource_Reference);
          break;
        case ControlPoint::SurfacePointSource::Basemap:
          protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_Basemap);
          break;
        case ControlPoint::SurfacePointSource::BundleSolution:
          protoPoint.set_apriorisurfpointsource(ControlPointFileEntryV0002_AprioriSource_BundleSolution);
          protoPoint.set_apriorisurfpointsource(
                           ControlPointFileEntryV0002_AprioriSource_BundleSolution);
          break;
        default:
          QString msg = "Unable to create ProtoPoint [" + toString(protoPoint.id().c_str()) + "] from file. "
                        "Type enumeration [" + toString((int)(controlPoint->GetAprioriSurfacePointSource())) + "] is invalid.";
          QString msg = "Unable to create ProtoPoint [" + toString(protoPoint.id().c_str())
                        + "] from file. Type enumeration ["
                        + toString((int)(controlPoint->GetAprioriSurfacePointSource()))
                        + "] is invalid.";
          throw IException(IException::Programmer, msg, _FILEINFO_);
          break;
      }
@@ -1881,10 +1906,12 @@ namespace Isis {
          protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_User);
          break;
        case ControlPoint::RadiusSource::AverageOfMeasures:
          protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures);
          protoPoint.set_aprioriradiussource(
                           ControlPointFileEntryV0002_AprioriSource_AverageOfMeasures);
          break;
        case ControlPoint::RadiusSource::BundleSolution:
          protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_BundleSolution);
          protoPoint.set_aprioriradiussource(
                           ControlPointFileEntryV0002_AprioriSource_BundleSolution);
          break;
        case ControlPoint::RadiusSource::Ellipsoid:
          protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_Ellipsoid);
@@ -1893,8 +1920,10 @@ namespace Isis {
          protoPoint.set_aprioriradiussource(ControlPointFileEntryV0002_AprioriSource_DEM);
          break;
        default:
          QString msg = "Unable to create ProtoPoint [" + toString(protoPoint.id().c_str()) + "] from file. "
                        "Type enumeration [" + toString((int)(controlPoint->GetAprioriRadiusSource())) + "] is invalid.";
          QString msg = "Unable to create ProtoPoint [" + toString(protoPoint.id().c_str())
                        + "] from file. Type enumeration ["
                        + toString((int)(controlPoint->GetAprioriRadiusSource()))
                        + "] is invalid.";
          throw IException(IException::Programmer, msg, _FILEINFO_);
          break;
      }
@@ -1910,7 +1939,8 @@ namespace Isis {
        protoPoint.set_aprioriy(aprioriSurfacePoint.GetY().meters());
        protoPoint.set_aprioriz(aprioriSurfacePoint.GetZ().meters());

        symmetric_matrix<double, upper> aprioriCovarianceMatrix = aprioriSurfacePoint.GetRectangularMatrix();
        symmetric_matrix<double, upper> aprioriCovarianceMatrix =
              aprioriSurfacePoint.GetRectangularMatrix();
        if ( aprioriCovarianceMatrix.size1() > 0 &&
             aprioriSurfacePoint.GetLatSigmaDistance().meters() != Isis::Null &&
             aprioriSurfacePoint.GetLonSigmaDistance().meters() != Isis::Null &&
@@ -1942,7 +1972,8 @@ namespace Isis {
        protoPoint.set_adjustedy(adjustedSurfacePoint.GetY().meters());
        protoPoint.set_adjustedz(adjustedSurfacePoint.GetZ().meters());

        symmetric_matrix<double, upper> adjustedCovarianceMatrix = adjustedSurfacePoint.GetRectangularMatrix();
        symmetric_matrix<double, upper> adjustedCovarianceMatrix =
              adjustedSurfacePoint.GetRectangularMatrix();
        if ( adjustedCovarianceMatrix.size1() > 0 ) {
          protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(0, 0));
          protoPoint.add_adjustedcovar(adjustedCovarianceMatrix(0, 1));
@@ -1956,15 +1987,10 @@ namespace Isis {
      // Converting Measures
      for (int j = 0; j < controlPoint->GetNumMeasures(); j++) {

        const ControlMeasure &
            controlMeasure = *controlPoint->GetMeasure(j);
        const ControlMeasure &controlMeasure = *controlPoint->GetMeasure(j);

        ControlPointFileEntryV0002_Measure protoMeasure;

//??? moved        if ( controlPoint->HasRefMeasure() && controlPoint->IndexOfRefMeasure() == j ) {
//??? moved             protoPoint.set_referenceindex(j);
//??? moved        }

        protoMeasure.set_serialnumber(controlMeasure.GetCubeSerialNumber().toLatin1().data());

        switch ( controlMeasure.GetType() ) {
@@ -1977,11 +2003,13 @@ namespace Isis {
                break;

            case (ControlMeasure::RegisteredPixel):
                protoMeasure.set_type(ControlPointFileEntryV0002_Measure_MeasureType_RegisteredPixel);
                protoMeasure.set_type(
                      ControlPointFileEntryV0002_Measure_MeasureType_RegisteredPixel);
                break;

            case (ControlMeasure::RegisteredSubPixel):
                protoMeasure.set_type(ControlPointFileEntryV0002_Measure_MeasureType_RegisteredSubPixel);
                protoMeasure.set_type(
                      ControlPointFileEntryV0002_Measure_MeasureType_RegisteredSubPixel);
                break;
        }

@@ -2046,9 +2074,7 @@ namespace Isis {
        }

        QVector<ControlMeasureLogData> measureLogs = controlMeasure.GetLogDataEntries();
        for (int logEntry = 0;
            logEntry < measureLogs.size(); // DNE?
            logEntry ++) {
        for (int logEntry = 0; logEntry < measureLogs.size(); logEntry ++) {

          const ControlMeasureLogData &log = measureLogs[logEntry];

@@ -2062,9 +2088,6 @@ namespace Isis {
          *protoMeasure.add_log() = logData;
        }

//???        if ( controlPoint->HasRefMeasure() && controlPoint->IndexOfRefMeasure() == j ) {
//???             protoPoint.set_referenceindex(j);
//???        }
        *protoPoint.add_measures() = protoMeasure;
      }