-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
90 lines (71 loc) · 2.35 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
/**
* @file mainwindow.cpp
* @brief Implementation of the Qt interface to the surface reconstruction algorithm.
*
*
* @author Noelia Barreira ([email protected])
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QFileDialog>
#include <QDir>
#include <QMessageBox>
#include <QtConcurrentRun>
#include <QFuture>
#include <QFutureWatcher>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle("qvtkDicomViewer");
ui->pushButton->setDisabled(true);
ui->progressBar->setVisible(false);
sr = new SurfaceReconstruction();
sr->Show(ui->qvtkWidget->GetRenderWindow()); // Reset the framebuffer with a dark background
}
MainWindow::~MainWindow()
{
delete sr;
delete ui;
}
extern void Update(void);
void MainWindow::on_pushButton_clicked()
{
ui->pushButton->setDisabled(true);
ui->progressBar->setVisible(true);
ui->progressBar->setMaximum(0);
ui->progressBar->setMinimum(0);
sr->setThreshold(ui->spinBox->text().toDouble());
// Surface computation is performed in another thread. When it finishes,
// the signal finished is thrown and the function handleFinished will be
// executed
connect(&watcher, SIGNAL(finished()), this, SLOT(handleFinished()));
QFuture<void> future = QtConcurrent::run(sr, &SurfaceReconstruction::Update);
watcher.setFuture(future);
}
// Displays the suface once the concurrent thread that executes the Update function
// finishes
void MainWindow::handleFinished() {
sr->Show(ui->qvtkWidget->GetRenderWindow());
ui->pushButton->setDisabled(false);
ui->progressBar->setVisible(false);
}
void MainWindow::on_actionOpen_directory_activated() {
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
QDir::home().absolutePath(),
QFileDialog::ShowDirsOnly);
delete sr;
sr = new SurfaceReconstruction();
int files = sr->ReadDICOMSeries(dir.toStdString());
QString message = QString::number(files) + " files read from " + dir;
ui->statusBar->showMessage(message);
ui->pushButton->setDisabled(false);
}
void MainWindow::on_actionAbout_activated() {
QMessageBox about;
about.setText("A simple DICOM viewer using vtk + qt");
about.setWindowTitle("qvtkDicomViewer");
about.exec();
}