X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=tools%2FclitkWriteDicomSeriesGenericFilter.txx;h=6f09ba9ea4fb48aef5b3b673b49c955a0dbfac40;hb=9e69bafb67552c371cf22e1f2a15792ac64deaad;hp=741ca234a99da038edb030fd82214903e062ca95;hpb=7a5d28f9a67bbf9f6eec89368010a5a08ca0838d;p=clitk.git diff --git a/tools/clitkWriteDicomSeriesGenericFilter.txx b/tools/clitkWriteDicomSeriesGenericFilter.txx index 741ca23..6f09ba9 100644 --- a/tools/clitkWriteDicomSeriesGenericFilter.txx +++ b/tools/clitkWriteDicomSeriesGenericFilter.txx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ +===========================================================================**/ #ifndef clitkWriteDicomSeriesGenericFilter_txx #define clitkWriteDicomSeriesGenericFilter_txx @@ -82,10 +82,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 +96,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(); @@ -161,12 +165,11 @@ WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() volumeReader->Update(); typename InputImageType::Pointer input = volumeReader->GetOutput(); - if (input->GetSpacing() != reader->GetOutput()->GetSpacing()) - { - // resampling is carried out on the fly if resolution between + if ((!m_ArgsInfo.useSizeAsReference_flag && (input->GetSpacing() != reader->GetOutput()->GetSpacing())) || + (m_ArgsInfo.useSizeAsReference_flag && (input->GetLargestPossibleRegion().GetSize() != reader->GetOutput()->GetLargestPossibleRegion().GetSize()))) { + + // resampling is carried out on the fly if resolution or size between // the input mhd and input dicom series is different - if (m_Verbose) - std::cout << "Warning: The image spacing differs between the MHD file and the input dicom series. Performing resampling with default options (for advanced options, use clitkResampleImage)." << std::endl; // Filter typedef clitk::ResampleImageWithOptionsFilter ResampleImageFilterType; @@ -175,16 +178,37 @@ WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() filter->SetVerboseOptions(m_Verbose); filter->SetGaussianFilteringEnabled(false); filter->SetDefaultPixelValue(0); - filter->SetOutputSpacing(reader->GetOutput()->GetSpacing()); - const SizeType& input_size = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); - SizeType output_size; - for (unsigned int i = 0; i < Dimension; i++) - output_size[i] = input_size[i]; - filter->SetOutputSize(output_size); - filter->Update(); - input = filter->GetOutput(); - } + + if (!m_ArgsInfo.useSizeAsReference_flag) { + filter->SetOutputSpacing(reader->GetOutput()->GetSpacing()); + if (m_Verbose) { + std::cout << "Warning: The image spacing differs between the MHD file and the input dicom series. Performing resampling with default options using spacing as reference (for advanced options, use clitkResampleImage)." << std::endl; + std::cout << "MHD -> " << input->GetSpacing() << std::endl; + std::cout << "dicom -> " << reader->GetOutput()->GetSpacing() << std::endl; + } + } + else { + const SizeType& dicom_size = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); + SizeType output_size; + for (unsigned int i = 0; i < Dimension; i++) + output_size[i] = dicom_size[i]; + filter->SetOutputSize(output_size); + if (m_Verbose) { + std::cout << "Warning: The image size differs between the MHD file and the input dicom series. Performing resampling with default options using size as reference (for advanced options, use clitkResampleImage)." << std::endl; + std::cout << "MHD -> " << input->GetLargestPossibleRegion().GetSize() << std::endl; + std::cout << "dicom -> " << reader->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl; + } + } + 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. @@ -193,8 +217,10 @@ WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() // in verbose mode const RegionType volumeRegion = input->GetLargestPossibleRegion(); const SizeType& volumeSize = volumeRegion.GetSize(); - if (Dimension == 3 && volumeSize[2] < numberOfFilenames) - { + 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; @@ -208,20 +234,16 @@ 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"<( *((*dictionary)[fni]), entryId, value ); } + // Output directory and filenames itksys::SystemTools::MakeDirectory( m_ArgsInfo.outputDir_arg ); // create if it doesn't exist