00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkThresholdLabelerImageFilter_h
00018 #define __itkThresholdLabelerImageFilter_h
00019
00020 #include "itkUnaryFunctorImageFilter.h"
00021 #include "itkConceptChecking.h"
00022
00023 namespace itk
00024 {
00025
00041 namespace Functor {
00042
00043 template< class TInput, class TOutput >
00044 class ThresholdLabeler
00045 {
00046 public:
00047 ThresholdLabeler() { m_LabelOffset = NumericTraits<TOutput>::One; }
00048 ~ThresholdLabeler() {};
00049
00050 typedef std::vector<TInput> ThresholdVector;
00051
00053 void SetThresholds( const ThresholdVector & thresholds )
00054 { m_Thresholds = thresholds; }
00055
00057 void SetLabelOffset( const TOutput & labelOffset )
00058 { m_LabelOffset = labelOffset; }
00059
00060 inline TOutput operator()( const TInput & A )
00061 {
00062 unsigned int size = m_Thresholds.size();
00063 if (size == 0)
00064 {
00065 return m_LabelOffset;
00066 }
00067 if (A <= m_Thresholds[0])
00068 {
00069 return m_LabelOffset;
00070 }
00071 for (unsigned int i=0; i<size-1; i++)
00072 {
00073
00074 if (m_Thresholds[i] < A && A <= m_Thresholds[i+1])
00075 {
00076 return static_cast<TOutput>(i+1) + m_LabelOffset;
00077 }
00078 }
00079 return static_cast<TOutput>(size) + m_LabelOffset;
00080 }
00081
00082 private:
00083
00084 ThresholdVector m_Thresholds;
00085 TOutput m_LabelOffset;
00086 };
00087 }
00088
00089 template <class TInputImage,class TOutputImage>
00090 class ThresholdLabelerImageFilter :
00091 public
00092 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00093 Functor::ThresholdLabeler<
00094 typename TInputImage::PixelType,
00095 typename TOutputImage::PixelType> >
00096 {
00097 public:
00099 typedef ThresholdLabelerImageFilter Self;
00100 typedef UnaryFunctorImageFilter<TInputImage,TOutputImage,
00101 Functor::ThresholdLabeler<
00102 typename TInputImage::PixelType,
00103 typename TOutputImage::PixelType>
00104 > Superclass;
00105 typedef SmartPointer<Self> Pointer;
00106 typedef SmartPointer<const Self> ConstPointer;
00107
00109 itkNewMacro(Self);
00110
00112 itkTypeMacro(ThresholdLabelerImageFilter, UnaryFunctorImageFilter);
00113
00115 typedef typename TInputImage::PixelType InputPixelType;
00116 typedef typename TOutputImage::PixelType OutputPixelType;
00117
00119 typedef std::vector<InputPixelType> ThresholdVector;
00120
00122 itkConceptMacro(PixelTypeComparable, (Concept::Comparable<InputPixelType>));
00123
00125 void SetThresholds( const ThresholdVector & thresholds )
00126 { m_Thresholds = thresholds; }
00128 const ThresholdVector & GetThresholds()
00129 { return m_Thresholds; }
00130
00132 itkSetClampMacro(LabelOffset,OutputPixelType, NumericTraits<OutputPixelType>::Zero,NumericTraits<OutputPixelType>::max() );
00133 itkGetMacro(LabelOffset,OutputPixelType);
00134
00135 protected:
00136 ThresholdLabelerImageFilter();
00137 virtual ~ThresholdLabelerImageFilter() {}
00138 void PrintSelf(std::ostream& os, Indent indent) const;
00139
00142 virtual void BeforeThreadedGenerateData();
00143
00144 private:
00145 ThresholdLabelerImageFilter(const Self&);
00146 void operator=(const Self&);
00147
00148 ThresholdVector m_Thresholds;
00149 OutputPixelType m_LabelOffset;
00150 };
00151
00152 }
00153
00154 #ifndef ITK_MANUAL_INSTANTIATION
00155 #include "itkThresholdLabelerImageFilter.txx"
00156 #endif
00157
00158 #endif