#include <vector>
#include "itksys/SystemTools.hxx"
int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0]
<< " DicomDirectory OutputDicomDirectory" << std::endl;
return EXIT_FAILURE;
}
using PixelType = signed short;
ImageIOType::Pointer gdcmIO = ImageIOType::New();
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
namesGenerator->SetInputDirectory(argv[1]);
const ReaderType::FileNamesContainer & filenames =
namesGenerator->GetInputFileNames();
std::size_t numberOfFileNames = filenames.size();
std::cout << numberOfFileNames << std::endl;
for (unsigned int fni = 0; fni < numberOfFileNames; ++fni)
{
std::cout << "filename # " << fni << " = ";
std::cout << filenames[fni] << std::endl;
}
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(gdcmIO);
reader->SetFileNames(filenames);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while writing the image" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
const char * outputDirectory = argv[2];
itksys::SystemTools::MakeDirectory(outputDirectory);
using OutputPixelType = signed short;
constexpr unsigned int OutputDimension = 2;
SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput(reader->GetOutput());
seriesWriter->SetImageIO(gdcmIO);
namesGenerator->SetOutputDirectory(outputDirectory);
seriesWriter->SetFileNames(namesGenerator->GetOutputFileNames());
seriesWriter->SetMetaDataDictionaryArray(
reader->GetMetaDataDictionaryArray());
try
{
seriesWriter->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown while writing the series " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}