Vespucci  1.0.0
mainwindow.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
20 #include "GUI/mainwindow.h"
21 #include "ui_mainwindow.h"
31 #include "GUI/Display/dataviewer.h"
32 #include "GUI/Analysis/plsdialog.h"
34 #include "GUI/Analysis/vcadialog.h"
40 #include "GUI/scriptdialog.h"
44 #include "GUI/settingsdialog.h"
50 #include "GUI/Display/mapdialog.h"
67 MainWindow::MainWindow(QWidget *parent, QSharedPointer<VespucciWorkspace> ws) :
68  QMainWindow(parent),
69  ui(new Ui::MainWindow)
70 {
71  workspace_ = ws;
72  ui->setupUi(this);
73  this->move(0, 0);
74  dataset_tree_model_ = new DatasetTreeModel(ui->datasetTreeView);
75  ui->datasetTreeView->setModel(dataset_tree_model_);
76  data_viewer_ = new DataViewer(this, workspace_);
77  plot_viewer_ = new PlotViewer(this, workspace_);
78  spectrum_editor_ = new SpectrumEditor(this, workspace_);
79  stats_viewer_ = new StatsDialog(this, workspace_);
80  macro_editor_ = new MacroDialog(this, workspace_);
81  python_shell_ = new PythonShellDialog(this, workspace_);
82  history_dialog_ = new HistoryDialog(this, workspace_);
83  matrix_selection_dialog_ = new MatrixSelectionDialog(this, dataset_tree_model_);
84 
85  setCentralWidget(ui->datasetTreeView);
86 
87  global_map_count_ = 0;
88  workspace_->SetPointers(this, dataset_tree_model_);
89 
90 
91  addDockWidget(Qt::BottomDockWidgetArea, data_viewer_);
92  addDockWidget(Qt::BottomDockWidgetArea, plot_viewer_);
93  addDockWidget(Qt::RightDockWidgetArea, spectrum_editor_);
94 
95  //Connects the closing of persistent dialogs to unchecking their menu entries
96  connect(data_viewer_, &DataViewer::SetActionChecked,
98  connect(plot_viewer_, &PlotViewer::SetActionChecked,
100  connect(spectrum_editor_, &SpectrumEditor::SetActionChecked,
102  connect(stats_viewer_, &StatsDialog::SetActionChecked,
104  connect(macro_editor_, &MacroDialog::SetActionChecked,
106  connect(python_shell_, &PythonShellDialog::SetActionChecked,
108 
109  //connects the change in active dataset connected to change in display
110  connect(this, &MainWindow::MatrixSelectionChanged,
111  stats_viewer_, &StatsDialog::MatrixSelectionChanged);
113  spectrum_editor_, &SpectrumEditor::DatasetSelectionChanged);
115  history_dialog_, &HistoryDialog::DatasetSelectionChanged);
117  macro_editor_, &MacroDialog::DatasetSelectionChanged);
118  connect(history_dialog_, &HistoryDialog::MacroRequested,
119  macro_editor_, &MacroDialog::MacroRequested);
120 
121 
122 
123  //Triggers the removal of references that are about to become bad
124  connect(this, &MainWindow::DatasetToBeRemoved,
125  data_viewer_, &DataViewer::DatasetToBeRemoved);
126  connect(this, &MainWindow::DatasetToBeRemoved,
127  spectrum_editor_, &SpectrumEditor::DatasetToBeRemoved);
128  connect(this, &MainWindow::DatasetToBeRemoved,
129  stats_viewer_, &StatsDialog::DatasetToBeRemoved);
130  connect(this, &MainWindow::MatrixToBeRemoved,
131  data_viewer_, &DataViewer::MatrixToBeRemoved);
132  connect(this, &MainWindow::MatrixToBeRemoved,
133  stats_viewer_, &StatsDialog::MatrixToBeRemoved);
134  item_selected_ = false;
135  connect(matrix_selection_dialog_, &MatrixSelectionDialog::ItemSelected,
136  this, &MainWindow::ItemSelected);
137 
138 }
139 
141 {
142  delete ui;
143 }
144 
150 {
151  dataset_tree_model_ = new DatasetTreeModel(ui->datasetTreeView, data_model);
152  ui->datasetTreeView->setModel(dataset_tree_model_);
153  ui->datasetTreeView->resizeColumnToContents(0);
154  ui->datasetTreeView->resizeColumnToContents(1);
155 }
156 
157 
162 void MainWindow::closeEvent(QCloseEvent *event)
163 {
164  int response = QMessageBox::question(this,
165  "Exit?",
166  "Are you sure you want to exit?");
167  if (response == QMessageBox::Yes) {
168  for (auto name: workspace_->dataset_names()){
169  CloseDataset(name);
170  }
171  event->accept();
172  qApp->exit();
173  }
174 
175  else {
176  event->ignore();
177  }
178 }
179 
183 void MainWindow::on_actionExit_triggered()
184 {
185  close();
186 }
187 
191 void MainWindow::on_actionImport_Dataset_from_File_triggered()
192 {
193  DatasetImportDialog *dataset_import_dialog = new DatasetImportDialog(this,workspace_);
194  dataset_import_dialog->setAttribute(Qt::WA_DeleteOnClose);
195  dataset_import_dialog->show();
196 }
197 
201 void MainWindow::on_actionAbout_Vespucci_triggered()
202 {
203  AboutDialog *about_window = new AboutDialog(this);
204  about_window->setAttribute(Qt::WA_DeleteOnClose);
205  about_window->show();
206 }
207 
211 void MainWindow::on_actionCiting_Vespucci_triggered()
212 {
213  CitationDialog *citation_window = new CitationDialog(this);
214  citation_window->setAttribute(Qt::WA_DeleteOnClose);
215  citation_window->show();
216 }
217 
221 void MainWindow::on_actionNew_Univariate_Map_triggered()
222 {
223  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
224  if (item->type() == TreeItem::ItemType::Base){
225  QMessageBox::information(this,
226  "No datasets loaded",
227  "No dataset exists on which to perform this operation");
228  return;
229  }
230  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
231  UnivariateDialog *univariate_dialog =
232  new UnivariateDialog(this, workspace_, dataset);
233  univariate_dialog->setAttribute(Qt::WA_DeleteOnClose);
234  univariate_dialog->show();
235 }
236 
240 void MainWindow::on_actionNew_Band_Ratio_Map_triggered()
241 {
242  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
243  if (item->type() == TreeItem::ItemType::Base){
244  QMessageBox::information(this,
245  "No datasets loaded",
246  "No dataset exists on which to perform this operation");
247  return;
248  }
249 
250  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
251 
252  BandRatioDialog *band_ratio_dialog = new BandRatioDialog(this, workspace_, dataset);
253  band_ratio_dialog->setAttribute(Qt::WA_DeleteOnClose);
254  band_ratio_dialog->show();
255 }
256 
260 void MainWindow::on_actionPrincipal_Components_Analysis_triggered()
261 {
262  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
263  if (item->type() == TreeItem::ItemType::Base){
264  QMessageBox::information(this,
265  "No datasets loaded",
266  "No dataset exists on which to perform this operation");
267  return;
268  }
269 
270  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
271 
272  PrincipalComponentsDialog *principal_components_dialog =
273  new PrincipalComponentsDialog(this, workspace_, dataset);
274  principal_components_dialog->setAttribute(Qt::WA_DeleteOnClose);
275  principal_components_dialog->show();
276 }
277 
278 
282 void MainWindow::on_actionVertex_Components_triggered()
283 {
284  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
285  if (item->type() == TreeItem::ItemType::Base){
286  QMessageBox::information(this,
287  "No datasets loaded",
288  "No dataset exists on which to perform this operation");
289  return;
290  }
291 
292  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
293 
294  VCADialog *vca_dialog = new VCADialog(this, workspace_, dataset);
295  vca_dialog->setAttribute(Qt::WA_DeleteOnClose);
296  vca_dialog->show();
297 }
298 
299 
304 void MainWindow::on_actionPartial_Least_Squares_triggered()
305 {
306  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
307  if (item->type() == TreeItem::ItemType::Base){
308  QMessageBox::information(this,
309  "No datasets loaded",
310  "No dataset exists on which to perform this operation");
311  return;
312  }
313 
314 
315  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
316 
317  PLSDialog *pls_dialog =
318  new PLSDialog(this, workspace_, dataset);
319  pls_dialog->setAttribute(Qt::WA_DeleteOnClose);
320  pls_dialog->show();
321 }
322 
327 void MainWindow::on_actionK_Means_Clustering_triggered()
328 {
329  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
330  if (item->type() == TreeItem::ItemType::Base){
331  QMessageBox::information(this,
332  "No datasets loaded",
333  "No dataset exists on which to perform this operation");
334  return;
335  }
336 
337  if (!item->DatasetKey().isEmpty()){
338  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
339  KMeansDialog *k_means_dialog =
340  new KMeansDialog(this, workspace_, dataset);
341  k_means_dialog->setAttribute(Qt::WA_DeleteOnClose);
342  k_means_dialog->show();
343  }
344 }
345 
346 
350 void MainWindow::on_actionNormalize_Standardize_triggered()
351 {
352  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
353  if (item->type() == TreeItem::ItemType::Base){
354  QMessageBox::information(this,
355  "No datasets loaded",
356  "No dataset exists on which to perform this operation");
357  return;
358  }
359  QString dataset_key = item->DatasetKey();
360  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
361  QStringList methods;
362  methods << "Min/Max" << "2-Norm (Unit Length)" << "1-Norm (Unit Area)" << "Z-score"
363  << "Standard Normal Variate" << "Peak Intensity" << "Scale Spectra"
364  << "Absolute Value" << "Mean Center";
365  bool ok;
366  QString method = QInputDialog::getItem(this,
367  "Normalization/Standardization",
368  "Method:", methods, 0, false, &ok);
369  double scaling_factor, offset;
370  try{
371  if (ok && method == "Min/Max"){dataset->MinMaxNormalize();}
372  else if (ok && method == "2-Norm (Unit Length)"){dataset->VectorNormalize(2);}
373  else if (ok && method == "Mean Center"){dataset->MeanCenter();}
374  else if (ok && method == "1-Norm (Unit Area)"){dataset->VectorNormalize(1);}
375  else if (ok && method == "Z-score"){
376  offset = QInputDialog::getDouble(this, "Enter Offset", "Offset",
377  0, -2147483647, 2147483647, 4, &ok);
378  dataset->SNVNormalize(offset, true);
379  }
380 
381  else if (ok && method == "Peak Intensity"){
382  double min = dataset->wavelength_ptr()->min();
383  double max = dataset->wavelength_ptr()->max();
384  RangeDialog *range_dialog = new RangeDialog(this, min, max);
385  range_dialog->setWindowTitle("Peak Intensity Normalization");
386  connect(range_dialog, &RangeDialog::DialogAccepted,
388  range_dialog->show();
389  }
390  else if (ok && method == "Scale Spectra"){
391  scaling_factor = QInputDialog::getDouble(this, "Enter Scaling Factor",
392  "Factor", 1, -100, 100, 2, &ok);
393  dataset->Scale(scaling_factor);
394  }
395  else if (ok && method == "Standard Normal Variate"){
396  offset = QInputDialog::getDouble(this, "Enter Offset", "Offset",
397  0, -2147483647, 2147483647, 4, &ok);
398  dataset->SNVNormalize(offset, false);
399  }
400  else if (ok && method == "Absolute Value"){dataset->AbsoluteValue();}
401  else
402  return;
403  }
404 
405  catch(exception e){
407  }
408 }
409 
413 void MainWindow::on_actionSubtract_Background_triggered()
414 {
415  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
416  if (item->type() == TreeItem::ItemType::Base){
417  QMessageBox::information(this,
418  "No datasets loaded",
419  "No dataset exists on which to perform this operation");
420  return;
421  }
422 
423  QString dataset_key = item->DatasetKey();
424 
425  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
426 
427  matrix_selection_dialog_->SetModel(dataset_tree_model_);
428  matrix_selection_dialog_->show();
429  if (item_selected_){
430  if (selected_item_->type() == TreeItem::ItemType::Matrix){
431  try{
432  dataset->SubtractBackground(selected_item_->keys());
433  }catch(exception e){
434  DisplayExceptionWarning("VespucciDataset::SubtractBackground", e);
435  }
436  }
437  else{
438  DisplayWarning("Not a matrix", "Selected item is not a matrix");
439  }
440  }
441  item_selected_ = false;
442 }
443 
447 void MainWindow::on_actionSpectra_triggered()
448 {
449  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
450  if (item->type() == TreeItem::ItemType::Base){
451  QMessageBox::information(this,
452  "No datasets loaded",
453  "No dataset exists on which to perform this operation");
454  return;
455  }
456 
457  bool success;
458  QString dataset_key = item->DatasetKey();
459  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
460  QString filename =
461  QFileDialog::getSaveFileName(this,
462  tr("Save Spectra Matrix"),
463  workspace_->directory(),
464  tr("Vespucci Binary (*.arma);;"
465  "Comma-separated Values (*.csv);;"
466  "Tab-separated Txt (*.txt);;"));
467  QFileInfo file_info(filename);
468  workspace_->set_directory(file_info.dir().path());
469 
470  if (file_info.suffix() == "arma")
471  success = dataset->spectra().save(filename.toStdString(), arma_binary);
472  else if (file_info.suffix() == "csv")
473  success = dataset->spectra().save(filename.toStdString(), csv_ascii);
474  else
475  success = dataset->spectra().save(filename.toStdString(), raw_ascii);
476 
477  if (success)
478  QMessageBox::information(this, "File Saved", "File written successfully!");
479  else
480  QMessageBox::warning(this, "File Not Saved", "Could not save file.");
481 }
482 
486 void MainWindow::on_actionSpectra_as_Columns_triggered()
487 {
488  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
489  if (item->type() == TreeItem::ItemType::Base){
490  QMessageBox::information(this,
491  "No datasets loaded",
492  "No dataset exists on which to perform this operation");
493  return;
494  }
495  bool success;
496 
497  QString dataset_key = item->DatasetKey();
498 
499  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
500 
501  QString filename =
502  QFileDialog::getSaveFileName(this,
503  tr("Save Spectra Matrix"),
504  workspace_->directory(),
505  tr("Vespucci Binary (*.arma);;"
506  "Comma-separated Values (*.csv);;"
507  "Tab-separated Txt (*.txt);;"));
508  QFileInfo file_info(filename);
509  workspace_->set_directory(file_info.dir().path());
510  mat output = dataset->spectra().t();
511 
512  if (file_info.suffix() == "arma")
513  success = output.save(filename.toStdString(), arma_binary);
514  else if (file_info.suffix() == "csv")
515  success = output.save(filename.toStdString(), csv_ascii);
516  else
517  success = output.save(filename.toStdString(), raw_ascii);
518 
519  if (success)
520  QMessageBox::information(this, "File Saved", "File written successfully!");
521  else
522  QMessageBox::warning(this, "File Not Saved", "Could not save file.");
523 }
524 
528 void MainWindow::on_actionAverage_Spectra_triggered()
529 {
530  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
531  if (item->type() == TreeItem::ItemType::Base){
532  QMessageBox::information(this,
533  "No datasets loaded",
534  "No dataset exists on which to perform this operation");
535  return;
536  }
537  bool success;
538 
539  QString dataset_key = item->DatasetKey();
540 
541  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
542 
543  QString filename =
544  QFileDialog::getSaveFileName(this,
545  tr("Save Average Spectrum"),
546  workspace_->directory(),
547  tr("Vespucci Binary (*.arma);;"
548  "Comma-separated Values (*.csv);;"
549  "Tab-separated Txt (*.txt);;"));
550  QFileInfo file_info(filename);
551  workspace_->set_directory(file_info.dir().path());
552 
553  if (file_info.suffix() == "arma")
554  success = dataset->AverageSpectrum(false).save(filename.toStdString(), arma_binary);
555  else if (file_info.suffix() == "csv")
556  success = dataset->AverageSpectrum(true).save(filename.toStdString(), csv_ascii);
557  else
558  success = dataset->AverageSpectrum(true).save(filename.toStdString(), raw_ascii);
559 
560  if (success)
561  QMessageBox::information(this, "File Saved", "File written successfully!");
562  else
563  QMessageBox::warning(this, "File Not Saved", "Could not save file.");
564 }
565 
569 void MainWindow::on_actionAverage_Spectra_with_Abscissa_triggered()
570 {
571  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
572  if (item->type() == TreeItem::ItemType::Base){
573  QMessageBox::information(this,
574  "No datasets loaded",
575  "No dataset exists on which to perform this operation");
576  return;
577  }
578  bool success;
579 
580  QString dataset_key = item->DatasetKey();
581 
582  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
583 
584  QString filename =
585  QFileDialog::getSaveFileName(this,
586  tr("Save Spectra Matrix"),
587  workspace_->directory(),
588  tr("Vespucci Binary (*.arma);;"
589  "Comma-separated Values (*.csv);;"
590  "Tab-separated Txt (*.txt);;"));
591  QFileInfo file_info(filename);
592  workspace_->set_directory(file_info.dir().path());
593 
594 
595  vec wavelength = dataset->wavelength();
596  mat output(wavelength);
597  try{
598  output.insert_cols(1, dataset->AverageSpectrum(true));
599  }
600  catch(exception e){
602  }
603 
604  if (file_info.suffix() == "arma")
605  success = output.save(filename.toStdString(), arma_binary);
606  else if (file_info.suffix() == "csv")
607  success = output.save(filename.toStdString(), csv_ascii);
608  else
609  success = output.save(filename.toStdString(), raw_ascii);
610 
611  if (success)
612  QMessageBox::information(this, "File Saved", "File written successfully!");
613  else
614  QMessageBox::warning(this, "File Not Saved", "Could not save file.");
615 }
616 
620 void MainWindow::on_actionSpectral_Abscissa_triggered()
621 {
622  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
623  if (item->type() == TreeItem::ItemType::Base){
624  QMessageBox::information(this,
625  "No datasets loaded",
626  "No dataset exists on which to perform this operation");
627  return;
628  }
629  bool success;
630 
631  QString dataset_key = item->DatasetKey();
632 
633  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
634 
635  QString filename =
636  QFileDialog::getSaveFileName(this,
637  tr("Save Spectra Matrix"),
638  workspace_->directory(),
639  tr("Vespucci Binary (*.arma);;"
640  "Comma-separated Values (*.csv);;"
641  "Tab-separated Txt (*.txt);;"));
642  QFileInfo file_info(filename);
643  workspace_->set_directory(file_info.dir().path());
644 
645 
646  if (file_info.suffix() == "arma")
647  success = dataset->wavelength().save(filename.toStdString(), arma_binary);
648  else if (file_info.suffix() == "csv")
649  success = dataset->wavelength().save(filename.toStdString(), csv_ascii);
650  else
651  success = dataset->wavelength().save(filename.toStdString(), raw_ascii);
652 
653  if (success)
654  QMessageBox::information(this, "File Saved", "File written successfully!");
655  else
656  QMessageBox::warning(this, "File Not Saved", "Could not save file.");
657 }
658 
662 void MainWindow::on_actionAll_Data_triggered()
663 {
664  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
665  if (item->type() == TreeItem::ItemType::Base){
666  QMessageBox::information(this,
667  "No datasets loaded",
668  "No dataset exists on which to perform this operation");
669  return;
670  }
671  if (ui->datasetTreeView->model()->rowCount() < 1)
672  return;
673  bool success;
674 
675  QString dataset_key = item->DatasetKey();
676 
677  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
678 
679  QString filename =
680  QFileDialog::getSaveFileName(this,
681  tr("Save Spectra Matrix"),
682  workspace_->directory(),
683  tr("Vespucci Dataset (*.vds)"));
684 
685  QFileInfo file_info(filename);
686  workspace_->set_directory(file_info.dir().path());
687 
688  //exception can be thrown when intializing field
689  try{
690  success = dataset->Save(filename);
691  }
692  catch(exception e){
694  success = false;
695  }
696 
697  if (success)
698  QMessageBox::information(this, "File Saved", "File written successfully!");
699  else
700  QMessageBox::warning(this, "File Not Saved", "Could not save file.");
701 }
702 
706 void MainWindow::on_actionFilter_Derivatize_triggered()
707 {
708  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
709  if (item->type() == TreeItem::ItemType::Base){
710  QMessageBox::information(this,
711  "No datasets loaded",
712  "No dataset exists on which to perform this operation");
713  return;
714  }
715 
716  QString dataset_key = item->DatasetKey();
717 
718  FilterDialog *filter_dialog = new FilterDialog(this, workspace_, dataset_key);
719  filter_dialog->setAttribute(Qt::WA_DeleteOnClose);
720  filter_dialog->show();
721 }
722 
726 void MainWindow::on_actionClose_Dataset_triggered()
727 {
728  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
729  if (item->type() == TreeItem::ItemType::Base){
730  QMessageBox::information(this,
731  "No datasets loaded",
732  "No dataset exists on which to perform this operation");
733  return;
734  }
735 
736  QString dataset_key = item->DatasetKey();
737 
738  CloseDataset(dataset_key);
739 }
740 
744 void MainWindow::on_actionDocumentation_triggered()
745 {
746  QUrl website_url("http://vespucciproject.org/");
747  QDesktopServices::openUrl(website_url);
748 }
749 
753 void MainWindow::on_actionCrop_triggered()
754 {
755  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
756  if (item->type() == TreeItem::ItemType::Base){
757  QMessageBox::information(this,
758  "No datasets loaded",
759  "No dataset exists on which to perform this operation");
760  return;
761  }
762 
763  QString dataset_key = item->DatasetKey();
764  CropDialog *crop_dialog = new CropDialog(this, workspace_, dataset_key);
765  crop_dialog->setAttribute(Qt::WA_DeleteOnClose);
766  crop_dialog->show();
767 }
768 
772 void MainWindow::on_actionCorrect_Baseline_triggered()
773 {
774  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
775  if (item->type() == TreeItem::ItemType::Base){
776  QMessageBox::information(this,
777  "No datasets loaded",
778  "No dataset exists on which to perform this operation");
779  return;
780  }
781 
782 
783  QString dataset_key = item->DatasetKey();
784 
785  BaselineDialog *baseline_dialog = new BaselineDialog(this, workspace_, dataset_key);
786  baseline_dialog->setAttribute(Qt::WA_DeleteOnClose);
787  baseline_dialog->show();
788 }
789 
794 QSharedPointer<VespucciWorkspace> MainWindow::workspace_ptr()
795 {
796  return workspace_;
797 }
798 
799 void MainWindow::on_actionUndo_triggered()
800 {
801  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
802  if (item->type() == TreeItem::ItemType::Base){
803  QMessageBox::information(this,
804  "No datasets loaded",
805  "No dataset exists on which to perform this operation");
806  return;
807  }
808 
809 
810  QString dataset_key = item->DatasetKey();
811 
812  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
813 
814  if (!dataset->Undoable()){
815  dataset.clear();
816  QMessageBox::information(this, "Nothing to Undo", "There are no actions to undo");
817  return;
818  }
819 
820  QString text = tr("Are you sure you want to undo ") + dataset->last_operation()
821  + " on " + dataset->name() + "?";
822  int response =
823  QMessageBox::question(this,
824  tr("Undo Operation"),
825  text,
826  QMessageBox::Ok | QMessageBox::Cancel);
827 
828  if (response == QMessageBox::Ok){
829  dataset->Undo();
830  return;
831  }
832  else{
833  return;
834  }
835  dataset.clear(); //should fall out of scope anyway, but let's be safe
836 
837 }
838 
846 {
847  string str = "The following exception was thrown: " + string(e.what());
848  QMessageBox::warning(this, "Exception Occurred", QString::fromStdString(str));
849 }
850 
851 void MainWindow::DisplayExceptionWarning(string where, exception e)
852 {
853  string str = "The following exception was thrown: "
854  + string(e.what())
855  + ". In the internal function: "
856  + where
857  + ".";
858  QMessageBox::warning(this, "Exception Occurred", QString::fromStdString(str));
859 }
860 
861 void MainWindow::SetActiveDatasetTreeIndex(const QModelIndex &index)
862 {
863  ui->datasetTreeView->setCurrentIndex(index);
864 }
865 
866 
867 void MainWindow::DisplayWarning(const QString &title, const QString &text)
868 {
869  QMessageBox *warning = new QMessageBox(QMessageBox::Warning, title, text,
870  QMessageBox::Ok, this);
871  warning->setAttribute(Qt::WA_DeleteOnClose);
872  warning->show();
873 }
874 
875 void MainWindow::DisplayInformation(const QString &title, const QString &text)
876 {
877  QMessageBox::information(this, title, text);
878 }
879 
881 {
882  ui->datasetTreeView->setModel(new_model);
883 }
884 
886 {
887  return dataset_tree_model_;
888 }
889 
891 {
892  return plot_viewer_;
893 }
894 
896 {
897  return data_viewer_;
898 }
899 
900 
901 void MainWindow::on_actionDelete_Map_triggered()
902 {
903  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
904  if (item->type() == TreeItem::ItemType::Map){
905  workspace_->GetDataset(item->keys().first())->RemoveMap(item->keys().last());
906  }
907 }
908 
909 void MainWindow::on_actionNew_Composite_Dataset_triggered()
910 {
911  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
912  if (item->type() == TreeItem::ItemType::Base){
913  QMessageBox::information(this,
914  "No datasets loaded",
915  "No dataset exists on which to perform this operation");
916  return;
917  }
918  MetaDatasetDialog *meta_dialog = new MetaDatasetDialog(this, workspace_);
919  meta_dialog->setAttribute(Qt::WA_DeleteOnClose);
920  meta_dialog->show();
921 }
922 
923 
924 
925 void MainWindow::on_actionReject_Clipped_Spectra_triggered()
926 {
927  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
928  if (item->type() == TreeItem::ItemType::Base){
929  QMessageBox::information(this,
930  "No datasets loaded",
931  "No dataset exists on which to perform this operation");
932  return;
933  }
934  QString dataset_key = item->DatasetKey();
935  ThresholdDialog *dialog = new ThresholdDialog(this, workspace_, dataset_key);
936  dialog->setAttribute(Qt::WA_DeleteOnClose);
937  dialog->show();
938 }
939 
940 
942 {
943  if (ui->datasetTreeView->model()->rowCount() < 1)
944  return;
945  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
946 
947  QString dataset_key = item->DatasetKey();
948 
949  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
950  try{
951  dataset->PeakIntensityNormalize(min, max);
952  }
953  catch(exception e){
955  }
956 }
957 
959 {
960  ui->actionPlot_Viewer->setChecked(checked);
961 }
962 
964 {
965  ui->actionData_Viewer->setChecked(checked);
966 }
967 
969 {
970  ui->actionStatistics_Viewer->setChecked(checked);
971 }
972 
974 {
975  ui->actionSpectrum_Editor->setChecked(checked);
976 }
977 
979 {
980  ui->actionMacro_Editor->setChecked(checked);
981 }
982 
984 {
985  ui->actionPython_Shell->setChecked(checked);
986 }
987 
989 {
990  ui->actionHistory->setChecked(checked);
991 }
992 
993 void MainWindow::SpectrumRequested(QString dataset_key, QString map_name, size_t index)
994 {
995  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
996  if (!dataset.isNull()){
997  mat spectrum = join_horiz(dataset->abscissa(), dataset->spectra(uvec({index})));
998  plot_viewer_->AddTransientPlot(spectrum, map_name);
999  }
1000 }
1001 
1002 void MainWindow::HeldSpectrumRequested(QString dataset_key, QString map_name, size_t index)
1003 {
1004  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_key);
1005  if (!dataset.isNull()){
1006  mat spectrum = join_horiz(dataset->abscissa(), dataset->spectra(uvec({index})));
1007  plot_viewer_->AddPlot(spectrum, map_name);
1008  }
1009 }
1010 
1012 {
1013  selected_item_ = item;
1014  item_selected_ = true;
1015 }
1016 
1017 void MainWindow::on_actionBooleanize_Clamp_triggered()
1018 {
1019  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1020  if (item->type() == TreeItem::ItemType::Base){
1021  QMessageBox::information(this,
1022  "No datasets loaded",
1023  "No dataset exists on which to perform this operation");
1024  return;
1025  }
1026  QString dataset_key = item->DatasetKey();
1027  BooleanizeDialog *booleanize_dialog = new BooleanizeDialog(this, workspace_, dataset_key);
1028  booleanize_dialog->setAttribute(Qt::WA_DeleteOnClose);
1029  booleanize_dialog->show();
1030 }
1031 
1032 void MainWindow::on_actionRemove_Vectors_of_Zeros_triggered()
1033 {
1034  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1035  if (item->type() == TreeItem::ItemType::Base){
1036  QMessageBox::information(this,
1037  "No datasets loaded",
1038  "No dataset exists on which to perform this operation");
1039  return;
1040  }
1041  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
1042  QStringList items;
1043  bool ok;
1044  items << "Remove columns of zeros (removes spectra)" << "Remove rows of zeros (removes wavelengths)";
1045  QString input = QInputDialog::getItem(this, "Select dimension", "Behavior", items, 0, false, &ok);
1046  if(!ok){
1047  return;
1048  }
1049  else{
1050  QSharedPointer<VespucciDataset> data = workspace_->DatasetAt(ui->datasetTreeView->currentIndex());
1051  if (input == "Remove columns of zeros (removes spectra)"){
1052  try{
1053  dataset->ShedZeroSpectra();
1054  }
1055  catch(std::exception e){
1057  }
1058  }
1059  else if (input == "Remove rows of zeros (removes wavelengths)"){
1060  try{
1061  dataset->ShedZeroWavelengths();
1062  }
1063  catch(std::exception e){
1065  }
1066  }
1067  else{
1068  QMessageBox::warning(this, "Invalid Entry", "Invalid response to QInputDialog::getItem()");
1069  }
1070  data.clear();
1071  }
1072 }
1073 
1074 void MainWindow::on_actionRun_script_triggered()
1075 {
1076  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1077  if (item->type() == TreeItem::ItemType::Base){
1078  QMessageBox::information(this,
1079  "No datasets loaded",
1080  "No dataset exists on which to perform this operation");
1081  return;
1082  }
1083 
1084  QString dataset_key = item->DatasetKey();
1085 
1086  ScriptDialog *script_dialog = new ScriptDialog(this, workspace_, dataset_key);
1087  script_dialog->setAttribute(Qt::WA_DeleteOnClose);
1088  script_dialog->show();
1089 }
1090 
1091 void MainWindow::on_actionDetect_Peaks_triggered()
1092 {
1093  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1094  if (item->type() == TreeItem::ItemType::Base){
1095  QMessageBox::information(this,
1096  "No datasets loaded",
1097  "No dataset exists on which to perform this operation");
1098  return;
1099  }
1100 
1101 
1102  QString dataset_key = item->DatasetKey();
1103 
1104 }
1105 
1106 void MainWindow::on_actionCalculate_Peak_Populations_triggered()
1107 {
1108  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1109  if (item->type() == TreeItem::ItemType::Base){
1110  QMessageBox::information(this,
1111  "No datasets loaded",
1112  "No dataset exists on which to perform this operation");
1113  return;
1114  }
1115 
1116 
1117  QString dataset_key = item->DatasetKey();
1118 
1119 
1120 }
1121 
1122 void MainWindow::on_actionImport_From_Multiple_Point_Spectra_triggered()
1123 {
1124  MultiImportDialog *import_dialog = new MultiImportDialog(this, workspace_);
1125  import_dialog->setAttribute(Qt::WA_DeleteOnClose);
1126  import_dialog->show();
1127 }
1128 
1129 
1130 void MainWindow::on_actionBatch_File_Conversion_triggered()
1131 {
1132  BulkConversionDialog *conversion_dialog = new BulkConversionDialog(this, workspace_);
1133  conversion_dialog->setAttribute(Qt::WA_DeleteOnClose);
1134  conversion_dialog->show();
1135 }
1136 
1137 void MainWindow::on_actionClassical_Least_Squares_triggered()
1138 {
1139  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1140  if (item->type() == TreeItem::ItemType::Base){
1141  QMessageBox::information(this,
1142  "No datasets loaded",
1143  "No dataset exists on which to perform this operation");
1144  return;
1145  }
1146 
1147  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
1148 
1149  ClassicalLeastSquaresDialog *cls_dialog = new ClassicalLeastSquaresDialog(this, workspace_, dataset);
1150  cls_dialog->setAttribute(Qt::WA_DeleteOnClose);
1151  cls_dialog->show();
1152 }
1153 
1154 void MainWindow::on_actionSettings_triggered()
1155 {
1156  SettingsDialog *settings_dialog = new SettingsDialog(this, workspace_);
1157  settings_dialog->setAttribute(Qt::WA_DeleteOnClose);
1158  settings_dialog->show();
1159 }
1160 
1161 void MainWindow::on_actionTransform_Abscissa_triggered()
1162 {
1163  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1164  if (item->type() == TreeItem::ItemType::Base){
1165  QMessageBox::information(this,
1166  "No datasets loaded",
1167  "No dataset exists on which to perform this operation");
1168  return;
1169  }
1170 
1171 
1172  QString dataset_key = item->DatasetKey();
1173 
1174  AbscissaTransformDialog *abscissa_transform_dialog = new AbscissaTransformDialog(this, workspace_, dataset_key);
1175  abscissa_transform_dialog->setAttribute(Qt::WA_DeleteOnClose);
1176  abscissa_transform_dialog->show();
1177 }
1178 
1179 void MainWindow::on_actionFourierTransform_triggered()
1180 {
1181  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1182  if (item->type() == TreeItem::ItemType::Base){
1183  QMessageBox::information(this,
1184  "No datasets loaded",
1185  "No dataset exists on which to perform this operation");
1186  return;
1187  }
1188 
1189 
1190  QString dataset_key = item->DatasetKey();
1191 
1192  FourierTransformDialog *fourier_transform_dialog = new FourierTransformDialog(this, workspace_, dataset_key);
1193  fourier_transform_dialog->setAttribute(Qt::WA_DeleteOnClose);
1194  fourier_transform_dialog->show();
1195 
1196 }
1197 
1198 void MainWindow::on_actionInterpolate_to_New_Abscissa_triggered()
1199 {
1200  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1201  if (item->type() == TreeItem::ItemType::Base){
1202  QMessageBox::information(this,
1203  "No datasets loaded",
1204  "No dataset exists on which to perform this operation");
1205  }
1206 
1207 
1208  QString dataset_key = item->DatasetKey();
1209 
1210  AbscissaInterpolationDialog *abs_interp_dialog =
1211  new AbscissaInterpolationDialog(this, workspace_, dataset_key);
1212  abs_interp_dialog->setAttribute(Qt::WA_DeleteOnClose);
1213  abs_interp_dialog->show();
1214 }
1215 
1216 void MainWindow::on_actionSave_Log_File_triggered()
1217 {
1218 }
1219 
1220 void MainWindow::on_actionImport_Dataset_from_Multiple_Files_triggered()
1221 {
1222  StitchImportDialog *stitch_dialog = new StitchImportDialog(this, workspace_);
1223  stitch_dialog->setAttribute(Qt::WA_DeleteOnClose);
1224  stitch_dialog->show();
1225 }
1226 
1227 void MainWindow::on_actionCreate_Plot_triggered()
1228 {
1229 
1230 }
1231 
1232 void MainWindow::on_actionPlot_Viewer_toggled(bool arg1)
1233 {
1234  plot_viewer_->setVisible(arg1);
1235 }
1236 
1237 void MainWindow::ChildDialogVisibleToggled(const QString &key, bool arg1)
1238 {
1239  if (child_dialogs_.contains(key)){
1240  child_dialogs_[key]->setVisible(arg1);
1241  }
1242 }
1243 
1244 void MainWindow::on_actionData_Viewer_toggled(bool arg1)
1245 {
1246  if (arg1) data_viewer_->show();
1247  else data_viewer_->close();
1248 }
1249 
1250 void MainWindow::on_actionStatistics_Viewer_toggled(bool arg1)
1251 {
1252  if (arg1) stats_viewer_->show();
1253  else stats_viewer_->close();
1254 }
1255 
1256 void MainWindow::on_actionSpectrum_Editor_toggled(bool arg1)
1257 {
1258  if (arg1) spectrum_editor_->show();
1259  else spectrum_editor_->close();
1260 }
1261 
1262 void MainWindow::on_actionPython_Shell_toggled(bool arg1)
1263 {
1264  if (arg1) python_shell_->show();
1265  else python_shell_->close();
1266 }
1267 
1268 void MainWindow::on_actionMacro_Editor_toggled(bool arg1)
1269 {
1270  if (arg1) macro_editor_->show();
1271  else macro_editor_->close();
1272 }
1273 
1274 void MainWindow::on_actionMapResult_triggered()
1275 {
1276  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1277  if (item->type() == TreeItem::ItemType::Matrix && workspace_->Mappable(item->keys())){
1278  QStringList item_keys = item->keys();
1279  MapDialog *map_dialog = new MapDialog(this, item_keys, workspace_);
1280  map_dialog->setAttribute(Qt::WA_DeleteOnClose);
1281  map_dialog->show();
1282  }
1283 }
1284 
1285 void MainWindow::on_actionOnline_Documentation_triggered()
1286 {
1287  QUrl website_url("http://vespucciproject.org/Vespucci-docs");
1288  QDesktopServices::openUrl(website_url);
1289 }
1290 
1291 void MainWindow::on_actionGlobal_Color_Scales_triggered()
1292 {
1293  GlobalGradientDialog *gradient_dialog = new GlobalGradientDialog(this, workspace_);
1294  gradient_dialog->setAttribute(Qt::WA_DeleteOnClose);
1295  gradient_dialog->show();
1296 }
1297 
1298 void MainWindow::on_datasetTreeView_clicked(const QModelIndex &index)
1299 {
1300  TreeItem *item = dataset_tree_model_->getItem(index);
1301  if (!item->keys().size()) return;
1302  QStringList data_keys = item->keys();
1303  emit DatasetSelectionChanged(data_keys.first());
1304  if (item->type() == TreeItem::ItemType::Matrix)
1305  emit MatrixSelectionChanged(data_keys);
1306 }
1307 
1308 void MainWindow::on_datasetTreeView_doubleClicked(const QModelIndex &index)
1309 {
1310  TreeItem *item = dataset_tree_model_->getItem(index);
1311  QStringList data_keys = item->keys();
1312  if (!data_keys.size()) return;
1313  emit DatasetSelectionChanged(data_keys.first());
1314  if (item->type() == TreeItem::ItemType::Matrix){
1315  data_viewer_->AddTab(data_keys);
1316  data_viewer_->setVisible(true);
1317  emit MatrixSelectionChanged(data_keys);
1318  }
1319  if (item->type() == TreeItem::ItemType::Map)
1320  workspace_->GetMap(data_keys.first(), data_keys.last())->ShowMapWindow(true);
1321 }
1322 
1323 void MainWindow::on_actionShow_in_Data_Viewer_triggered()
1324 {
1325  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1326  QStringList data_keys = item->keys();
1327  if (item->type() == TreeItem::ItemType::Matrix){
1328  data_viewer_->AddTab(data_keys);
1329  data_viewer_->setVisible(true);
1330  emit MatrixSelectionChanged(data_keys);
1331  }
1332 }
1333 
1334 void MainWindow::on_actionView_Statistics_triggered()
1335 {
1336  stats_viewer_->setVisible(true);
1337 }
1338 
1339 void MainWindow::on_actionPlotResult_triggered()
1340 {
1341  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1342  if (item->type() == TreeItem::ItemType::Matrix){
1343  QStringList data_keys = item->keys();
1344  PlotMakerDialog *plot_maker_dialog =
1345  new PlotMakerDialog(this,
1346  plot_viewer_,
1347  workspace_,
1348  data_keys);
1349  plot_maker_dialog->setAttribute(Qt::WA_DeleteOnClose);
1350  plot_maker_dialog->show();
1351  }
1352 }
1353 
1354 
1355 void MainWindow::on_actionSave_Dataset_triggered()
1356 {
1357  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1358  if (!item->keys().size()) return;
1359  QString dataset_name = item->keys().first();
1360  QString path = workspace_->directory() + "/" + dataset_name;
1361  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_name);
1362  QString filename;
1363  if (dataset->saved())
1364  filename = dataset->last_save_filename();
1365  else
1366  filename = QFileDialog::getSaveFileName(this,
1367  "Save Dataset",
1368  path,
1369  "Vespucci Dataset (*.h5)");
1370  if (!filename.isEmpty()){
1371  bool ok = dataset->Save(filename);
1372  if (!ok) DisplayWarning("Dataset Not Saved", "The file failed to save");
1373  else QMessageBox::information(this, "Success", "Dataset saved successfully");
1374  }
1375 }
1376 
1377 void MainWindow::on_actionOpenDataset_triggered()
1378 {
1379  QString filename = QFileDialog::getOpenFileName(this,
1380  "Open Dataset",
1381  workspace_->directory(),
1382  "Vespucci Dataset (*.h5)");
1383  QSharedPointer<VespucciDataset> dataset(NULL);
1384 
1385  try{
1386  dataset = QSharedPointer<VespucciDataset>(new VespucciDataset(filename,
1387  this,
1388  workspace_));
1389  }catch (exception e){
1390  DisplayExceptionWarning("VespucciDataset::VespucciDataset", e);
1391  return;
1392  }
1393 
1394  if (!dataset.isNull() && !dataset->ConstructorCancelled()){
1395  int count = 1;
1396  QString name = dataset->name();
1397  while (workspace_->dataset_names().contains(dataset->name()))
1398  dataset->SetName(name + "(" + QString::number(count++) + ")");
1399  workspace_->AddDataset(dataset);
1400  }
1401  else{
1402  DisplayWarning("Dataset Loading Error", "The dataset file could not be loaded");
1403  }
1404 }
1405 
1406 void MainWindow::CloseDataset(const QString &name)
1407 {
1408  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(name);
1409 
1410  int response;
1411  QString filename;
1412  QString path = workspace_->directory() + "/" + dataset->name();
1413  if (dataset->state_changed()){
1414  do{
1415  response = QMessageBox::question(this,
1416  "Save Dataset?",
1417  "Would you like to save " +
1418  name + "?", QMessageBox::Yes,
1419  QMessageBox::No);
1420  if (response == QMessageBox::No) break;
1421  if (dataset->saved())
1422  filename = dataset->last_save_filename();
1423  else
1424  filename = QFileDialog::getSaveFileName(this,
1425  "Save Dataset",
1426  path,
1427  "Vespucci Dataset (*.h5)");
1428  }while (response == QMessageBox::Yes && filename.isEmpty());
1429 
1430  if (response == QMessageBox::Yes) dataset->Save(filename);
1431  }
1432 
1433  emit DatasetToBeRemoved(name);
1434  workspace_->RemoveDataset(name);
1435 }
1436 
1437 void MainWindow::on_actionSave_Dataset_As_triggered()
1438 {
1439  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1440  if (!item->keys().size()) return;
1441  QString dataset_name = item->keys().first();
1442  QString path = workspace_->directory() + "/" + dataset_name;
1443  QString filename = QFileDialog::getSaveFileName(this,
1444  "Save Dataset",
1445  path,
1446  "Vespucci Dataset (*.h5)");
1447  if (!filename.isEmpty()){
1448  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(dataset_name);
1449  bool ok = dataset->Save(filename);
1450  if (!ok) DisplayWarning("Dataset Not Saved", "The file failed to save");
1451  }
1452 }
1453 
1454 void MainWindow::on_actionExport_Matrix_triggered()
1455 {
1456  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1457  if (item->type() == TreeItem::ItemType::Matrix){
1458  QString filename = QFileDialog::getSaveFileName(this, "Save " + item->keys().last(),
1459  workspace_->directory(),
1460  "Comma-separated text (*.csv);;"
1461  "Space-delimited text (*.txt);;"
1462  "Armadillo binary (*.arma);;"
1463  "Raw binary (*.bin)");
1464  QString extension = QFileInfo(filename).suffix();
1465  try{
1466  if (extension == "bin")
1467  workspace_->GetMatrix(item->keys()).save(filename.toStdString(), raw_binary);
1468  else if (extension == "arma")
1469  workspace_->GetMatrix(item->keys()).save(filename.toStdString(), arma_binary);
1470  else if (extension == "csv")
1471  workspace_->GetMatrix(item->keys()).save(filename.toStdString(), csv_ascii);
1472  else
1473  workspace_->GetMatrix(item->keys()).save(filename.toStdString(), raw_ascii);
1474  }catch(exception e){
1476  }
1477  }
1478 }
1479 
1480 void MainWindow::on_actionImport_Data_Into_Dataset_triggered()
1481 {
1482  QString filename = QFileDialog::getOpenFileName(this, "Select data file",
1483  workspace_->directory());
1484  mat matrix;
1485  bool ok = matrix.load(filename.toStdString());
1486  QFileInfo file_info(filename);
1487  QString matrix_name = file_info.completeBaseName();
1488  if (ok){
1489  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1490  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
1491  dataset->AddAuxiliaryMatrix(matrix_name, matrix);
1492  }
1493  else{
1494  DisplayWarning("Could not load file", "The matrix could not be loaded from the selected file");
1495  }
1496 }
1497 
1498 void MainWindow::on_actionCalculate_Representative_Spectrum_triggered()
1499 {
1500  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1501  QString key = item->DatasetKey();
1502  if (workspace_->dataset_names().contains(key)){
1504  workspace_,
1505  key);
1506  dialog->setAttribute(Qt::WA_DeleteOnClose);
1507  dialog->show();
1508  }
1509 }
1510 
1511 void MainWindow::on_actionTransform_triggered()
1512 {
1513  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1514  if (item->type() == TreeItem::ItemType::Matrix){
1515  TransformDialog *dialog = new TransformDialog(this, workspace_, item->keys());
1516  dialog->setAttribute(Qt::WA_DeleteOnClose);
1517  dialog->show();
1518  }
1519 }
1520 
1521 void MainWindow::on_actionOn_Multiple_Datasets_triggered()
1522 {
1523  MultiAnalysisDialog *dialog = new MultiAnalysisDialog(this, workspace_);
1524  //dialog->setAttribute(Qt::WA_DeleteOnClose);
1525  dialog->show();
1526 }
1527 
1528 void MainWindow::on_actionHierarchical_Clustering_triggered()
1529 {
1530  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1531  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(item->DatasetKey());
1532  if (!item->DatasetKey().isEmpty()){
1533  AHCADialog *dialog = new AHCADialog(this, workspace_, dataset);
1534  dialog->setAttribute(Qt::WA_DeleteOnClose);
1535  dialog->show();
1536  }
1537 }
1538 
1539 
1540 void MainWindow::on_actionHistory_toggled(bool arg1)
1541 {
1542  if (arg1 && !history_dialog_->isVisible())
1543  history_dialog_->show();
1544  if (!arg1 && history_dialog_->isVisible())
1545  history_dialog_->close();
1546 }
1547 
1548 void MainWindow::on_actionConcatenate_triggered()
1549 {
1550  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1551  QString dataset_key = item->DatasetKey();
1552  if (!dataset_key.isEmpty()){
1553  UnivariateConcatenationDialog *dialog = new UnivariateConcatenationDialog(this, workspace_, dataset_key);
1554  dialog->setAttribute(Qt::WA_DeleteOnClose);
1555  dialog->show();
1556  }
1557 }
1558 
1559 void MainWindow::on_actionAnalyze_triggered()
1560 {
1561  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1562  if (item->type() == TreeItem::ItemType::Matrix){
1563  MetaAnalysisDialog *dialog = new MetaAnalysisDialog(this, workspace_, item->keys());
1564  //dialog->setAttribute(Qt::WA_DeleteOnClose);
1565  dialog->show();
1566  }
1567 }
1568 
1569 void MainWindow::on_actionNew_Dataset_from_Matrix_triggered()
1570 {
1571  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1572  if (item->type() == TreeItem::ItemType::Matrix){
1573  DatasetExtractorDialog *dialog = new DatasetExtractorDialog(this, workspace_, item->keys());
1574  dialog->setAttribute(Qt::WA_DeleteOnClose);
1575  dialog->show();
1576  }
1577 }
1578 
1579 void MainWindow::on_actionEstimate_Dimensionality_triggered()
1580 {
1581  TreeItem *item = dataset_tree_model_->getItem(ui->datasetTreeView->currentIndex());
1582  if (item->type() == TreeItem::ItemType::Matrix){
1583  DimensionalityEstimationDialog *dialog = new DimensionalityEstimationDialog(this, workspace_, item->keys());
1584  dialog->setAttribute(Qt::WA_DeleteOnClose);
1585  dialog->show();
1586  }
1587 }
QStringList keys() const
Definition: treeitem.cpp:98
void MatrixToBeRemoved(QStringList keys)
void SetHistoryDialogActionChecked(bool checked)
Definition: mainwindow.cpp:988
void DisplayInformation(const QString &title, const QString &text)
Definition: mainwindow.cpp:875
void DatasetToBeRemoved(QString name)
The BandRatioDialog class The dialog that allows the user to create a band-ratio map.
void DatasetSelectionChanged(QString dataset_key)
Definition: ahcadialog.h:26
void SetActionChecked(bool checked)
The RangeDialog class.
Definition: rangedialog.h:32
void DisplayExceptionWarning(std::exception e)
MainWindow::DisplayExceptionWarning.
Definition: mainwindow.cpp:845
VESPUCCI_EXPORT arma::uword max(arma::uword a, arma::uword b)
Vespucci::Math::max.
Definition: accessory.cpp:237
TreeItem::ItemType type() const
Definition: treeitem.cpp:93
QSharedPointer< VespucciWorkspace > workspace_ptr()
MainWindow::workspace_ptr.
Definition: mainwindow.cpp:794
void SetDataViewerActionChecked(bool checked)
Definition: mainwindow.cpp:963
void SetPythonShellActionChecked(bool checked)
Definition: mainwindow.cpp:983
void DatasetSelectionChanged(QString key)
void DatasetToBeRemoved(QString name)
DataViewer::DatasetRemoved.
Definition: dataviewer.cpp:59
The VespucciDataset class This is the main class for dealing with hyperspectral data. This handles the import and export of spectra, and the creation of maps. Images are handled by the MapData class. This class is intended to be allocated on the heap inside of a smart pointer, there is no copy constructor.
The DatasetImportDialog class Dialog that allows the user to import files into the program...
The CropDialog class A dialog that allows the user to "Crop" the dataset (delete all spectra that are...
Definition: cropdialog.h:35
void DatasetSelectionChanged(QString dataset_key)
void SetModel(DatasetTreeModel *model)
void MatrixToBeRemoved(QStringList matrix_keys)
Definition: statsdialog.cpp:38
PlotViewer * plot_viewer()
Definition: mainwindow.cpp:890
void SetActiveDatasetTreeIndex(const QModelIndex &index)
Definition: mainwindow.cpp:861
The DataViewer class Window that displays dataset elements in a QTableView widget inside a QTabWidget...
Definition: dataviewer.h:41
The AboutDialog class A QDialog that displays information about Vespucci.
Definition: aboutdialog.h:31
void RangeDialogAccepted(double min, double max)
Definition: mainwindow.cpp:941
void closeEvent(QCloseEvent *event)
MainWindow::closeEvent.
Definition: mainwindow.cpp:162
void DialogAccepted(double min, double max)
void SpectrumRequested(QString dataset_key, QString map_name, size_t index)
Definition: mainwindow.cpp:993
void HeldSpectrumRequested(QString dataset_key, QString map_name, size_t index)
The PLSDialog class Dialog that allows the user to perform PLS determinant analysis.
Definition: plsdialog.h:33
void SetActionChecked(bool checked)
void MatrixSelectionChanged(QStringList matrix_keys)
TreeItem * getItem(const QModelIndex &index) const
void DatasetToBeRemoved(QString key)
DatasetTreeModel * dataset_tree_model()
Definition: mainwindow.cpp:885
void MatrixSelectionChanged(QStringList matrix_keys)
Definition: statsdialog.cpp:32
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
Definition: accessory.cpp:249
void SetActionChecked(bool checked)
MainWindow(QWidget *parent, QSharedPointer< VespucciWorkspace > ws)
MainWindow::MainWindow.
Definition: mainwindow.cpp:67
void SetStatsViewerActionChecked(bool checked)
Definition: mainwindow.cpp:968
void MatrixToBeRemoved(QStringList keys)
DataViewer::MatrixToBeRemoved.
Definition: dataviewer.cpp:76
void SetMacroEditorActionChecked(bool checked)
Definition: mainwindow.cpp:978
The CitationDialog class The dialog that displays how to cite Vespucci.
void SetPlotViewerActionChecked(bool checked)
Definition: mainwindow.cpp:958
void ItemSelected(TreeItem *item)
const QString DatasetKey() const
Definition: treeitem.cpp:103
void DatasetSelectionChanged(QString dataset_key)
Definition: macrodialog.cpp:53
void MacroRequested(const QStringList &macro)
Definition: macrodialog.cpp:44
void AddTab(QStringList keys)
Definition: dataviewer.cpp:87
The FilterDialog class This dialog allows the user to apply filtering, smoothing or derivatization to...
Definition: filterdialog.h:37
The UnivariateDialog class Class allowing user to create univariate images.
void AddPlot(const mat &paired_data, const QString &tab_title)
Definition: plotviewer.cpp:19
The PrincipalComponentsDialog class Dialog for performing principal components analysis.
void SetActionChecked(bool checked)
void DisplayWarning(const QString &title, const QString &text)
Definition: mainwindow.cpp:867
The KMeansDialog class Allows the user to create a k-means clustering map.
Definition: kmeansdialog.h:33
void SetActionChecked(bool checked)
void SetSpectrumEditorActionChecked(bool checked)
Definition: mainwindow.cpp:973
The MainWindow class The main window of the program, this is where the user performs most operations...
Definition: mainwindow.h:58
void MacroRequested(const QStringList &macro)
void ItemSelected(TreeItem *item)
void AddTransientPlot(const vec &abscissa, const vec &data, const QString &tab_title)
Definition: plotviewer.cpp:47
void DatasetToBeRemoved(QString name)
Definition: statsdialog.cpp:47
The VCADialog class A dialog that allows the user to perform vertex components analysis.
Definition: vcadialog.h:32
void RefreshTreeModel(const DataModel *data_model)
MainWindow::RefreshTreeModel.
Definition: mainwindow.cpp:149
void SetActionChecked(bool checked)
The BaselineDialog class The dialog that allows the user to baseline-correct the data.
DataViewer * data_viewer()
Definition: mainwindow.cpp:895
void SetDatasetTreeModel(DatasetTreeModel *new_model)
Definition: mainwindow.cpp:880