ITK  5.2.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  * 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 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  else
79  {
80  return m_BackgroundValue;
81  }
82  }
83 
85 
86  TInputPixel m_ForegroundValue;
87 
88  TOutputPixel m_BackgroundValue;
89 };
90 } // namespace Functor
91 
92 template <typename TInputImage, typename TOutputImage>
94  : public ProjectionImageFilter<
95  TInputImage,
96  TOutputImage,
97  Functor::BinaryAccumulator<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
98 {
99 public:
100  ITK_DISALLOW_COPY_AND_MOVE(BinaryProjectionImageFilter);
101 
104  TInputImage,
105  TOutputImage,
107 
110 
113 
115  itkNewMacro(Self);
116 
118  using InputImageType = TInputImage;
119  using OutputImageType = TOutputImage;
120 
122  using InputPixelType = typename InputImageType::PixelType;
123  using OutputPixelType = typename OutputImageType::PixelType;
124 
126 
130  itkSetMacro(ForegroundValue, InputPixelType);
131 
134  itkGetConstMacro(ForegroundValue, InputPixelType);
135 
140  itkSetMacro(BackgroundValue, OutputPixelType);
141 
146  itkGetConstMacro(BackgroundValue, OutputPixelType);
147 
148 #ifdef ITK_USE_CONCEPT_CHECKING
149  // Begin concept checking
150  itkConceptMacro(InputPixelTypeGreaterThanComparable, (Concept::EqualityComparable<InputPixelType>));
151  itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
152  // End concept checking
153 #endif
154 
155 protected:
157  {
160  }
161 
162  ~BinaryProjectionImageFilter() override = default;
163 
164  void
165  PrintSelf(std::ostream & os, Indent indent) const override
166  {
167  Superclass::PrintSelf(os, indent);
168 
169  using InputPixelPrintType = typename NumericTraits<InputPixelType>::PrintType;
170 
171  os << indent << "ForegroundValue: " << static_cast<InputPixelPrintType>(m_ForegroundValue) << std::endl;
172 
173  using OutputPixelPrintType = typename NumericTraits<OutputPixelType>::PrintType;
174 
175  os << indent << "BackgroundValue: " << static_cast<OutputPixelPrintType>(m_BackgroundValue) << std::endl;
176  }
177 
179  NewAccumulator(SizeValueType size) const override
180  {
181  AccumulatorType accumulator(size);
182 
183  accumulator.m_ForegroundValue = m_ForegroundValue;
184  accumulator.m_BackgroundValue = m_BackgroundValue;
185  return accumulator;
186  }
187 
190 
193 }; // end BinaryProjectionImageFilter
194 } // end namespace itk
195 
196 #endif
itk::ProjectionImageFilter::AccumulatorType
TAccumulator AccumulatorType
Definition: itkProjectionImageFilter.h:84
itkProjectionImageFilter.h
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:714
itk::Functor::BinaryAccumulator::m_ForegroundValue
TInputPixel m_ForegroundValue
Definition: itkBinaryProjectionImageFilter.h:86
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:97
itk::BinaryProjectionImageFilter::m_BackgroundValue
OutputPixelType m_BackgroundValue
Definition: itkBinaryProjectionImageFilter.h:192
itkConceptChecking.h
itk::BinaryProjectionImageFilter::m_ForegroundValue
InputPixelType m_ForegroundValue
Definition: itkBinaryProjectionImageFilter.h:189
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:179
itk::BinaryProjectionImageFilter::AccumulatorType
typename Superclass::AccumulatorType AccumulatorType
Definition: itkBinaryProjectionImageFilter.h:125
itk::BinaryProjectionImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkBinaryProjectionImageFilter.h:123
itk::BinaryProjectionImageFilter::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkBinaryProjectionImageFilter.h:165
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::BinaryProjectionImageFilter
Binary projection.
Definition: itkBinaryProjectionImageFilter.h:93
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:167
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
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:84
itk::Functor::BinaryAccumulator::m_BackgroundValue
TOutputPixel m_BackgroundValue
Definition: itkBinaryProjectionImageFilter.h:88
itk::BinaryProjectionImageFilter::BinaryProjectionImageFilter
BinaryProjectionImageFilter()
Definition: itkBinaryProjectionImageFilter.h:156
itk::Functor::BinaryAccumulator::~BinaryAccumulator
~BinaryAccumulator()=default
itk::BinaryProjectionImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkBinaryProjectionImageFilter.h:122
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90