ITK  6.0.0
Insight Toolkit
itkClampImageFilter.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 itkClampImageFilter_h
19 #define itkClampImageFilter_h
20 
22 
23 namespace itk
24 {
25 
26 namespace Functor
27 {
28 
42 template <typename TInput, typename TOutput = TInput>
43 class ITK_TEMPLATE_EXPORT Clamp
44 {
45 public:
46  using Self = Clamp;
47 
48  using InputType = TInput;
49  using OutputType = TOutput;
50 
54  Clamp();
55 
56  ~Clamp() = default;
57 
59  GetLowerBound() const;
61  GetUpperBound() const;
62 
67  void
68  SetBounds(const OutputType lowerBound, const OutputType upperBound);
69 
70  bool
71  operator==(const Self & other) const;
72 
73  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
74 
76  operator()(const InputType & A) const;
77 
78 #ifdef ITK_USE_CONCEPT_CHECKING
80  itkConceptMacro(InputConvertibleToDoubleCheck, (Concept::Convertible<InputType, double>));
81  itkConceptMacro(DoubleLessThanComparableToOutputCheck, (Concept::LessThanComparable<double, OutputType>));
82  itkConceptMacro(DoubleGreaterThanComparableToOutputCheck, (Concept::GreaterThanComparable<double, OutputType>));
83 #endif
84 
85 private:
88 };
89 
90 
91 template <typename TInput, typename TOutput>
92 inline auto
94 {
95  const auto dA = static_cast<double>(A);
96 
97  if (dA < m_LowerBound)
98  {
99  return m_LowerBound;
100  }
101 
102  if (dA > m_UpperBound)
103  {
104  return m_UpperBound;
105  }
106 
107  return static_cast<OutputType>(A);
108 }
109 
110 } // end namespace Functor
111 
112 
138 template <typename TInputImage, typename TOutputImage>
139 class ITK_TEMPLATE_EXPORT ClampImageFilter
140  : public UnaryFunctorImageFilter<TInputImage,
141  TOutputImage,
142  Functor::Clamp<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
143 {
144 public:
145  ITK_DISALLOW_COPY_AND_MOVE(ClampImageFilter);
146 
149  using Superclass =
150  UnaryFunctorImageFilter<TInputImage,
151  TOutputImage,
153 
156 
157  using InputPixelType = typename TInputImage::PixelType;
158  using OutputPixelType = typename TOutputImage::PixelType;
159 
161  itkNewMacro(Self);
162 
164  itkOverrideGetNameOfClassMacro(ClampImageFilter);
165 
167  GetLowerBound() const;
169  GetUpperBound() const;
170 
175  void
176  SetBounds(const OutputPixelType lowerBound, const OutputPixelType upperBound);
177 
178 protected:
179  ClampImageFilter() = default;
180  ~ClampImageFilter() override = default;
181 
182  void
183  GenerateData() override;
184 
185  void
186  PrintSelf(std::ostream & os, Indent indent) const override;
187 };
188 
189 } // end namespace itk
190 
191 #ifndef ITK_MANUAL_INSTANTIATION
192 # include "itkClampImageFilter.hxx"
193 #endif
194 
195 #endif
itkUnaryFunctorImageFilter.h
itk::Functor::Clamp::m_UpperBound
OutputType m_UpperBound
Definition: itkClampImageFilter.h:87
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::Concept::GreaterThanComparable
Definition: itkConceptChecking.h:284
itk::Functor::Clamp::m_LowerBound
OutputType m_LowerBound
Definition: itkClampImageFilter.h:79
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:543
itk::ClampImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkClampImageFilter.h:158
itk::Functor::Clamp::operator()
OutputType operator()(const InputType &A) const
Definition: itkClampImageFilter.h:93
itk::Functor::Clamp< TInputImage::PixelType, TOutputImage::PixelType >::InputType
TInputImage::PixelType InputType
Definition: itkClampImageFilter.h:48
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::Functor::Clamp
Functor used to clamp a value to a specified range.
Definition: itkClampImageFilter.h:43
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itk::ClampImageFilter
Casts input pixels to output pixel type and clamps the output pixel values to a specified range.
Definition: itkClampImageFilter.h:139
itk::Functor::Clamp< TInputImage::PixelType, TOutputImage::PixelType >::OutputType
TOutputImage::PixelType OutputType
Definition: itkClampImageFilter.h:49
itk::ClampImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkClampImageFilter.h:157
itk::Concept::LessThanComparable
Definition: itkConceptChecking.h:262