#include "gdcmGlobal.h"
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cerr << "Usage: " << argv[0] << " DicomFile [user defined dict]"
<< std::endl;
return EXIT_FAILURE;
}
using PixelType = signed short;
if (argc == 3)
{
gdcm::Global::GetInstance().Prepend(
itksys::SystemTools::GetFilenamePath(argv[2]).c_str());
gdcm::Global::GetInstance().LoadResourcesFiles();
}
ReaderType::Pointer reader = ReaderType::New();
ImageIOType::Pointer dicomIO = ImageIOType::New();
reader->SetFileName(argv[1]);
reader->SetImageIO(dicomIO);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
const DictionaryType & dictionary = dicomIO->GetMetaDataDictionary();
auto itr = dictionary.Begin();
auto end = dictionary.End();
while (itr != end)
{
MetaDataStringType::Pointer entryvalue =
dynamic_cast<MetaDataStringType *>(entry.
GetPointer());
if (entryvalue)
{
std::string tagkey = itr->first;
std::string labelId;
std::string tagvalue = entryvalue->GetMetaDataObjectValue();
if (found)
{
std::cout << "(" << tagkey << ") " << labelId;
std::cout << " = " << tagvalue.c_str() << std::endl;
}
else
{
std::cout << "(" << tagkey << ") "
<< "Unknown";
std::cout << " = " << tagvalue.c_str() << std::endl;
}
}
++itr;
}
std::string entryId = "0010|0010";
auto tagItr = dictionary.Find(entryId);
if (tagItr != end)
{
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.c_str() << std::endl;
}
}
std::string tagkey = "0008|1050";
std::string labelId;
{
std::string value;
std::cout << labelId << " (" << tagkey << "): ";
if (dicomIO->GetValueFromTag(tagkey, value))
{
std::cout << value;
}
else
{
std::cout << "(No Value Found in File)";
}
std::cout << std::endl;
}
else
{
std::cerr << "Trying to access inexistant DICOM tag." << std::endl;
}
reader->GetImageIO()->GetComponentType();
std::cout << "PixelType: "
<< reader->GetImageIO()->GetPixelTypeAsString(pixelType)
<< std::endl;
std::cout << "Component Type: "
<< reader->GetImageIO()->GetComponentTypeAsString(componentType)
<< std::endl;
return EXIT_SUCCESS;
}