ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkClampImageFilter_h 00019 #define __itkClampImageFilter_h 00020 00021 #include "itkUnaryFunctorImageFilter.h" 00022 #include "itkProgressReporter.h" 00023 00024 namespace itk 00025 { 00026 00048 namespace Functor { 00049 00050 template< class TInput, class TOutput> 00051 class Clamp 00052 { 00053 public: 00054 Clamp() {}; 00055 virtual ~Clamp() {}; 00056 bool operator!=( const Clamp & ) const 00057 { 00058 return false; 00059 } 00060 bool operator==( const Clamp & other ) const 00061 { 00062 return !(*this != other); 00063 } 00064 inline TOutput operator()( const TInput & A ) const 00065 { 00066 double dA = static_cast< double >( A ); 00067 double typeMin = 00068 static_cast< double >( NumericTraits< TOutput >::NonpositiveMin() ); 00069 double typeMax = 00070 static_cast< double >( NumericTraits< TOutput >::max() ); 00071 00072 if ( dA < typeMin ) 00073 { 00074 return NumericTraits< TOutput >::NonpositiveMin(); 00075 } 00076 00077 if ( dA > typeMax ) 00078 { 00079 return NumericTraits< TOutput >::max(); 00080 } 00081 00082 return static_cast< TOutput >( A ); 00083 } 00084 }; 00085 } 00086 00087 template <class TInputImage, class TOutputImage> 00088 class ITK_EXPORT ClampImageFilter : 00089 public 00090 UnaryFunctorImageFilter<TInputImage,TOutputImage, 00091 Functor::Clamp< 00092 typename TInputImage::PixelType, 00093 typename TOutputImage::PixelType > > 00094 { 00095 public: 00097 typedef ClampImageFilter Self; 00098 typedef UnaryFunctorImageFilter< TInputImage, TOutputImage, 00099 Functor::Clamp< 00100 typename TInputImage::PixelType, 00101 typename TOutputImage::PixelType > > 00102 Superclass; 00103 00104 typedef SmartPointer< Self > Pointer; 00105 typedef SmartPointer< const Self > ConstPointer; 00106 00108 itkNewMacro(Self); 00109 00111 itkTypeMacro(ClampImageFilter, UnaryFunctorImageFilter); 00112 00113 #ifdef ITK_USE_CONCEPT_CHECKING 00114 00115 itkConceptMacro(InputConvertibleToOutputCheck, 00116 (Concept::Convertible< typename TInputImage::PixelType, 00117 typename TOutputImage::PixelType >)); 00118 itkConceptMacro(InputConvertibleToDoubleCheck, 00119 (Concept::Convertible< typename TInputImage::PixelType, 00120 double > )); 00121 itkConceptMacro(OutputConvertibleToDoubleCheck, 00122 (Concept::Convertible< typename TOutputImage::PixelType, 00123 double > )); 00124 00126 #endif 00127 00128 protected: 00129 ClampImageFilter() {} 00130 virtual ~ClampImageFilter() {} 00131 00132 void GenerateData() 00133 { 00134 if( this->GetInPlace() && this->CanRunInPlace() ) 00135 { 00136 // Nothing to do, so avoid iterating over all the pixels for 00137 // nothing! Allocate the output, generate a fake progress and exit. 00138 this->AllocateOutputs(); 00139 ProgressReporter progress(this, 0, 1); 00140 return; 00141 } 00142 Superclass::GenerateData(); 00143 } 00144 00145 private: 00146 ClampImageFilter(const Self&); //purposely not implemented 00147 void operator=(const Self&); //purposely not implemented 00148 00149 }; 00150 00151 00152 } // end namespace itk 00153 00154 #endif 00155