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<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 TInput &a, const TInput &b)
00049 {
00050 typename TInput::ValueType dotProduct = vnl_math_abs(a * b);
00051 return (1.0 - dotProduct <= threshold);
00052 };
00053
00054 protected:
00055 typename TInput::ValueType threshold;
00056
00057 };
00058
00059 }
00060
00061 template <class TInputImage, class TOutputImage, class TMaskImage=TInputImage>
00062 class ITK_EXPORT VectorConnectedComponentImageFilter :
00063 public ConnectedComponentFunctorImageFilter<TInputImage,TOutputImage,
00064 Functor::SimilarVectorsFunctor<typename TInputImage::ValueType>,
00065 TMaskImage>
00066 {
00067 public:
00069 typedef VectorConnectedComponentImageFilter Self;
00070 typedef ConnectedComponentFunctorImageFilter<TInputImage,TOutputImage,
00071 Functor::SimilarVectorsFunctor<typename TInputImage::ValueType>,
00072 TMaskImage> Superclass;
00073 typedef SmartPointer<Self> Pointer;
00074 typedef SmartPointer<const Self> ConstPointer;
00075
00077 itkNewMacro(Self);
00078
00080 itkTypeMacro(VectorConnectedComponentImageFilter,ConnectedComponentFunctorImageFilter);
00081
00082 typedef typename TInputImage::PixelType::ValueType InputValueType;
00083
00084 virtual void SetDistanceThreshold(const InputValueType& thresh)
00085 {this->GetFunctor().SetDistanceThreshold(thresh);}
00086
00087 virtual InputValueType GetDistanceThreshold()
00088 {return (this->GetFunctor().GetDistanceThreshold());}
00089
00090 protected:
00091 VectorConnectedComponentImageFilter() {};
00092 virtual ~VectorConnectedComponentImageFilter() {};
00093
00094 private:
00095 VectorConnectedComponentImageFilter(const Self&);
00096 void operator=(const Self&);
00097
00098 };
00099
00100 }
00101
00102 #endif