ITK  4.2.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 #include "itkProgressReporter.h"
23 
24 namespace itk
25 {
26 
48 namespace Functor {
49 
50 template< class TInput, class TOutput>
51 class Clamp
52 {
53 public:
54  Clamp() {};
55  virtual ~Clamp() {};
56  bool operator!=( const Clamp & ) const
57  {
58  return false;
59  }
60  bool operator==( const Clamp & other ) const
61  {
62  return !(*this != other);
63  }
64  inline TOutput operator()( const TInput & A ) const
65  {
66  double dA = static_cast< double >( A );
67  double typeMin =
68  static_cast< double >( NumericTraits< TOutput >::NonpositiveMin() );
69  double typeMax =
70  static_cast< double >( NumericTraits< TOutput >::max() );
71 
72  if ( dA < typeMin )
73  {
75  }
76 
77  if ( dA > typeMax )
78  {
80  }
81 
82  return static_cast< TOutput >( A );
83  }
84 };
85 }
86 
87 template <class TInputImage, class TOutputImage>
88 class ITK_EXPORT ClampImageFilter :
89  public
90 UnaryFunctorImageFilter<TInputImage,TOutputImage,
91  Functor::Clamp<
92  typename TInputImage::PixelType,
93  typename TOutputImage::PixelType > >
94 {
95 public:
98  typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
100  typename TInputImage::PixelType,
101  typename TOutputImage::PixelType > >
103 
106 
108  itkNewMacro(Self);
109 
112 
113 #ifdef ITK_USE_CONCEPT_CHECKING
114 
115  itkConceptMacro(InputConvertibleToOutputCheck,
116  (Concept::Convertible< typename TInputImage::PixelType,
117  typename TOutputImage::PixelType >));
118  itkConceptMacro(InputConvertibleToDoubleCheck,
119  (Concept::Convertible< typename TInputImage::PixelType,
120  double > ));
121  itkConceptMacro(OutputConvertibleToDoubleCheck,
122  (Concept::Convertible< typename TOutputImage::PixelType,
123  double > ));
124 
126 #endif
127 
128 protected:
130  virtual ~ClampImageFilter() {}
131 
132  void GenerateData()
133  {
134  if( this->GetInPlace() && this->CanRunInPlace() )
135  {
136  // Nothing to do, so avoid iterating over all the pixels for
137  // nothing! Allocate the output, generate a fake progress and exit.
138  this->AllocateOutputs();
139  ProgressReporter progress(this, 0, 1);
140  return;
141  }
142  Superclass::GenerateData();
143  }
144 
145 private:
146  ClampImageFilter(const Self&); //purposely not implemented
147  void operator=(const Self&); //purposely not implemented
148 
149 };
150 
151 
152 } // end namespace itk
153 
154 #endif
155