]> Creatis software - clitk.git/blob - registration/clitkMultiResolutionPyramidGenericFilter.txx
11b7ad5a0b1597967c24f9acb974407f82c1bfe6
[clitk.git] / registration / clitkMultiResolutionPyramidGenericFilter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef clitkMultiResolutionPyramidGenericFilter_txx
19 #define clitkMultiResolutionPyramidGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkMultiResolutionPyramidGenericFilter.txx
23  * @author 
24  * @date   
25  * 
26  * @brief 
27  * 
28  ===================================================*/
29
30
31 namespace clitk
32 {
33
34   //-------------------------------------------------------------------
35   // Update with the number of dimensions
36   //-------------------------------------------------------------------
37   template<unsigned int Dimension>
38   void 
39   MultiResolutionPyramidGenericFilter::UpdateWithDim(std::string PixelType)
40   {
41     if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
42
43     if(PixelType == "short"){  
44       if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
45       UpdateWithDimAndPixelType<Dimension, signed short>(); 
46     }
47     //    else if(PixelType == "unsigned_short"){  
48     //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
49     //       UpdateWithDimAndPixelType<Dimension, unsigned short>(); 
50     //     }
51     
52     else if (PixelType == "unsigned_char"){ 
53       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
54       UpdateWithDimAndPixelType<Dimension, unsigned char>();
55     }
56     
57     //     else if (PixelType == "char"){ 
58     //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
59     //       UpdateWithDimAndPixelType<Dimension, signed char>();
60     //     }
61     else {
62       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
63       UpdateWithDimAndPixelType<Dimension, float>();
64     }
65   }
66
67
68   //-------------------------------------------------------------------
69   // Update with the number of dimensions and the pixeltype
70   //-------------------------------------------------------------------
71   template <unsigned int Dimension, class  PixelType> 
72   void 
73   MultiResolutionPyramidGenericFilter::UpdateWithDimAndPixelType()
74   {
75
76     // ImageTypes
77     typedef itk::Image<PixelType, Dimension> InputImageType;
78     typedef itk::Image<PixelType, Dimension> OutputImageType;
79     
80     // Read the input
81     typedef itk::ImageFileReader<InputImageType> InputReaderType;
82     typename InputReaderType::Pointer reader = InputReaderType::New();
83     reader->SetFileName( m_InputFileName);
84     reader->Update();
85     typename InputImageType::Pointer input= reader->GetOutput();
86
87     // Filter
88     typedef itk::ImageToImageFilter<InputImageType, OutputImageType> FilterType;
89     typename FilterType::Pointer filter;
90     switch(m_ArgsInfo.type_arg)
91       {
92       case 0: 
93         {
94           typedef itk::MultiResolutionPyramidImageFilter<InputImageType, OutputImageType> MRFilterType;
95           typename MRFilterType::Pointer rmFilter =MRFilterType::New();
96           if (m_Verbose) std::cout<<"Using the multi-resolution filter..."<<std::endl;
97           rmFilter->SetNumberOfLevels(m_ArgsInfo.levels_arg); 
98           filter=rmFilter;
99           break;
100         }
101       case 1: 
102         {
103           typedef itk::RecursiveMultiResolutionPyramidImageFilter<InputImageType, OutputImageType> RecursiveFilterType;
104           typename RecursiveFilterType::Pointer rFilter=RecursiveFilterType::New();
105           if (m_Verbose) std::cout<<"Using the recursive multi-resolution filter..."<<std::endl;
106           rFilter->SetNumberOfLevels(m_ArgsInfo.levels_arg); 
107           rFilter->SetUseShrinkImageFilter(false);
108           filter=rFilter;
109           break;
110         }
111       case 2: 
112         {
113           typedef clitk::SpatioTemporalMultiResolutionPyramidImageFilter<InputImageType, OutputImageType> SpatioTemporalFilterType;
114           typename SpatioTemporalFilterType::Pointer spFilter=SpatioTemporalFilterType::New();
115           if (m_Verbose) std::cout<<"Using the spatio-temporal multi-resolution filter..."<<std::endl;
116           spFilter->SetNumberOfLevels(m_ArgsInfo.levels_arg); 
117           filter=spFilter;
118           break;
119         }
120     case 3: 
121         {
122           typedef clitk::RecursiveSpatioTemporalMultiResolutionPyramidImageFilter<InputImageType, OutputImageType> RecursiveSpatioTemporalFilterType;
123           typename RecursiveSpatioTemporalFilterType::Pointer rspFilter=RecursiveSpatioTemporalFilterType::New();
124           if (m_Verbose) std::cout<<"Using the recursive spatio-temporal multi-resolution filter..."<<std::endl;
125           rspFilter->SetNumberOfLevels(m_ArgsInfo.levels_arg); 
126           rspFilter->SetUseShrinkImageFilter(false);
127           filter=rspFilter;
128           break;
129         }
130       }
131
132     // Common
133     filter->SetInput(input);  
134     try
135       {
136         filter->Update();
137       }
138     catch (itk::ExceptionObject)
139       {
140         std::cerr<<"Exception thrown during update() of the multi-resolution pyramid filter!"<<std::endl; 
141       }    
142
143     // Output
144     for(unsigned int i=0; i< m_ArgsInfo.output_given;i++)
145       {
146         // Get image at level i
147         typename OutputImageType::Pointer output=filter->GetOutput(i);
148                 
149         // Write 
150         writeImage<OutputImageType>(output,m_ArgsInfo.output_arg[i], m_Verbose);
151 //      typedef itk::ImageFileWriter<OutputImageType> WriterType;
152 //      typename WriterType::Pointer writer = WriterType::New();
153 //      writer->SetFileName(m_ArgsInfo.output_arg[i]);
154 //      writer->SetInput(output);
155 //      writer->Update();
156       }
157   }
158
159
160 }//end clitk
161  
162 #endif //#define clitkMultiResolutionPyramidGenericFilter_txx