/*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the copyright notices for more information. It is distributed under dual licence - 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 /* ================================================= * @file clitkWriteDicomSeriesGenericFilter.txx * @author * @date * * @brief * ===================================================*/ namespace clitk { //----------------------------------------------------------- // Constructor //----------------------------------------------------------- template WriteDicomSeriesGenericFilter::WriteDicomSeriesGenericFilter() { m_Verbose=false; m_InputFileName=""; } //----------------------------------------------------------- // Update //----------------------------------------------------------- template void WriteDicomSeriesGenericFilter::Update() { // Read the Dimension and PixelType int Dimension; std::string PixelType; ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType); // Call UpdateWithDim if(Dimension==2) UpdateWithDim<2>(PixelType); else if(Dimension==3) UpdateWithDim<3>(PixelType); // else if (Dimension==4)UpdateWithDim<4>(PixelType); else { std::cout<<"Error, Only for 2 or 3 Dimensions!!!"< template void WriteDicomSeriesGenericFilter::UpdateWithDim(std::string PixelType) { if (m_Verbose) std::cout << "Image was detected to be "<(); } // 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; UpdateWithDimAndPixelType(); } // else if (PixelType == "char"){ // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; // UpdateWithDimAndPixelType(); // } else { if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; UpdateWithDimAndPixelType(); } } //------------------------------------------------------------------- // Update with the number of dimensions and the pixeltype //------------------------------------------------------------------- template template void WriteDicomSeriesGenericFilter::UpdateWithDimAndPixelType() { // ImageTypes typedef itk::Image InputImageType; typedef itk::Image OutputImageType; // Read the input (volumetric) typedef itk::ImageFileReader InputReaderType; typename InputReaderType::Pointer volumeReader = InputReaderType::New(); volumeReader->SetFileName( m_InputFileName); volumeReader->Update(); typename InputImageType::Pointer input= volumeReader->GetOutput(); // Read the dicom directory typedef itk::ImageSeriesReader< InputImageType > ReaderType; typedef itk::GDCMImageIO ImageIOType; typedef itk::GDCMSeriesFileNames NamesGeneratorType; ImageIOType::Pointer gdcmIO = ImageIOType::New(); NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New(); namesGenerator->SetInputDirectory( m_ArgsInfo.inputDir_arg ); typename ReaderType::FileNamesContainer filenames = namesGenerator->GetInputFileNames(); // Output the dicom files unsigned int numberOfFilenames = filenames.size(); if (m_Verbose) { std::cout << numberOfFilenames <<" were read in the directory "<* 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 typedef itk::ImageSeriesWriter SeriesWriterType; typename SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New(); seriesWriter->SetInput( volumeReader->GetOutput() ); seriesWriter->SetImageIO( gdcmIO ); namesGenerator->SetOutputDirectory( m_ArgsInfo.outputDir_arg ); seriesWriter->SetFileNames( namesGenerator->GetOutputFileNames() ); //seriesWriter->SetMetaDataDictionaryArray( dictionary ); seriesWriter->SetMetaDataDictionaryArray( dictionary ); // Write try { seriesWriter->Update(); } catch( itk::ExceptionObject & excp ) { std::cerr << "Error: Exception thrown while writing the series!!" << std::endl; std::cerr << excp << std::endl; } } }//end clitk #endif //#define clitkWriteDicomSeriesGenericFilter_txx