ITK  6.0.0
Insight Toolkit
itkBinaryProjectionImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkBinaryProjectionImageFilter_h
19 #define itkBinaryProjectionImageFilter_h
20 
22 #include "itkConceptChecking.h"
23 
24 namespace itk
25 {
47 namespace Functor
48 {
49 template <typename TInputPixel, typename TOutputPixel>
51 {
52 public:
54  ~BinaryAccumulator() = default;
55 
56  inline void
58  {
59  m_IsForeground = false;
60  }
61 
62  inline void
63  operator()(const TInputPixel & input)
64  {
65  if (input == m_ForegroundValue)
66  {
67  m_IsForeground = true;
68  }
69  }
70 
71  inline TOutputPixel
73  {
74  if (m_IsForeground)
75  {
76  return (TOutputPixel)m_ForegroundValue;
77  }
78 
79  return m_BackgroundValue;
80  }
81 
83 
84  TInputPixel m_ForegroundValue;
85 
86  TOutputPixel m_BackgroundValue;
87 };
88 } // namespace Functor
89 
90 template <typename TInputImage, typename TOutputImage>
92  : public ProjectionImageFilter<
93  TInputImage,
94  TOutputImage,
95  Functor::BinaryAccumulator<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
96 {
97 public:
98  ITK_DISALLOW_COPY_AND_MOVE(BinaryProjectionImageFilter);
99 
102  TInputImage,
103  TOutputImage,
105 
108 
110  itkOverrideGetNameOfClassMacro(BinaryProjectionImageFilter);
111 
113  itkNewMacro(Self);
114 
116  using InputImageType = TInputImage;
117  using OutputImageType = TOutputImage;
118 
120  using InputPixelType = typename InputImageType::PixelType;
121  using OutputPixelType = typename OutputImageType::PixelType;
122 
123  using typename Superclass::AccumulatorType;
124 
128  itkSetMacro(ForegroundValue, InputPixelType);
129 
132  itkGetConstMacro(ForegroundValue, InputPixelType);
133 
138  itkSetMacro(BackgroundValue, OutputPixelType);
139 
144  itkGetConstMacro(BackgroundValue, OutputPixelType);
145 
146 #ifdef ITK_USE_CONCEPT_CHECKING
147  // Begin concept checking
148  itkConceptMacro(InputPixelTypeGreaterThanComparable, (Concept::EqualityComparable<InputPixelType>));
149  itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
150  // End concept checking
151 #endif
152 
153 protected:
155  {
158  }
159 
160  ~BinaryProjectionImageFilter() override = default;
161 
162  void
163  PrintSelf(std::ostream & os, Indent indent) const override
164  {
165  Superclass::PrintSelf(os, indent);
166 
167  using InputPixelPrintType = typename NumericTraits<InputPixelType>::PrintType;
168 
169  os << indent << "ForegroundValue: " << static_cast<InputPixelPrintType>(m_ForegroundValue) << std::endl;
170 
171  using OutputPixelPrintType = typename NumericTraits<OutputPixelType>::PrintType;
172 
173  os << indent << "BackgroundValue: " << static_cast<OutputPixelPrintType>(m_BackgroundValue) << std::endl;
174  }
175 
177  NewAccumulator(SizeValueType size) const override
178  {
179  AccumulatorType accumulator(size);
180 
181  accumulator.m_ForegroundValue = m_ForegroundValue;
182  accumulator.m_BackgroundValue = m_BackgroundValue;
183  return accumulator;
184  }
185 
188 
191 }; // end BinaryProjectionImageFilter
192 } // end namespace itk
193 
194 #endif
itk::ProjectionImageFilter::AccumulatorType
TAccumulator AccumulatorType
Definition: itkProjectionImageFilter.h:84
itkProjectionImageFilter.h
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:717
itk::Functor::BinaryAccumulator::m_ForegroundValue
TInputPixel m_ForegroundValue
Definition: itkBinaryProjectionImageFilter.h:84
itk::ProjectionImageFilter::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::Functor::BinaryAccumulator::operator()
void operator()(const TInputPixel &input)
Definition: itkBinaryProjectionImageFilter.h:63
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:99
itk::BinaryProjectionImageFilter::m_BackgroundValue
OutputPixelType m_BackgroundValue
Definition: itkBinaryProjectionImageFilter.h:190
itkConceptChecking.h
itk::BinaryProjectionImageFilter::m_ForegroundValue
InputPixelType m_ForegroundValue
Definition: itkBinaryProjectionImageFilter.h:187
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Functor::BinaryAccumulator::BinaryAccumulator
BinaryAccumulator(SizeValueType)
Definition: itkBinaryProjectionImageFilter.h:53
itk::BinaryProjectionImageFilter::~BinaryProjectionImageFilter
~BinaryProjectionImageFilter() override=default
itk::ProjectionImageFilter
Implements an accumulation of an image along a selected direction.
Definition: itkProjectionImageFilter.h:57
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::BinaryAccumulator::Initialize
void Initialize()
Definition: itkBinaryProjectionImageFilter.h:57
itk::BinaryProjectionImageFilter::NewAccumulator
AccumulatorType NewAccumulator(SizeValueType size) const override
Definition: itkBinaryProjectionImageFilter.h:177
itk::BinaryProjectionImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkBinaryProjectionImageFilter.h:121
itk::BinaryProjectionImageFilter::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkBinaryProjectionImageFilter.h:163
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::BinaryProjectionImageFilter
Binary projection.
Definition: itkBinaryProjectionImageFilter.h:91
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:169
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::Functor::BinaryAccumulator
Definition: itkBinaryProjectionImageFilter.h:50
itk::Functor::BinaryAccumulator::GetValue
TOutputPixel GetValue()
Definition: itkBinaryProjectionImageFilter.h:72
itk::Functor::BinaryAccumulator::m_IsForeground
bool m_IsForeground
Definition: itkBinaryProjectionImageFilter.h:82
itk::Functor::BinaryAccumulator::m_BackgroundValue
TOutputPixel m_BackgroundValue
Definition: itkBinaryProjectionImageFilter.h:86
itk::BinaryProjectionImageFilter::BinaryProjectionImageFilter
BinaryProjectionImageFilter()
Definition: itkBinaryProjectionImageFilter.h:154
itk::Functor::BinaryAccumulator::~BinaryAccumulator
~BinaryAccumulator()=default
itk::BinaryProjectionImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkBinaryProjectionImageFilter.h:120
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:307
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90