-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtivisualization.cpp
148 lines (134 loc) · 4.91 KB
/
dtivisualization.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 "dtivisualization.h"
#include "trackingconfigdlg.h"
#include <QMessageBox>
DTIVisualization::DTIVisualization(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
_volumeVis = new VolumeVis();
QHBoxLayout * layout = new QHBoxLayout();
layout->setMargin(0);
layout->addWidget(_volumeVis);
ui.volumeTab->setLayout(layout);
_seedVis = new SeedVis();
_fiberVis = new FiberVis();
connectSignalSlots();
}
DTIVisualization::~DTIVisualization()
{
}
void DTIVisualization::connectSignalSlots()
{
connect(ui.actionOpen_folder, SIGNAL(triggered()), this, SLOT(handleOpenFolder()));
connect(ui.fileTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(handleTreeItemClicked(QTreeWidgetItem *)));
connect(ui.actionLoad_selected_series, SIGNAL(triggered()), this, SLOT(handleLoadSeries()));
connect(ui.actionLoad_series_as_DTI, SIGNAL(triggered()), this, SLOT(handleLoadDTI()));
connect(ui.actionSave_tensor_field, SIGNAL(triggered()), this, SLOT(handleSaveDTI()));
connect(ui.actionFolder_explorer, SIGNAL(toggled(bool)), ui.dockWidget, SLOT(setVisible(bool)));
connect(ui.actionTest, SIGNAL(triggered()), this, SLOT(handleTest()));
connect(ui.actionFuse_with_current_series, SIGNAL(triggered()), this, SLOT(handleFuseSeries()));
connect(_seedVis, SIGNAL(fiberTrackingStarted()), this, SLOT(handleFiberTracking()));
}
void DTIVisualization::handleOpenFolder()
{
/*QFileDialog fileDlg;
fileDlg.setFileMode(QFileDialog::DirectoryOnly);
if (fileDlg.exec())
{*/
//QString folderName = fileDlg.selectedFiles()[0];
//QString folderName = "D:\\+Study\\LEUNG KIN PING\\19-Jan-2009\\";
QString folderName = "D:\\Stella\\Research\\Sample data\\From Henry Mak\\DICOM\\LEUNG KIN PING\\19-Jan-2009\\";
QDir folder (folderName);
if (!folder.exists(DATASET_FILE_NAME))
{
parseFolder(folderName);
}
readDatasetFile(folder.filePath(DATASET_FILE_NAME), ui.fileTreeWidget);
_currentFolder = folderName;/**/
//}
}
void DTIVisualization::handleTreeItemClicked(QTreeWidgetItem *item)
{
QString itemData = item->data(0, Qt::UserRole).toString();
if (!itemData.isEmpty())
{
_selectedSeries = getOrderedDcmFiles(QDir(_currentFolder).filePath(DATASET_FILE_NAME), itemData+"/File");
if (!_selectedSeries.isEmpty())
{
ui.actionLoad_selected_series->setEnabled(true);
ui.actionLoad_series_as_DTI->setEnabled(true);
ui.actionSave_tensor_field->setEnabled(true);
} else
{
ui.actionLoad_selected_series->setEnabled(false);
ui.actionLoad_series_as_DTI->setEnabled(false);
ui.actionSave_tensor_field->setEnabled(false);
}
}
}
void DTIVisualization::handleLoadSeries()
{
_volumeVis->loadVolumeData(_selectedSeries);
ui.tabWidget->removeTab(1);
ui.actionFuse_with_current_series->setEnabled(true);
}
void DTIVisualization::handleLoadDTI()
{
QTreeWidgetItem * loadedItem = ui.fileTreeWidget->currentItem();
QString queryStr = loadedItem->data(0, Qt::UserRole).toString();
QString dtiFileName = getDTIFileName(_currentFolder, queryStr);
_volumeVis->loadDTIData(_selectedSeries, dtiFileName);
if (_volumeVis->isTensorDataLoaded())
{
ui.tabWidget->addTab(_seedVis, "Seed Viewer");
_seedVis->setTensorData(_volumeVis->getTensorData());
_seedVis->setCurrentFolder(_currentFolder);
}
ui.actionFuse_with_current_series->setEnabled(true);
}
void DTIVisualization::handleSaveDTI()
{
QString fileName = QFileDialog::getSaveFileName(NULL, "Save tensor field", _currentFolder, "Tensor file (*.tsf)");
if (!fileName.isEmpty())
{
QTreeWidgetItem * loadedItem = ui.fileTreeWidget->currentItem();
QString queryStr = loadedItem->data(0, Qt::UserRole).toString();
if(_volumeVis->saveTensorField(fileName))
{
insertDTIFileItem(_currentFolder, queryStr, fileName);
if (loadedItem->text(0).right(1).compare("*")!=0)
{
loadedItem->setText(0, loadedItem->text(0)+"*");
}
}
}
}
void DTIVisualization::handleTest ()
{
/*QString queryStr = "root/Patient[@patients_name = 'LEUNG KIN PING']/Date[@acquisition_date = '733792']/Protocol[@protocol_name = 'T2W_FLAIR SENSE ']/Collection[@acquisition_number = '1001']";
insertDTIFileItem(_currentFolder+"dicom_dataset.xml", queryStr, "D:/Stella/Research/Sample data/From Henry Mak/DICOM/LEUNG KIN PING/19-Jan-2009/test1.tsf");*/
TensorData::test();
}
void DTIVisualization::handleFuseSeries()
{
_volumeVis->fuseVolumeData(_selectedSeries);
ui.actionFuse_with_current_series->setEnabled(false);
}
void DTIVisualization::handleFiberTracking()
{
SeedData * seedData = _seedVis->_seedData;
if (seedData->refreshSeedBuf())
{
TrackingConfig * pConfig = TrackingConfigDlg::getConfig(this, "Fiber Tracking Configuration");
if (!pConfig)
{
return;
}
_fiberVis->startFiberTracking(seedData, _seedVis->_tensorData, *pConfig);
ui.tabWidget->addTab(_fiberVis, "Tractography Viewer");
ui.tabWidget->setCurrentWidget(_fiberVis);
} else
{
QMessageBox::warning(NULL, "Empty seed buffer", "No seed region is specified yet!");
}
}