ITK  5.0.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() = default;
61  ~BinaryNot() = default;
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:
90  ITK_DISALLOW_COPY_AND_ASSIGN(BinaryNotImageFilter);
91 
94  using Superclass = UnaryFunctorImageFilter<TImage, TImage,
98 
100  itkNewMacro(Self);
101 
103  itkTypeMacro(BinaryNotImageFilter,
105 
106  using PixelType = typename TImage::PixelType;
107 
110  itkSetMacro(ForegroundValue, PixelType);
111  itkGetConstMacro(ForegroundValue, PixelType);
113 
116  itkSetMacro(BackgroundValue, PixelType);
117 
120  itkGetConstMacro(BackgroundValue, PixelType);
121 
122 protected:
124  {
127  }
128  ~BinaryNotImageFilter() override = default;
129 
130  void PrintSelf(std::ostream& os, Indent indent) const override
131  {
132  Superclass::PrintSelf(os,indent);
133 
134  using PixelPrintType = typename NumericTraits<PixelType>::PrintType;
135 
136  os << indent << "ForegroundValue: "
137  << static_cast< PixelPrintType > (m_ForegroundValue)
138  << std::endl;
139 
140  os << indent << "BackgroundValue: "
141  << static_cast< PixelPrintType > (m_BackgroundValue)
142  << std::endl;
143  }
144 
145  void GenerateData() override
146  {
150  }
151 
152 private:
155 
156 };
157 
158 } // end namespace itk
159 
160 
161 #endif
void PrintSelf(std::ostream &os, Indent indent) const override
Light weight base class for most itk classes.
TPixel operator()(const TPixel &A)
Define numeric traits for std::vector.
void PrintSelf(std::ostream &os, Indent indent) const override
bool operator!=(const BinaryNot &) const
Implements the BinaryNot logical operator pixel-wise between two images.
~BinaryNotImageFilter() override=default
bool operator==(const BinaryNot &other) const
Implements pixel-wise generic operation on one image.
void GenerateData() override
typename TImage::PixelType PixelType
Control indentation during Print() invocation.
Definition: itkIndent.h:49