1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef VVDICOMSERIESSELECTOR_CXX
19 #define VVDICOMSERIESSELECTOR_CXX
20 #include <itkGDCMImageIO.h>
21 #include <itkGDCMSeriesFileNames.h>
23 #include <gdcmDocEntry.h>
25 #include "vvQDicomSeriesSelector.h"
26 //#include "vvUserConfig.h"
28 //====================================================================
29 vvDicomSeriesSelector::vvDicomSeriesSelector(QWidget* parent)
34 // Correct GUI for splitter ...
35 // QSplitter * splitter = new QSplitter(this);
36 // splitter->setOrientation(Qt::Horizontal);
37 // ui.gridLayout1->addWidget(splitter, 0, 0, 1, 1);
38 // ui.mFrameLeft->setParent(splitter);
39 // ui.mFrameRight->setParent(splitter);
40 // ui.toolBox->setCurrentIndex(0);
44 ui.mButtonBox->button(QDialogButtonBox::Open)->setEnabled(false);
46 connect(ui.mBrowseButton, SIGNAL(released()),
47 this, SLOT(BrowseButtonRelease()));
48 connect(ui.mSearchButton, SIGNAL(released()),
49 this, SLOT(SearchButtonRelease()));
50 connect(ui.mListWidget, SIGNAL(itemSelectionChanged()),
51 this, SLOT(itemSelectionChanged()));
52 connect(ui.mDicomDetailsListWidget, SIGNAL(itemSelectionChanged()),
53 this, SLOT(itemDetailsSelectionChanged()));
56 /* if (config::get_current_path() != QString(0))
57 mFoldername = config::get_current_path();
59 mFoldername = QFileInfo("./").absolutePath();
61 mPreviousPath = mFoldername;
62 ui.mFolderLineEdit->setText(mFoldername);
63 // ui.mTableWidget->setRowCount(0);
65 //====================================================================
67 //====================================================================
68 void vvDicomSeriesSelector::show()
72 // ui.mListWidget->grabKeyboard();
73 // ui.mDicomDetailsListWidget->grabKeyboard();
75 //====================================================================
77 //====================================================================
78 void vvDicomSeriesSelector::close()
81 // ui.mListWidget->releaseKeyboard()
84 //====================================================================
86 //====================================================================
87 void vvDicomSeriesSelector::BrowseButtonRelease()
89 QFileDialog dialog(this);
90 dialog.setFileMode(QFileDialog::AnyFile);
91 dialog.setFilter("DICOM files (*.dcm); All files (*)");
92 mFoldername = dialog.getExistingDirectory(this,
93 "Select a folder to find DICOM image",
95 ui.mFolderLineEdit->setText(mFoldername);
96 mPreviousPath = QFileInfo(mFoldername).absolutePath();
97 // config::set_current_path(mPreviousPath);
99 //====================================================================
101 //====================================================================
102 void vvDicomSeriesSelector::SearchButtonRelease()
104 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
105 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
106 nameGenerator->SetUseSeriesDetails(true);
107 //nameGenerator->SetDirectory(mFoldername.toStdString());
108 nameGenerator->SetRecursive(ui.mIsRecursiveCheckBox->checkState() == Qt::Checked);
110 //ds gérer recursive moi-meme pour progress ...
111 nameGenerator->SetInputDirectory(mFoldername.toStdString());
114 typedef std::vector<std::string> SeriesIdContainer;
115 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
117 for (unsigned int i=0; i<seriesUID.size(); i++) {
118 // std::cout << seriesUID[i] << std::endl; //ds verif existe pas déja
120 if (mListOfSeriesFilenames[seriesUID[i]]) {
121 std::cout << seriesUID[i] << " exist" << std::endl;
124 std::vector<std::string> * filenames = new std::vector<std::string>;
125 const std::vector<std::string> & temp = nameGenerator->GetFileNames(seriesUID[i]);
126 for (unsigned int j=0; j<temp.size(); j++) {
127 filenames->push_back(temp[j]);
129 mListOfSeriesFilenames[seriesUID[i]] = filenames;
131 // store first header
132 gdcm::File *header = new gdcm::File();
133 header->SetFileName((*filenames)[0]);
134 header->SetMaxSizeLoadEntry(16384);
135 header->SetLoadMode(gdcm::LD_NOSHADOW);// don't load shadow tags (in order to save memory)
140 DD(header->GetEntryValue(0x0028,0x0030).c_str());
143 DD(header->GetXSize());
144 DD(header->GetYSize());
145 DD(header->GetZSize());
146 DD(header->GetXSpacing());
147 DD(header->GetYSpacing());
148 DD(header->GetZSpacing());
149 DD(header->GetXOrigin());
150 DD(header->GetYOrigin());
151 DD(header->GetZOrigin());
154 QString size = QString("%1x%2x%3")
155 .arg(header->GetXSize())
156 .arg(header->GetYSize())
157 .arg(header->GetZSize());
158 QString spacing = QString("%1x%2x%3")
159 .arg(header->GetXSpacing())
160 .arg(header->GetYSpacing())
161 .arg(header->GetZSpacing());
162 QString origin = QString("%1x%2x%3")
163 .arg(header->GetXOrigin())
164 .arg(header->GetYOrigin())
165 .arg(header->GetZOrigin());
169 mDicomHeader[seriesUID[i]] = header;
172 QListWidgetItem *newItem = new QListWidgetItem;
173 newItem->setText(seriesUID[i].c_str());
174 ui.mListWidget->insertItem(i, newItem);
176 //AddSerieToTheTable(i, *filenames);
180 //====================================================================
182 //====================================================================
183 void vvDicomSeriesSelector::itemSelectionChanged()
185 // mLabelSelected.setText(
186 mCurrentSerie = ui.mListWidget->selectedItems()[0]->text().toStdString();
187 mFilenames = mListOfSeriesFilenames[mCurrentSerie];
188 ui.mButtonBox->button(QDialogButtonBox::Open)->setEnabled(true);
190 if (mDicomInfo[mCurrentSerie] == "") {
192 // m = QString("Patient : <font color=\"blue\">%1</font><br>").arg(mDicomHeader[s]->GetEntryValue(0x0010,0x0010).c_str()); // Patient's name
193 mDicomInfo[mCurrentSerie] = MakeDicomInfo(mCurrentSerie, mDicomHeader[mCurrentSerie]);
195 ui.mDicomInfoPanel->setText(mDicomInfo[mCurrentSerie]);
198 ui.mDicomDetailsListWidget->clear();
199 for (unsigned int i=0; i<mFilenames->size(); i++) {
200 QListWidgetItem * newItem = new QListWidgetItem;
201 newItem->setText(QFileInfo((*mFilenames)[i].c_str()).fileName());
202 ui.mDicomDetailsListWidget->insertItem(i, newItem);
206 //====================================================================
208 //====================================================================
209 void vvDicomSeriesSelector::itemDetailsSelectionChanged()
211 unsigned int i = ui.mDicomDetailsListWidget->currentRow();
212 if (i<mFilenames->size()) {
213 if (mDicomDetails[(*mFilenames)[i]] == "") {
214 std::ostringstream s;
215 mDicomHeader[mCurrentSerie]->Print(s);
218 gdcm::File * header = mDicomHeader[mCurrentSerie];
219 gdcm::DocEntry * e = header->GetFirstEntry();
221 if (e->GetName() != "gdcm::Unknown") {
222 l += QString("%1 : %2\n")
223 .arg(e->GetName().c_str())
224 .arg((header->GetEntryValue(e->GetGroup(), e->GetElement())).c_str());
226 e = header->GetNextEntry();
229 mDicomDetails[(*mFilenames)[i]] = l.toStdString();
231 ui.mDicomDetailsLabel->setText(mDicomDetails[(*mFilenames)[i]].c_str());
234 //====================================================================
236 //====================================================================
237 QString vvDicomSeriesSelector::MakeDicomInfo(std::string & s, gdcm::File *header)
239 QString n = QString("%1").arg(mListOfSeriesFilenames[s]->size());
240 QString size = QString("%1x%2x%3")
241 .arg(header->GetXSize())
242 .arg(header->GetYSize())
243 .arg(header->GetZSize());
244 QString spacing = QString("%1x%2x%3")
245 .arg(header->GetXSpacing())
246 .arg(header->GetYSpacing())
247 .arg(header->GetZSpacing());
248 QString origin = QString("%1x%2x%3")
249 .arg(header->GetXOrigin())
250 .arg(header->GetYOrigin())
251 .arg(header->GetZOrigin());
253 //AddInfo( "Serie ID : ", s)+
254 AddInfo(header, "Patient : ", 0x0010,0x0010)+
255 AddInfo( "Folder : ", QFileInfo((*mFilenames)[0].c_str()).canonicalPath().toStdString())+
256 AddInfo(header, "Series Description : ", 0x0008,0x103e)+
257 AddInfo(header, "Modality : ", 0x0008,0x0060)+
258 AddInfo(header, "# images : ", 0x0020,0x0013)+
259 AddInfo( "# files : ", n.toStdString())+
260 AddInfo( "Size : ", size.toStdString())+
261 AddInfo( "Spacing : ", spacing.toStdString())+
262 AddInfo( "Origin : ", origin.toStdString())+
263 AddInfo(header, "Pixel size : ", 0x0028,0x0100)+
264 AddInfo( "Pixel type : ", header->GetPixelType());
267 //====================================================================
269 //====================================================================
270 QString vvDicomSeriesSelector::AddInfo(gdcm::File *header, QString n, uint16_t group, uint16_t elem)
272 return AddInfo(n.toStdString(), header->GetEntryValue(group, elem));
274 //====================================================================
276 //====================================================================
277 QString vvDicomSeriesSelector::AddInfo(std::string n, std::string m)
279 QString s = QString("%1 <font color=\"blue\">%2</font><br>").
280 arg(n.c_str()).arg(m.c_str());
283 //====================================================================
285 //====================================================================
286 void vvDicomSeriesSelector::AddSerieToTheTable(int i, std::vector<std::string> & filenames)
288 gdcm::File *header = new gdcm::File();
289 header->SetFileName(filenames[0]);
290 header->SetMaxSizeLoadEntry(16384);
291 header->SetLoadMode(gdcm::LD_NOSHADOW);// don't load shadow tags (in order to save memory)
293 //header->Print(cout);
295 // mDicomHeader[] = header;
299 QTableWidgetItem *newItem = new
300 QTableWidgetItem(QString("# images = %1").arg(header->GetImageNumber()));
301 // newItem->setCheckState(Qt::Checked);
302 //newItem->setFlags(!Qt::ItemIsEditable);
303 DD(ui.mTableWidget->rowCount());
304 ui.mTableWidget->setItem(i, 0, newItem);
307 //====================================================================
309 #endif // VVDICOMSERIESSELECTOR_CXX