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) const
00064 {
00065 return (vnl_math_abs(a-b) <= m_Threshold);
00066 }
00067
00068 protected:
00069 TInput m_Threshold;
00070
00071 };
00072
00073 }
00074
00075 template <class TInputImage, class TOutputImage, class TMaskImage=TInputImage>
00076 class ITK_EXPORT ScalarConnectedComponentImageFilter :
00077 public ConnectedComponentFunctorImageFilter<TInputImage,TOutputImage,
00078 Functor::SimilarPixelsFunctor<typename TInputImage::ValueType>,
00079 TMaskImage>
00080 {
00081 public:
00083 typedef ScalarConnectedComponentImageFilter Self;
00084 typedef ConnectedComponentFunctorImageFilter<
00085 TInputImage,TOutputImage,
00086 Functor::SimilarPixelsFunctor<typename TInputImage::ValueType>,
00087 TMaskImage> Superclass;
00088 typedef SmartPointer<Self> Pointer;
00089 typedef SmartPointer<const Self> ConstPointer;
00090
00092 itkNewMacro(Self);
00093
00095 itkTypeMacro(ScalarConnectedComponentImageFilter,ConnectedComponentFunctorImageFilter);
00096
00097 typedef typename TInputImage::PixelType InputPixelType;
00098
00099 virtual void SetDistanceThreshold(const InputPixelType& thresh)
00100 {this->GetFunctor().SetDistanceThreshold(thresh);}
00101
00102 virtual InputPixelType GetDistanceThreshold()
00103 {return (this->GetFunctor().GetDistanceThreshold());}
00104
00105 #ifdef ITK_USE_CONCEPT_CHECKING
00106
00107 itkConceptMacro(InputEqualityComparableCheck,
00108 (Concept::EqualityComparable<InputPixelType>));
00109 itkConceptMacro(OutputEqualityComparableCheck,
00110 (Concept::EqualityComparable<typename TOutputImage::PixelType>));
00111 itkConceptMacro(MaskEqualityComparableCheck,
00112 (Concept::EqualityComparable<typename TMaskImage::PixelType>));
00113 itkConceptMacro(OutputIncrementDecrementOperatorsCheck,
00114 (Concept::IncrementDecrementOperators<typename TOutputImage::PixelType>));
00115
00117 #endif
00118
00119 protected:
00120 ScalarConnectedComponentImageFilter() {};
00121 virtual ~ScalarConnectedComponentImageFilter() {};
00122
00123 private:
00124 ScalarConnectedComponentImageFilter(const Self&);
00125 void operator=(const Self&);
00126
00127 };
00128
00129 }
00130
00131 #endif
00132