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://www.centreleonberard.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 #if GDCM_MAJOR_VERSION == 2
24 #include <gdcmImageReader.h>
25 #include <gdcmDataSetHelper.h>
26 #include <gdcmStringFilter.h>
27 #include <gdcmImageHelper.h>
29 #include <gdcmDocEntry.h>
32 #include "vvQDicomSeriesSelector.h"
33 //#include "vvUserConfig.h"
35 //====================================================================
36 vvDicomSeriesSelector::vvDicomSeriesSelector(QWidget* parent)
41 // Correct GUI for splitter ...
42 // QSplitter * splitter = new QSplitter(this);
43 // splitter->setOrientation(Qt::Horizontal);
44 // ui.gridLayout1->addWidget(splitter, 0, 0, 1, 1);
45 // ui.mFrameLeft->setParent(splitter);
46 // ui.mFrameRight->setParent(splitter);
47 // ui.toolBox->setCurrentIndex(0);
51 ui.mButtonBox->button(QDialogButtonBox::Open)->setEnabled(false);
53 connect(ui.mBrowseButton, SIGNAL(released()),
54 this, SLOT(BrowseButtonRelease()));
55 connect(ui.mSearchButton, SIGNAL(released()),
56 this, SLOT(SearchButtonRelease()));
57 connect(ui.mListWidget, SIGNAL(itemSelectionChanged()),
58 this, SLOT(itemSelectionChanged()));
59 connect(ui.mDicomDetailsListWidget, SIGNAL(itemSelectionChanged()),
60 this, SLOT(itemDetailsSelectionChanged()));
63 /* if (config::get_current_path() != QString(0))
64 mFoldername = config::get_current_path();
66 mFoldername = QFileInfo("./").absolutePath();
68 mPreviousPath = mFoldername;
69 ui.mFolderLineEdit->setText(mFoldername);
70 // ui.mTableWidget->setRowCount(0);
72 //====================================================================
74 //====================================================================
75 void vvDicomSeriesSelector::show()
79 // ui.mListWidget->grabKeyboard();
80 // ui.mDicomDetailsListWidget->grabKeyboard();
82 //====================================================================
84 //====================================================================
85 void vvDicomSeriesSelector::close()
88 // ui.mListWidget->releaseKeyboard()
91 //====================================================================
93 //====================================================================
94 void vvDicomSeriesSelector::BrowseButtonRelease()
96 QFileDialog dialog(this);
97 dialog.setFileMode(QFileDialog::AnyFile);
98 dialog.setFilter("DICOM files (*.dcm); All files (*)");
99 mFoldername = dialog.getExistingDirectory(this,
100 "Select a folder to find DICOM image",
102 ui.mFolderLineEdit->setText(mFoldername);
103 mPreviousPath = QFileInfo(mFoldername).absolutePath();
104 // config::set_current_path(mPreviousPath);
106 //====================================================================
108 //====================================================================
109 void vvDicomSeriesSelector::SearchButtonRelease()
111 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
112 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
113 nameGenerator->SetUseSeriesDetails(true);
114 //nameGenerator->SetDirectory(mFoldername.toStdString());
115 nameGenerator->SetRecursive(ui.mIsRecursiveCheckBox->checkState() == Qt::Checked);
117 //ds gérer recursive moi-meme pour progress ...
118 nameGenerator->SetInputDirectory(mFoldername.toStdString());
121 typedef std::vector<std::string> SeriesIdContainer;
122 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
124 for (unsigned int i=0; i<seriesUID.size(); i++) {
125 // std::cout << seriesUID[i] << std::endl; //ds verif existe pas déja
127 if (mListOfSeriesFilenames[seriesUID[i]]) {
128 std::cout << seriesUID[i] << " exist" << std::endl;
131 std::vector<std::string> * filenames = new std::vector<std::string>;
132 const std::vector<std::string> & temp = nameGenerator->GetFileNames(seriesUID[i]);
133 for (unsigned int j=0; j<temp.size(); j++) {
134 filenames->push_back(temp[j]);
136 mListOfSeriesFilenames[seriesUID[i]] = filenames;
138 // store first header
139 #if GDCM_MAJOR_VERSION == 2
140 mDicomHeader[seriesUID[i]].SetFileName( (*filenames)[0].c_str() );
141 mDicomHeader[seriesUID[i]].Read();
143 gdcm::File *header = new gdcm::File();
144 header->SetFileName((*filenames)[0]);
145 header->SetMaxSizeLoadEntry(16384);
146 header->SetLoadMode(gdcm::LD_NOSHADOW);// don't load shadow tags (in order to save memory)
151 DD(header->GetEntryValue(0x0028,0x0030).c_str());
154 DD(header->GetXSize());
155 DD(header->GetYSize());
156 DD(header->GetZSize());
157 DD(header->GetXSpacing());
158 DD(header->GetYSpacing());
159 DD(header->GetZSpacing());
160 DD(header->GetXOrigin());
161 DD(header->GetYOrigin());
162 DD(header->GetZOrigin());
165 QString size = QString("%1x%2x%3")
166 .arg(header->GetXSize())
167 .arg(header->GetYSize())
168 .arg(header->GetZSize());
169 QString spacing = QString("%1x%2x%3")
170 .arg(header->GetXSpacing())
171 .arg(header->GetYSpacing())
172 .arg(header->GetZSpacing());
173 QString origin = QString("%1x%2x%3")
174 .arg(header->GetXOrigin())
175 .arg(header->GetYOrigin())
176 .arg(header->GetZOrigin());
180 mDicomHeader[seriesUID[i]] = header;
184 QListWidgetItem *newItem = new QListWidgetItem;
185 newItem->setText(seriesUID[i].c_str());
186 ui.mListWidget->insertItem(i, newItem);
188 //AddSerieToTheTable(i, *filenames);
192 //====================================================================
194 //====================================================================
195 void vvDicomSeriesSelector::itemSelectionChanged()
197 // mLabelSelected.setText(
198 mCurrentSerie = ui.mListWidget->selectedItems()[0]->text().toStdString();
199 mFilenames = mListOfSeriesFilenames[mCurrentSerie];
200 ui.mButtonBox->button(QDialogButtonBox::Open)->setEnabled(true);
202 if (mDicomInfo[mCurrentSerie] == "") {
204 // m = QString("Patient : <font color=\"blue\">%1</font><br>").arg(mDicomHeader[s]->GetEntryValue(0x0010,0x0010).c_str()); // Patient's name
206 mDicomInfo[mCurrentSerie] = MakeDicomInfo(mCurrentSerie, mDicomHeader[mCurrentSerie]);
208 ui.mDicomInfoPanel->setText(mDicomInfo[mCurrentSerie]);
211 ui.mDicomDetailsListWidget->clear();
212 for (unsigned int i=0; i<mFilenames->size(); i++) {
213 QListWidgetItem * newItem = new QListWidgetItem;
214 newItem->setText(QFileInfo((*mFilenames)[i].c_str()).fileName());
215 ui.mDicomDetailsListWidget->insertItem(i, newItem);
219 //====================================================================
221 //====================================================================
222 void vvDicomSeriesSelector::itemDetailsSelectionChanged()
224 unsigned int i = ui.mDicomDetailsListWidget->currentRow();
225 if (i<mFilenames->size()) {
226 if (mDicomDetails[(*mFilenames)[i]] == "") {
227 std::ostringstream s;
230 #if GDCM_MAJOR_VERSION == 2
231 mDicomHeader[mCurrentSerie].GetFile().Print(s);
232 const gdcm::File& header = mDicomHeader[mCurrentSerie].GetFile();
233 gdcm::StringFilter sf;
234 sf.SetFile( header );
235 const gdcm::DataSet &ds = header.GetDataSet();
236 gdcm::DataSet::ConstIterator it = ds.Begin();
237 for (; it != ds.End(); ++it )
239 const gdcm::DataElement & ref = *it;
240 const gdcm::Tag & tag = ref.GetTag();
241 gdcm::VR vr = gdcm::DataSetHelper::ComputeVR(header, ds, tag);
242 if ( vr & ( gdcm::VR::OB | gdcm::VR::OF | gdcm::VR::OW | gdcm::VR::SQ | gdcm::VR::UN ) )
244 // What is the behavior for binary stuff ?
246 else /* if ( vr & gdcm::VR::VRASCII ) */
248 if ( tag.IsPublic() )
250 std::pair<std::string, std::string> p = sf.ToStringPair(tag);
251 l += QString("%1 : %2\n")
252 .arg( p.first.c_str() )
253 .arg( p.second.c_str() );
258 mDicomHeader[mCurrentSerie]->Print(s);
259 gdcm::File * header = mDicomHeader[mCurrentSerie];
260 gdcm::DocEntry * e = header->GetFirstEntry();
262 if (e->GetName() != "gdcm::Unknown") {
263 l += QString("%1 : %2\n")
264 .arg(e->GetName().c_str())
265 .arg((header->GetEntryValue(e->GetGroup(), e->GetElement())).c_str());
267 e = header->GetNextEntry();
271 mDicomDetails[(*mFilenames)[i]] = l.toStdString();
273 ui.mDicomDetailsLabel->setText(mDicomDetails[(*mFilenames)[i]].c_str());
276 //====================================================================
278 //====================================================================
279 #if GDCM_MAJOR_VERSION == 2
280 QString vvDicomSeriesSelector::MakeDicomInfo(std::string & s, const gdcm::Reader& header)
282 QString n = QString("%1").arg(mListOfSeriesFilenames[s]->size());
283 const gdcm::File &f = header.GetFile();
284 std::vector<double> thespacing = gdcm::ImageHelper::GetSpacingValue(f);
285 std::vector<double> theorigin = gdcm::ImageHelper::GetOriginValue(f);
287 QString size = QString("%1x%2x%3")
291 QString spacing = QString("%1x%2x%3")
295 QString origin = QString("%1x%2x%3")
301 //AddInfo( "Serie ID : ", s)+
302 AddInfo(&header.GetFile(), "Patient : ", 0x0010,0x0010)+
303 AddInfo( "Folder : ", QFileInfo((*mFilenames)[0].c_str()).canonicalPath().toStdString())+
304 AddInfo(&header.GetFile(), "Series Description : ", 0x0008,0x103e)+
305 AddInfo(&header.GetFile(), "Modality : ", 0x0008,0x0060)+
306 AddInfo(&header.GetFile(), "# images : ", 0x0020,0x0013)+
307 AddInfo( "# files : ", n.toStdString())+
308 AddInfo( "Size : ", size.toStdString())+
309 AddInfo( "Spacing : ", spacing.toStdString())+
310 AddInfo( "Origin : ", origin.toStdString())+
311 AddInfo(&header.GetFile(), "Pixel size : ", 0x0028,0x0100)+
312 AddInfo( "Pixel type : ", "");
316 QString vvDicomSeriesSelector::MakeDicomInfo(std::string & s, gdcm::File *header)
318 QString n = QString("%1").arg(mListOfSeriesFilenames[s]->size());
319 QString size = QString("%1x%2x%3")
320 .arg(header->GetXSize())
321 .arg(header->GetYSize())
322 .arg(header->GetZSize());
323 QString spacing = QString("%1x%2x%3")
324 .arg(header->GetXSpacing())
325 .arg(header->GetYSpacing())
326 .arg(header->GetZSpacing());
327 QString origin = QString("%1x%2x%3")
328 .arg(header->GetXOrigin())
329 .arg(header->GetYOrigin())
330 .arg(header->GetZOrigin());
332 //AddInfo( "Serie ID : ", s)+
333 AddInfo(header, "Patient : ", 0x0010,0x0010)+
334 AddInfo( "Folder : ", QFileInfo((*mFilenames)[0].c_str()).canonicalPath().toStdString())+
335 AddInfo(header, "Series Description : ", 0x0008,0x103e)+
336 AddInfo(header, "Modality : ", 0x0008,0x0060)+
337 AddInfo(header, "# images : ", 0x0020,0x0013)+
338 AddInfo( "# files : ", n.toStdString())+
339 AddInfo( "Size : ", size.toStdString())+
340 AddInfo( "Spacing : ", spacing.toStdString())+
341 AddInfo( "Origin : ", origin.toStdString())+
342 AddInfo(header, "Pixel size : ", 0x0028,0x0100)+
343 AddInfo( "Pixel type : ", header->GetPixelType());
347 //====================================================================
349 //====================================================================
350 QString vvDicomSeriesSelector::AddInfo(const gdcm::File *header, QString n, uint16_t group, uint16_t elem)
352 #if GDCM_MAJOR_VERSION == 2
353 gdcm::StringFilter sf;
354 sf.SetFile( *header );
355 gdcm::Tag t( group, elem );
356 std::string s = sf.ToString( t );
357 return AddInfo(n.toStdString(), s);
359 return AddInfo(n.toStdString(), const_cast<gdcm::File*>(header)->GetEntryValue(group, elem));
362 //====================================================================
364 //====================================================================
365 QString vvDicomSeriesSelector::AddInfo(std::string n, std::string m)
367 QString s = QString("%1 <font color=\"blue\">%2</font><br>").
368 arg(n.c_str()).arg(m.c_str());
371 //====================================================================
373 //====================================================================
374 void vvDicomSeriesSelector::AddSerieToTheTable(int i, std::vector<std::string> & filenames)
376 #if GDCM_MAJOR_VERSION == 2
378 gdcm::File *header = new gdcm::File();
379 header->SetFileName(filenames[0]);
380 header->SetMaxSizeLoadEntry(16384);
381 header->SetLoadMode(gdcm::LD_NOSHADOW);// don't load shadow tags (in order to save memory)
383 //header->Print(cout);
385 // mDicomHeader[] = header;
389 QTableWidgetItem *newItem = new
390 QTableWidgetItem(QString("# images = %1").arg(header->GetImageNumber()));
391 // newItem->setCheckState(Qt::Checked);
392 //newItem->setFlags(!Qt::ItemIsEditable);
393 DD(ui.mTableWidget->rowCount());
394 ui.mTableWidget->setItem(i, 0, newItem);
398 //====================================================================
400 #endif // VVDICOMSERIESSELECTOR_CXX