00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __itkScalarConnectedComponentImageFilter_h
00021 #define __itkScalarConnectedComponentImageFilter_h
00022
00023 #include "vnl/vnl_math.h"
00024 #include "itkNumericTraits.h"
00025 #include "itkConnectedComponentFunctorImageFilter.h"
00026
00027 namespace itk
00028 {
00029
00038 namespace Functor {
00039
00040 template<class TInput>
00041 class SimilarPixelsFunctor
00042 {
00043 public:
00044 SimilarPixelsFunctor()
00045 {m_Threshold = itk::NumericTraits<TInput>::Zero;};
00046 ~SimilarPixelsFunctor() {};
00047 bool operator!=( const SimilarPixelsFunctor & other ) const
00048 {
00049 if( m_Threshold != other.m_Threshold )
00050 {
00051 return true;
00052 }
00053 return false;
00054 }
00055 bool operator==( const SimilarPixelsFunctor & other ) const
00056 {
00057 return !(*this != other);
00058 }
00059
00060 void SetDistanceThreshold(const TInput &thresh) {m_Threshold = thresh;};
00061 TInput GetDistanceThreshold() {return (m_Threshold);};
00062
00063 bool operator()(const TInput &a, const TInput &b) {
00064 return (vnl_math_abs(a-b) <= m_Threshold);
00065 };
00066
00067 protected:
00068 TInput m_Threshold;
00069
00070 };
00071
00072 }
00073
00074 template <class TInputImage, class TOutputImage, class TMaskImage=TInputImage>
00075 class ITK_EXPORT ScalarConnectedComponentImageFilter :
00076 public ConnectedComponentFunctorImageFilter<TInputImage,TOutputImage,
00077 Functor::SimilarPixelsFunctor<typename TInputImage::ValueType>,
00078 TMaskImage>
00079 {
00080 public:
00082 typedef ScalarConnectedComponentImageFilter Self;
00083 typedef ConnectedComponentFunctorImageFilter<TInputImage,TOutputImage,
00084 Functor::SimilarPixelsFunctor<typename TInputImage::ValueType>,
00085 TMaskImage> Superclass;
00086 typedef SmartPointer<Self> Pointer;
00087 typedef SmartPointer<const Self> ConstPointer;
00088
00090 itkNewMacro(Self);
00091
00093 itkTypeMacro(ScalarConnectedComponentImageFilter,ConnectedComponentFunctorImageFilter);
00094
00095 typedef typename TInputImage::PixelType InputPixelType;
00096
00097 virtual void SetDistanceThreshold(const InputPixelType& thresh)
00098 {this->GetFunctor().SetDistanceThreshold(thresh);}
00099
00100 virtual InputPixelType GetDistanceThreshold()
00101 {return (this->GetFunctor().GetDistanceThreshold());}
00102
00103 #ifdef ITK_USE_CONCEPT_CHECKING
00104
00105 itkConceptMacro(InputEqualityComparableCheck,
00106 (Concept::EqualityComparable<InputPixelType>));
00107 itkConceptMacro(OutputEqualityComparableCheck,
00108 (Concept::EqualityComparable<typename TOutputImage::PixelType>));
00109 itkConceptMacro(MaskEqualityComparableCheck,
00110 (Concept::EqualityComparable<typename TMaskImage::PixelType>));
00111 itkConceptMacro(OutputIncrementDecrementOperatorsCheck,
00112 (Concept::IncrementDecrementOperators<typename TOutputImage::PixelType>));
00113
00115 #endif
00116
00117 protected:
00118 ScalarConnectedComponentImageFilter() {};
00119 virtual ~ScalarConnectedComponentImageFilter() {};
00120
00121 private:
00122 ScalarConnectedComponentImageFilter(const Self&);
00123 void operator=(const Self&);
00124
00125 };
00126
00127 }
00128
00129 #endif
00130