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