// clitk
#include "clitkResampleImageWithOptionsFilter.h"
+#if GDCM_MAJOR_VERSION >= 2
+#include "gdcmUIDGenerator.h"
+#else
+#include "gdcmFile.h"
+#include "gdcmUtil.h"
+#endif
namespace clitk
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
UpdateWithDimAndPixelType<Dimension, signed short>();
}
- // else if(PixelType == "unsigned_short"){
- // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
- // UpdateWithDimAndPixelType<Dimension, unsigned short>();
- // }
+ else if(PixelType == "unsigned_short"){
+ if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
+ UpdateWithDimAndPixelType<Dimension, unsigned short>();
+ }
else if (PixelType == "unsigned_char") {
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
// if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
// UpdateWithDimAndPixelType<Dimension, signed char>();
// }
+ else if (PixelType == "double") {
+ if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and double..." << std::endl;
+ UpdateWithDimAndPixelType<Dimension, double>();
+ }
else {
if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
UpdateWithDimAndPixelType<Dimension, float>();
}
}
- filter->Update();
- input = filter->GetOutput();
+ try {
+ filter->Update();
+ input = filter->GetOutput();
+ } catch( itk::ExceptionObject & excp ) {
+ std::cerr << "Error: Exception thrown while resampling!!" << std::endl;
+ std::cerr << excp << std::endl;
+ }
}
-
+
// In some cases, due to resampling approximation issues,
// the number of slices in the MHD file may be different (smaller)
// from the number of files in the template dicom directory.
// in verbose mode
const RegionType volumeRegion = input->GetLargestPossibleRegion();
const SizeType& volumeSize = volumeRegion.GetSize();
+ if (m_Verbose) {
+ std::cout << volumeRegion << volumeSize << std::endl;
+ }
if (Dimension == 3 && volumeSize[2] < numberOfFilenames) {
if (m_Verbose)
std::cout << "Warning: The number of files in " << m_ArgsInfo.inputDir_arg << " (" << filenames_in.size() << " files) is greater than the number of slices in MHD (" << volumeSize[2] << " slices). Using only " << volumeSize[2] << " files." << std::endl;
const std::vector<DictionaryType*>* dictionary = reader->GetMetaDataDictionaryArray();
// Get keys
- unsigned int numberOfKeysGiven=0;
- if(m_ArgsInfo.midP_flag && m_ArgsInfo.key_given)
- std::cerr<<"Error: both keys and midP option are given"<<std::endl;
- else if (m_ArgsInfo.midP_flag)
- numberOfKeysGiven=1;
+ unsigned int numberOfKeysGiven=m_ArgsInfo.key_given;
+
+ std::string seriesUID;
+ std::string frameOfReferenceUID;
+ if (m_ArgsInfo.newSeriesUID_flag) {
+#if GDCM_MAJOR_VERSION >= 2
+ gdcm::UIDGenerator suid;
+ seriesUID = suid.Generate();
+ gdcm::UIDGenerator fuid;
+ frameOfReferenceUID = fuid.Generate();
+#else
+ seriesUID = gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
+ frameOfReferenceUID = gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
+#endif
+ if (m_ArgsInfo.verbose_flag)
+ {
+ DD(seriesUID);
+ DD(frameOfReferenceUID);
+ }
+ }
+
+
+ std::string studyUID;
+ if (m_ArgsInfo.newStudyUID_flag) {
+#if GDCM_MAJOR_VERSION >= 2
+ gdcm::UIDGenerator suid;
+ studyUID = suid.Generate();
+#else
+ studyUID = gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
+#endif
+ if (m_ArgsInfo.verbose_flag)
+ DD(studyUID);
+ }
+#if GDCM_MAJOR_VERSION < 2
else
- numberOfKeysGiven=m_ArgsInfo.key_given;
+ gdcmIO->KeepOriginalUID();
+#endif
+
+ std::string seriesUIDkey = "0020|000e";
+ std::string frameOfReferenceUIDKey = "0020|0052";
+ std::string studyUIDKey = "0020|000d";
+ for(unsigned int fni = 0; fni<numberOfFilenames; fni++) {
+ bool series_id_given = false;
+ bool study_id_given = false;
+ for (unsigned int i = 0; i < numberOfKeysGiven; i++) {
+ std::string entryId(m_ArgsInfo.key_arg[i] );
+ std::string value( m_ArgsInfo.tag_arg[i] );
- for (unsigned int i = 0; i < numberOfKeysGiven; i++) {
- std::string entryId(m_ArgsInfo.key_arg[i] );
- std::string value( m_ArgsInfo.tag_arg[i] );
- for(unsigned int fni = 0; fni<numberOfFilenames; fni++)
itk::EncapsulateMetaData<std::string>( *((*dictionary)[fni]), entryId, value );
+ if (entryId == seriesUIDkey || entryId == frameOfReferenceUIDKey)
+ series_id_given = true;
+ if (entryId == studyUIDKey)
+ study_id_given = true;
+ }
+
+ if (!series_id_given) {
+ if (m_ArgsInfo.newSeriesUID_flag) {
+ itk::EncapsulateMetaData<std::string>( *((*dictionary)[fni]), seriesUIDkey, seriesUID );
+ itk::EncapsulateMetaData<std::string>( *((*dictionary)[fni]), frameOfReferenceUIDKey, frameOfReferenceUID );
+ }
+ }
+
+ if (!study_id_given) {
+ if (m_ArgsInfo.newStudyUID_flag)
+ itk::EncapsulateMetaData<std::string>( *((*dictionary)[fni]), studyUIDKey, studyUID );
+ }
}
+
// Output directory and filenames
itksys::SystemTools::MakeDirectory( m_ArgsInfo.outputDir_arg ); // create if it doesn't exist