]> Creatis software - clitk.git/blob - itk/clitkSetBackgroundImageFilter.h
removed headers
[clitk.git] / itk / clitkSetBackgroundImageFilter.h
1 #ifndef __clitkSetBackgroundImageFilter_h
2 #define __clitkSetBackgroundImageFilter_h
3 #include "itkBinaryFunctorImageFilter.h"
4 #include "itkNumericTraits.h"
5
6
7 namespace clitk
8 {
9   
10 namespace Functor {  
11   
12 template< class TInput, class TMask, class TOutput=TInput >
13 class SetBackground
14 {
15 public:
16   typedef typename itk::NumericTraits< TInput >::AccumulateType AccumulatorType;
17
18   //SetBackground(): m_OutsideValue(itk::NumericTraits< TOutput >::Zero),m_Fg(false),m_MaskValue( static_cast<TMask>(0) ) {};
19   SetBackground()
20   { 
21     m_OutsideValue=itk::NumericTraits< TOutput >::Zero;
22     m_Fg=false;
23     m_MaskValue= static_cast<TMask>(0);
24   }
25   ~SetBackground() {};
26   bool operator!=( const SetBackground & ) const
27     {
28     return false;
29     }
30   bool operator==( const SetBackground & other ) const
31     {
32     return !(*this != other);
33     }
34
35   inline TOutput operator()( const TInput & A, const TMask & B)
36     {
37       // Background mode: set everything = background value
38       if(!m_Fg)
39         {
40           if (B == m_MaskValue ) 
41             {
42               return static_cast<TOutput>( m_OutsideValue );
43             }
44           else
45             {
46               return A;
47             }
48         }
49
50       // Foreground mode: set everything != foreground value
51       else
52         {
53           if (B != m_MaskValue ) 
54             {
55               return static_cast<TOutput>( m_OutsideValue );
56             }
57           else
58             {
59               return A;
60             }
61         }
62     }
63   
64   /** Method to explicitly set the outside value of the mask */
65   void SetOutsideValue( const TOutput &outsideValue )
66   {
67     m_OutsideValue = static_cast<TOutput>(outsideValue);
68   }
69   
70   /** Method to get the outside value of the mask */
71   const TOutput &GetOutsideValue() const
72   {
73     return m_OutsideValue;
74   }
75   
76   /** Method to explicitly set the relevant value of the mask */
77   void SetMaskValue( const TMask &maskValue )
78   {
79     m_MaskValue = static_cast<TMask>(maskValue);
80   }
81   
82   /** Method to get the relevant value of the mask */
83   const TMask &GetMaskValue() const
84   {
85     return m_MaskValue;
86   }
87
88   /** Method to explicitly set the foreground mode of the mask */
89   void SetForeground( const bool &fg )
90   {
91     m_Fg = fg;
92   }
93   
94   /** Method to get the foregroundmode of the mask */
95   const bool &GetForeground() const
96   {
97     return m_Fg;
98   }
99
100 private:
101   TOutput m_OutsideValue;
102   TMask m_MaskValue;
103   bool m_Fg;
104 }; 
105
106 } //end namespace
107
108 template <class TInputImage, class TMaskImage, class TOutputImage=TInputImage>
109 class ITK_EXPORT SetBackgroundImageFilter :
110     public
111     itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage, 
112                          Functor::SetBackground< 
113   typename TInputImage::PixelType, 
114   typename TMaskImage::PixelType,
115   typename TOutputImage::PixelType>   >
116
117
118 {
119 public:
120   /** Standard class typedefs. */
121   typedef SetBackgroundImageFilter           Self;
122   typedef itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage, 
123                                    Functor::SetBackground< 
124     typename TInputImage::PixelType, 
125     typename TMaskImage::PixelType,
126     typename TOutputImage::PixelType>   
127   >                                 Superclass;
128   typedef itk::SmartPointer<Self>        Pointer;
129   typedef itk::SmartPointer<const Self>  ConstPointer;
130
131   /** Method for creation through the object factory. */
132   itkNewMacro(Self);
133
134   /** Runtime information support. */
135   itkTypeMacro(SetBackgroundImageFilter, 
136                BinaryFunctorImageFilter);
137
138   /** Method to explicitly set the outside value of the mask. Defaults to 0 */
139   void SetOutsideValue( const typename TOutputImage::PixelType & outsideValue ) 
140     {
141     if( this->GetOutsideValue() != outsideValue )
142       {
143       this->Modified();
144       this->GetFunctor().SetOutsideValue( outsideValue );
145       }
146     }
147
148   const typename TOutputImage::PixelType & GetOutsideValue() const
149     {
150     return this->GetFunctor().GetOutsideValue();
151     }
152
153   /** Method to explicitly set the value of the mask. Defaults to 0 */
154   void SetMaskValue( const typename TMaskImage::PixelType & maskValue ) 
155     {
156     if( this->GetMaskValue() != maskValue )
157       {
158       this->Modified();
159       this->GetFunctor().SetMaskValue( maskValue );
160       }
161     }
162
163   const typename TMaskImage::PixelType & GetMaskValue() const
164     {
165     return this->GetFunctor().GetMaskValue();
166     }
167
168   /** Method to set the foreground mode. Defaults to 0 */
169   void SetForeground( const bool & fg ) 
170     {
171     if( this->GetForeground() != fg )
172       {
173       this->Modified();
174       this->GetFunctor().SetForeground( fg );
175       }
176     }
177
178   const bool & GetForeground() const
179     {
180     return this->GetFunctor().GetForeground();
181     }
182
183 #ifdef ITK_USE_CONCEPT_CHECKING
184   /** Begin concept checking */
185   itkConceptMacro(MaskEqualityComparableCheck,
186                   (itk::Concept::EqualityComparable<typename TMaskImage::PixelType>));
187   itkConceptMacro(InputConvertibleToOutputCheck,
188     (itk::Concept::Convertible<typename TInputImage::PixelType,
189                           typename TOutputImage::PixelType>));
190   /** End concept checking */
191 #endif
192
193 protected:
194   SetBackgroundImageFilter() {}
195   virtual ~SetBackgroundImageFilter() {}
196
197   void PrintSelf(std::ostream &os, itk::Indent indent) const
198     {
199     Superclass::PrintSelf(os, indent);
200     os << indent << "OutsideValue: "  << this->GetOutsideValue() << std::endl;
201     os << indent << "MaskValue: "  << this->GetMaskValue() << std::endl;
202     os << indent << "Foreground mode: "  << this->GetForeground() << std::endl;
203     }
204
205 private:
206   SetBackgroundImageFilter(const Self&); //purposely not implemented
207   void operator=(const Self&); //purposely not implemented
208
209 };
210
211 } // end namespace clitk
212
213
214 #endif