#include "itkDICOMImageIO2.h"
#include "itkDICOMSeriesFileNames.h"
int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0]
<< " DicomDirectory outputFileName [seriesName]" << std::endl;
return EXIT_FAILURE;
}
itk::DICOMImageIO2::Pointer dicomIO = itk::DICOMImageIO2::New();
itk::DICOMSeriesFileNames::Pointer nameGenerator =
itk::DICOMSeriesFileNames::New();
nameGenerator->SetDirectory(argv[1]);
try
{
using seriesIdContainer = std::vector<std::string>;
const seriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
seriesIdContainer::const_iterator seriesItr = seriesUID.begin();
seriesIdContainer::const_iterator seriesEnd = seriesUID.end();
std::cout << std::endl << "The directory: " << std::endl;
std::cout << std::endl << argv[1] << std::endl << std::endl;
std::cout << "Contains the following DICOM Series: ";
std::cout << std::endl << std::endl;
while (seriesItr != seriesEnd)
{
std::cout << seriesItr->c_str() << std::endl;
++seriesItr;
}
std::cout << std::endl << std::endl;
std::cout << "Now reading series: " << std::endl << std::endl;
using fileNamesContainer = std::vector<std::string>;
fileNamesContainer fileNames;
if (argc < 4)
{
std::cout << seriesUID.begin()->c_str() << std::endl;
fileNames = nameGenerator->GetFileNames();
}
else
{
std::cout << argv[3] << std::endl;
fileNames = nameGenerator->GetFileNames(argv[3]);
}
std::cout << std::endl << std::endl;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileNames(fileNames);
reader->SetImageIO(dicomIO);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
WriterType::Pointer writer = WriterType::New();
std::cout << "Writing the image as " << std::endl << std::endl;
std::cout << argv[2] << std::endl << std::endl;
writer->SetFileName(argv[2]);
writer->SetInput(reader->GetOutput());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & ex)
{
std::cout << ex;
return EXIT_FAILURE;
}
}
catch (const itk::ExceptionObject & ex)
{
std::cout << ex;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}