ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkClampImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 itkClampImageFilter_h
19 #define itkClampImageFilter_h
20 
22 
23 namespace itk
24 {
25 
26 namespace Functor
27 {
28 
41 template< typename TInput, typename TOutput = TInput >
42 class ITK_TEMPLATE_EXPORT Clamp
43 {
44 public:
45 
46  using Self = Clamp;
47 
48  using InputType = TInput;
49  using OutputType = TOutput;
50 
54  Clamp();
55 
56  ~Clamp() = default;
57 
58  OutputType GetLowerBound() const;
59  OutputType GetUpperBound() const;
60 
65  void SetBounds( const OutputType lowerBound, const OutputType upperBound);
66 
67  bool operator!=( const Self & other ) const;
68  bool operator==( const Self & other ) const;
69 
70  OutputType operator()( const InputType & A ) const;
71 
72 #ifdef ITK_USE_CONCEPT_CHECKING
73  itkConceptMacro(InputConvertibleToOutputCheck,
75  itkConceptMacro(InputConvertibleToDoubleCheck,
77  itkConceptMacro(DoubleLessThanComparableToOutputCheck,
79  itkConceptMacro(DoubleGreaterThanComparableToOutputCheck,
81 #endif
82 
83 private:
86 };
87 
88 
89 template< typename TInput, typename TOutput >
90 inline
93 ::operator()( const InputType & A ) const
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 
137 template <typename TInputImage, typename TOutputImage>
138 class ITK_TEMPLATE_EXPORT ClampImageFilter :
139  public UnaryFunctorImageFilter< TInputImage,TOutputImage,
140  Functor::Clamp< typename TInputImage::PixelType,
141  typename TOutputImage::PixelType > >
142 {
143 public:
144  ITK_DISALLOW_COPY_AND_ASSIGN(ClampImageFilter);
145 
148  using Superclass = UnaryFunctorImageFilter< TInputImage, TOutputImage,
149  Functor::Clamp< typename TInputImage::PixelType,
150  typename TOutputImage::PixelType > >;
151 
154 
155  using InputPixelType = typename TInputImage::PixelType;
156  using OutputPixelType = typename TOutputImage::PixelType;
157 
159  itkNewMacro(Self);
160 
163 
164  OutputPixelType GetLowerBound() const;
165  OutputPixelType GetUpperBound() const;
166 
171  void SetBounds(const OutputPixelType lowerBound, const OutputPixelType upperBound);
172 
173 protected:
174  ClampImageFilter() = default;
175  ~ClampImageFilter() override = default;
176 
177  void GenerateData() override;
178 
179  void PrintSelf(std::ostream & os, Indent indent) const override;
180 };
181 
182 } // end namespace itk
183 
184 #ifndef ITK_MANUAL_INSTANTIATION
185 #include "itkClampImageFilter.hxx"
186 #endif
187 
188 #endif
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:485
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Casts input pixels to output pixel type and clamps the output pixel values to a specified range...
Base class for all process objects that output image data.
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:492
Functor used to clamp a value to a specified range.
OutputType operator()(const InputType &A) const
typename TInputImage::PixelType InputPixelType
typename TOutputImage::PixelType OutputPixelType
Implements pixel-wise generic operation on one image.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
#define itkConceptMacro(name, concept)