Vespucci  1.0.0
datasetextractordialog.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 "datasetextractordialog.h"
21 #include "ui_datasetextractordialog.h"
22 
23 DatasetExtractorDialog::DatasetExtractorDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws, const QStringList &matrix_keys) :
24  QDialog(parent),
25  ui(new Ui::DatasetExtractorDialog)
26 {
27  ui->setupUi(this);
28  matrix_keys_ = matrix_keys;
29  workspace_ = ws;
30  ui->columnSpinBox->setMaximum(workspace_->GetMatrix(matrix_keys_).n_cols);
31  ui->columnSpinBox->setMinimum(1);
32  ui->valueDoubleSpinBox->setMinimum(workspace_->GetMatrix(matrix_keys_).min());
33  ui->valueDoubleSpinBox->setMaximum(workspace_->GetMatrix(matrix_keys_).max());
34  ui->nameLineEdit->setText(matrix_keys_.first() + " (" + matrix_keys_.last() + ")");
35 }
36 
38 {
39  delete ui;
40 }
41 
42 void DatasetExtractorDialog::on_buttonBox_accepted()
43 {
44  QString op = ui->operatorComboBox->currentText();
45  QString name = ui->nameLineEdit->text();
46  uword column = ui->columnSpinBox->value() - 1;
47  double value = ui->valueDoubleSpinBox->value();
48  mat spectra;
49  vec x, y, abscissa;
50  uvec indices;
51  vec matrix = workspace_->GetMatrix(matrix_keys_).col(column);
52  try{
53  QSharedPointer<VespucciDataset> dataset = workspace_->GetDataset(matrix_keys_.first());
54  if (dataset.isNull()) throw runtime_error("Dataset not found");
55  if (dataset->spectra_ref().n_cols != matrix.n_rows) throw invalid_argument("Dimension mismatch");
56  if (op == "=") indices = arma::find(matrix == value);
57  else if (op == ">") indices = arma::find(matrix > value);
58  else if (op == "<") indices = arma::find(matrix < value);
59  else if (op == "≠") indices = arma::find(matrix != value);
60  if (indices.n_elem == 0) throw runtime_error("No values with specified relationship");
61  spectra = dataset->spectra(indices);
62  x = dataset->x_ref().rows(indices);
63  y = dataset->y_ref().rows(indices);
64  abscissa = dataset->abscissa();
65  QSharedPointer<VespucciDataset> new_dataset(new VespucciDataset(name,
66  workspace_->main_window(),
67  workspace_->directory_ptr()));
68  new_dataset->SetData(spectra, abscissa, x, y);
69  workspace_->AddDataset(new_dataset);
70  }catch(exception e){
71  workspace_->main_window()->DisplayExceptionWarning(e);
72  }
73  close();
74 }
Definition: ahcadialog.h:26
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.
DatasetExtractorDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, const QStringList &matrix_keys)