ITK  4.6.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 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>
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 
165 
170  void SetBounds(const OutputPixelType lowerBound, const OutputPixelType upperBound);
171 
172 protected:
174  virtual ~ClampImageFilter() {}
175 
176  void GenerateData();
177 
178  void PrintSelf(std::ostream & os, Indent indent) const;
179 
180 private:
181  ClampImageFilter(const Self&); //purposely not implemented
182  void operator=(const Self&); //purposely not implemented
183 
184 };
185 
186 } // end namespace itk
187 
188 #ifndef ITK_MANUAL_INSTANTIATION
189 #include "itkClampImageFilter.hxx"
190 #endif
191 
192 #endif
OutputType GetLowerBound() const
bool operator!=(const Self &other) const
Casts input pixels to output pixel type and clamps the output pixel values to a specified range...
void operator=(const Self &)
Base class for all process objects that output image data.
bool operator==(const Self &other) const
Functor used to clamp a value to a specified range.
void SetBounds(const OutputPixelType lowerBound, const OutputPixelType upperBound)
OutputType GetUpperBound() const
TOutputImage::PixelType OutputPixelType
OutputPixelType GetUpperBound() const
OutputType operator()(const InputType &A) const
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Clamp< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
OutputPixelType GetLowerBound() const
Implements pixel-wise generic operation on one image.
TInputImage::PixelType InputPixelType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void SetBounds(const OutputType lowerBound, const OutputType upperBound)
SmartPointer< const Self > ConstPointer
#define itkConceptMacro(name, concept)
void PrintSelf(std::ostream &os, Indent indent) const
SmartPointer< Self > Pointer