ReadAndDumpDICOMDIR.cxx
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
* This example shows how to read and dump a DICOMDIR File
*
* Thanks:
* Tom Marynowski (lordglub gmail) for contributing this example
*/
#include "gdcmReader.h"
#include "gdcmMediaStorage.h"
typedef std::set<gdcm::DataElement> DataElementSet;
typedef DataElementSet::const_iterator ConstIterator;
int main(int argc, char *argv [])
{
if( argc < 2 ) return 1;
const char *filename = argv[1];
gdcm::Reader reader;
reader.SetFileName( filename);
if( !reader.Read() )
{
std::cerr << "Could not read: " << filename << std::endl;
return 1;
}
std::stringstream strm;
gdcm::File &file = reader.GetFile();
gdcm::DataSet &ds = file.GetDataSet();
gdcm::FileMetaInformation &fmi = file.GetHeader();
gdcm::MediaStorage ms;
ms.SetFromFile(file);
if( ms != gdcm::MediaStorage::MediaStorageDirectoryStorage )
{
std::cout << "This file is not a DICOMDIR" << std::endl;
return 1;
}
if (fmi.FindDataElement( gdcm::Tag (0x0002, 0x0002)))
{ strm.str("");
fmi.GetDataElement( gdcm::Tag (0x0002, 0x0002) ).GetValue().Print(strm);
}
else
{
std::cerr << " Media Storage Sop Class UID not present" << std::endl;
}
//TODO il faut trimer strm.str() avant la comparaison au cas ou...
if ("1.2.840.10008.1.3.10"!=strm.str())
{
std::cout << "This file is not a DICOMDIR" << std::endl;
return 1;
}
ConstIterator it = ds.GetDES().begin();
for( ; it != ds.GetDES().end(); ++it)
{
if (it->GetTag()==gdcm::Tag (0x0004, 0x1220))
{
const gdcm::DataElement &de = (*it);
// ne pas utiliser GetSequenceOfItems pour extraire les items
gdcm::SmartPointer<gdcm::SequenceOfItems> sqi =de.GetValueAsSQ();
unsigned int itemused = 1;
while (itemused<=sqi->GetNumberOfItems())
{
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);
//TODO il faut trimer strm.str() avant la comparaison
while((strm.str()=="PATIENT")||((strm.str()=="PATIENT ")))
{
std::cout << strm.str() << std::endl;
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0010, 0x0010)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0010, 0x0010)).GetValue().Print(strm);
std::cout << "PATIENT NAME : " << strm.str() << std::endl;
//PATIENT ID
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0010, 0x0020)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0010, 0x0020)).GetValue().Print(strm);
std::cout << "PATIENT ID : " << strm.str() << std::endl;
/*ADD TAG TO READ HERE*/
std::cout << "=========================== " << std::endl;
itemused++;
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);
//TODO il faut trimer strm.str() avant la comparaison
while((strm.str()=="STUDY")||((strm.str()=="STUDY ")))
{
std::cout << " " << strm.str() << std::endl;
//UID
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0020, 0x000d)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0020, 0x000d)).GetValue().Print(strm);
std::cout << " STUDY UID : " << strm.str() << std::endl;
//STUDY DATE
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x0020)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x0020)).GetValue().Print(strm);
std::cout << " STUDY DATE : " << strm.str() << std::endl;
//STUDY DESCRIPTION
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x1030)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x1030)).GetValue().Print(strm);
std::cout << " STUDY DESCRIPTION : " << strm.str() << std::endl;
/*ADD TAG TO READ HERE*/
std::cout << " " << "=========================== " << std::endl;
itemused++;
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);
//TODO il faut trimer strm.str() avant la comparaison
while((strm.str()=="SERIES")||((strm.str()=="SERIES ")))
{
std::cout << " " << strm.str() << std::endl;
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0020, 0x000e)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0020, 0x000e)).GetValue().Print(strm);
std::cout << " SERIE UID" << strm.str() << std::endl;
//SERIE MODALITY
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x0060)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x0060)).GetValue().Print(strm);
std::cout << " SERIE MODALITY" << strm.str() << std::endl;
//SERIE DESCRIPTION
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0008, 0x103e)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0008, 0x103e)).GetValue().Print(strm);
std::cout << " SERIE DESCRIPTION" << strm.str() << std::endl;
/*ADD TAG TO READ HERE*/
std::cout << " " << "=========================== " << std::endl;
itemused++;
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);
//TODO il faut trimer strm.str() avant la comparaison
while ((strm.str()=="IMAGE")||((strm.str()=="IMAGE ")))
// if(tmp=="IMAGE")
{
std::cout << " " << strm.str() << std::endl;
//UID
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1511)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1511)).GetValue().Print(strm);
std::cout << " IMAGE UID : " << strm.str() << std::endl;
//PATH de l'image
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1500)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1500)).GetValue().Print(strm);
std::cout << " IMAGE PATH : " << strm.str() << std::endl;
/*ADD TAG TO READ HERE*/
if(itemused < sqi->GetNumberOfItems())
{itemused++;
}else{break;}
strm.str("");
if (sqi->GetItem(itemused).FindDataElement(gdcm::Tag (0x0004, 0x1430)))
sqi->GetItem(itemused).GetDataElement(gdcm::Tag (0x0004, 0x1430)).GetValue().Print(strm);
}
}
}
}
itemused++;
}
}
}
return 0;
}
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::GetValue
Value const & GetValue() const
Set/Get Value (bytes array, SQ of items, SQ of fragments):
Definition gdcmDataElement.h:94
gdcm::DataElement::GetValueAsSQ
SmartPointer< SequenceOfItems > GetValueAsSQ() const
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements).
Definition gdcmDataSet.h:56
gdcm::DataSet::GetDataElement
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
gdcm::DataSet::FindDataElement
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
gdcm::DataSet::GetDES
const DataElementSet & GetDES() const
Definition gdcmDataSet.h:68
gdcm::FileMetaInformation
Class to represent a File Meta Information.
Definition gdcmFileMetaInformation.h:41
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::File::GetHeader
const FileMetaInformation & GetHeader() const
Get File Meta Information.
Definition gdcmFile.h:48
gdcm::MediaStorage
MediaStorage.
Definition gdcmMediaStorage.h:44
gdcm::MediaStorage::MediaStorageDirectoryStorage
@ MediaStorageDirectoryStorage
Definition gdcmMediaStorage.h:47
gdcm::MediaStorage::SetFromFile
bool SetFromFile(File const &file)
gdcm::Object::Print
virtual void Print(std::ostream &) const
Definition gdcmObject.h:87
gdcm::Reader
Reader ala DOM (Document Object Model).
Definition gdcmReader.h:54
gdcm::Reader::GetFile
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
gdcm::Reader::Read
virtual bool Read()
Main function to read a file.
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcmMediaStorage.h
gdcmReader.h