ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkBinaryNotImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkBinaryNotImageFilter_h
19 #define __itkBinaryNotImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 
24 
25 namespace itk
26 {
27 
54 namespace Functor {
55 
56 template< class TPixel >
57 class BinaryNot
58 {
59 public:
60  BinaryNot() {};
61  ~BinaryNot() {};
62  bool operator!=( const BinaryNot & ) const
63  {
64  return false;
65  }
66  bool operator==( const BinaryNot & other ) const
67  {
68  return !(*this != other);
69  }
70  inline TPixel operator()( const TPixel & A )
71  {
72  bool a = ( A == m_ForegroundValue );
73  if( !a )
74  {
75  return m_ForegroundValue;
76  }
77  return m_BackgroundValue;
78  }
79 
82 };
83 
84 }
85 template <class TImage>
86 class ITK_EXPORT BinaryNotImageFilter :
87  public
88 UnaryFunctorImageFilter<TImage, TImage,
89  Functor::BinaryNot< typename TImage::PixelType > >
90 
91 
92 {
93 public:
96  typedef UnaryFunctorImageFilter<TImage, TImage,
100 
102  itkNewMacro(Self);
103 
105  itkTypeMacro(BinaryNotImageFilter,
107 
108  typedef typename TImage::PixelType PixelType;
109 
112  itkSetMacro(ForegroundValue, PixelType);
113  itkGetConstMacro(ForegroundValue, PixelType);
115 
118  itkSetMacro(BackgroundValue, PixelType);
119 
122  itkGetConstMacro(BackgroundValue, PixelType);
123 
124 
125 protected:
127  {
128  m_ForegroundValue = NumericTraits<PixelType>::max();
129  m_BackgroundValue = NumericTraits<PixelType>::NonpositiveMin();
130  }
132 
133  void PrintSelf(std::ostream& os, Indent indent) const
134  {
135  Superclass::PrintSelf(os,indent);
136 
137  typedef typename NumericTraits<PixelType>::PrintType
138  PixelPrintType;
139 
140  os << indent << "ForegroundValue: "
141  << static_cast< PixelPrintType > (m_ForegroundValue)
142  << std::endl;
143 
144  os << indent << "BackgroundValue: "
145  << static_cast< PixelPrintType > (m_BackgroundValue)
146  << std::endl;
147  }
148 
149  void GenerateData()
150  {
151  this->GetFunctor().m_ForegroundValue = m_ForegroundValue;
152  this->GetFunctor().m_BackgroundValue = m_BackgroundValue;
153  Superclass::GenerateData();
154  }
155 
156 private:
157  BinaryNotImageFilter(const Self&); //purposely not implemented
158  void operator=(const Self&); //purposely not implemented
159 
162 
163 };
164 
165 } // end namespace itk
166 
167 
168 #endif
169