X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkWriteDicomSeriesGenericFilter.txx;h=20e980ca603f86beb37fd4ea96ca08b4ab2e26f9;hb=a49ce6bf246efbaa348468bcb915493e0db17a9b;hp=d49c51e567b9ac836ddd6cb817df51195b4dbf79;hpb=573d80d0f7a17607d2ee883c21c940c0ba020282;p=clitk.git diff --git a/tools/clitkWriteDicomSeriesGenericFilter.txx b/tools/clitkWriteDicomSeriesGenericFilter.txx index d49c51e..20e980c 100644 --- a/tools/clitkWriteDicomSeriesGenericFilter.txx +++ b/tools/clitkWriteDicomSeriesGenericFilter.txx @@ -29,6 +29,12 @@ // clitk #include "clitkResampleImageWithOptionsFilter.h" +#if GDCM_MAJOR_VERSION >= 2 +#include "gdcmUIDGenerator.h" +#else +#include "gdcmFile.h" +#include "gdcmUtil.h" +#endif namespace clitk @@ -82,10 +88,10 @@ WriteDicomSeriesGenericFilter::UpdateWithDim(std::string PixelTy if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl; UpdateWithDimAndPixelType(); } - // else if(PixelType == "unsigned_short"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; - // UpdateWithDimAndPixelType(); - // } + else if(PixelType == "unsigned_short"){ + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; + UpdateWithDimAndPixelType(); + } else if (PixelType == "unsigned_char") { if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; @@ -96,6 +102,10 @@ WriteDicomSeriesGenericFilter::UpdateWithDim(std::string PixelTy // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; // UpdateWithDimAndPixelType(); // } + else if (PixelType == "double") { + if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and double..." << std::endl; + UpdateWithDimAndPixelType(); + } else { if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; UpdateWithDimAndPixelType(); @@ -196,10 +206,15 @@ WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() } } - 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. @@ -208,6 +223,9 @@ WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() // 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; @@ -222,20 +240,74 @@ WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() const std::vector* 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"<= 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( *((*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( *((*dictionary)[fni]), seriesUIDkey, seriesUID ); + itk::EncapsulateMetaData( *((*dictionary)[fni]), frameOfReferenceUIDKey, frameOfReferenceUID ); + } + } + + if (!study_id_given) { + if (m_ArgsInfo.newStudyUID_flag) + itk::EncapsulateMetaData( *((*dictionary)[fni]), studyUIDKey, studyUID ); + } } + // Output directory and filenames itksys::SystemTools::MakeDirectory( m_ArgsInfo.outputDir_arg ); // create if it doesn't exist