-
Notifications
You must be signed in to change notification settings - Fork 5
/
rtstructreaderdialog.cpp
180 lines (154 loc) · 6.61 KB
/
rtstructreaderdialog.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
180
/********************************************************************************
MIT License
Copyright (c) 2021 Jothy Selvaraj
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
********************************************************************************/
#include "rtstructreaderdialog.h"
#include "ui_rtstructreaderdialog.h"
#define vtkRenderingCore_AUTOINIT \
3(vtkInteractionStyle, vtkRenderingFreeType, vtkRenderingOpenGL2)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL2)
#include <gdcmAttribute.h>
#include <gdcmDataElement.h>
#include <gdcmDataSet.h>
#include <gdcmFile.h>
#include <gdcmItem.h>
#include <gdcmNestedModuleEntries.h>
#include <gdcmReader.h>
#include <gdcmSequenceOfItems.h>
#include <gdcmTag.h>
#include <QDebug>
#include <QFileDialog>
#include <QListWidgetItem>
#include <QMessageBox>
RTStructReaderDialog::RTStructReaderDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::RTStructReaderDialog) {
ui->setupUi(this);
// For auto opening the file dialog
this->ui->pushButtonChooseFile->click();
}
RTStructReaderDialog::~RTStructReaderDialog() { delete ui; }
void RTStructReaderDialog::on_pushButtonChooseFile_clicked() {
this->ui->listWidgetStructs->clear();
this->structFileName =
QFileDialog::getOpenFileName(this, "Open RT Structures");
this->ui->lineEdit->setText(this->structFileName);
gdcm::Reader RTreader;
RTreader.SetFileName(this->structFileName.toLatin1().data());
// show error msg if file can't be read.
if (!RTreader.Read()) {
QMessageBox msgBox;
msgBox.setText("Not a valid DICOM file!");
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
}
else // Start reading the necessary info
{
const gdcm::DataSet &ds = RTreader.GetFile().GetDataSet();
gdcm::Tag tssroisq(0x3006, 0x0020); // Structure set ROI sequence
if (!ds.FindDataElement(tssroisq)) {
// qDebug() <<"Problem locating 0x3006,0x0020 - Is this a valid RT Struct
// file?";
QMessageBox msgBox;
msgBox.setText("This is not a valid RT structure file!");
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
}
else {
gdcm::Tag troicsq(0x3006, 0x0039); // ROI contour sequence
if (!ds.FindDataElement(troicsq)) {
// qDebug() << "Problem locating 0x3006,0x0039 - Is this a valid RT
// Struct file?";
QMessageBox msgBox;
msgBox.setText("This is not a RT structure file!");
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
} else {
gdcm::Tag troiobsq(0x3006, 0x0080); // ROI observation sequence
const gdcm::DataElement &roicsq = ds.GetDataElement(troicsq);
gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = roicsq.GetValueAsSQ();
const gdcm::DataElement &ssroisq = ds.GetDataElement(tssroisq);
gdcm::SmartPointer<gdcm::SequenceOfItems> ssqi = ssroisq.GetValueAsSQ();
this->NumberOfROIs = sqi->GetNumberOfItems();
// qDebug()<< "Number of structures found:" << this->NumberOfROIs;
const gdcm::DataElement &roiobsq = ds.GetDataElement(troiobsq);
gdcm::SmartPointer<gdcm::SequenceOfItems> obsq =
roiobsq.GetValueAsSQ(); // observation sequence
qDebug() << "No. of ROIs found:" << this->NumberOfROIs;
if (this->NumberOfROIs > 50) {
this->NumberOfROIs = 50; // Only read the first 50 ROIs
QMessageBox messageBox;
messageBox.warning(
this, "Warning",
"More than 50 ROIs found, only reading the first 50.");
messageBox.setFixedSize(500, 200);
}
for (int i = 1; i < this->NumberOfROIs + 1; i++) {
// Get the ROI Nos.
gdcm::Item &item = sqi->GetItem(i);
const gdcm::DataSet &nestedds = item.GetNestedDataSet();
// Get ROIs color
gdcm::Attribute<0x3006, 0x002a> roiColor; // ROI color tag
roiColor.SetFromDataElement(
nestedds.GetDataElement(roiColor.GetTag()));
double R = roiColor.GetValues()[0];
double G = roiColor.GetValues()[1];
double B = roiColor.GetValues()[2];
// qDebug()<<"ROi color:"<<R<<G<<B;
this->ROIColors[i - 1][0] = R;
this->ROIColors[i - 1][1] = G;
this->ROIColors[i - 1][2] = B; // C++ array starts from "0".
// Get ROI Names
gdcm::Item &sitem = ssqi->GetItem(i);
gdcm::Attribute<0x3006, 0x0026>
roiName; // ROI Name tag in Structure Set ROI Sequence
const gdcm::DataSet &snestedds = sitem.GetNestedDataSet();
roiName.SetFromDataElement(
snestedds.GetDataElement(roiName.GetTag()));
// qDebug()<<roiName.GetValue();
this->ROINames.append(QString(roiName.GetValue()));
QListWidgetItem *wItem =
new QListWidgetItem(QString(roiName.GetValue()));
wItem->setCheckState(Qt::Unchecked);
wItem->setBackgroundColor(QColor(R, G, B));
this->ui->listWidgetStructs->addItem(wItem);
}
}
}
}
}
void RTStructReaderDialog::getSelectedItems() {
this->selectedItems.clear();
if (this->ui->groupBox->isChecked()) {
for (int i = 0; i < this->NumberOfROIs; i++) {
int checkState = this->ui->listWidgetStructs->item(i)->checkState();
// qDebug()<<checkState<<"checkState";
if (checkState == 2) {
this->selectedItems.append(i +
1); // In GDCM dicom items start from "1";
}
}
} else {
for (int i = 0; i < this->NumberOfROIs; i++) {
this->selectedItems.append(i + 1);
}
}
}
void RTStructReaderDialog::on_pushButtonRead_clicked() {
this->getSelectedItems();
this->close();
}