ITK  4.13.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  typedef Clamp Self;
47 
48  typedef TInput InputType;
49  typedef TOutput OutputType;
50 
54  Clamp();
55 
56  ~Clamp();
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 double 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:
146  typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
147  Functor::Clamp< typename TInputImage::PixelType,
148  typename TOutputImage::PixelType > >
150 
153 
154  typedef typename TInputImage::PixelType InputPixelType;
155  typedef typename TOutputImage::PixelType OutputPixelType;
156 
158  itkNewMacro(Self);
159 
162 
163  OutputPixelType GetLowerBound() const;
164  OutputPixelType GetUpperBound() const;
165 
170  void SetBounds(const OutputPixelType lowerBound, const OutputPixelType upperBound);
171 
172 protected:
174  virtual ~ClampImageFilter() ITK_OVERRIDE {}
175 
176  void GenerateData() ITK_OVERRIDE;
177 
178  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
179 
180 private:
181  ITK_DISALLOW_COPY_AND_ASSIGN(ClampImageFilter);
182 
183 };
184 
185 } // end namespace itk
186 
187 #ifndef ITK_MANUAL_INSTANTIATION
188 #include "itkClampImageFilter.hxx"
189 #endif
190 
191 #endif
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
virtual ~ClampImageFilter() override
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.
Functor used to clamp a value to a specified range.
TOutputImage::PixelType OutputPixelType
OutputType operator()(const InputType &A) const
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Clamp< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
Implements pixel-wise generic operation on one image.
TInputImage::PixelType InputPixelType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SmartPointer< const Self > ConstPointer
#define itkConceptMacro(name, concept)
bool ITKIOXML_EXPORT operator==(itk::FancyString &s, const std::string &)
SmartPointer< Self > Pointer