forked from BITS-DIC/BITS-DIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
148 lines (130 loc) · 4.8 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "setroi.h"
#include "utils.h"
#include <QFile>
#include <QDir>
#include <QStatusBar>
#include <QFileDialog>
#include <QDesktopWidget>
#include <cstdlib>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle(WINDOW_TITLE);
this->showMaximized();
dic = new Dic();
setRoiDialog = new SetROI(this);
currImgIndex = -1;
/*std::vector<float> distanceF{0, 1, 2, 3, 4, 5, 6, 7}; // this is the type of the vector
std::vector<cv::Complex<float> > ff;
cv::dft(distanceF, ff, cv::DFT_ROWS|cv::DFT_COMPLEX_OUTPUT);
for (int i = 0; i < ff.size(); i++) {
qDebug("%f + %f i\t", ff[i].re, ff[i].im);
}*/
}
MainWindow::~MainWindow()
{
delete ui;
delete dic;
delete setRoiDialog;
}
void MainWindow::setCurrentImageIndex(int i) {
currImgIndex = i;
QImage qim = Utils::matToQImage(dic->getCurrentImage(i));
Utils::loadImage(qim, ui->currImage, 512);
ui->currentImageIndex->setText(tr(std::to_string(i + 1).c_str()));
ui->prevImage->setEnabled(i > 0);
ui->nextImage->setEnabled(i < dic->getCurrentImagesCount() - 1);
ui->currentImageIndex->setEnabled(true);
}
void MainWindow::on_actionLoad_Reference_Image_triggered() {
QString fileName = QFileDialog::getOpenFileName(this,
tr("Select Reference Image File"),
QDir::homePath(),
"Images (*.png *.jpg *.jpeg *.tif *.tiff);;All Files (*)",
nullptr,
QFileDialog::DontUseNativeDialog
);
QString status = tr("");
if (fileName.length() == 0) status = tr("No File Selected");
else {
status = tr("Selected ") + fileName;
statusBar()->showMessage(status, 2000);
cv::Mat refImage = cv::imread(fileName.toStdString(), cv::IMREAD_GRAYSCALE);
dic->setReferenceImage(refImage);
QImage convertedImage = Utils::matToQImage(refImage);
Utils::loadImage(convertedImage, ui->refImage, 512);
ui->refImgChk->setChecked(true);
ui->refImgChk->setText(tr("Reference \n Image Loaded"));
}
}
QStringList files;
void MainWindow::on_actionLoad_Current_Image_s_triggered() {
files = QFileDialog::getOpenFileNames(this,
tr("Select Current Image(s)"),
QDir::homePath(),
"Images (*.png *.jpg *.jpeg *.tif *.tiff);;All Files (*)",
0, QFileDialog::DontUseNativeDialog
);
if (files.length() == 0) {
statusBar()->showMessage(tr("No File Selected"), 2000);
return;
}
cv::Mat *imagesList = (cv::Mat *) calloc(files.length(), sizeof(cv::Mat));
for (int i = 0; i < files.length(); i++) {
imagesList[i] = cv::imread(files[i].toStdString(), cv::IMREAD_GRAYSCALE);
}
dic->setCurrentImages(files.length(), imagesList);
setCurrentImageIndex(0);
QString status;
if (files.length() == 1) {
status = tr("Selected file ") + files.at(0);
ui->currImgChk->setText("Loaded 1 \ncurrent image");
} else {
status = tr("Selected ") + tr(std::to_string(files.length()).c_str()) + tr(" Files : ")
+ files.first() + " ... " + files.last();
ui->currImgChk->setText(tr("Loaded ") + tr(std::to_string(files.length()).c_str()) + tr(" \ncurrent images"));
}
ui->currImgChk->setChecked(true);
statusBar()->showMessage(status, 2000);
}
void MainWindow::on_prevImage_clicked()
{
setCurrentImageIndex(currImgIndex - 1);
}
void MainWindow::on_nextImage_clicked()
{
setCurrentImageIndex(currImgIndex + 1);
}
void MainWindow::on_actionSet_Region_of_Interest_ROI_triggered()
{
qDebug() << "Loading SetROI";
setRoiDialog->open();
qDebug() << "Setting up signal/slot connection for ROI";
connect(setRoiDialog, SIGNAL(onRoiSet(cv::Mat)), this, SLOT(onRoiSet(cv::Mat)), Qt::UniqueConnection);
}
/**
* @brief MainWindow::onRoiSet When SetROI gives a signal that user has decided on ROI data.
* @param roiImage cv::Mat image data. //TODO make sure it is either 0/255 data.
*/
void MainWindow::onRoiSet(cv::Mat roiImage) {
dic->setROI(roiImage);
ui->roiChk->setChecked(true);
ui->roiChk->setText(tr("ROI set"));
// Show preview of ROI (to be removed later)
//NOTE If this fails, high-gui may be not have been implemented in opencv build
//cv::namedWindow("ROI preview", cv::WINDOW_NORMAL);
//cv::imshow("ROI preview", roiImage);
//cv::waitKey(0);
//TODO what happens in case SetROI window gets closed. Maybe unique connection will prevent extra connects.
qDebug() << "Disconnecting signal/slot connection for ROI";
disconnect(setRoiDialog, SIGNAL(onRoiSet(cv::Mat)), this, SLOT(onRoiSet(cv::Mat)));
}
void MainWindow::on_actionPerform_DIC_Analysis_triggered()
{
dic->performDicAnalysis();
}