Vespucci  1.0.0
bandratiodialog.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 #include "ui_bandratiodialog.h"
23 
25  QSharedPointer<VespucciWorkspace> ws,
26  QSharedPointer<AbstractDataAnalyzer> analyzer) :
27  QDialog(parent),
28  ui(new Ui::BandRatioDialog),
29  workspace_(ws),
30  analyzer_(analyzer)
31 {
32  ui->setupUi(this);
33 
34  first_min_line_ = new QCPItemStraightLine(ui->spectrumCustomPlot);
35  first_max_line_ = new QCPItemStraightLine(ui->spectrumCustomPlot);
36  second_min_line_ = new QCPItemStraightLine(ui->spectrumCustomPlot);
37  second_max_line_ = new QCPItemStraightLine(ui->spectrumCustomPlot);
38 
39  first_min_line_->point1->setCoords(0, 0);
40  first_min_line_->point2->setCoords(0, 1);
41  first_max_line_->point1->setCoords(0, 0);
42  first_max_line_->point2->setCoords(0, 1);
43  second_min_line_->point1->setCoords(0, 0);
44  second_min_line_->point2->setCoords(0, 1);
45  second_max_line_->point1->setCoords(0, 0);
46  second_max_line_->point2->setCoords(0, 1);
47 
48  second_min_line_->setPen(QPen(Qt::GlobalColor::red));
49  second_max_line_->setPen(QPen(Qt::GlobalColor::red));
50 
51  double min = analyzer_->AbscissaMin();
52  double max = analyzer_->AbscissaMax();
53 
54  QDoubleValidator *validator = new QDoubleValidator(min, max, 2, this);
55 
56 
57  QString label_text = QString::number(min) + "–" + QString::number(max);
58  ui->rangeLabel->setText(label_text);
59  ui->indexSpinBox->setRange(0, analyzer_->columns() - 1);
60 
61  uword middle = analyzer_->columns() / 2;
62  ui->indexSpinBox->setValue(middle);
63 
64  QVector<double> plot_data = Vespucci::FromArmaVec(analyzer_->PointSpectrum(middle));
65  QVector<double> wavelength = Vespucci::FromArmaVec(analyzer_->abscissa());
66  if (plot_data.isEmpty()){plot_data = Vespucci::FromArmaVec(analyzer_->PointSpectrum(0));}
67 
68  ui->firstMinLineEdit->setValidator(validator);
69  ui->firstMaxLineEdit->setValidator(validator);
70  ui->secondMinLineEdit->setValidator(validator);
71  ui->secondMaxLineEdit->setValidator(validator);
72  ui->spectrumCustomPlot->addGraph();
73  ui->spectrumCustomPlot->graph(0)->addData(wavelength, plot_data);
74  ui->spectrumCustomPlot->rescaleAxes();
75  ui->spectrumCustomPlot->setInteraction(QCP::iRangeDrag, true);
76  ui->spectrumCustomPlot->setInteraction(QCP::iRangeZoom, true);
77 }
78 
80 {
81  delete ui;
82 }
83 
88 void BandRatioDialog::on_buttonBox_accepted()
89 {
90  bool ok = !ui->firstMinLineEdit->text().isEmpty()
91  && !ui->firstMaxLineEdit->text().isEmpty()
92  && !ui->secondMinLineEdit->text().isEmpty()
93  && !ui->secondMaxLineEdit->text().isEmpty();
94 
95  if (ok){
96  double first_entered_min = ui->firstMinLineEdit->text().toDouble();
97  double second_entered_min = ui->secondMinLineEdit->text().toDouble();
98  double first_entered_max = ui->firstMaxLineEdit->text().toDouble();
99  double second_entered_max = ui->secondMaxLineEdit->text().toDouble();
100 
101  if (first_entered_min < analyzer_->AbscissaMin()
102  || second_entered_min < analyzer_->AbscissaMin()){
103  QMessageBox::warning(this,
104  "Invalid Input!",
105  "You have entered a left bound that is smaller "
106  "than the smallest number on the spectral abscissa");
107  return;
108  }
109 
110  if (first_entered_max > analyzer_->AbscissaMax()
111  || second_entered_max > analyzer_->AbscissaMax()){
112  QMessageBox::warning(this,
113  "Invalid Input!",
114  "You have entered a right bound that is larger "
115  "than the largest number on the spectral abscissa");
116  return;
117  }
118  uint bound_window = ui->searchWindowSpinBox->value();
119 
120 
121  QString name = ui->nameLineEdit->text();
122  QString value_method = ui->methodComboBox->currentText();
123 
124  if (value_method == "Empirical"){
125  try{
126  analyzer_->BandRatio(name, first_entered_min, first_entered_max,
127  second_entered_min, second_entered_max,
128  bound_window);
129  }catch(exception e){
130  workspace_->main_window()->DisplayExceptionWarning(e);
131  }
132  }
133  else if (value_method == "Gaussian Fit"){
134  try{
135 
136  }catch(exception e){
137  workspace_->main_window()->DisplayExceptionWarning(e);
138  }
139  }
140  else{
141  QMessageBox::warning(this, "Error Occurred",
142  "A non-fatal error occurred: invalid input from ui->methodComboBox");
143  }
144  }
145  else{
146  QMessageBox::warning(this,
147  "Invalid Input!",
148  "You must enter numbers for left and right bounds.");
149  }
150  analyzer_.clear();
151  close();
152 }
153 
154 
158 void BandRatioDialog::on_buttonBox_rejected()
159 {
160  close();
161  analyzer_.clear();
162 }
163 
164 void BandRatioDialog::on_firstMinLineEdit_textChanged(const QString &arg1)
165 {
166  bool ok;
167  double value = arg1.toDouble(&ok);
168  if (!ok)
169  return;
170  first_min_line_->point1->setCoords(value, 0);
171  first_min_line_->point2->setCoords(value, 1);
172  if (!ui->spectrumCustomPlot->hasItem(first_min_line_))
173  ui->spectrumCustomPlot->addItem(first_min_line_);
174  ui->spectrumCustomPlot->repaint();
175 }
176 
177 void BandRatioDialog::on_firstMaxLineEdit_textChanged(const QString &arg1)
178 {
179  bool ok;
180  double value = arg1.toDouble(&ok);
181  if (!ok)
182  return;
183  first_max_line_->point1->setCoords(value, 0);
184  first_max_line_->point2->setCoords(value, 1);
185  if (!ui->spectrumCustomPlot->hasItem(first_max_line_))
186  ui->spectrumCustomPlot->addItem(first_max_line_);
187  ui->spectrumCustomPlot->repaint();
188 }
189 
190 void BandRatioDialog::on_secondMinLineEdit_textChanged(const QString &arg1)
191 {
192  bool ok;
193  double value = arg1.toDouble(&ok);
194  if (!ok)
195  return;
196  second_min_line_->point1->setCoords(value, 0);
197  second_min_line_->point2->setCoords(value, 1);
198  if (!ui->spectrumCustomPlot->hasItem(second_min_line_))
199  ui->spectrumCustomPlot->addItem(second_min_line_);
200 }
201 
202 void BandRatioDialog::on_secondMaxLineEdit_textChanged(const QString &arg1)
203 {
204  bool ok;
205  double value = arg1.toDouble(&ok);
206  if (!ok)
207  return;
208  second_max_line_->point1->setCoords(value, 0);
209  second_max_line_->point2->setCoords(value, 1);
210  if (!ui->spectrumCustomPlot->hasItem(second_max_line_))
211  ui->spectrumCustomPlot->addItem(second_max_line_);
212 }
213 
214 
215 void BandRatioDialog::on_indexSpinBox_editingFinished()
216 {
217  size_t index = ui->indexSpinBox->value();
218  QVector<double> plot_data = Vespucci::FromArmaVec(analyzer_->PointSpectrum(index));
219  QVector<double> abscissa = Vespucci::FromArmaVec(analyzer_->abscissa());
220  ui->spectrumCustomPlot->graph(0)->clearData();
221  ui->spectrumCustomPlot->graph(0)->addData(abscissa, plot_data);
222  ui->spectrumCustomPlot->replot(QCustomPlot::rpImmediate);
223 }
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes) ...
Definition: qcustomplot.h:160
The BandRatioDialog class The dialog that allows the user to create a band-ratio map.
Definition: ahcadialog.h:26
BandRatioDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, QSharedPointer< AbstractDataAnalyzer > analyzer)
VESPUCCI_EXPORT arma::uword max(arma::uword a, arma::uword b)
Vespucci::Math::max.
Definition: accessory.cpp:237
void setCoords(double key, double value)
QVector< double > FromArmaVec(const arma::vec &data)
Definition: global.cpp:180
A straight line that spans infinitely in both directions.
Definition: qcustomplot.h:3287
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
Definition: accessory.cpp:249
The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot...
Definition: qcustomplot.h:1715
QCPItemPosition *const point1
Definition: qcustomplot.h:3309
0x002 Axis ranges are zoomable with the mouse wheel (see QCPAxisRect::setRangeZoom, QCPAxisRect::setRangeZoomAxes)
Definition: qcustomplot.h:161
QCPItemPosition *const point2
Definition: qcustomplot.h:3310
void setPen(const QPen &pen)