int main( int argc, char* argv[] )
{
if( argc < 2 )
{
std::cerr << "Usage: " << argv[0] << " DicomDirectory " << std::endl;
return EXIT_FAILURE;
}
typedef signed short PixelType;
ReaderType::Pointer reader = ReaderType::New();
ImageIOType::Pointer dicomIO = ImageIOType::New();
reader->SetImageIO( dicomIO );
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
nameGenerator->SetInputDirectory( argv[1] );
typedef std::vector<std::string> FileNamesContainer;
FileNamesContainer fileNames = nameGenerator->GetInputFileNames();
reader->SetFileNames( fileNames );
try
{
reader->Update();
}
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
const DictionaryType & dictionary = dicomIO->GetMetaDataDictionary();
DictionaryType::ConstIterator itr = dictionary.Begin();
DictionaryType::ConstIterator end = dictionary.End();
while( itr != end )
{
MetaDataStringType::Pointer entryvalue =
dynamic_cast<MetaDataStringType *
>( entry.
GetPointer() );
if( entryvalue )
{
std::string tagkey = itr->first;
std::string tagvalue = entryvalue->GetMetaDataObjectValue();
std::cout << tagkey << " = " << tagvalue << std::endl;
}
++itr;
}
std::string entryId = "0010|0010";
DictionaryType::ConstIterator tagItr = dictionary.Find( entryId );
if( tagItr == end )
{
std::cerr << "Tag " << entryId;
std::cerr << " not found in the DICOM header" << std::endl;
return EXIT_FAILURE;
}
MetaDataStringType::ConstPointer entryvalue =
dynamic_cast<const MetaDataStringType *>( tagItr->second.GetPointer() );
if( entryvalue )
{
std::string tagvalue = entryvalue->GetMetaDataObjectValue();
std::cout << "Patient's Name (" << entryId << ") ";
std::cout << " is: " << tagvalue << std::endl;
}
else
{
std::cerr << "Entry was not of string type" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}