From 5ce3eec189c720473972869df4dd44d91fd52bc4 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Fri, 21 Sep 2012 17:46:20 +0200 Subject: [PATCH] new options to auto-generate dcm series UIDs --- segmentation/clitkExtractLungFilter.txx | 2 +- tools/clitkWriteDicomSeries.ggo | 4 +- tools/clitkWriteDicomSeriesGenericFilter.txx | 70 ++++++++++++++++++-- 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/segmentation/clitkExtractLungFilter.txx b/segmentation/clitkExtractLungFilter.txx index 8dcdb5b..ffca1df 100644 --- a/segmentation/clitkExtractLungFilter.txx +++ b/segmentation/clitkExtractLungFilter.txx @@ -812,7 +812,7 @@ TracheaRegionGrowing() f->SetUpper(GetUpperThresholdForTrachea()); f->SetMinimumLowerThreshold(-2000); // f->SetMaximumUpperThreshold(0); // MAYBE TO CHANGE ??? - f->SetMaximumUpperThreshold(-700); // MAYBE TO CHANGE ??? + f->SetMaximumUpperThreshold(-300); // MAYBE TO CHANGE ??? f->SetAdaptLowerBorder(false); f->SetAdaptUpperBorder(true); f->SetMinimumSize(5000); diff --git a/tools/clitkWriteDicomSeries.ggo b/tools/clitkWriteDicomSeries.ggo index f6bccde..80d4334 100644 --- a/tools/clitkWriteDicomSeries.ggo +++ b/tools/clitkWriteDicomSeries.ggo @@ -11,4 +11,6 @@ option "inputDir" d "Input dicom directory" string yes option "outputDir" o "Output dicom directory" string yes option "key" k "Keys of tags to modify" string no multiple default="0008|103e" option "tag" t "Tags values" string no multiple default="MIDPOSITION" -option "useSizeAsReference" s "Use the size of the dicom image as reference for an occasional resampling" flag off \ No newline at end of file +option "newSeriesUID" e "Write the series with a new series UID (ignored if given in key/tag option)" flag off +option "newStudyUID" u "Write the series with a new study UID (ignored if given in key/tag option)" flag off +option "useSizeAsReference" s "Use the size of the dicom image as reference for an occasional resampling" flag off diff --git a/tools/clitkWriteDicomSeriesGenericFilter.txx b/tools/clitkWriteDicomSeriesGenericFilter.txx index 6f09ba9..225aae5 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 @@ -236,12 +242,66 @@ WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() // Get keys unsigned int numberOfKeysGiven=m_ArgsInfo.key_given; - for (unsigned int i = 0; i < numberOfKeysGiven; i++) { - std::string entryId(m_ArgsInfo.key_arg[i] ); - std::string value( m_ArgsInfo.tag_arg[i] ); - std::cout << entryId << " " << value << std::endl; - for(unsigned int fni = 0; fni= 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); + } + + 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 ); + } } -- 2.47.1