ITK  4.4.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 protected:
126  {
127  m_ForegroundValue = NumericTraits<PixelType>::max();
128  m_BackgroundValue = NumericTraits<PixelType>::NonpositiveMin();
129  }
131 
132  void PrintSelf(std::ostream& os, Indent indent) const
133  {
134  Superclass::PrintSelf(os,indent);
135 
136  typedef typename NumericTraits<PixelType>::PrintType
137  PixelPrintType;
138 
139  os << indent << "ForegroundValue: "
140  << static_cast< PixelPrintType > (m_ForegroundValue)
141  << std::endl;
142 
143  os << indent << "BackgroundValue: "
144  << static_cast< PixelPrintType > (m_BackgroundValue)
145  << std::endl;
146  }
147 
148  void GenerateData()
149  {
150  this->GetFunctor().m_ForegroundValue = m_ForegroundValue;
151  this->GetFunctor().m_BackgroundValue = m_BackgroundValue;
152  Superclass::GenerateData();
153  }
154 
155 private:
156  BinaryNotImageFilter(const Self&); //purposely not implemented
157  void operator=(const Self&); //purposely not implemented
158 
161 
162 };
163 
164 } // end namespace itk
165 
166 
167 #endif
168