Isis 3.0 Programmer Reference
Back | Home
JigsawDialog.cpp
1 #include "JigsawDialog.h"
2 
3 #include <QDebug>
4 #include <QScrollBar>
5 #include <QThread>
6 
7 #include "JigsawSetupDialog.h"
8 //#include "ui_JigsawDialog.h"
9 
10 #include "BundleAdjust.h"
11 #include "BundleSolutionInfo.h"
12 #include "Directory.h"
13 #include "IException.h"
14 #include "JigsawSetupDialog.h"
15 #include "Control.h"
16 #include "iTime.h"
17 #include "Process.h"
18 #include "Project.h"
19 #include "ui_JigsawDialog.h"
20 
21 namespace Isis {
22 
23  JigsawDialog::JigsawDialog(Project *project, QWidget *parent) :
24  QDialog(parent), m_ui(new Ui::JigsawDialog) {
25  m_ui->setupUi(this);
26 
27  m_bundleAdjust = NULL;
28  m_project = project;
29  m_selectedControl = NULL;
30 
31  m_bRunning = false;
32 
33  QList<BundleSolutionInfo *> bundleSolutionInfo = m_project->bundleSolutionInfo();
34  if (bundleSolutionInfo.size() <= 0) {
35  m_ui->useLastSettings->setEnabled(false);
36  }
37 
38  m_ui->iterationLcdNumber->setDigitCount(3);
39 
40  m_ui->sigma0LcdNumber->setMode(QLCDNumber::Dec);
41  m_ui->sigma0LcdNumber->setDigitCount(5);
42 
43  setWindowFlags(Qt::WindowStaysOnTopHint);
44  }
45 
46 
47  JigsawDialog::~JigsawDialog() {
48  if (m_ui) {
49  delete m_ui;
50  }
51  m_ui = NULL;
52  }
53 
54 
55  void JigsawDialog::on_JigsawSetupButton_pressed() {
56 
57  // Each time the SetUp button is pressed, create JigsawSetupDialog object with
58  // project,
59  // useLastSettings = matches check box
60  // readOnly = false,
61  // parent = this
62  JigsawSetupDialog setupdlg(m_project,
63  m_ui->useLastSettings->isChecked(),
64  false,
65  this);
66 
67  // how to set up default settings object if last is not used or doesnt exist ???
68  // if (m_bundleSettings != NULL && setupdlg.useLastSettings()) {
69  // }
70  // if (m_bundleSettings == NULL) {
71  // m_bundleSettings = setupdlg.bundleSettings();
72  // }
73 
74  if (setupdlg.exec() == QDialog::Accepted) {
75  m_selectedControlName = setupdlg.selectedControlName();
76  m_selectedControl = setupdlg.selectedControl();
77  m_bundleSettings = setupdlg.bundleSettings();
78  }
79  }
80 
81 
82  void JigsawDialog::on_JigsawRunButton_clicked() {
83 
84  if (!m_bRunning) {
85  // ??? warning dialogs ???
86  if (m_selectedControl == NULL) {
87  }
88 
89  if (m_project->images().size() == 0) {
90  }
91 
92  // assume defaults or send warning???
93  if (m_bundleSettings == NULL) {
94  }
95 
96  QList<BundleSolutionInfo *> bundleSolutionInfo = m_project->bundleSolutionInfo();
97  if (m_ui->useLastSettings->isChecked() && bundleSolutionInfo.size() > 0) {
98  BundleSettingsQsp lastBundleSettings = (bundleSolutionInfo.last())->bundleSettings();
99 
100  if (lastBundleSettings) {
101  m_bundleSettings = lastBundleSettings;
102  }
103  }
104 
105  // Non threaded *************************************************************
106 // SerialNumberList snlist;
107 
108 // QList<ImageList *> imagelists = m_project->images();
109 
110 // for (int i = 0; i < imagelists.size( ); i++) {
111 // ImageList* list = imagelists.at(i);
112 // for (int j = 0; j < list->size(); j++) {
113 // Image* image = list->at(j);
114 // snlist.Add(image->fileName());
115 // }
116 // }
117 
118 // BundleAdjust bundleAdjustment(m_bundleSettings, *m_selectedControl, snlist, false);
119 
120 // connect( &bundleAdjustment, SIGNAL( statusUpdate(QString) ),
121 // this, SLOT( outputBundleStatus(QString) ) );
122 
123 // // clear dialog output window
124 // m_ui->statusUpdatesLabel->clear();
125 
126 // BundleSolutionInfo br = bundleAdjustment.solveCholeskyBR();
127 
128 // bundleFinished(&br);
129  // **************************************************************************
130 
131  // Threaded *****************************************************************
132  QThread *bundleThread = new QThread;
133 
134  // Takes too long to copy/recreate the serial number list
135 // BundleAdjust *ba = new BundleAdjust(m_bundleSettings,
136 // *m_selectedControl,
137 // m_project->images(),
138 // false);
139 
140  // Use the run time to create a uniquely named directory in the results
141  // directory. This run time directory will contain the output files for
142  // this run (along with correlation matrix and serialized bundle
143  // information files).
144 
145 // KLE - test commenting out 2016-05-30
146 // QString runTime = Isis::iTime::CurrentLocalTime().toLatin1().data();
147 // QDir cwd = m_project->addBundleSolutionInfoFolder(runTime);
148 // QString path = cwd.absolutePath() + "/";
149 // m_bundleSettings->setOutputFilePrefix(path);
150 
151 // m_bundleAdjust = new BundleAdjust(m_bundleSettings,
152 // *m_selectedControl,
153 // m_project->images(),
154 // false);
155  m_bundleAdjust = new BundleAdjust(m_bundleSettings, *m_selectedControl, m_project->images(),
156  false);
157 
158  m_bundleAdjust->moveToThread(bundleThread);
159 
160  connect( m_bundleAdjust, SIGNAL( statusUpdate(QString) ),
161  this, SLOT( outputBundleStatus(QString) ) );
162 
163  connect( m_bundleAdjust, SIGNAL( error(QString) ),
164  this, SLOT( errorString(QString) ) );
165 
166  connect( m_bundleAdjust, SIGNAL( bundleException(QString) ),
167  this, SLOT( reportException(QString) ) );
168 
169  connect( m_bundleAdjust, SIGNAL( iterationUpdate(int, double) ),
170  this, SLOT( updateIterationSigma0(int, double) ) );
171 
172  connect( bundleThread, SIGNAL( started() ),
173  m_bundleAdjust, SLOT( solveCholesky() ) );
174 
175  connect( m_bundleAdjust, SIGNAL( resultsReady(BundleSolutionInfo *) ),
176  this, SLOT( bundleFinished(BundleSolutionInfo *) ) );
177 
178  connect( bundleThread, SIGNAL( finished() ),
179  bundleThread, SLOT( deleteLater() ) );
180 
181  // ken testing
182  connect( bundleThread, SIGNAL( finished() ),
183  this, SLOT( notifyThreadFinished() ) );
184 
185  connect( m_bundleAdjust, SIGNAL( finished() ),
186  bundleThread, SLOT( quit() ) );
187 
188  connect( m_bundleAdjust, SIGNAL( finished() ),
189  m_bundleAdjust, SLOT( deleteLater() ) );
190  // ken testing
191 
192  bundleThread->start();
193 
194  // change "Run" button text to "Abort" (or maybe pause)
195  m_bRunning = true;
196  m_ui->JigsawRunButton->setText("&Abort");
197  update();
198  }
199  else {
200  // if bundle is running then we want to abort
201  if (m_bRunning) {
202  m_bundleAdjust->abortBundle();
203  m_bRunning = false;
204  m_ui->JigsawRunButton->setText("&Aborting...");
205  update();
206  }
207  }
208 
209  // ********************************************** ****************************
210 //#if 0
211  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212  m_ui->useLastSettings->setEnabled(true);
213  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214 //#endif
215  }
216 
217 
224  void JigsawDialog::outputBundleStatus(QString status) {
225  QString updateStr = "\n" + status;
226 
227  m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(updateStr) );
228 
229  m_ui->statusUpdateScrollArea->verticalScrollBar()->setSliderPosition(
230  m_ui->statusUpdateScrollArea->verticalScrollBar()->maximum());
231 
232  update();
233  }
234 
235 
241  void JigsawDialog::errorString(QString error) {
242  QString errorStr = "\n" + error;
243  m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(errorStr) );
244 
245  m_ui->statusUpdateScrollArea->verticalScrollBar()->setSliderPosition(
246  m_ui->statusUpdateScrollArea->verticalScrollBar()->maximum());
247 
248  update();
249  }
250 
251 
257  void JigsawDialog::reportException(QString exception) {
258  QString exceptionStr = "\n" + exception;
259  m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(exceptionStr) );
260 
261  m_ui->statusUpdateScrollArea->verticalScrollBar()->setSliderPosition(
262  m_ui->statusUpdateScrollArea->verticalScrollBar()->maximum());
263 
264  update();
265  }
266 
267 
273  void JigsawDialog::updateIterationSigma0(int iteration, double sigma0) {
274  m_ui->iterationLcdNumber->display(iteration);
275  m_ui->sigma0LcdNumber->display(sigma0);
276 
277  update();
278  }
279 
280 
281  void JigsawDialog::notifyThreadFinished() {
282  QString str = "\nThread Finished signal received";
283  m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(str) );
284 
285  // set Run button text back to "Run"
286  m_ui->JigsawRunButton->setText("&Run...");
287 
288  update();
289 
290  m_ui->statusUpdateScrollArea->verticalScrollBar()->setSliderPosition(
291  m_ui->statusUpdateScrollArea->verticalScrollBar()->maximum());
292  }
293 
294 
305  if ( bundleSolutionInfo->bundleResults().converged() ) {
306  bundleSolutionInfo->setRunTime( Isis::iTime::CurrentLocalTime().toLatin1().data() );
307  m_project->addBundleSolutionInfo( new BundleSolutionInfo(*bundleSolutionInfo) );
308 
309  //TODO: move correlation matrix to correct position in project directory
310 
311  // create output control net
312  // bundleAdjustment.controlNet()->Write("ONET.net");
313  //
314  // for (int i = 0; i < bundleAdjustment.images(); i++) {
315  // Process p;
316  // CubeAttributeInput inAtt;
317  // Cube *c = p.SetInputCube(bundleAdjustment.fileName(i), inAtt, ReadWrite);
318  // //check for existing polygon, if exists delete it
319  // if (c->label()->hasObject("Polygon")) {
320  // c->label()->deleteObject("Polygon");
321  // }
322  //
323  // // check for CameraStatistics Table, if exists, delete
324  // for (int iobj = 0; iobj < c->label()->objects(); iobj++) {
325  // PvlObject obj = c->label()->object(iobj);
326  // if (obj.name() != "Table") continue;
327  // if (obj["Name"][0] != QString("CameraStatistics")) continue;
328  // c->label()->deleteObject(iobj);
329  // break;
330  // }
331  //
332  // // Get Kernel group and add or replace LastModifiedInstrumentPointing
333  // // keyword.
334  // Table cmatrix = bundleAdjustment.cMatrix(i);
335  // QString jigComment = "Jigged = " + Isis::iTime::CurrentLocalTime();
336  // cmatrix.Label().addComment(jigComment);
337  // Table spvector = bundleAdjustment.spVector(i);
338  // spvector.Label().addComment(jigComment);
339  // c->write(cmatrix);
340  // c->write(spvector);
341  // p.WriteHistory(*c);
342  // }
343  // m_ui->convergenceStatusLabel->setText("Bundle converged, camera pointing updated");
344  }
345  else {
346  //This bundle was bad so we should delete all remenants.
347 
348  //TODO: delete correlation matrix cov file...
349  //TODO: delete bundle results object
350 
351 // m_ui->convergenceStatusLabel->setText("Bundle did not converge, camera pointing NOT updated");
352  }
353 
354  // TODO: Give user the option to keep or throw away the bundle. Even if the bundle converged it
355  // could still be worthless.
356  }
357 }
358 
403 /*
404  void JigsawDialog::on_JigsawRunButton_clicked() {
405 
406  // Non threaded *************************************************************
407  SerialNumberList snlist;
408 
409  QList<ImageList *> imagelists = m_project->images();
410 
411  for (int i = 0; i < imagelists.size( ); i++) {
412  ImageList* list = imagelists.at(i);
413  for (int j = 0; j < list->size(); j++) {
414  Image* image = list->at(j);
415  snlist.Add(image->fileName());
416  }
417  }
418 
419  BundleAdjust bundleAdjustment(m_bundleSettings, *m_selectedControl, snlist, false);
420 
421  connect( &bundleAdjustment, SIGNAL( statusUpdate(QString) ),
422  this, SLOT( outputBundleStatus(QString) ) );
423 
424  // clear dialog output window
425  m_ui->statusUpdatesLabel->clear();
426 
427  BundleSolutionInfo br = bundleAdjustment.solveCholeskyBR();
428 
429  bundleFinished(&br);
430  // **************************************************************************
431 
432  // ********************************************** ****************************
433 //#if 0
434  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
435  m_ui->useLastSettings->setEnabled(true);
436  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
437 //#endif
438  }
439 */
void setRunTime(QString runTime)
Sets the run time.
QSharedPointer< BundleSettings > BundleSettingsQsp
Definition for a BundleSettingsQsp, a shared pointer to a BundleSettings object.
The main project for cnetsuite.
Definition: Project.h:105
static QString CurrentLocalTime()
Returns the current local time This time is taken directly from the system clock, so if the system cl...
Definition: iTime.cpp:519
Container class for BundleAdjustment results.
void updateIterationSigma0(int iteration, double sigma0)
Update the label or text edit area with the error message by appending to list and refreshing...
void bundleFinished(BundleSolutionInfo *bundleSolutionInfo)
This method will be called when the bundle is complete.
static QStringList images(QStringList)
Verify that the input fileNames are image files.
Definition: Project.cpp:561
void addBundleSolutionInfo(BundleSolutionInfo *bundleSolutionInfo)
Add the given BundleSolutionInfo to the current project.
Definition: Project.cpp:789
void abortBundle()
Flag to abort when bundle is threaded.
void outputBundleStatus(QString status)
Update the label or text edit area with the most recent status update by appending to list and refres...
void reportException(QString exception)
Update the label or text edit area with the error message by appending to list and refreshing...
This dialog allows the user to select the bundle adjust parameters, run the bundle, and view the results.
Definition: JigsawDialog.h:41
void errorString(QString error)
Update the label or text edit area with the error message by appending to list and refreshing...
bool converged() const
Returns whether or not the bundle adjustment converged.
BundleResults bundleResults()
Returns the bundle results.
An image bundle adjustment object.
Definition: BundleAdjust.h:271

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:21:28