]> Creatis software - clitk.git/blob - filters/clitkSplitImageGenericFilter.txx
remove antique RCS headers
[clitk.git] / filters / clitkSplitImageGenericFilter.txx
1 /*-------------------------------------------------------------------------
2                                                                                 
3   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4   l'Image). All rights reserved. See Doc/License.txt or
5   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
6                                                                                 
7   This software is distributed WITHOUT ANY WARRANTY; without even
8   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9   PURPOSE.  See the above copyright notices for more information.
10                                                                              
11   -------------------------------------------------------------------------*/
12
13 #ifndef clitkSplitImageGenericFilter_TXX
14 #define clitkSplitImageGenericFilter_TXX
15
16 //This is where you put the actual implementation
17
18 #include <sstream>
19 #include <itkExtractImageFilter.h>
20
21
22 //--------------------------------------------------------------------
23 template<unsigned int Dimension>
24 void clitk::SplitImageGenericFilter::UpdateWithDim(std::string PixelType, int Components) { 
25
26   if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<<Components<<" component(s) of "<<  PixelType<<"..."<<std::endl;
27
28     if (Components==1)
29       {
30         if(PixelType == "short"){  
31           if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
32           UpdateWithDimAndPixelType<Dimension, signed short>(); 
33         }
34             else if(PixelType == "unsigned_short"){  
35                if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
36                UpdateWithDimAndPixelType<Dimension, unsigned short>(); 
37              }
38         
39         else if (PixelType == "unsigned_char"){ 
40           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
41           UpdateWithDimAndPixelType<Dimension, unsigned char>();
42         }
43         
44              else if (PixelType == "char"){ 
45                if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
46                UpdateWithDimAndPixelType<Dimension, signed char>();
47              }
48         else {
49           if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
50           UpdateWithDimAndPixelType<Dimension, float>();
51         }
52       }
53
54     else if (Components==3)
55       {
56         if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and 3D float (DVF)" << std::endl;
57         UpdateWithDimAndPixelType<Dimension, itk::Vector<float, Dimension> >();
58       }
59     else std::cerr<<"Number of components is "<<Components<<", not supported!"<<std::endl;
60
61 }
62 //--------------------------------------------------------------------
63
64 //--------------------------------------------------------------------
65 template<unsigned int Dimension, class PixelType>
66 void clitk::SplitImageGenericFilter::UpdateWithDimAndPixelType() {
67
68   // Read input
69   typedef itk::Image<PixelType,Dimension> ImageType;
70   typedef itk::Image<PixelType,Dimension-1> OutputImageType;
71   typename ImageType::Pointer input = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
72   typedef itk::ExtractImageFilter<ImageType,OutputImageType> FilterType;
73   typename FilterType::Pointer filter= FilterType::New();
74
75   filter->SetInput(input);
76   typename ImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
77   size[mSplitDimension]=0;
78   typename ImageType::RegionType extracted_region;
79   extracted_region.SetSize(size);
80   filter->SetExtractionRegion(extracted_region);
81   filter->Update();
82
83   typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
84   std::string base_filename=GetOutputFilename();
85   unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension];
86   for (unsigned int i=0;i<number_of_output_images;i++)
87   {
88       std::ostringstream ss;
89       ss << i;
90       index[mSplitDimension]=i;
91       extracted_region.SetIndex(index);
92       filter->SetExtractionRegion(extracted_region);
93       filter->Update();
94       SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
95       typename OutputImageType::Pointer output=filter->GetOutput();
96       SetNextOutput<OutputImageType>(output);
97   }
98 }
99 //--------------------------------------------------------------------
100
101 #endif  //#define clitkSplitImageGenericFilter_TXX