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