ITK  4.13.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< typename 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 <typename TImage>
87  public UnaryFunctorImageFilter< TImage, TImage, Functor::BinaryNot< typename TImage::PixelType > >
88 {
89 public:
92  typedef UnaryFunctorImageFilter<TImage, TImage,
96 
98  itkNewMacro(Self);
99 
101  itkTypeMacro(BinaryNotImageFilter,
103 
104  typedef typename TImage::PixelType PixelType;
105 
108  itkSetMacro(ForegroundValue, PixelType);
109  itkGetConstMacro(ForegroundValue, PixelType);
111 
114  itkSetMacro(BackgroundValue, PixelType);
115 
118  itkGetConstMacro(BackgroundValue, PixelType);
119 
120 protected:
122  {
125  }
126  virtual ~BinaryNotImageFilter() ITK_OVERRIDE {}
127 
128  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE
129  {
130  Superclass::PrintSelf(os,indent);
131 
132  typedef typename NumericTraits<PixelType>::PrintType
133  PixelPrintType;
134 
135  os << indent << "ForegroundValue: "
136  << static_cast< PixelPrintType > (m_ForegroundValue)
137  << std::endl;
138 
139  os << indent << "BackgroundValue: "
140  << static_cast< PixelPrintType > (m_BackgroundValue)
141  << std::endl;
142  }
143 
144  void GenerateData() ITK_OVERRIDE
145  {
149  }
150 
151 private:
152  ITK_DISALLOW_COPY_AND_ASSIGN(BinaryNotImageFilter);
153 
156 
157 };
158 
159 } // end namespace itk
160 
161 
162 #endif
Light weight base class for most itk classes.
TPixel operator()(const TPixel &A)
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void GenerateData() override
SmartPointer< const Self > ConstPointer
bool operator!=(const BinaryNot &) const
static ITK_CONSTEXPR_FUNC T max(const T &)
virtual void PrintSelf(std::ostream &os, Indent indent) const override
Implements the BinaryNot logical operator pixel-wise between two images.
static ITK_CONSTEXPR_FUNC T NonpositiveMin()
bool operator==(const BinaryNot &other) const
Implements pixel-wise generic operation on one image.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual ~BinaryNotImageFilter() override
UnaryFunctorImageFilter< TImage, TImage, Functor::BinaryNot< typename TImage::PixelType > > Superclass
Define additional traits for native types such as int or float.