ITK  5.4.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
23namespace itk
24{
25
26namespace Functor
27{
28
42template <typename TInput, typename TOutput = TInput>
43class ITK_TEMPLATE_EXPORT Clamp
44{
45public:
46 using Self = Clamp;
47
48 using InputType = TInput;
49 using OutputType = TOutput;
50
55
56 ~Clamp() = default;
57
62
67 void
68 SetBounds(const OutputType lowerBound, const OutputType upperBound);
69
70 bool
71 operator==(const Self & other) const;
72
74
76 operator()(const InputType & A) const;
77
78#ifdef ITK_USE_CONCEPT_CHECKING
79 itkConceptMacro(InputConvertibleToOutputCheck, (Concept::Convertible<InputType, OutputType>));
80 itkConceptMacro(InputConvertibleToDoubleCheck, (Concept::Convertible<InputType, double>));
81 itkConceptMacro(DoubleLessThanComparableToOutputCheck, (Concept::LessThanComparable<double, OutputType>));
82 itkConceptMacro(DoubleGreaterThanComparableToOutputCheck, (Concept::GreaterThanComparable<double, OutputType>));
83#endif
84
85private:
88};
89
90
91template <typename TInput, typename TOutput>
92inline 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
138template <typename TInputImage, typename TOutputImage>
139class ITK_TEMPLATE_EXPORT ClampImageFilter
140 : public UnaryFunctorImageFilter<TInputImage,
141 TOutputImage,
142 Functor::Clamp<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
143{
144public:
145 ITK_DISALLOW_COPY_AND_MOVE(ClampImageFilter);
146
149 using Superclass =
150 UnaryFunctorImageFilter<TInputImage,
151 TOutputImage,
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
178protected:
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
Casts input pixels to output pixel type and clamps the output pixel values to a specified range.
typename TInputImage::PixelType InputPixelType
typename TOutputImage::PixelType OutputPixelType
Functor used to clamp a value to a specified range.
bool operator==(const Self &other) const
OutputType GetUpperBound() const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
OutputType GetLowerBound() const
void SetBounds(const OutputType lowerBound, const OutputType upperBound)
OutputType operator()(const InputType &A) const
Base class for all process objects that output image data.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Implements pixel-wise generic operation on one image.
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....