forked from githubdoe/DFTFringe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
averagewavefrontfilesdlg.cpp
179 lines (161 loc) · 5.36 KB
/
averagewavefrontfilesdlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "averagewavefrontfilesdlg.h"
#include "ui_averagewavefrontfilesdlg.h"
#include "surfacemanager.h"
#include "mainwindow.h"
#include "wavefrontaveragefilterdlg.h"
#include <opencv/cv.h>
#include "rejectedwavefrontsdlg.h"
#include <QFileInfo>
#include "utils.h"
void showData(const std::string &txt, Mat mat, bool useLog);
averageWaveFrontFilesDlg::averageWaveFrontFilesDlg(QStringList list, SurfaceManager *m, QWidget *parent) :
QDialog(parent),
ui(new Ui::averageWaveFrontFilesDlg)
{
sm = m;
average = 0;
ui->setupUi(this);
ui->fileList->addItems(list);
ui->progressBar->setRange(0,10);
ui->progressBar->setValue(0);
useFilter = false;
}
averageWaveFrontFilesDlg::~averageWaveFrontFilesDlg()
{
delete ui;
}
void averageWaveFrontFilesDlg::on_MoveUp_clicked()
{
int currentIndex = ui->fileList->currentRow();
if (currentIndex == 0)
return;
QListWidgetItem *currentItem = ui->fileList->takeItem(currentIndex);
ui->fileList->insertItem(currentIndex-1, currentItem);
ui->fileList->setCurrentRow(currentIndex-1);
}
extern double outputLambda;
void averageWaveFrontFilesDlg::on_process_clicked()
{
bool first = true;
abort = false;
QStringList rejects;
bool configChanged = false;
int count = ui->fileList->count();
if (count == 0)
return;
ui->progressBar->setMaximum(count -1);
ui->progressBar->setFormat("%p%");
QApplication::setOverrideCursor(Qt::WaitCursor);
cv::Mat mask;
static mirrorDlg *md = mirrorDlg::get_Instance();
int total = 0;
for(int i = 0; i < count; ++i)
{
if (abort)
break;
QListWidgetItem* item = ui->fileList->item(i);
QString name = item->text();
ui->fileList->setCurrentRow(i);
qApp->processEvents();
wavefront *wf = sm->readWaveFront(name,configChanged);
if (useFilter){
sm->makeMask(wf);
sm->generateSurfacefromWavefront(wf);
cv::Scalar mean,std;
cv::meanStdDev(wf->workData,mean,std,wf->workMask);
double stdVal = std.val[0]* md->lambda/outputLambda;
if (stdVal > filterRMS){
QFileInfo info(name);
QString item = QString().sprintf("%s RMS:%lf", info.baseName().toStdString().c_str(), stdVal);
rejects << item;
ui->fileList->item(i)->setForeground(Qt::red);
qApp->processEvents();
delete wf;
continue;
}
}
if (first){
first = false;
average = wf;
sm->makeMask(average, false);
mask = average->mask.clone();
total = 1;
}
else {
wavefront *second = wf;
++total;
sm->makeMask(second, false);
int size1 = average->data.rows * average->data.cols;
int size2 = second->data.rows * second->data.cols;
cv::Mat resize = second->data.clone();
cv::Mat resizeMask = second->mask;
if (size1 != size2) {
cv::resize(resize,resize, cv::Size(average->data.cols, average->data.rows));
cv::resize(mask,resizeMask, cv::Size(average->data.cols, average->data.rows));
}
average->data = average->data + resize;
cv::Mat maskResult;
cv::bitwise_and(mask, resizeMask, mask);
delete second;
}
ui->progressBar->setValue(i);
}
if (total > 1){
average->mask = mask.clone();
average->data.copyTo(average->data,average->mask);
if (abort){
if (average)
delete average;
average = 0;
}
else {
average->data/= total;
// set average to surface manager.
}
ui->progressBar->setValue(0);
ui->progressBar->setFormat("Done");
emit averageComplete( average );
}
if (rejects.size() > 0){
rejectedWavefrontsDlg dlg(rejects);
dlg.exec();
}
QApplication::restoreOverrideCursor();
}
void averageWaveFrontFilesDlg::on_addFiles_clicked()
{
MainWindow * mw = ((MainWindow*)(sm->parent()));
QStringList files = mw->SelectWaveFrontFiles();
if (files.size() == 0)
return;
ui->fileList->addItems(files);
}
void averageWaveFrontFilesDlg::on_buttonBox_clicked(QAbstractButton *button)
{
}
void averageWaveFrontFilesDlg::on_moveDown_clicked()
{
int currentIndex = ui->fileList->currentRow();
if (currentIndex == ui->fileList->count() -1)
return;
QListWidgetItem *currentItem = ui->fileList->takeItem(currentIndex);
ui->fileList->insertItem(currentIndex+1, currentItem);
ui->fileList->setCurrentRow(currentIndex+1);
}
void averageWaveFrontFilesDlg::on_deleteFiles_clicked()
{
int currentIndex = ui->fileList->currentRow();
QListWidgetItem *currentItem = ui->fileList->takeItem(currentIndex);
delete currentItem;
ui->fileList->setCurrentRow(currentIndex-1);
}
void averageWaveFrontFilesDlg::on_filterCB_clicked(bool checked)
{
useFilter = checked;
if (checked) {
wavefrontAverageFilterDlg dlg;
if (dlg.exec()){
filterRMS = dlg.rms();
}
}
}