]> Creatis software - clitk.git/blob - segmentation/clitkAndGenericFilter.txx
6bf0cccda1bf993439bd80e241006eebc70a8f72
[clitk.git] / segmentation / clitkAndGenericFilter.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://www.centreleonberard.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 clitkAndGenericFilter_txx
19 #define clitkAndGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkAndGenericFilter.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   AndGenericFilter::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   AndGenericFilter::UpdateWithDimAndPixelType()
74   {
75
76     // ImageTypes
77     typedef itk::Image<PixelType, Dimension> InputImageType;
78     typedef itk::Image<int, Dimension> InternalImageType;
79     typedef itk::Image<PixelType, Dimension> OutputImageType;
80     
81     // Read the input
82     typedef itk::ImageFileReader<InputImageType> InputReaderType;
83     typename InputReaderType::Pointer reader = InputReaderType::New();
84     reader->SetFileName( m_InputFileName);
85     reader->Update();
86     typename InputImageType::Pointer input= reader->GetOutput();
87
88     // Read the second input
89     typename InputReaderType::Pointer reader2 = InputReaderType::New();
90     reader2->SetFileName( m_ArgsInfo.input2_arg);
91     reader2->Update();
92     typename InputImageType::Pointer input2= reader2->GetOutput();
93
94
95     // Cast
96     typedef itk::CastImageFilter<InputImageType, InternalImageType> InputCastImageFilterType;
97     typename InputCastImageFilterType::Pointer caster= InputCastImageFilterType::New();
98     caster->SetInput(input);
99     typename InputCastImageFilterType::Pointer caster2= InputCastImageFilterType::New();
100     caster->SetInput(input2);
101     
102     // Filter
103     typedef    itk::AndImageFilter< InternalImageType , InternalImageType , InternalImageType> AndFilterType;
104     typename   AndFilterType::Pointer andFilter = AndFilterType::New();
105     andFilter->SetInput1(caster->GetOutput());
106     andFilter->SetInput2(caster2->GetOutput());
107     if (m_Verbose) std::cout<<"Performing a logical AND..."<<std::endl;
108
109     // Cast
110     typedef itk::CastImageFilter<InternalImageType, OutputImageType> OutputCastImageFilterType;
111     typename OutputCastImageFilterType::Pointer caster3= OutputCastImageFilterType::New();
112     caster3->SetInput(andFilter->GetOutput());
113     typename OutputImageType::Pointer output =caster3->GetOutput();
114     
115     // Output
116     typedef itk::ImageFileWriter<OutputImageType> WriterType;
117     typename WriterType::Pointer writer = WriterType::New();
118     writer->SetFileName(m_ArgsInfo.output_arg);
119     writer->SetInput(output);
120     writer->Update();
121
122   }
123
124
125 }//end clitk
126  
127 #endif //#define clitkAndGenericFilter_txx