Vespucci  1.0.0
metadataset.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 *******************************************************************************/
21 
22 
35  MainWindow *main_window,
36  QString *directory,
37  QString method_description,
38  MetaMethod::Method method,
39  QList<QSharedPointer<VespucciDataset> > parent_datasets)
40  : VespucciDataset(name, main_window, directory)
41 {
42  parent_datasets_ = parent_datasets;
43 
44  if(!ParentsValid()){
45  throw std::runtime_error("Improper input to MetaDataset constructor");
46  cerr << "Improper input to MetaDataset constructor\n";
47 
48  }
49  method_ = method;
50  method_description_ = method_description;
51  mat spectra;
52  vec wavelength = parent_datasets_[0]->wavelength();
53  vec x;
54  vec y;
55  switch(method_) {
57  try{
58  spectra = ProcessAverage(x, y);
59  }
60  catch(std::exception e){
61  throw std::runtime_error("MetaDataset::ProcessAverage");
62  }
63 
64  break;
66  try{
67  spectra = Concatenate(x, y);
68  }
69  catch(std::exception e){
70  throw std::runtime_error("MetaDataset::Concatenate");
71  }
72  break;
73  default:
74  throw std::runtime_error("Improper input to MetaDataset");
75  }
76 
77  try{
78  SetData(spectra, wavelength, x, y);
79  SetParentDatasetIndices(parent_coordinates_);
80  }
81  catch(std::exception e){
82  throw std::runtime_error("Failure to set data in MetaDataset constructor");
83  }
84  vec indices_temp(spectra.n_cols);
85  for (uword i = 0; i < indices_temp.n_elem; ++i){
86  indices_temp(i) = i;
87  }
88  SetIndices(indices_temp);
89 }
90 
95 mat MetaDataset::ProcessAverage(vec &x, vec &y)
96 {
97  mat spectra;
98  vec parent(1);
99  mat indices_buf(1, 3);
100  for (int i = 0; i < parent_datasets_.size(); ++i){
101  spectra.insert_cols(spectra.n_cols, parent_datasets_[i]->AverageSpectrum(false));
102  parent(0) = i + 1;
103  indices_buf(0, 0) = i + 1;
104  indices_buf(0, 1) = 0;
105  indices_buf(0, 2) = 0;
106  x.insert_rows(x.n_rows, parent);
107  y.insert_rows(y.n_rows, parent);
108  parent_coordinates_.insert_rows(parent_coordinates_.n_rows, indices_buf);
109  }
110  return spectra;
111 }
112 
117 mat MetaDataset::Concatenate(vec &x, vec &y)
118 {
119  mat spectra;
120  mat indices_buf;
121  indices_buf.set_size(1, 3);
122  cout << "Concatenate()\n";
123 
124  for (int i = 0; i < parent_datasets_.size(); ++i){
125  spectra.insert_cols(spectra.n_cols, parent_datasets_[i]->spectra());
126  indices_buf.set_size(parent_datasets_[i]->x().n_rows, 3);
127  indices_buf.col(0) = (i+1)*ones(indices_buf.n_rows);
128  indices_buf.col(1) = parent_datasets_[i]->x();
129  indices_buf.col(2) = parent_datasets_[i]->y();
130  parent_coordinates_.insert_rows(parent_coordinates_.n_rows, indices_buf);
131  x.insert_rows(x.n_rows, indices_buf.col(1));
132  y.insert_rows(y.n_rows, indices_buf.col(2));
133  }
134  return spectra;
135 }
136 
142 bool MetaDataset::ParentsValid()
143 {
144  uword size = parent_datasets_[0]->wavelength_ptr()->n_elem;
145  for (int i = 0; i<parent_datasets_.size(); ++i)
146  if (parent_datasets_[i]->wavelength_ptr()->n_elem != size)
147  return false;
148 
149  return true;
150 }
151 
153 {
154  return &parents_;
155 }
void SetData(const mat &spectra, const vec &wavelength, const vec &x, const vec &y)
VespucciDataset::SetData.
vec wavelength() const
VespucciDataset::wavelength.
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.
mat spectra() const
VespucciDataset::spectra.
vec * parents()
void SetParentDatasetIndices(mat parent_dataset_indices)
VespucciDataset::SetParentDatasetIndices.
MetaDataset(QString name, MainWindow *main_window, QString *directory, QString method_description, MetaMethod::Method method, QList< QSharedPointer< VespucciDataset > > parent_datasets)
MetaDataset::MetaDataset.
Definition: metadataset.cpp:34
vec y() const
VespucciDataset::y.
void SetIndices(vec indices)
VespucciDataset::SetIndices.
vec x() const
VespucciDataset::x.
The MainWindow class The main window of the program, this is where the user performs most operations...
Definition: mainwindow.h:58