Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkThresholdLabelerImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkThresholdLabelerImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-10-18 16:11:15 $
00007   Version:   $Revision: 1.10 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkThresholdLabelerImageFilter_h
00018 #define __itkThresholdLabelerImageFilter_h
00019 
00020 #include "itkUnaryFunctorImageFilter.h"
00021 #include "itkConceptChecking.h"
00022 #include "itkNumericTraits.h"
00023 
00024 namespace itk
00025 {
00026   
00042 namespace Functor {  
00043   
00044 template< class TInput, class TOutput >
00045 class ThresholdLabeler
00046 {
00047 public:
00048   ThresholdLabeler() { m_LabelOffset = NumericTraits<TOutput>::One; }
00049   ~ThresholdLabeler() {};
00050 
00051   typedef typename NumericTraits< TInput >::RealType RealThresholdType;
00052   typedef std::vector<RealThresholdType>             RealThresholdVector;
00053 
00055   void SetThresholds( const RealThresholdVector & thresholds )
00056     { m_Thresholds = thresholds; }
00057 
00059   void SetLabelOffset( const TOutput & labelOffset )
00060     { m_LabelOffset = labelOffset; }
00061 
00062   bool operator!=( const ThresholdLabeler & other ) const
00063     {
00064     if( m_Thresholds != other.m_Thresholds ||
00065         m_LabelOffset != other.m_LabelOffset )
00066       {
00067       return true;
00068       }
00069     return false;
00070     }
00071   bool operator==( const ThresholdLabeler & other ) const
00072     {
00073     return !(*this != other);
00074     }
00075 
00076   inline TOutput operator()( const TInput & A )
00077     {
00078     unsigned int size = m_Thresholds.size();
00079     if (size == 0)
00080       {
00081       return m_LabelOffset;
00082       }
00083     if (A <= m_Thresholds[0])
00084       {
00085       return m_LabelOffset;
00086       }
00087     for (unsigned int i=0; i<size-1; i++)
00088       {
00089       /* Value is in this class if it equals the upper bound. */
00090       if (m_Thresholds[i] < A && A <= m_Thresholds[i+1])
00091         {
00092         return static_cast<TOutput>(i+1) + m_LabelOffset;
00093         }
00094       }
00095     return static_cast<TOutput>(size) + m_LabelOffset;
00096     }
00097 
00098 private:
00099 
00100   RealThresholdVector m_Thresholds;
00101   TOutput             m_LabelOffset;
00102 };
00103 }
00104 
00105 template <class TInputImage,class TOutputImage>
00106 class ThresholdLabelerImageFilter :
00107     public
00108 UnaryFunctorImageFilter<TInputImage,TOutputImage, 
00109                         Functor::ThresholdLabeler< 
00110   typename TInputImage::PixelType,
00111   typename TOutputImage::PixelType> >
00112 {
00113 public:
00115   typedef ThresholdLabelerImageFilter  Self;
00116   typedef UnaryFunctorImageFilter<
00117     TInputImage,TOutputImage, 
00118     Functor::ThresholdLabeler< 
00119       typename TInputImage::PixelType,
00120       typename TOutputImage::PixelType>   
00121     >                                  Superclass;
00122   typedef SmartPointer<Self>           Pointer;
00123   typedef SmartPointer<const Self>     ConstPointer;
00124 
00126   itkNewMacro(Self);
00127 
00129   itkTypeMacro(ThresholdLabelerImageFilter, UnaryFunctorImageFilter);
00130 
00132   typedef typename TInputImage::PixelType   InputPixelType;
00133   typedef typename TOutputImage::PixelType  OutputPixelType;
00134 
00136   typedef std::vector<InputPixelType>                        ThresholdVector;
00137   typedef typename NumericTraits< InputPixelType >::RealType RealThresholdType;
00138   typedef std::vector<RealThresholdType>                     RealThresholdVector;
00139 
00140 
00142 #ifdef ITK_USE_CONCEPT_CHECKING
00143 
00145   itkConceptMacro(PixelTypeComparable,
00146                   (Concept::Comparable<InputPixelType>));
00147   itkConceptMacro(OutputPixelTypeComparable,
00148                   (Concept::Comparable<OutputPixelType>));
00149   itkConceptMacro(OutputPixelTypeOStreamWritable,
00150                   (Concept::OStreamWritable<OutputPixelType>));
00151 
00153 #endif
00154 
00156   void SetThresholds( const ThresholdVector & thresholds )
00157     { 
00158     m_Thresholds = thresholds;
00159     m_RealThresholds.clear();
00160     typename ThresholdVector::const_iterator itr = m_Thresholds.begin();
00161     while( itr != m_Thresholds.end() )
00162       {
00163       m_RealThresholds.push_back( static_cast< RealThresholdType >( *itr ) );
00164       ++itr;
00165       }
00166     this->Modified();
00167     }
00169 
00171   const ThresholdVector & GetThresholds() const
00172     { return m_Thresholds; }
00173 
00175   void SetRealThresholds( const RealThresholdVector & thresholds )
00176     { 
00177     m_RealThresholds = thresholds;
00178     m_Thresholds.clear();
00179     typename RealThresholdVector::const_iterator itr = m_RealThresholds.begin();
00180     while( itr != m_RealThresholds.end() )
00181       {
00182       m_Thresholds.push_back( static_cast< InputPixelType >( *itr ) );
00183       ++itr;
00184       }
00185     this->Modified();
00186     }
00188 
00190   const RealThresholdVector & GetRealThresholds() const
00191     { return m_RealThresholds; }
00192 
00194   itkSetClampMacro(LabelOffset,OutputPixelType, NumericTraits<OutputPixelType>::Zero,NumericTraits<OutputPixelType>::max() );
00195   itkGetMacro(LabelOffset,OutputPixelType);
00197 
00198 protected:
00199   ThresholdLabelerImageFilter();
00200   virtual ~ThresholdLabelerImageFilter() {}
00201   void PrintSelf(std::ostream& os, Indent indent) const;
00202 
00205   virtual void BeforeThreadedGenerateData();
00206 
00207 private:
00208   ThresholdLabelerImageFilter(const Self&); //purposely not implemented
00209   void operator=(const Self&); //purposely not implemented
00210 
00211   ThresholdVector        m_Thresholds;
00212   RealThresholdVector    m_RealThresholds;
00213   OutputPixelType        m_LabelOffset;
00214 };
00215 
00216 } // end namespace itk
00217 
00218 #ifndef ITK_MANUAL_INSTANTIATION
00219 #include "itkThresholdLabelerImageFilter.txx"
00220 #endif
00221 
00222 #endif
00223 

Generated at Sat Feb 28 13:39:37 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000