Unverified Commit 7c4eb802 authored by Kristin Berry's avatar Kristin Berry Committed by GitHub
Browse files

Get jigsaw tests passing on csmbundle branch (#4413)



* Add virtuals to AbstractBundleObservation and get compiling again

* Remove function from parent

* Get existing jigsaw tests passing

* Remove unneeded functions from BundleObservation

* Clean up a bit more

* Clean up BundleObservation and AbstractBundleObservation more

* Remove unneeded BodyRotation

* Add target body solve back into bundle adjusment calc

* Remove debug output

* Removed unneeded memeber variables BundleObservation

Co-authored-by: default avatarKristin Berry <kberry@gyro.wr.usgs.gov>
parent f17c8fc3
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -425,6 +425,7 @@ namespace Isis {
          throw IException(IException::Programmer, msg, _FILEINFO_);
        }

        // TODO ISIS vs. CSM (addNewIsisObservation?)
        AbstractBundleObservationQsp observation =
            m_bundleObservations.addNew(image, observationNumber, instrumentId, m_bundleSettings);

@@ -436,9 +437,11 @@ namespace Isis {
      }

      // initialize exterior orientation (spice) for all BundleImages in all BundleObservations
      // 
      // TODO!!! - should these initializations just be done when we add the new observation above?
      m_bundleObservations.initializeExteriorOrientation();

      // TODO
      if (m_bundleSettings->solveTargetBody()) {
        m_bundleObservations.initializeBodyRotation();
      }
@@ -2164,8 +2167,10 @@ namespace Isis {
      observation->applyParameterCorrections(subrange(m_imageSolution,t,t+numParameters));

      if (m_bundleSettings->solveTargetBody()) {
        // TODO: needs to be updated for ISIS vs. CSM CSM has no updateBodyRotation
//        observation->updateBodyRotation();
        // TODO: needs to be updated for ISIS vs. CSM CSM has no updateBodyRotation]
        // TODO: this is no good. 
        QSharedPointer<BundleObservation> isisObservation = qSharedPointerDynamicCast<BundleObservation>(observation);  
        isisObservation->updateBodyRotation();
      }

      t += numParameters;
+1 −0
Original line number Diff line number Diff line
@@ -220,6 +220,7 @@ namespace Isis {
   *                                                    settings for this AbstractBundleObservation
   */
  const BundleObservationSolveSettingsQsp AbstractBundleObservation::solveSettings() {
    // NEEDED for BundleMeasure
    return m_solveSettings;
  }

+9 −10
Original line number Diff line number Diff line
@@ -55,16 +55,17 @@ namespace Isis {

      QString instrumentId();

      LinearAlgebra::Vector &parameterWeights();
      LinearAlgebra::Vector &parameterCorrections();
      LinearAlgebra::Vector &aprioriSigmas();
      LinearAlgebra::Vector &adjustedSigmas();
      virtual LinearAlgebra::Vector &parameterWeights();
      virtual LinearAlgebra::Vector &parameterCorrections();
      virtual LinearAlgebra::Vector &aprioriSigmas();
      virtual LinearAlgebra::Vector &adjustedSigmas();


      // TODO: remove later
      virtual const BundleObservationSolveSettingsQsp solveSettings();              
      int numberParameters();
      virtual int numberParameters();
      virtual bool applyParameterCorrections(LinearAlgebra::Vector corrections);


      virtual void bundleOutputString(std::ostream &fpOut,bool errorPropagation);
      virtual QString bundleOutputCSV(bool errorPropagation);

@@ -87,17 +88,15 @@ namespace Isis {
      QStringList m_imageNames;         //!< List of all cube names.
      QString m_instrumentId;      //!< Spacecraft instrument id.

      BundleObservationSolveSettingsQsp m_solveSettings; //!< Solve settings for this observation.

      // TODO??? change these to LinearAlgebra vectors...
      LinearAlgebra::Vector m_weights;     //!< Parameter weights.
      //! Cumulative parameter correction vector.
      LinearAlgebra::Vector m_corrections;
      //LinearAlgebra::Vector m_solution;  //!< parameter solution vector.
      //! A posteriori (adjusted) parameter sigmas.
      LinearAlgebra::Vector m_aprioriSigmas;
      //! A posteriori (adjusted) parameter sigmas.
      LinearAlgebra::Vector m_adjustedSigmas;
      BundleObservationSolveSettingsQsp m_solveSettings; //!< Solve settings for this observation.
  };

  //! Typdef for AbstractBundleObservation QSharedPointer.
+87 −270
Original line number Diff line number Diff line
@@ -29,19 +29,16 @@ namespace Isis {
   * Constructs a BundleObservation initialized to a default state.
   */
  BundleObservation::BundleObservation() {
    m_serialNumbers.clear();
    m_imageNames.clear();
    m_parameterNamesList.clear();
    m_observationNumber = "";
    m_instrumentId = "";
    m_instrumentRotation = NULL;
    m_instrumentPosition = NULL;
    m_index = 0;
    m_weights.clear();
    m_corrections.clear();
//    m_solution.clear();
    m_aprioriSigmas.clear();
    m_adjustedSigmas.clear();

    m_parameterNamesList.clear();
    m_instrumentPosition = NULL;
    m_instrumentRotation = NULL;
    // m_solveSettings?
    // m_bundleTargetBody ? 
  }


@@ -55,32 +52,18 @@ namespace Isis {
   * @param bundleTargetBody QSharedPointer to the target body of the observation
   */
  BundleObservation::BundleObservation(BundleImageQsp image, QString observationNumber,
                                       QString instrumentId, BundleTargetBodyQsp bundleTargetBody) {
    m_serialNumbers.clear();
    m_imageNames.clear();
    m_parameterNamesList.clear();
    m_observationNumber = "";
    m_instrumentId = "";
    m_instrumentRotation = NULL;
    m_instrumentPosition = NULL;
    m_index = 0;
                                       QString instrumentId, BundleTargetBodyQsp bundleTargetBody) : AbstractBundleObservation(image, observationNumber, instrumentId, bundleTargetBody) {
    m_weights.clear();
    m_corrections.clear();
//    m_solution.clear();
    m_aprioriSigmas.clear();
    m_adjustedSigmas.clear();

    m_observationNumber = observationNumber;
    m_instrumentId = instrumentId;

    m_parameterNamesList.clear();
    m_bundleTargetBody = bundleTargetBody;
    m_instrumentRotation = NULL;
    m_instrumentPosition = NULL;

    if (image) {
      append(image);
      m_serialNumbers.append(image->serialNumber());
      m_imageNames.append(image->fileName());
      m_cubeSerialNumberToBundleImageMap.insert(image->serialNumber(), image);

      // set the observations spice position and rotation objects from the primary image in the
      // observation (this is, by design at the moment, the first image added to the observation)
      // if the image, camera, or instrument position/orientation is null, then set to null
@@ -96,10 +79,6 @@ namespace Isis {
      // set the observations target body spice rotation object from the primary image in the
      // observation (this is, by design at the moment, the first image added to the observation)
      // if the image, camera, or instrument position/orientation is null, then set to null
//      m_bodyRotation = (image->camera() ?
//                           (image->camera()->bodyRotation() ?
//                             image->camera()->bodyRotation() : NULL)
//                           : NULL);
    }
  }

@@ -109,19 +88,11 @@ namespace Isis {
   *
   * @param src Reference to the BundleObservation to copy
   */
  BundleObservation::BundleObservation(const BundleObservation &src) {
    m_serialNumbers = src.m_serialNumbers;
    m_cubeSerialNumberToBundleImageMap = src.m_cubeSerialNumberToBundleImageMap;

    m_observationNumber = src.m_observationNumber;
    m_instrumentId = src.m_instrumentId;

  BundleObservation::BundleObservation(const BundleObservation &src) : AbstractBundleObservation(src) {
    m_instrumentPosition = src.m_instrumentPosition;
    m_instrumentRotation = src.m_instrumentRotation;

    m_solveSettings = src.m_solveSettings;

    m_index = src.m_index;
    // why not m_targetBody?
  }


@@ -146,57 +117,16 @@ namespace Isis {
   */
  BundleObservation &BundleObservation::operator=(const BundleObservation &src) {
    if (&src != this) {
      m_serialNumbers = src.m_serialNumbers;
      m_cubeSerialNumberToBundleImageMap = src.m_cubeSerialNumberToBundleImageMap;

      m_observationNumber = src.m_observationNumber;
      m_instrumentId = src.m_instrumentId;

      AbstractBundleObservation::operator=(src);
      m_instrumentPosition = src.m_instrumentPosition;
      m_instrumentRotation = src.m_instrumentRotation;

      m_solveSettings = src.m_solveSettings;
    // why not m_targetBody?
    }
    return *this;
  }


  /**
   * Appends a BundleImage shared pointer to the BundleObservation.
   * If the pointer is valid, then the BundleImage and its serial number will be inserted into
   * the serial number to BundleImage map.
   *
   * @param value The BundleImage to be appended.
   *
   * @see QVector::append()
   */
  void BundleObservation::append(const BundleImageQsp &value) {
    if (value) {
      m_cubeSerialNumberToBundleImageMap.insert(value->serialNumber(), value);
    }
    QVector<BundleImageQsp>::append(value);
  }


  /**
   * Returns the BundleImage shared pointer associated with the given serial number.
   * If no BundleImage with that serial number is contained a NULL pointer is returned.
   *
   * @param cubeSerialNumber The serial number of the cube to be returned.
   *
   * @return @b BundleImageQsp A shared pointer to the BundleImage (NULL if not found).
   */
  BundleImageQsp BundleObservation::imageByCubeSerialNumber(QString cubeSerialNumber) {
    BundleImageQsp bundleImage;

    if (m_cubeSerialNumberToBundleImageMap.contains(cubeSerialNumber)) {
      bundleImage = m_cubeSerialNumberToBundleImageMap.value(cubeSerialNumber);
    }

    return bundleImage;
  }


  /**
   * Set solve parameters
   *
@@ -225,8 +155,6 @@ namespace Isis {
    m_weights.clear();
    m_corrections.resize(nParameters);
    m_corrections.clear();
//    m_solution.resize(nParameters);
//    m_solution.clear();
    m_adjustedSigmas.resize(nParameters);
    m_adjustedSigmas.clear();
    m_aprioriSigmas.resize(nParameters);
@@ -243,16 +171,6 @@ namespace Isis {
  }


  /**
   * Accesses the instrument id
   *
   * @return @b QString Returns the instrument id of the observation
   */
  QString BundleObservation::instrumentId() {
    return m_instrumentId;
  }


  /**
   * Accesses the instrument's spice rotation
   *
@@ -293,15 +211,6 @@ namespace Isis {
  }


  /**
   * @internal
   *   @todo
   */
//  LinearAlgebra::Vector &BundleObservation::parameterSolution() {
//    return m_solution;
//  }


  /**
   * Accesses the a priori sigmas
   *
@@ -342,150 +251,62 @@ namespace Isis {
   *   @todo Should this always return true?
   */
  bool BundleObservation::initializeExteriorOrientation() {
    std::cout << "do something with states instead" << std::endl;
//    if (m_solveSettings->instrumentPositionSolveOption() !=
//        BundleObservationSolveSettings::NoPositionFactors) {
//
//      double positionBaseTime = 0.0;
//      double positiontimeScale = 0.0;
//      std::vector<double> posPoly1, posPoly2, posPoly3;
//
//      for (int i = 0; i < size(); i++) {
//        BundleImageQsp image = at(i);
//        SpicePosition *spicePosition = image->camera()->instrumentPosition();
//
//        if (i > 0) {
//          spicePosition->SetPolynomialDegree(m_solveSettings->spkSolveDegree());
//          spicePosition->SetOverrideBaseTime(positionBaseTime, positiontimeScale);
//          spicePosition->SetPolynomial(posPoly1, posPoly2, posPoly3,
//                                       m_solveSettings->positionInterpolationType());
//        }
//        else {
//          // first, set the degree of the spk polynomial to be fit for a priori values
//          spicePosition->SetPolynomialDegree(m_solveSettings->spkDegree());
//
//          // now, set what kind of interpolation to use (SPICE, memcache, hermitecache, polynomial
//          // function, or polynomial function over constant hermite spline)
//          // TODO: verify - I think this actually performs the a priori fit
//          spicePosition->SetPolynomial(m_solveSettings->positionInterpolationType());
//
//          // finally, set the degree of the spk polynomial actually used in the bundle adjustment
//          spicePosition->SetPolynomialDegree(m_solveSettings->spkSolveDegree());
//
//          if (m_instrumentPosition) { // ??? TODO: why is this different from rotation code below???
//            positionBaseTime = m_instrumentPosition->GetBaseTime();
//            positiontimeScale = m_instrumentPosition->GetTimeScale();
//            m_instrumentPosition->GetPolynomial(posPoly1, posPoly2, posPoly3);
//          }
//        }
//      }
//    }
//
//    if (m_solveSettings->instrumentPointingSolveOption() !=
//        BundleObservationSolveSettings::NoPointingFactors) {
//
//      double rotationBaseTime = 0.0;
//      double rotationtimeScale = 0.0;
//      std::vector<double> anglePoly1, anglePoly2, anglePoly3;
//
//      for (int i = 0; i < size(); i++) {
//        BundleImageQsp image = at(i);
//        SpiceRotation *spicerotation = image->camera()->instrumentRotation();
//
//        if (i > 0) {
//          spicerotation->SetPolynomialDegree(m_solveSettings->ckSolveDegree());
//          spicerotation->SetOverrideBaseTime(rotationBaseTime, rotationtimeScale);
//          spicerotation->SetPolynomial(anglePoly1, anglePoly2, anglePoly3,
//                                       m_solveSettings->pointingInterpolationType());
//        }
//        else {
//          // first, set the degree of the spk polynomial to be fit for a priori values
//          spicerotation->SetPolynomialDegree(m_solveSettings->ckDegree());
//
//          // now, set what kind of interpolation to use (SPICE, memcache, hermitecache, polynomial
//          // function, or polynomial function over constant hermite spline)
//          // TODO: verify - I think this actually performs the a priori fit
//          spicerotation->SetPolynomial(m_solveSettings->pointingInterpolationType());
//
//          // finally, set the degree of the spk polynomial actually used in the bundle adjustment
//          spicerotation->SetPolynomialDegree(m_solveSettings->ckSolveDegree());
//
//          rotationBaseTime = spicerotation->GetBaseTime();
//          rotationtimeScale = spicerotation->GetTimeScale();
//          spicerotation->GetPolynomial(anglePoly1, anglePoly2, anglePoly3);
//        }
//      }
//    }
//
    return true;
  }


  /**
   * Intializes the body rotation
   *
   * @todo check to make sure m_bundleTargetBody is valid
   */
  void BundleObservation::initializeBodyRotation() {
    std::vector<Angle> raCoefs = m_bundleTargetBody->poleRaCoefs();
    std::vector<Angle> decCoefs = m_bundleTargetBody->poleDecCoefs();
    std::vector<Angle> pmCoefs = m_bundleTargetBody->pmCoefs();

    for (int i = 0; i < size(); i++) {
      BundleImageQsp image = at(i);
      image->camera()->bodyRotation()->setPckPolynomial(raCoefs, decCoefs, pmCoefs);
    }
  }


  /**
   * Updates the body rotation
   *
   * @internal
   *   @todo Is this a duplicate of initializeBodyRotation?
   */
  void BundleObservation::updateBodyRotation() {
    std::vector<Angle> raCoefs = m_bundleTargetBody->poleRaCoefs();
    std::vector<Angle> decCoefs = m_bundleTargetBody->poleDecCoefs();
    std::vector<Angle> pmCoefs = m_bundleTargetBody->pmCoefs();

    for (int i = 0; i < size(); i++) {
      BundleImageQsp image = at(i);
      image->camera()->bodyRotation()->setPckPolynomial(raCoefs, decCoefs, pmCoefs);
    }
  }


/*
  bool BundleObservation::initializeExteriorOrientation() {

    if (m_solveSettings->instrumentPositionSolveOption() !=
        BundleObservationSolveSettings::NoPositionFactors) {

      double positionBaseTime = 0.0;
      double positiontimeScale = 0.0;
      std::vector<double> posPoly1, posPoly2, posPoly3;

      for (int i = 0; i < size(); i++) {
        BundleImageQsp image = at(i);
        SpicePosition *spiceposition = image->camera()->instrumentPosition();
        SpicePosition *spicePosition = image->camera()->instrumentPosition();

        if (i > 0) {
          spicePosition->SetPolynomialDegree(m_solveSettings->spkSolveDegree());
          spicePosition->SetOverrideBaseTime(positionBaseTime, positiontimeScale);
          spicePosition->SetPolynomial(posPoly1, posPoly2, posPoly3,
                                       m_solveSettings->positionInterpolationType());
        }
        else {
          // first, set the degree of the spk polynomial to be fit for a priori values
        spiceposition->SetPolynomialDegree(m_solveSettings->spkDegree());
          spicePosition->SetPolynomialDegree(m_solveSettings->spkDegree());

          // now, set what kind of interpolation to use (SPICE, memcache, hermitecache, polynomial
          // function, or polynomial function over constant hermite spline)
          // TODO: verify - I think this actually performs the a priori fit
        spiceposition->SetPolynomial(m_solveSettings->positionInterpolationType());
          spicePosition->SetPolynomial(m_solveSettings->positionInterpolationType());

          // finally, set the degree of the spk polynomial actually used in the bundle adjustment
        spiceposition->SetPolynomialDegree(m_solveSettings->spkSolveDegree());
          spicePosition->SetPolynomialDegree(m_solveSettings->spkSolveDegree());

          if (m_instrumentPosition) { // ??? TODO: why is this different from rotation code below???
            positionBaseTime = m_instrumentPosition->GetBaseTime();
            positiontimeScale = m_instrumentPosition->GetTimeScale();
            m_instrumentPosition->GetPolynomial(posPoly1, posPoly2, posPoly3);
          }
        }
      }
    }

    if (m_solveSettings->instrumentPointingSolveOption() !=
        BundleObservationSolveSettings::NoPointingFactors) {

      double rotationBaseTime = 0.0;
      double rotationtimeScale = 0.0;
      std::vector<double> anglePoly1, anglePoly2, anglePoly3;

      for (int i = 0; i < size(); i++) {
        BundleImageQsp image = at(i);
        SpiceRotation *spicerotation = image->camera()->instrumentRotation();

        if (i > 0) {
          spicerotation->SetPolynomialDegree(m_solveSettings->ckSolveDegree());
          spicerotation->SetOverrideBaseTime(rotationBaseTime, rotationtimeScale);
          spicerotation->SetPolynomial(anglePoly1, anglePoly2, anglePoly3,
                                       m_solveSettings->pointingInterpolationType());
        }
        else {
          // first, set the degree of the spk polynomial to be fit for a priori values
          spicerotation->SetPolynomialDegree(m_solveSettings->ckDegree());

@@ -496,12 +317,50 @@ namespace Isis {

          // finally, set the degree of the spk polynomial actually used in the bundle adjustment
          spicerotation->SetPolynomialDegree(m_solveSettings->ckSolveDegree());

          rotationBaseTime = spicerotation->GetBaseTime();
          rotationtimeScale = spicerotation->GetTimeScale();
          spicerotation->GetPolynomial(anglePoly1, anglePoly2, anglePoly3);
        }
      }
    }

    return true;
  }


  /**
   * Intializes the body rotation
   *
   * @todo check to make sure m_bundleTargetBody is valid
   */
  void BundleObservation::initializeBodyRotation() {
    std::vector<Angle> raCoefs = m_bundleTargetBody->poleRaCoefs();
    std::vector<Angle> decCoefs = m_bundleTargetBody->poleDecCoefs();
    std::vector<Angle> pmCoefs = m_bundleTargetBody->pmCoefs();

    for (int i = 0; i < size(); i++) {
      BundleImageQsp image = at(i);
      image->camera()->bodyRotation()->setPckPolynomial(raCoefs, decCoefs, pmCoefs);
    }
  }


  /**
   * Updates the body rotation
   *
   * @internal
   *   @todo Is this a duplicate of initializeBodyRotation?
   */
  void BundleObservation::updateBodyRotation() {
    std::vector<Angle> raCoefs = m_bundleTargetBody->poleRaCoefs();
    std::vector<Angle> decCoefs = m_bundleTargetBody->poleDecCoefs();
    std::vector<Angle> pmCoefs = m_bundleTargetBody->pmCoefs();

    for (int i = 0; i < size(); i++) {
      BundleImageQsp image = at(i);
      image->camera()->bodyRotation()->setPckPolynomial(raCoefs, decCoefs, pmCoefs);
    }
  }


  /**
@@ -601,9 +460,6 @@ namespace Isis {
      }
    }

//    for ( int i = 0; i < (int)m_weights.size(); i++ )
//      std::cout << m_weights[i] << std::endl;

    return true;
  }

@@ -772,25 +628,6 @@ namespace Isis {
  }


  /**
   * Sets the index for the observation
   *
   * @param n Value to set the index of the observation to
   */
  void BundleObservation::setIndex(int n) {
    m_index = n;
  }


  /**
   * Accesses the observation's index
   *
   * @return @b int Returns the observation's index
   */
  int BundleObservation::index() {
    return m_index;
  }

  /**
 * @brief Creates and returns a formatted QString representing the bundle coefficients and
 * parameters
@@ -1574,24 +1411,4 @@ QString BundleObservation::formatBundleOutputString(bool errorPropagation, bool

    return finalqStr;
  }


  /**
   * Access to parameters for CorrelationMatrix to use.
   *
   * @return @b QStringList Returns a QStringList of the names of the parameters
   */
  QStringList BundleObservation::parameterList() {
    return m_parameterNamesList;
  }


  /**
   * Access to image names for CorrelationMatrix to use.
   *
   * @return @b QStringList Returns a QStringList of the image names
   */
  QStringList BundleObservation::imageNames() {
    return m_imageNames;
  }
}
+1 −31
Original line number Diff line number Diff line
@@ -104,21 +104,12 @@ namespace Isis {
      // copy method
      void copy(const BundleObservation &src);

      void append(const BundleImageQsp &value);

      BundleImageQsp imageByCubeSerialNumber(QString cubeSerialNumber);

      bool setSolveSettings(BundleObservationSolveSettings solveSettings);

      void setIndex(int n);
      int index();

      int numberPositionParameters();
      int numberPointingParameters();
      int numberParameters();

      QString instrumentId();

      SpiceRotation *spiceRotation();
      SpicePosition *spicePosition();

@@ -142,35 +133,15 @@ namespace Isis {
      QString bundleOutputCSV(bool errorPropagation);

      QString formatBundleOutputString(bool errorPropagation, bool imageCSV=false);
      QStringList parameterList();
      QStringList imageNames();

   private:
      bool initParameterWeights();

    private:
      QString m_observationNumber; /**< This is typically equivalent to serial number
                                        except in the case of "observation mode" (e.g.
                                        Lunar Orbiter) where for each image in the
                                        observation, the observation number is the serial number
                                        augmented with an additional integer. **/

      int m_index; //!< Index of this observation.

      //! Map between cube serial number and BundleImage pointers.
      QMap<QString, BundleImageQsp> m_cubeSerialNumberToBundleImageMap;

      QStringList m_serialNumbers;      //!< List of all cube serial numbers in observation.
      QStringList m_parameterNamesList; //!< List of all cube parameters.
      QStringList m_imageNames;         //!< List of all cube names.

      QString m_instrumentId;      //!< Spacecraft instrument id.

      BundleObservationSolveSettingsQsp m_solveSettings; //!< Solve settings for this observation.

      SpiceRotation *m_instrumentRotation;   //!< Instrument spice rotation (in primary image).
      SpicePosition *m_instrumentPosition;   //!< Instrument spice position (in primary image).
//    SpiceRotation *m_bodyRotation;         //!< Instrument body rotation (in primary image).

      BundleTargetBodyQsp m_bundleTargetBody;       //!< QShared pointer to BundleTargetBody.

@@ -178,7 +149,6 @@ namespace Isis {
      LinearAlgebra::Vector m_weights;     //!< Parameter weights.
      //! Cumulative parameter correction vector.
      LinearAlgebra::Vector m_corrections;
      //LinearAlgebra::Vector m_solution;  //!< parameter solution vector.
      //! A posteriori (adjusted) parameter sigmas.
      LinearAlgebra::Vector m_aprioriSigmas;
      //! A posteriori (adjusted) parameter sigmas.
Loading