Commit d58ce2e2 authored by Kim Oyama's avatar Kim Oyama
Browse files

Added code in JigsawDialog to thread bundle run. This code is commented out...

Added code in JigsawDialog to thread bundle run. This code is commented out but it works. Just uncomment if you want to thread the bundle.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@5986 41f8697f-d340-4b68-9986-7bafba869bb8
parent b755265f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include <QDir>
#include <QObject>
#include <QList>
#include <QObject>

#include "BundleAdjust.h"
#include "BundleResults.h"
+71 −5
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

#include <QDebug>
#include <QFile>
#include <QMutex>

#include <iomanip>
#include <iostream>
@@ -26,6 +27,7 @@
#include "ControlPoint.h"
#include "Control.h"
#include "CorrelationMatrix.h"
#include "ImageList.h"
#include "iTime.h"
#include "Latitude.h"
#include "Longitude.h"
@@ -150,8 +152,8 @@ namespace Isis {


  BundleAdjust::BundleAdjust(BundleSettings bundleSettings,
                             Isis::ControlNet &cnet, 
                             Isis::SerialNumberList &snlist,
                             ControlNet &cnet,
                             SerialNumberList &snlist,
                             bool bPrintSummary) {
    // initialize m_dConvergenceThreshold ???
    // ??? deleted keyword ??? m_dConvergenceThreshold = 0.0;    // This is needed for deltack???
@@ -172,6 +174,37 @@ namespace Isis {
  }


  ////////////////////////////////////////////////////////////////////////////////////My Constructor
  /**
   * Thread safe constructor.
   */
  BundleAdjust::BundleAdjust(BundleSettings bundleSettings,
                             Control &control,
                             QList<ImageList *> imgLists,
                             bool bPrintSummary) {
    m_bundleSettings = bundleSettings;

    Progress progress;
    m_pCnet = new Isis::ControlNet(control.fileName(), &progress);

    m_pSnList = new SerialNumberList;
    foreach (ImageList *imgList, imgLists) {
      foreach (Image *image, *imgList) {
        m_pSnList->Add(image->fileName());
      }
    }

    m_bPrintSummary = bPrintSummary;

    m_pHeldSnList = NULL;
    m_bCleanUp = false;
    m_strCnetFileName = control.fileName();
    
    init();
  }
  ////////////////////////////////////////////////////////////////////////////////////My Constructor


  BundleAdjust::~BundleAdjust() {
    // If we have ownership
    if (m_bCleanUp) {
@@ -527,10 +560,16 @@ namespace Isis {


  bool BundleAdjust::solveCholesky() {
//     QMutex mux;
//     mux.lock();

//     emit statusUpdate(QString("Begin solve: %1").arg(m_pSnList->Size()));

    // TODO what are the next two lines doing?
    cout << "cnet = " << m_strCnetFileName << endl;
    PvlObject forTesting = m_bundleSettings.pvlObject();
    
//     emit statusUpdate(QString("before cout: %1").arg(m_pSnList->Size()));
    
    cout << forTesting << endl;

    // throw error if a frame camera is included AND if m_bundleSettings.solveInstrumentPositionOverHermiteSpline()
@@ -545,8 +584,15 @@ namespace Isis {
//      }
//    }

//     SerialNumberList myList = *m_pSnList;


//     emit statusUpdate(QString("before initialize: %1").arg(m_pSnList->Size()));
    
    initialize();

//     emit statusUpdate(QString("before apriori: %1").arg(m_pSnList->Size()));

    // Compute the apriori lat/lons for each nonheld point
    m_pCnet->ComputeApriori(); // original location

@@ -557,8 +603,12 @@ namespace Isis {
    // start the clock
    clock_t t1 = clock();
    
//     emit statusUpdate(QString("after clock: %1").arg(m_pSnList->Size()));

    for (;;) {

      emit statusUpdate( QString("\n starting iteration %1 \n").arg(m_nIteration) );

      clock_t iterationclock1 = clock();

      // send notification to UI indicating "new iteration"
@@ -661,7 +711,9 @@ namespace Isis {
          else {  // otherwise iterations are complete
            m_bLastIteration = true;
            m_bundleStatistics.setConverged(true);

            emit statusUpdate("\n Bundle has converged");

            break;
          }
        }
@@ -692,6 +744,7 @@ namespace Isis {
      emit statusUpdate( QString("End of Iteration %1").arg(m_nIteration) );
      emit statusUpdate( QString("Elapsed Time: %1").arg(dIterationTime) );

//       emit statusUpdate( QString("\tsnlist before wrapup: %1").arg(m_pSnList->Size()) );
      // send notification to UI indicating "new iteration"
      // UI.Notify(BundleEvent.END_ITERATION);

@@ -732,9 +785,12 @@ namespace Isis {
    output();

    emit statusUpdate("\n Bundle Complete");
    BundleResults *results = new BundleResults(bundleResults());
    emit resultsReady(results);

    iterationSummary();

//     mux.unlock();
    return true;

    QString msg = "Need to return something here, or just change the whole darn thing? [";
@@ -2933,6 +2989,7 @@ namespace Isis {

      point->ComputeResiduals();
    }
//     emit statusUpdate(QString("SerialNumberList in wrapUp") + QString::number(m_pSnList->Size()));
    m_bundleStatistics.computeBundleStatistics(m_pSnList,
                                               m_pCnet,
                                               m_bundleSettings.errorPropagation(),
@@ -3541,6 +3598,7 @@ namespace Isis {
   */
  // TODO: probably don't need this, can get from BundleObservation
  QString BundleAdjust::fileName(int i) {
//     emit statusUpdate(QString("SerialNumberList in fileName(i):") + QString::number(m_pSnList->Size()));
    return m_pSnList->FileName(i);
  }

@@ -3550,6 +3608,7 @@ namespace Isis {
   *
   */
  bool BundleAdjust::isHeld(int i) {
//     emit statusUpdate(QString("SerialNumberList in isHeld(i):") + QString::number(m_pSnList->Size()));
    if ( m_bundleStatistics.numberHeldImages() > 0 )
         if ((m_pHeldSnList->HasSerialNumber(m_pSnList->SerialNumber(i))))
           return true;
@@ -3628,10 +3687,12 @@ namespace Isis {
   */
  void BundleAdjust::iterationSummary() {
    QString itlog;

    if ( m_bundleStatistics.converged() ) 
        itlog = "Iteration" + toString(m_nIteration) + ": Final";
    else
        itlog = "Iteration" + toString(m_nIteration);

    PvlGroup gp(itlog);

    gp += PvlKeyword( "Sigma0",
@@ -3649,9 +3710,11 @@ namespace Isis {
    gp += PvlKeyword( "Rejected_Measures",
                      toString( m_bundleStatistics.numberRejectedObservations()/2) );


    if ( m_bundleStatistics.numberMaximumLikelihoodModels() >
         m_bundleStatistics.maximumLikelihoodModelIndex() ) {
      // if maximum likelihood estimation is being used

      gp += PvlKeyword( "Maximum_Likelihood_Tier: ",
                        toString( m_bundleStatistics.maximumLikelihoodModelIndex() ) );
      gp += PvlKeyword( "Median_of_R^2_residuals: ",
@@ -4094,7 +4157,7 @@ namespace Isis {
      }
      fp_out << buf;
    }

// emit statusUpdate(QString("SerialNumberList in outputHeader:") + QString::number(m_pSnList->Size()));
    return true;
  }

@@ -4164,6 +4227,9 @@ namespace Isis {
    // Save list of images and their associated parameters for CorrelationMatrix to use in ice.
    m_bundleStatistics.setCorrMatImgsAndParams(imagesAndParameters);

    // Save list of images and their associated parameters for CorrelationMatrix to use in ice.
    m_bundleStatistics.setCorrMatImgsAndParams(imagesAndParameters);

    // output point uncertainty statistics if error propagation is on
    if (berrorProp) {
      sprintf(buf, "\n\n\nPOINTS UNCERTAINTY SUMMARY\n==========================\n\n");
@@ -4403,7 +4469,7 @@ namespace Isis {
        Camera *pCamera = measure->Camera();
        if (!pCamera)
          continue;

// emit statusUpdate(QString("SerialNumberList in outputResiduals:") + QString::number(m_pSnList->Size()));
        // Determine the image index
        nImageIndex = m_pSnList->SerialNumberIndex(measure->GetCubeSerialNumber());

+14 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "BundleObservationSolveSettings.h"
#include "BundleControlPointVector.h"
#include "BundleObservationVector.h"
#include "BundleResults.h"
#include "BundleSettings.h"
#include "BundleStatistics.h"
#include "Camera.h"
@@ -56,8 +57,8 @@ template< typename T > class QList;
template< typename A, typename B > class QMap;

namespace Isis {
  class BundleResults;
  class Control;
  class ImageList;

  /**
   * @author 2006-05-30 Jeff Anderson, Debbie A. Cook, and Tracie Sucharski
@@ -184,6 +185,8 @@ namespace Isis {
   *                           CorrelationMatrix object.
   *   @history 2014-07-23 Jeannie Backer - Modified to print "N/A" for rejection multiplier if 
   *                           outlier rejection is turned off.
   *   @history 2014-09-18 Kimberly Oyama - Added a constructor for running the bunlde in a
   *                           separate thread.
   */
  class BundleAdjust : public QObject {
      Q_OBJECT
@@ -214,12 +217,18 @@ namespace Isis {
                   SerialNumberList &snlist, 
                   SerialNumberList &heldsnlist, 
                   bool printSummary = true);
      BundleAdjust(BundleSettings bundleSettings,
                   Control &control,
                   QList<ImageList *> imgList,
                   bool bPrintSummary);
      ~BundleAdjust();
    
      double           solve();
      BundleResults    solveCholeskyBR();
///////////////////////////////////////////////////////////////////////////////////////////////////
    public slots:
      bool             solveCholesky();

///////////////////////////////////////////////////////////////////////////////////////////////////
      // accessors
      ControlNet       *controlNet() { return m_pCnet; } // TODO: change from pointer to const ref???
      SerialNumberList *serialNumberList() { return m_pSnList; } // TODO: move implementation to cpp per ISIS standards
@@ -248,8 +257,8 @@ namespace Isis {
      } // TODO: move implementation to cpp per ISIS standards

    signals:
      void statusUpdate(QString status);
      void bundleConvergence(bool converged);
      void statusUpdate(QString);
      void resultsReady(BundleResults *bundleResults);

    public slots:
      void outputBundleStatus(QString status);
@@ -435,6 +444,7 @@ namespace Isis {
      BundleObservationVector m_BundleObservations;
      BundleControlPointVector m_BundleControlPoints;

//       BundleObservationSolveSettings m_boss;
      double m_dRTM;                                    //!< radians to meters conversion factor (body specific)
      double m_dMTR;                                    //!< meters to radians conversion factor (body specific)
      Distance m_BodyRadii[3];                          //!< body radii i meters
+71 −25
Original line number Diff line number Diff line
#include "JigsawDialog.h"

#include <QDebug>
#include <QThread>

#include "JigsawSetupDialog.h"
#include "ui_JigsawDialog.h"
@@ -8,10 +9,12 @@
#include "BundleAdjust.h"
#include "BundleResults.h"
#include "BundleSettings.h"
#include "JigsawSetupDialog.h"
#include "Control.h"
#include "iTime.h"
#include "Process.h"
#include "Project.h"
#include "ui_JigsawDialog.h"

namespace Isis {

@@ -78,6 +81,7 @@ namespace Isis {
       }
    }

    // Non threaded *************************************************************
    SerialNumberList snlist;

    QList<ImageList *> imagelists = m_project->images();
@@ -90,7 +94,6 @@ namespace Isis {
      }
    }


    BundleAdjust bundleAdjustment(*m_bundleSettings, *m_selectedControl, snlist, false);

    connect( &bundleAdjustment, SIGNAL( statusUpdate(QString) ),
@@ -98,12 +101,71 @@ namespace Isis {

    BundleResults br = bundleAdjustment.solveCholeskyBR();

    if ( br.bundleStatistics()->converged() ) {
      br.setRunTime( Isis::iTime::CurrentLocalTime().toAscii().data() );
      m_project->addBundleResults(new BundleResults(br));
    bundleFinished(&br);
    // **************************************************************************
    
    // Threaded *****************************************************************
//     QThread *bundleThread = new QThread;
// 
//     // Takes too long to copy/recreate the serial number list
//     BundleAdjust *ba = new BundleAdjust(*m_bundleSettings,
//                                         *m_selectedControl,
//                                         m_project->images(),
//                                         false);
//     ba->moveToThread(bundleThread);
// 
//     connect( ba, SIGNAL( statusUpdate(QString) ),
//              this, SLOT( outputBundleStatus(QString) ) );
// 
//     connect( bundleThread, SIGNAL( started() ),
//              ba, SLOT( solveCholesky() ) );
// 
//     connect( ba, SIGNAL( resultsReady(BundleResults *) ),
//              this, SLOT( bundleFinished(BundleResults *) ) );
// 
//     connect( bundleThread, SIGNAL( finished() ),
//              bundleThread, SLOT( deleteLater() ) );
// 
//     bundleThread->start();
    // **************************************************************************

//#if 0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    m_ui->useLastSettings->setEnabled(true);
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//#endif
  }


  
  /**
   * Update the label or text edit area with the most recent status update by appending to
   * list and refreshing.
   *
   * @param status Current status of bundle.
   */
  void JigsawDialog::outputBundleStatus(QString status) {
    QString update = "\n" + status;
    m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(update) );
  }


  /**
   * This method will be called when the bundle is complete. This method will only be used when the
   * bundle is threaded. It can be used when the bundle is not threaded but we don't need it
   * because we have solveCholeskyBR().
   *
   *
   *
   * @param bundleResults The results of the bundle run.
   */
  void JigsawDialog::bundleFinished(BundleResults *bundleResults) {
    if ( bundleResults->bundleStatistics()->converged() ) {
      bundleResults->setRunTime( Isis::iTime::CurrentLocalTime().toAscii().data() );
      m_project->addBundleResults( new BundleResults(*bundleResults) );

      //TODO: move correlation matrix to correct position in project directory
/*
      
      // create output control net
  //     bundleAdjustment.controlNet()->Write("ONET.net");
  //
@@ -136,35 +198,19 @@ namespace Isis {
  //         c->write(spvector);
  //         p.WriteHistory(*c);
  //       }
*/
  //       m_ui->convergenceStatusLabel->setText("Bundle converged, camera pointing updated");
  }
  else {
    //This bundle was bad so we should delete all remenants.
    
    //TODO: delete correlation matrix cov file...
    //TODO: delete bundle results object

//       m_ui->convergenceStatusLabel->setText("Bundle did not converge, camera pointing NOT updated");
  }


//#if 0
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    m_ui->useLastSettings->setEnabled(true);
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//#endif
  }



  /**
   * Update the label or text edit area with the most recent status update by appending to
   * list and refreshing.
   *
   * @param status Current status of bundle.
   */
  void JigsawDialog::outputBundleStatus(QString status) {
    QString update = "\n" + status;
    m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(update) );
  // TODO: Give user the option to keep or throw away the bundle. Even if the bundle converged it
  //       coulde still be worthless.
  }  
}
+13 −1
Original line number Diff line number Diff line
@@ -10,10 +10,21 @@ namespace Ui {
class QString;

namespace Isis {
  class BundleResults;
  class BundleSettings;
  class Control;
  class Project;

  /**
   * This dialog allows the user to select the bundle adjust parameters, run the bundle, and view
   * the results.
   * 
   * @author 2014-??-?? Ken Edmundson
   *
   * @internal
   *   @history 2014-09-18 Kimberly Oyama - Added code to thread the bundle run. It is currently
   *                           commented out but it works. 
   */
  class JigsawDialog : public QDialog {
    Q_OBJECT

@@ -23,6 +34,7 @@ namespace Isis {

  public slots:
    void outputBundleStatus(QString status);
    void bundleFinished(BundleResults *bundleResults);
    
  protected:
    Project *m_project;
@@ -38,4 +50,4 @@ namespace Isis {
    Ui::JigsawDialog *m_ui;
  };
};
#endif // JigsawDialog_h
#endif 
Loading