Vespucci  1.0.0
stitchimportdialog.cpp
Go to the documentation of this file.
1 #include "stitchimportdialog.h"
2 #include "ui_stitchimportdialog.h"
5 
6 StitchImportDialog::StitchImportDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws) :
7  QDialog(parent),
8  ui(new Ui::StitchImportDialog)
9 {
10  ui->setupUi(this);
11  workspace_ = ws;
12 }
13 
15 {
16  delete ui;
17 }
18 
19 void StitchImportDialog::on_browsePushButton_clicked()
20 {
21  QString filename =
22  QFileDialog::getOpenFileName(this,
23  "Select Instruction File",
24  workspace_->directory(),
25  "Instruction File (*.csv)");
26  ui->filenameLineEdit->setText(filename);
27 }
28 
29 bool StitchImportDialog::LoadDatasets(field<string> filenames, mat &spectra, vec &x, vec &y, vec &abscissa, bool swap_spatial, QString type)
30 {
31  //follows the vespuccci binary field format:
32  field<field<mat> > datasets(filenames.n_rows, filenames.n_cols);
33  mat current_spectra;
34  vec current_x, current_y, current_abscissa;
35  bool ok;
36  bool two_dim = datasets.n_rows > 1 && datasets.n_cols > 1;
37  for (uword j = 0; j < filenames.n_cols; ++j){
38  for (uword i = 0; i < filenames.n_rows; ++i){
39  QString filename;
40  if (two_dim)
41  filename = path_ + "/" + QString::fromStdString(filenames(i, j));
42  else
43  filename = path_ + "/" + QString::fromStdString(filenames(i));
44  if (type == "Vespucci Dataset"){
45 
46  ok = BinaryImport::ImportVespucciBinary(filename.toStdString(),
47  current_spectra,
48  current_abscissa,
49  current_x,
50  current_y);
51  }
52  else if (type == "Wide Text" || type == "Wide CSV"){
53  ok = TextImport::ImportWideText(filename.toStdString(),
54  current_spectra,
55  current_abscissa,
56  current_x,
57  current_y,
58  swap_spatial);
59 
60 
61  }
62 
63  else if (type == "Long Text" || "Long CSV"){
64  ok = TextImport::ImportLongText(filename.toStdString(),
65  current_spectra,
66  current_abscissa,
67  current_x,
68  current_y,
69  swap_spatial);
70  }
71  else{
72  cout << "Improper!\n";
73 
74  return false;
75  }
76 
77 
78 
79  if (ok){
80  field<mat> dataset(4);
81  dataset(0) = current_spectra;
82  dataset(1) = current_abscissa;
83  dataset(2) = current_x;
84  dataset(3) = current_y;
85  datasets(i, j) = dataset;
86  }
87  }
88  }
89 
90  try{
91  ok = Vespucci::StitchDatasets(datasets, spectra, x, y, abscissa);
92  }catch(exception e){
93  workspace_->main_window()->DisplayExceptionWarning("Vespucci::StitchDatasets", e);
94  ok = false;
95  }
96 
97  return ok;
98 }
99 
100 void StitchImportDialog::on_buttonBox_accepted()
101 {
102  QString filename = ui->filenameLineEdit->text();
103  path_ = QFileInfo(filename).absolutePath();
104  QString data_format = ui->formatComboBox->currentText();
105  bool swap_spatial = ui->swapSpatialCheckBox->isChecked();
106  bool ok;
107  mat spectra;
108  vec x, y, abscissa;
109  field<string> instruction;
110  ok = instruction.load(filename.toStdString());
111  if (!ok){
112  QMessageBox::warning(this,
113  "Failed to Load Instructions",
114  "The instruction file could not be loaded");
115  }
116  try{
117  ok = LoadDatasets(instruction,
118  spectra, x, y, abscissa,
119  swap_spatial, data_format);
120  }catch (exception e){
121  workspace_->main_window()->DisplayExceptionWarning(e);
122  ok = false;
123  }
124  if (!ok){
125  QMessageBox::warning(this,
126  "Failed to Load Dataset",
127  "One or more datasets could not be loaded, or "
128  "datasets of incompatible spatial coordinates.");
129  }
130  else{
131  QString x_description = ui->xLineEdit->text();
132  QString x_units = ui->xUnitsLineEdit->text();
133  QString y_description = ui->yLineEdit->text();
134  QString y_units = ui->yUnitsLineEdit->text();
135  QString name = ui->nameLineEdit->text();
136  QSharedPointer<VespucciDataset>
137  dataset(new VespucciDataset(name,
138  workspace_->main_window(),
139  workspace_));
140  dataset->SetData(spectra, abscissa, x, y);
141  dataset->SetXDescription(x_description + " (" + x_units + ")");
142  dataset->SetYDescription(y_description + " (" + y_units + ")");
143  workspace_->AddDataset(dataset);
144  }
145 }
VESPUCCI_EXPORT bool ImportVespucciBinary(std::string filename, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y)
Definition: ahcadialog.h:26
VESPUCCI_EXPORT bool StitchDatasets(const arma::field< arma::field< arma::mat > > &datasets, arma::mat &spectra, arma::vec &x, arma::vec &y, arma::vec &abscissa)
Vespucci::StitchDatasets.
Definition: vespucci.cpp:114
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.
StitchImportDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws)
VESPUCCI_EXPORT bool ImportWideText(std::string filename, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y, bool swap_spatial)
TextImport::ImportWideText.
Definition: textimport.cpp:97
VESPUCCI_EXPORT bool ImportLongText(std::string filename, arma::mat &spectra, arma::mat &abscissa, arma::vec &x, arma::vec &y, bool swap_spatial)
TextImport::ImportLongText.
Definition: textimport.cpp:311