Isis 3 Programmer Reference
BundleAdjust.h
1 #ifndef BundleAdjust_h
2 #define BundleAdjust_h
3 
10 /* SPDX-License-Identifier: CC0-1.0 */
11 
12 #include <QObject> // parent class
13 
14 // std lib
15 #include <vector>
16 #include <fstream>
17 
18 // cholmod lib
19 #include <cholmod.h>
20 
21 // Isis lib
22 #include "BundleControlPoint.h"
23 #include "BundleObservationSolveSettings.h"
24 #include "BundleObservationVector.h"
25 #include "BundleResults.h"
26 #include "BundleSettings.h"
27 #include "BundleSolutionInfo.h"
28 #include "BundleTargetBody.h"
29 #include "Camera.h"
30 #include "CameraGroundMap.h"
31 #include "ControlMeasure.h"
32 #include "ControlNet.h"
33 #include "LinearAlgebra.h"
34 #include "MaximumLikelihoodWFunctions.h" // why not just forward declare???
35 #include "ObservationNumberList.h"
36 #include "Progress.h"
37 #include "SerialNumberList.h"
38 #include "SparseBlockMatrix.h"
39 #include "Statistics.h"
40 
41 template< typename T > class QList;
42 template< typename A, typename B > class QMap;
43 
44 namespace Isis {
45  class Control;
46  class ImageList;
47 
318  class BundleAdjust : public QObject {
319  Q_OBJECT
320  public:
321  BundleAdjust(BundleSettingsQsp bundleSettings,
322  const QString &cnetFile,
323  const QString &cubeList,
324  bool printSummary = true);
325  BundleAdjust(BundleSettingsQsp bundleSettings,
326  QString &cnet,
327  SerialNumberList &snlist,
328  bool printSummary = true);
329  BundleAdjust(BundleSettingsQsp bundleSettings,
330  Control &cnet,
331  SerialNumberList &snlist,
332  bool bPrintSummary);
333  BundleAdjust(BundleSettingsQsp bundleSettings,
334  ControlNet &cnet,
335  SerialNumberList &snlist,
336  bool printSummary = true);
337  BundleAdjust(BundleSettingsQsp bundleSettings,
338  ControlNetQsp cnet,
339  const QString &cubeList,
340  bool printSummary = true);
341  BundleAdjust(BundleSettingsQsp bundleSettings,
342  Control &control,
343  QList<ImageList *> imgList,
344  bool printSummary);
345  ~BundleAdjust();
347 
349  bool isAborted();
350 
351  public slots:
352  bool solveCholesky();
353  void abortBundle();
354  void outputBundleStatus(QString status);
355 
356  // accessors
357 
360  QString fileName(int index);
361  QString iterationSummaryGroup() const;
362  bool isConverged();
363  Table cMatrix(int index);
364  Table spVector(int index);
365  QString modelState(int index);
366  int numberOfImages() const;
367  double iteration() const;
368 
369  signals:
370  void statusUpdate(QString);
371  void error(QString);
372  void iterationUpdate(int);
373  void pointUpdate(int);
374  void statusBarUpdate(QString);
375  void resultsReady(BundleSolutionInfo *bundleSolveInformation);
376  void finished();
377 
378  private:
379  //TODO Should there be a resetBundle(BundleSettings bundleSettings) method
380  // that allows for rerunning with new settings? JWB
381  void init(Progress *progress = 0);
383  bool validateNetwork();
384  bool solveSystem();
385  void iterationSummary();
389  bool errorPropagation();
390  double computeResiduals();
391  bool computeRejectionLimit();
392  bool flagOutliers();
393 
394  // normal equation matrices methods
395 
396  bool formNormalEquations();
397  bool computePartials(LinearAlgebra::Matrix &coeffTarget,
398  LinearAlgebra::Matrix &coeffImage,
399  LinearAlgebra::Matrix &coeffPoint3D,
400  LinearAlgebra::Vector &coeffRHS,
401  BundleMeasure &measure,
402  BundleControlPoint &point);
403  bool formMeasureNormals(boost::numeric::ublas::symmetric_matrix<
404  double, boost::numeric::ublas::upper > &N22,
406  boost::numeric::ublas::compressed_vector< double > &n1,
408  LinearAlgebra::Matrix &coeffTarget,
409  LinearAlgebra::Matrix &coeffImage,
410  LinearAlgebra::Matrix &coeffPoint3D,
411  LinearAlgebra::Vector &coeffRHS,
412  int observationIndex);
413  bool formPointNormals(boost::numeric::ublas::symmetric_matrix<
414  double, boost::numeric::ublas::upper > &N22,
418  BundleControlPointQsp &point);
419  bool formWeightedNormals(boost::numeric::ublas::compressed_vector< double > &n1,
421 
422  // dedicated matrix functions
423 
426  void accumProductAlphaAB(double alpha,
430  bool invert3x3(boost::numeric::ublas::symmetric_matrix<
431  double, boost::numeric::ublas::upper > &m);
432  bool productATransB(boost::numeric::ublas::symmetric_matrix<
433  double, boost::numeric::ublas::upper > &N22,
436  void productAlphaAV(double alpha,
437  boost::numeric::ublas::bounded_vector< double, 3 > &v2,
440 
441  // CHOLMOD library methods
442 
445  bool cholmodInverse();
446  bool loadCholmodTriplet();
447  bool wrapUp();
448 
449  // member variables
450 
458  QString m_cnetFileName;
459  QVector <BundleControlPointQsp> m_bundleControlPoints;
467  BundleTargetBodyQsp m_bundleTargetBody;
469  bool m_abort;
470  QString m_iterationSummary;
475  bool m_cleanUp;
478  int m_rank;
481  QList<ImageList *> m_imageLists;
484  // ==========================================================================================
485  // === BEYOND THIS PLACE (THERE BE DRAGONS) all refers to the folded bundle solution. ===
486  // === Currently, everything uses the CHOLMOD library, ===
487  // === there is no dependence on the least-squares class. ===
488  // ==========================================================================================
489 
491  boost::numeric::ublas::symmetric_matrix<
492  double,
493  boost::numeric::ublas::upper,
494  boost::numeric::ublas::column_major > m_normalInverse;
495  cholmod_common m_cholmodCommon;
504  cholmod_triplet *m_cholmodTriplet;
510  cholmod_sparse *m_cholmodNormal;
515  cholmod_factor *m_L;
525  };
526 }
527 
528 #endif
Isis::BundleAdjust::m_numberOfImagePartials
int m_numberOfImagePartials
number of image-related partials.
Definition: BundleAdjust.h:480
Isis::BundleAdjust::fileName
QString fileName(int index)
Return the ith filename in the cube list file given to constructor.
Definition: BundleAdjust.cpp:2806
Isis::BundleAdjust::iteration
double iteration() const
Returns what iteration the BundleAdjust is currently on.
Definition: BundleAdjust.cpp:2816
Isis::BundleAdjust::serialNumberList
SerialNumberList * serialNumberList()
Returns a pointer to the serial number list.
Definition: BundleAdjust.cpp:2783
Isis::BundleAdjust::m_abort
bool m_abort
!< Contains information about the target body.
Definition: BundleAdjust.h:469
Isis::BundleAdjust
An image bundle adjustment object.
Definition: BundleAdjust.h:318
Isis::BundleAdjust::computeResiduals
double computeResiduals()
This method computes the focal plane residuals for the measures.
Definition: BundleAdjust.cpp:2010
Isis::BundleAdjust::wrapUp
bool wrapUp()
Compute the residuals for each adjusted point and store adjustment results in m_bundleResults.
Definition: BundleAdjust.cpp:2118
Isis::BundleAdjust::m_normalInverse
boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper, boost::numeric::ublas::column_major > m_normalInverse
!< The lists of images used in the bundle.
Definition: BundleAdjust.h:494
Isis::Statistics
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:94
Isis::BundleAdjust::m_L
cholmod_factor * m_L
!< The CHOLMOD sparse normal equations matrix used by cholmod_factorize to solve the system.
Definition: BundleAdjust.h:515
Isis::SparseBlockColumnMatrix
SparseBlockColumnMatrix.
Definition: SparseBlockMatrix.h:58
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::BundleAdjust::invert3x3
bool invert3x3(boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper > &m)
Dedicated quick inverse of 3x3 matrix.
Definition: BundleAdjust.cpp:1806
Isis::BundleAdjust::bundleSolveInformation
BundleSolutionInfo * bundleSolveInformation()
Create a BundleSolutionInfo containing the settings and results from the bundle adjustment.
Definition: BundleAdjust.cpp:1029
Isis::BundleAdjust::freeCHOLMODLibraryVariables
bool freeCHOLMODLibraryVariables()
Free CHOLMOD library variables.
Definition: BundleAdjust.cpp:676
Isis::BundleAdjust::isConverged
bool isConverged()
Returns if the BundleAdjust converged.
Definition: BundleAdjust.cpp:2949
Isis::BundleAdjust::flagOutliers
bool flagOutliers()
Flags outlier measures and control points.
Definition: BundleAdjust.cpp:2246
Isis::BundleAdjust::formWeightedNormals
bool formWeightedNormals(boost::numeric::ublas::compressed_vector< double > &n1, LinearAlgebra::Vector &nj)
Apply weighting for spacecraft position, velocity, acceleration and camera angles,...
Definition: BundleAdjust.cpp:1387
Isis::BundleAdjust::abortBundle
void abortBundle()
Flag to abort when bundle is threaded.
Definition: BundleAdjust.cpp:707
Isis::BundleAdjust::m_sparseNormals
SparseBlockMatrix m_sparseNormals
!< The right hand side of the normal equations.
Definition: BundleAdjust.h:500
Isis::BundleAdjust::init
void init(Progress *progress=0)
Initialize all solution parameters.
Definition: BundleAdjust.cpp:372
Isis::BundleAdjust::spVector
Table spVector(int index)
Return the updated instrument position table for the ith cube in the cube list given to the construct...
Definition: BundleAdjust.cpp:2846
Isis::BundleControlPoint
This class holds information about a control point that BundleAdjust needs to run correctly.
Definition: BundleControlPoint.h:91
Isis::Control
This represents an ISIS control net in a project-based GUI interface.
Definition: Control.h:66
QSharedPointer< BundleSettings >
Isis::BundleAdjust::cholmodInverse
bool cholmodInverse()
Compute inverse of normal equations matrix for CHOLMOD.
Definition: BundleAdjust.cpp:1757
Isis::BundleAdjust::modelState
QString modelState(int index)
Return the updated model state for the ith cube in the cube list given to the constructor.
Definition: BundleAdjust.cpp:2859
Isis::LinearAlgebra::Matrix
boost::numeric::ublas::matrix< double > Matrix
Definition for an Isis::LinearAlgebra::Matrix of doubles.
Definition: LinearAlgebra.h:100
Isis::SerialNumberList
Serial Number list generator.
Definition: SerialNumberList.h:64
Isis::BundleAdjust::controlNet
ControlNetQsp controlNet()
Returns a pointer to the output control network.
Definition: BundleAdjust.cpp:2773
Isis::BundleAdjust::m_imageSolution
LinearAlgebra::Vector m_imageSolution
!< The lower triangular L matrix from Cholesky decomposition.
Definition: BundleAdjust.h:519
Isis::BundleAdjust::m_xyResiduals
Statistics m_xyResiduals
xy residual statistics.
Definition: BundleAdjust.h:456
Isis::BundleAdjust::solveCholesky
bool solveCholesky()
Compute the least squares bundle adjustment solution using Cholesky decomposition.
Definition: BundleAdjust.cpp:726
Isis::BundleAdjust::solveSystem
bool solveSystem()
Compute the solution to the normal equations using the CHOLMOD library.
Definition: BundleAdjust.cpp:1572
Isis::ImageList
Internalizes a list of images and allows for operations on the entire list.
Definition: ImageList.h:55
Isis::BundleAdjust::validateNetwork
bool validateNetwork()
control network validation - on the very real chance that the net has not been checked before running...
Definition: BundleAdjust.cpp:566
Isis::BundleAdjust::m_serialNumberList
SerialNumberList * m_serialNumberList
!< Vector of observations.
Definition: BundleAdjust.h:466
Isis::BundleAdjust::isAborted
bool isAborted()
Returns if the BundleAdjust has been aborted.
Definition: BundleAdjust.cpp:2959
Isis::BundleAdjust::m_bundleSettings
BundleSettingsQsp m_bundleSettings
Contains the solve settings.
Definition: BundleAdjust.h:451
Isis::BundleAdjust::m_cholmodTriplet
cholmod_triplet * m_cholmodTriplet
!< The sparse block normal equations matrix.
Definition: BundleAdjust.h:504
Isis::LinearAlgebra::Vector
boost::numeric::ublas::vector< double > Vector
Definition for an Isis::LinearAlgebra::Vector of doubles.
Definition: LinearAlgebra.h:120
Isis::BundleAdjust::applyParameterCorrections
void applyParameterCorrections()
Apply parameter corrections for solution.
Definition: BundleAdjust.cpp:1944
Isis::BundleAdjust::productATransB
bool productATransB(boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper > &N22, SparseBlockColumnMatrix &N12, SparseBlockRowMatrix &Q)
Perform the matrix multiplication Q = N22 x N12(transpose)
Definition: BundleAdjust.cpp:1458
Isis::BundleAdjust::initializeNormalEquationsMatrix
bool initializeNormalEquationsMatrix()
Initialize Normal Equations matrix (m_sparseNormals).
Definition: BundleAdjust.cpp:634
Isis::BundleAdjust::loadCholmodTriplet
bool loadCholmodTriplet()
Load sparse normal equations matrix into CHOLMOD triplet.
Definition: BundleAdjust.cpp:1643
Isis::BundleAdjust::m_bundleResults
BundleResults m_bundleResults
Stores the results of the bundle adjust.
Definition: BundleAdjust.h:452
Isis::BundleAdjust::cMatrix
Table cMatrix(int index)
Return the updated instrument pointing table for the ith cube in the cube list given to the construct...
Definition: BundleAdjust.cpp:2831
Isis::BundleAdjust::BundleAdjust
BundleAdjust(BundleSettingsQsp bundleSettings, const QString &cnetFile, const QString &cubeList, bool printSummary=true)
Construct a BundleAdjust object from the given settings, control network file, and cube list.
Definition: BundleAdjust.cpp:104
Isis::BundleSolutionInfo
Container class for BundleAdjustment results.
Definition: BundleSolutionInfo.h:159
Isis::Table
Class for storing Table blobs information.
Definition: Table.h:61
Isis::BundleAdjust::formMeasureNormals
bool formMeasureNormals(boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper > &N22, SparseBlockColumnMatrix &N12, boost::numeric::ublas::compressed_vector< double > &n1, LinearAlgebra::Vector &n2, LinearAlgebra::Matrix &coeffTarget, LinearAlgebra::Matrix &coeffImage, LinearAlgebra::Matrix &coeffPoint3D, LinearAlgebra::Vector &coeffRHS, int observationIndex)
Form the auxilary normal equation matrices for a measure.
Definition: BundleAdjust.cpp:1179
Isis::BundleAdjust::m_yResiduals
Statistics m_yResiduals
y residual statistics.
Definition: BundleAdjust.h:455
Isis::BundleAdjust::m_cleanUp
bool m_cleanUp
!< If the iteration summaries should be output to the log file.
Definition: BundleAdjust.h:475
Isis::BundleAdjust::~BundleAdjust
~BundleAdjust()
Destroys BundleAdjust object, deallocates pointers (if we have ownership), and frees variables from c...
Definition: BundleAdjust.cpp:330
Isis::ControlNet
a control network
Definition: ControlNet.h:257
Isis::BundleMeasure
A container class for a ControlMeasure.
Definition: BundleMeasure.h:55
Isis::BundleAdjust::m_RHS
LinearAlgebra::Vector m_RHS
!< Contains object parameters, statistics, and workspace used by the CHOLMOD library.
Definition: BundleAdjust.h:498
Isis::BundleAdjust::m_rank
int m_rank
!< If the serial number lists need to be deleted by the destructor.
Definition: BundleAdjust.h:478
Isis::Progress
Program progress reporter.
Definition: Progress.h:42
Isis::BundleAdjust::numberOfImages
int numberOfImages() const
Returns the number of images.
Definition: BundleAdjust.cpp:2793
Isis::BundleAdjust::m_cnetFileName
QString m_cnetFileName
The control net filename.
Definition: BundleAdjust.h:458
Isis::BundleAdjust::accumProductAlphaAB
void accumProductAlphaAB(double alpha, SparseBlockRowMatrix &A, LinearAlgebra::Vector &B, LinearAlgebra::Vector &C)
Performs the matrix multiplication nj = nj + alpha (Q x n2).
Definition: BundleAdjust.cpp:1533
Isis::BundleAdjust::m_bundleObservations
BundleObservationVector m_bundleObservations
!< Vector of control points.
Definition: BundleAdjust.h:463
Isis::BundleAdjust::productAB
void productAB(SparseBlockColumnMatrix &A, SparseBlockRowMatrix &B)
Perform the matrix multiplication C = N12 x Q.
Definition: BundleAdjust.cpp:1488
Isis::BundleAdjust::solveCholeskyBR
BundleSolutionInfo * solveCholeskyBR()
Compute the least squares bundle adjustment solution using Cholesky decomposition.
Definition: BundleAdjust.cpp:697
Isis::BundleAdjust::m_xResiduals
Statistics m_xResiduals
x residual statistics.
Definition: BundleAdjust.h:454
Isis::BundleAdjust::formPointNormals
bool formPointNormals(boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper > &N22, SparseBlockColumnMatrix &N12, LinearAlgebra::Vector &n2, LinearAlgebra::Vector &nj, BundleControlPointQsp &point)
Compute the Q matrix and NIC vector for a control point.
Definition: BundleAdjust.cpp:1315
Isis::BundleAdjust::computeRejectionLimit
bool computeRejectionLimit()
Compute rejection limit.
Definition: BundleAdjust.cpp:2147
Isis::BundleAdjust::formNormalEquations
bool formNormalEquations()
Form the least-squares normal equations matrix via cholmod.
Definition: BundleAdjust.cpp:1050
Isis::BundleAdjust::m_controlNet
ControlNetQsp m_controlNet
Output control net.
Definition: BundleAdjust.h:457
Isis::BundleAdjust::iterationSummaryGroup
QString iterationSummaryGroup() const
Returns the iteration summary string.
Definition: BundleAdjust.cpp:2971
Isis::BundleAdjust::iterationSummary
void iterationSummary()
Creates an iteration summary and an iteration group for the solution summary.
Definition: BundleAdjust.cpp:2880
Isis::BundleAdjust::m_iteration
int m_iteration
The current iteration.
Definition: BundleAdjust.h:479
Isis::BundleAdjust::m_cholmodNormal
cholmod_sparse * m_cholmodNormal
!< The CHOLMOD triplet representation of the sparse normal equations matrix.
Definition: BundleAdjust.h:510
Isis::BundleAdjust::computeBundleStatistics
bool computeBundleStatistics()
Compute Bundle statistics and store them in m_bundleResults.
Definition: BundleAdjust.cpp:3031
QMap
This is free and unencumbered software released into the public domain.
Definition: CubeIoHandler.h:22
Isis::BundleAdjust::outputBundleStatus
void outputBundleStatus(QString status)
Slot for deltack and jigsaw to output the bundle status.
Definition: BundleAdjust.cpp:2985
Isis::BundleAdjust::errorPropagation
bool errorPropagation()
Error propagation for solution.
Definition: BundleAdjust.cpp:2425
Isis::BundleAdjust::imageLists
QList< ImageList * > imageLists()
This method returns the image list used in the bundle adjust.
Definition: BundleAdjust.cpp:2376
Isis::BundleAdjust::initializeCHOLMODLibraryVariables
bool initializeCHOLMODLibraryVariables()
Initializations for CHOLMOD sparse matrix package.
Definition: BundleAdjust.cpp:604
Isis::SparseBlockRowMatrix
SparseBlockRowMatrix.
Definition: SparseBlockMatrix.h:125
Isis::BundleResults
A container class for statistical results from a BundleAdjust solution.
Definition: BundleResults.h:82
QObject
QVector
This is free and unencumbered software released into the public domain.
Definition: Calculator.h:18
Isis::BundleAdjust::computePartials
bool computePartials(LinearAlgebra::Matrix &coeffTarget, LinearAlgebra::Matrix &coeffImage, LinearAlgebra::Matrix &coeffPoint3D, LinearAlgebra::Vector &coeffRHS, BundleMeasure &measure, BundleControlPoint &point)
Compute partial derivatives and weighted residuals for a measure.
Definition: BundleAdjust.cpp:1853
Isis::SparseBlockMatrix
SparseBlockMatrix.
Definition: SparseBlockMatrix.h:186
Isis::BundleAdjust::m_printSummary
bool m_printSummary
!< Summary of the most recently completed iteration.
Definition: BundleAdjust.h:472
Isis::BundleAdjust::m_previousNumberImagePartials
int m_previousNumberImagePartials
!< The image parameter solution vector.
Definition: BundleAdjust.h:522
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::BundleObservationVector
This class is a container class for BundleObservations.
Definition: BundleObservationVector.h:55