From aa136d28e83a9b149621689f4f2e102d322c9cef Mon Sep 17 00:00:00 2001 From: tbaudier Date: Wed, 20 Mar 2019 10:02:24 +0100 Subject: [PATCH] Add 2 options to clitkImage2Dicom volum option: To save a volume instead of a slice serie Need to know the output dimension before compilitaion, so the template of the function is modified tag and key options: To change dicom tag Keep the model of clitkWriteDicomSeries --- tools/clitkImage2Dicom.ggo | 3 ++ tools/clitkImage2DicomGenericFilter.h | 4 +- tools/clitkImage2DicomGenericFilter.txx | 69 +++++++++++++++++-------- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/tools/clitkImage2Dicom.ggo b/tools/clitkImage2Dicom.ggo index 3c3022a..bb56d55 100644 --- a/tools/clitkImage2Dicom.ggo +++ b/tools/clitkImage2Dicom.ggo @@ -11,4 +11,7 @@ option "inputDcm" d "Input dicom filename" string no option "outputDcm" o "Output dicom folder" string no option "nameDicom" n "Output dicom filename" string no option "newUID" u "Write output with new UID" flag off +option "volume" - "Save a dicom volume" flag off +option "key" k "Keys of tags to modify" string no multiple +option "tag" t "Tags values" string no multiple diff --git a/tools/clitkImage2DicomGenericFilter.h b/tools/clitkImage2DicomGenericFilter.h index 3e47a34..5b56222 100644 --- a/tools/clitkImage2DicomGenericFilter.h +++ b/tools/clitkImage2DicomGenericFilter.h @@ -129,8 +129,8 @@ namespace clitk //---------------------------------------- // Templated members //---------------------------------------- - template void UpdateWithDim(std::string PixelType); - template void UpdateWithDimAndPixelType(); + template void UpdateWithDim(std::string PixelType); + template void UpdateWithDimAndPixelType(); //---------------------------------------- diff --git a/tools/clitkImage2DicomGenericFilter.txx b/tools/clitkImage2DicomGenericFilter.txx index 37fa8a5..dc5415b 100644 --- a/tools/clitkImage2DicomGenericFilter.txx +++ b/tools/clitkImage2DicomGenericFilter.txx @@ -84,8 +84,17 @@ void Image2DicomGenericFilter::Update() // Call UpdateWithDim - if(Dimension==2) UpdateWithDim<2>(PixelType); - else if(Dimension==3) UpdateWithDim<3>(PixelType); + if(Dimension==2) { + if (m_ArgsInfo.volume_flag) + UpdateWithDim<2,2>(PixelType); + else + UpdateWithDim<2,1>(PixelType); + } else if(Dimension==3) { + if (m_ArgsInfo.volume_flag) + UpdateWithDim<3,3>(PixelType); + else + UpdateWithDim<3,2>(PixelType); + } // else if (Dimension==4)UpdateWithDim<4>(PixelType); else { std::cout<<"Error, Only for 2 or 3 Dimensions!!!"<::Update() // Update with the number of dimensions //------------------------------------------------------------------- template -template +template void Image2DicomGenericFilter::UpdateWithDim(std::string PixelType) { - if (m_Verbose) std::cout << "Image was detected to be "<(); + if (m_Verbose) std::cout << "Launching filter in "<< inputDimension <<"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(); + if (m_Verbose) std::cout << "Launching filter in "<< inputDimension <<"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; - UpdateWithDimAndPixelType(); + if (m_Verbose) std::cout << "Launching filter in "<< inputDimension <<"D and unsigned_char..." << std::endl; + UpdateWithDimAndPixelType(); } // else if (PixelType == "char"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; - // UpdateWithDimAndPixelType(); + // if (m_Verbose) std::cout << "Launching filter in "<< inputDimension <<"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(); + if (m_Verbose) std::cout << "Launching filter in "<< inputDimension <<"D and double..." << std::endl; + UpdateWithDimAndPixelType(); } else { - if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; - UpdateWithDimAndPixelType(); + if (m_Verbose) std::cout << "Launching filter in "<< inputDimension <<"D and float..." << std::endl; + UpdateWithDimAndPixelType(); } } @@ -139,14 +148,14 @@ Image2DicomGenericFilter::UpdateWithDim(std::string PixelType) // series. //------------------------------------------------------------------- template -template +template void Image2DicomGenericFilter::UpdateWithDimAndPixelType() { // Validate input parameters - const unsigned int InputDimension = Dimension; - const unsigned int OutputDimension = Dimension-1; + const unsigned int InputDimension = inputDimension; + const unsigned int OutputDimension = outputDimension; typedef itk::Image< PixelType, InputDimension > InputImageType; typedef itk::Image< PixelType, OutputDimension > OutputImageType; @@ -237,7 +246,12 @@ Image2DicomGenericFilter::UpdateWithDimAndPixelType() itk::ExposeMetaData(*inputDict, "0020|000d", studyUID); itk::ExposeMetaData(*inputDict, "0008|0016", sopClassUID); gdcmIO->KeepOriginalUIDOn(); - for (unsigned int f = 0; f < outputSize[2]; f++) + unsigned int numberOfKeysGiven=m_ArgsInfo.key_given; + unsigned int fLimit = outputSize[2]; + if (m_ArgsInfo.volume_flag) + fLimit = 1; + + for (unsigned int f = 0; f < fLimit; f++) { // Create a new dictionary for this slice typename ReaderType::DictionaryRawPointer dict = new typename ReaderType::DictionaryType; @@ -348,6 +362,15 @@ Image2DicomGenericFilter::UpdateWithDimAndPixelType() itk::EncapsulateMetaData(*dict,"0018|0050", value.str()); // Spacing Between Slices itk::EncapsulateMetaData(*dict,"0018|0088", value.str()); + + //Add ggo key + for (unsigned int i = 0; i < numberOfKeysGiven; i++) { + std::string entryId(m_ArgsInfo.key_arg[i] ); + std::string value( m_ArgsInfo.tag_arg[i] ); + + itk::EncapsulateMetaData(*dict, entryId, value); + } + // Save the dictionary outputArray.push_back(dict); } @@ -388,7 +411,11 @@ Image2DicomGenericFilter::UpdateWithDimAndPixelType() seriesFormat = seriesFormat + "IM%d.dcm"; outputNames->SetSeriesFormat(seriesFormat.c_str()); outputNames->SetStartIndex(1); - outputNames->SetEndIndex(outputSize[2]); + if (m_ArgsInfo.volume_flag) { + outputNames->SetEndIndex(1); + } else { + outputNames->SetEndIndex(outputSize[2]); + } typename SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New(); #if ( ( ITK_VERSION_MAJOR == 4 ) && ( ITK_VERSION_MINOR < 6 ) ) -- 2.45.0