Vespucci  1.0.0
fouriertransformdialog.cpp
Go to the documentation of this file.
2 #include "ui_fouriertransformdialog.h"
3 #include "Global/global.h"
4 FourierTransformDialog::FourierTransformDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws, const QString &dataset_key) :
5  QDialog(parent),
7 {
8  ui->setupUi(this);
9  workspace_ = ws;
10  dataset_ = workspace_->GetDataset(dataset_key);
11 
12  ui->parameterDoubleSpinBox->setVisible(false);
13  ui->parameterLabel->setVisible(false);
14  ui->endDoubleSpinBox->setVisible(false);
15  ui->endLabel->setVisible(false);
16  ui->sinePowerDoubleSpinBox->setVisible(false);
17  ui->sinePowerLabel->setVisible(false);
18  ui->spectrumSpinBox->setRange(1, dataset_->spectra_ptr()->n_cols);
19 
20  ui->spectrumCustomPlot->addGraph();
21 
22 }
23 
25 {
26  delete ui;
27 }
28 
29 
30 
31 void FourierTransformDialog::on_typeComboBox_currentIndexChanged(const QString &arg1)
32 {
33  if (arg1 == "Inverse FFT"){
34  ui->endDoubleSpinBox->setVisible(false);
35  ui->endLabel->setVisible(false);
36  ui->weightsComboBox->setVisible(false);
37  ui->weightsLabel->setVisible(false);
38  ui->parameterLabel->setVisible(false);
39  ui->parameterDoubleSpinBox->setVisible(false);
40  }
41  QString weights = ui->weightsComboBox->currentText();
42  if (arg1 == "FFT"){
43  ui->weightsComboBox->setVisible(true);
44  ui->weightsLabel->setVisible(true);
45  if (weights == "Sine"){
46  ui->endDoubleSpinBox->setVisible(true);
47  ui->endLabel->setVisible(true);
48  ui->endLabel->setText("Ending Offset");
49  ui->parameterLabel->setVisible(true);
50  ui->parameterLabel->setText("Starting Offset");
51  ui->sinePowerDoubleSpinBox->setVisible(true);
52  ui->sinePowerLabel->setVisible(true);
53  }
54  else if (weights == "Gaussian"){
55  ui->parameterDoubleSpinBox->setVisible(true);
56  ui->parameterLabel->setVisible(true);
57  ui->endDoubleSpinBox->setVisible(false);
58  ui->endLabel->setVisible(false);
59  ui->sinePowerLabel->setVisible(false);
60  ui->sinePowerDoubleSpinBox->setVisible(false);
61  ui->parameterLabel->setText("σ");
62  }
63  else if (weights == "Exponential"){
64  ui->parameterDoubleSpinBox->setVisible(true);
65  ui->parameterLabel->setVisible(true);
66  ui->endDoubleSpinBox->setVisible(false);
67  ui->endLabel->setVisible(false);
68  ui->sinePowerLabel->setVisible(false);
69  ui->sinePowerDoubleSpinBox->setVisible(false);
70  ui->parameterLabel->setText("λ");
71  }
72  else{
73  ui->parameterDoubleSpinBox->setVisible(false);
74  ui->parameterLabel->setVisible(false);
75  ui->endDoubleSpinBox->setVisible(false);
76  ui->endLabel->setVisible(false);
77  ui->sinePowerDoubleSpinBox->setVisible(false);
78  ui->sinePowerLabel->setVisible(false);
79  }
80  }
81 }
82 
83 void FourierTransformDialog::on_weightsComboBox_currentIndexChanged(const QString &arg1)
84 {
85 
86  if (arg1 == "Sine Bell"){
87  ui->endDoubleSpinBox->setVisible(true);
88  ui->endLabel->setVisible(true);
89  ui->endLabel->setText("Ending Offset");
90  ui->parameterLabel->setVisible(true);
91  ui->parameterLabel->setText("Starting Offset");
92  ui->sinePowerDoubleSpinBox->setVisible(true);
93  ui->sinePowerLabel->setVisible(true);
94  }
95  else if (arg1 == "Gaussian"){
96  ui->parameterDoubleSpinBox->setVisible(true);
97  ui->parameterLabel->setVisible(true);
98  ui->endDoubleSpinBox->setVisible(false);
99  ui->endLabel->setVisible(false);
100  ui->sinePowerLabel->setVisible(false);
101  ui->sinePowerDoubleSpinBox->setVisible(false);
102  ui->parameterLabel->setText("σ");
103  }
104  else if (arg1 == "Exponential"){
105  ui->parameterDoubleSpinBox->setVisible(true);
106  ui->parameterLabel->setVisible(true);
107  ui->endDoubleSpinBox->setVisible(false);
108  ui->endLabel->setVisible(false);
109  ui->sinePowerLabel->setVisible(false);
110  ui->sinePowerDoubleSpinBox->setVisible(false);
111  ui->parameterLabel->setText("λ");
112  }
113  else{
114  ui->parameterDoubleSpinBox->setVisible(false);
115  ui->parameterLabel->setVisible(false);
116  ui->endDoubleSpinBox->setVisible(false);
117  ui->endLabel->setVisible(false);
118  ui->sinePowerDoubleSpinBox->setVisible(false);
119  ui->sinePowerLabel->setVisible(false);
120  }
121 }
122 
123 void FourierTransformDialog::on_previewPushButton_clicked()
124 {
125  typedef QVector<double> qvec;
126  typedef std::vector<double> stdvec;
127  qvec abs_qvec;
128  qvec spc_qvec;
129 
130  arma::vec abscissa = dataset_->abscissa();
131  arma::uvec ind = {(arma::uword) ui->spectrumSpinBox->value() - 1};
132  arma::uword n = std::pow(2.0, ui->powerSpinBox->value());
133 
134  if (ui->typeComboBox->currentText() == "FFT"){
135  arma::cx_mat f_spectrum;
136  arma::vec f_abscissa;
137  arma::mat spectrum = dataset_->spectra(ind);
138  try{
139  Vespucci::Math::Transform::fft_mat(spectrum, abscissa, f_spectrum, f_abscissa, n);
140  abs_qvec = qvec::fromStdVector(arma::conv_to<stdvec>::from(f_abscissa));
141  spc_qvec = qvec::fromStdVector(arma::conv_to<stdvec>::from(arma::real(f_spectrum)));
142  }catch(exception e){
143  workspace_->main_window()->DisplayExceptionWarning(e);
144  close();
145  }
146  }
147  else if (ui->typeComboBox->currentText() == "Inverse FFT"){
148  arma::cx_mat t_spectrum;
149  arma::vec t_abscissa;
150  arma::cx_mat cx_spectrum = dataset_->cx_spectra(ind);
151 
152  try{
153  Vespucci::Math::Transform::ifft_mat(cx_spectrum, abscissa,
154  t_spectrum, t_abscissa,
155  n);
156  abs_qvec =
157  qvec::fromStdVector(arma::conv_to<stdvec>::from(t_abscissa));
158  spc_qvec =
159  qvec::fromStdVector(arma::conv_to<stdvec>::from(arma::real(t_spectrum)));
160  }catch(exception e){
161  workspace_->main_window()->DisplayExceptionWarning(e);
162  close();
163  }
164  }
165  else{return;}
166 
167  ui->spectrumCustomPlot->graph(0)->setData(abs_qvec, spc_qvec);
168  ui->spectrumCustomPlot->replot();
169 
170 }
171 
172 
173 void FourierTransformDialog::on_powerSpinBox_valueChanged(int arg1)
174 {
175  ui->valueLabel->setText("= " + QString::number( std::pow(2.0, arg1) ) );
176 }
177 
178 void FourierTransformDialog::on_weightsPushButton_clicked()
179 {
180  QString type = ui->weightsComboBox->currentText();
181  int response = QMessageBox::warning(this, "Apply Weights",
182  "Applying weights will change the spectra permanently."
183  "This can be undone, but only once. Are you sure you "
184  "want to proceed?",
185  QMessageBox::Ok, QMessageBox::Cancel);
186  if (response == QMessageBox::Cancel){return;}
187  if (type == "Sine Bell"){
188  dataset_->ApplyFTWeight(ui->parameterDoubleSpinBox->value(),
189  ui->endDoubleSpinBox->value(),
190  ui->sinePowerDoubleSpinBox->value());
191  }
192  else if (type == "Exponential"
193  || type == "Gaussian"){
194  dataset_->ApplyFTWeight(type, ui->parameterDoubleSpinBox->value());
195  }
196  else{
197  return;
198  }
199 }
200 
201 void FourierTransformDialog::on_buttonBox_accepted()
202 {
203  int n = std::pow(2, ui->powerSpinBox->value());
204  cout << "n = " << n << "\n";
205 
206 
207  if (ui->typeComboBox->currentText() == "FFT"){
208  QProgressDialog *progress =
210  "Performing FFT",
211  "Performing FFT...");
212  try{
213  dataset_->FourierTransform(n);
214  }catch(exception e){
215  workspace_->main_window()->DisplayExceptionWarning(e);
216  progress->cancel();
217  }
218  progress->cancel();
219  }
220  else if (ui->typeComboBox->currentText() == "Inverse FFT"){
221  QProgressDialog *progress =
223  "Performing Inverse FFT",
224  "Performing Inverse FFT...");
225  try{
226  dataset_->InverseFourierTransform(n);
227  }catch(exception e){
228  workspace_->main_window()->DisplayExceptionWarning(e);
229  progress->cancel();
230  }
231  progress->cancel();
232  }
233  else{close();}
234  close();
235 }
Definition: ahcadialog.h:26
QProgressDialog * DisplayProgressDialog(QWidget *parent, QString title, QString text)
Definition: global.cpp:156
FourierTransformDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws, const QString &dataset_key)
VESPUCCI_EXPORT void ifft_mat(const arma::cx_mat &f_signal, const arma::vec f_abscissa, arma::cx_mat &t_signal, arma::vec &t_abscissa, arma::uword n)
Vespucci::Math::Transform::ifft_mat.
Definition: fft.cpp:72
QVector< double > qvec
Definition: mapplot.h:28
std::vector< double > stdvec
Definition: mapplot.h:27
VESPUCCI_EXPORT void fft_mat(const arma::mat &t_signal, const arma::vec &t_abscissa, arma::cx_mat &f_signal, arma::vec &f_abscissa, arma::uword n)
Vespucci::Math::Transform::fft_mat.
Definition: fft.cpp:29