ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 itkConceptMacro(InputConvertibleToOutputCheck, (Concept::Convertible<InputType, OutputType>));
79 itkConceptMacro(InputConvertibleToDoubleCheck, (Concept::Convertible<InputType, double>));
80 itkConceptMacro(DoubleLessThanComparableToOutputCheck, (Concept::LessThanComparable<double, OutputType>));
81 itkConceptMacro(DoubleGreaterThanComparableToOutputCheck, (Concept::GreaterThanComparable<double, OutputType>));
82
83private:
86};
87
88
89template <typename TInput, typename TOutput>
90inline auto
92{
93 const auto dA = static_cast<double>(A);
94
95 if (dA < m_LowerBound)
96 {
97 return m_LowerBound;
98 }
99
100 if (dA > m_UpperBound)
101 {
102 return m_UpperBound;
103 }
104
105 return static_cast<OutputType>(A);
106}
107
108} // end namespace Functor
109
110
136template <typename TInputImage, typename TOutputImage>
137class ITK_TEMPLATE_EXPORT ClampImageFilter
138 : public UnaryFunctorImageFilter<TInputImage,
139 TOutputImage,
140 Functor::Clamp<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
141{
142public:
143 ITK_DISALLOW_COPY_AND_MOVE(ClampImageFilter);
144
148 UnaryFunctorImageFilter<TInputImage,
149 TOutputImage,
151
154
155 using InputPixelType = typename TInputImage::PixelType;
156 using OutputPixelType = typename TOutputImage::PixelType;
157
159 itkNewMacro(Self);
160
162 itkOverrideGetNameOfClassMacro(ClampImageFilter);
163
168
173 void
174 SetBounds(const OutputPixelType lowerBound, const OutputPixelType upperBound);
175
176protected:
177 ClampImageFilter() = default;
178 ~ClampImageFilter() override = default;
179
180 void
181 GenerateData() override;
182
183 void
184 PrintSelf(std::ostream & os, Indent indent) const override;
185};
186
187} // end namespace itk
188
189#ifndef ITK_MANUAL_INSTANTIATION
190# include "itkClampImageFilter.hxx"
191#endif
192
193#endif
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Clamp< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
ClampImageFilter()=default
SmartPointer< Self > Pointer
typename TInputImage::PixelType InputPixelType
void GenerateData() override
typename TOutputImage::PixelType OutputPixelType
void PrintSelf(std::ostream &os, Indent indent) const override
~ClampImageFilter() override=default
SmartPointer< const Self > ConstPointer
OutputPixelType GetUpperBound() const
void SetBounds(const OutputPixelType lowerBound, const OutputPixelType upperBound)
OutputPixelType GetLowerBound() const
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
Control indentation during Print() invocation.
Definition itkIndent.h:50
Implements transparent reference counting.
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....