-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWidget.cpp
More file actions
144 lines (122 loc) · 5.76 KB
/
Copy pathWidget.cpp
File metadata and controls
144 lines (122 loc) · 5.76 KB
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
//-------------------------------------------------------------------------------------------------------------------
/*! \brief Implementation of class Widget
* \file Widget.cpp
*///-----------------------------------------------------------------------------------------------------------------
#include "Widget.h"
/*---- Internal Includes ----*/
#include "ApplicationData.h"
#include "View2D.h"
#include "View3D.h"
/*---- QT Includes ----*/
#include <QFileDialog>
#include <QDebug>
#include <QHBoxLayout>
#include <QtWidgets/QMessageBox>
//-----------------------------------------------------------------------------------------------------------------
Widget::Widget(QWidget * p_parent) : QWidget(p_parent)
//-----------------------------------------------------------------------------------------------------------------
{
m_ui.setupUi(this);
//Hide view
m_ui.segmentButton->setDisabled(true);
m_ui.view2D->hide();
m_ui.view3D->hide();
m_ui.progressBar->hide();
//Connect signals and slots for Load button
connect(m_ui.loadButton, SIGNAL(clicked()), this, SLOT(slotSelectDir()));
connect(m_ui.saveButton, SIGNAL(clicked()), this, SLOT(slotSave3dModels()));
connect(m_ui.segmentButton, SIGNAL(clicked()), this, SLOT(slotSegmentData()));
connect(m_ui.countButton, SIGNAL(clicked()), this, SLOT(coutObjectInSlice()));
connect(m_ui.colorsButton, SIGNAL(toggled(bool)), m_ui.view3D, SLOT(slotEnableColors(bool)));
connect(m_ui.invertBgColorButton, SIGNAL(toggled(bool)), m_ui.view3D, SLOT(slotInvertBackgroundColor()));
auto data = ApplicationData::getInstance();
connect(data, SIGNAL(progressStarted()), this, SLOT(slotProgressStarted()));
connect(data, SIGNAL(progressStopped()), this, SLOT(slotProgressStopped()));
connect(data, SIGNAL(progressNewStep(QString, int)), this, SLOT(slotProgressNewStep(QString, int)));
connect(data, SIGNAL(progressUpdate(int)), m_ui.progressBar , SLOT(setValue(int)));
setFixedWidth(1200);
}
//-----------------------------------------------------------------------------------------------------------------
Widget::~Widget()
//-----------------------------------------------------------------------------------------------------------------
{
}
//-----------------------------------------------------------------------------------------------------------------
void Widget::slotSelectDir()
//-----------------------------------------------------------------------------------------------------------------
{
const QString dirPath = QFileDialog::getExistingDirectory(this, "Open DICOM image directory", ApplicationData::getInstance()->getLastOpenedPath());
if(dirPath != "")
{
m_ui.segmentButton->setDisabled(true);
m_ui.saveButton->setDisabled(true);
m_ui.view2D->hide();
m_ui.view3D->hide();
update();
//Load directory
if(!ApplicationData::getInstance()->loadDirectory(dirPath))
{
QMessageBox::critical(this, "Error opening DICOM folder", "Selected folder does not contains any DICOM image file.");
return;
}
//Connect signals and slots for Segment button
m_ui.segmentButton->setDisabled(false);
m_ui.countButton->setEnabled(true);
m_ui.view2D->initData();
//Show view2D and view3D
m_ui.view2D->show();
}
}
//-----------------------------------------------------------------------------------------------------------------
void Widget::slotSegmentData()
//-----------------------------------------------------------------------------------------------------------------
{
//Disconnect segment button
m_ui.segmentButton->setDisabled(true);
m_ui.colorsButton->setDisabled(false);
m_ui.invertBgColorButton->setDisabled(false);
m_ui.saveButton->setDisabled(false);
//Segment data
ApplicationData::getInstance()->segmentData();
//Init view3D
m_ui.view3D->initData();
m_ui.view3D->show();
}
//-----------------------------------------------------------------------------------------------------------------
void Widget::slotSave3dModels()
//-----------------------------------------------------------------------------------------------------------------
{
const QString dirPath = QFileDialog::getExistingDirectory(this, "Save 3d models in directory", ApplicationData::getInstance()->getLastSaveddPath());
if(dirPath != "")
{
ApplicationData::getInstance()->save3dModels(dirPath);
}
}
//-----------------------------------------------------------------------------------------------------------------
void Widget::coutObjectInSlice()
//-----------------------------------------------------------------------------------------------------------------
{
ApplicationData::getInstance()->countObjectInSlices();
m_ui.countButton->setEnabled(false);
m_ui.view2D->displaySliceObjectCounter();
}
//-----------------------------------------------------------------------------------------------------------------
void Widget::slotProgressStarted()
//-----------------------------------------------------------------------------------------------------------------
{
m_ui.progressBar->show();
}
//-----------------------------------------------------------------------------------------------------------------
void Widget::slotProgressStopped()
//-----------------------------------------------------------------------------------------------------------------
{
m_ui.progressBar->hide();
}
//-----------------------------------------------------------------------------------------------------------------
void Widget::slotProgressNewStep(QString stepName, int subStepsNumber)
//-----------------------------------------------------------------------------------------------------------------
{
m_ui.progressBar->setFormat(stepName + " %v/%m (%p%)");
m_ui.progressBar->setValue(0);
m_ui.progressBar->setMaximum(subStepsNumber);
}