Vespucci  1.0.0
univariatedialog.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_univariatedialog.h"
23 
30 UnivariateDialog::UnivariateDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws, QSharedPointer<AbstractDataAnalyzer> analyzer) :
31  QDialog(parent),
32  ui(new Ui::UnivariateDialog),
33  workspace_(ws),
34  analyzer_(analyzer)
35 {
36  ui->setupUi(this);
37  min_line_ = new QCPItemStraightLine(ui->spectrumPlot);
38  min_line_->point1->setCoords(0, 0);
39  min_line_->point2->setCoords(0, 1);
40  max_line_ = new QCPItemStraightLine(ui->spectrumPlot);
41  max_line_->point1->setCoords(0, 0);
42  max_line_->point2->setCoords(0, 1);
43  double min, max;
44  try{
45  min = analyzer_->AbscissaMin();
46  max = analyzer_->AbscissaMax();
47  }
48  catch(exception e){
49  cerr << e.what();
50  workspace_->main_window()->DisplayExceptionWarning(e);
51  min = 0;
52  max = 0;
53  }
54 
55  QString label_text = QString::number(min) + "–" + QString::number(max);
56  ui->rangeLabel->setText(label_text);
57 
58  ui->minLineEdit->setValidator(new QDoubleValidator(min, max, 2, this));
59  ui->maxLineEdit->setValidator(new QDoubleValidator(min, max, 2, this));
60 
61  uword middle = analyzer_->columns() / 2;
62  ui->indexSpinBox->setRange(0, analyzer_->columns() - 1);
63  ui->indexSpinBox->setValue(middle);
64  QVector<double> plot_data, wavelength;
65 
66  try{
67  plot_data = Vespucci::FromArmaVec(analyzer_->PointSpectrum(middle));
68  wavelength = Vespucci::FromArmaVec(analyzer_->abscissa());
69  }
70  catch(exception e){}
71  if (plot_data.isEmpty())
72  plot_data = Vespucci::FromArmaVec(analyzer_->PointSpectrum(0));
73  ui->spectrumPlot->addGraph();
74  ui->spectrumPlot->graph(0)->addData(wavelength, plot_data);
75  ui->spectrumPlot->rescaleAxes();
76  ui->spectrumPlot->setInteraction(QCP::iRangeDrag, true);
77  ui->spectrumPlot->setInteraction(QCP::iRangeZoom, true);
78 
79 }
80 
82 {
83  delete ui;
84 }
85 
89 void UnivariateDialog::on_buttonBox_accepted()
90 {
91  close();
92  if (ui->minLineEdit->text().isEmpty() || ui->maxLineEdit->text().isEmpty()){
93  QMessageBox::warning(this, "Invalid Input!", "You must enter numbers for left and right bounds.");
94  return;
95  }
96  double entered_min = ui->minLineEdit->text().toDouble();
97  double entered_max = ui->maxLineEdit->text().toDouble();
98  uint bound_window = ui->searchWindowSpinBox->value();
99  QString name = ui->nameLineEdit->text();
100  if(!name.size()){
101  name = "Univariate";
102  }
103  QString value_method = ui->methodComboBox->currentText();
104  if (!analyzer_.isNull()){
105  if (value_method == "Empirical"){
106  try{
107  analyzer_->Univariate(name, entered_min, entered_max, bound_window);
108  }catch(exception e){
109  workspace_->main_window()->DisplayExceptionWarning(e);
110  }
111  }
112  else{
113  try{
114  analyzer_->FitPeak(name, value_method, entered_min, entered_max);
115  }catch(exception e){
116 
117  }
118  }
119  }
120  analyzer_.clear();
121  close();
122 }
123 
124 
128 void UnivariateDialog::on_buttonBox_rejected()
129 {
130  analyzer_.clear();
131 }
132 
133 void UnivariateDialog::on_minLineEdit_textChanged(const QString &arg1)
134 {
135  bool ok;
136  double value = arg1.toDouble(&ok);
137  if (!ok)
138  return;
139 
140  min_line_->point1->setCoords(value, 0);
141  min_line_->point2->setCoords(value, 1);
142  if(!ui->spectrumPlot->hasItem(min_line_))
143  ui->spectrumPlot->addItem(min_line_);
144  ui->spectrumPlot->replot(QCustomPlot::rpImmediate);
145 }
146 
147 void UnivariateDialog::on_maxLineEdit_textChanged(const QString &arg1)
148 {
149  bool ok;
150  double value = arg1.toDouble(&ok);
151  if (!ok)
152  return;
153 
154  max_line_->point1->setCoords(value, 0);
155  max_line_->point2->setCoords(value, 1);
156 
157  if(!ui->spectrumPlot->hasItem(max_line_))
158  ui->spectrumPlot->addItem(max_line_);
159  ui->spectrumPlot->replot(QCustomPlot::rpImmediate);
160 }
161 
162 void UnivariateDialog::on_indexSpinBox_editingFinished()
163 {
164  size_t index = ui->indexSpinBox->value();
165  QVector<double> plot_data = Vespucci::FromArmaVec(analyzer_->PointSpectrum(index));
166  QVector<double> abscissa = Vespucci::FromArmaVec(analyzer_->abscissa());
167  ui->spectrumPlot->graph(0)->clearData();
168  ui->spectrumPlot->graph(0)->addData(abscissa, plot_data);
169  ui->spectrumPlot->replot(QCustomPlot::rpImmediate);
170 }
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes) ...
Definition: qcustomplot.h:160
Definition: ahcadialog.h:26
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
UnivariateDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, QSharedPointer< AbstractDataAnalyzer > analyzer)
UnivariateDialog::UnivariateDialog.
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
The UnivariateDialog class Class allowing user to create univariate images.
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