Orfeo Toolbox  3.16
itkThresholdLabelerImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkThresholdLabelerImageFilter.h,v $
5  Language: C++
6  Date: $Date: 2009-05-12 17:22:57 $
7  Version: $Revision: 1.13 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkThresholdLabelerImageFilter_h
18 #define __itkThresholdLabelerImageFilter_h
19 
21 #include "itkConceptChecking.h"
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 
42 namespace Functor {
43 
44 template< class TInput, class TOutput >
46 {
47 public:
50 
51  typedef typename NumericTraits< TInput >::RealType RealThresholdType;
52  typedef std::vector<RealThresholdType> RealThresholdVector;
53 
55  void SetThresholds( const RealThresholdVector & thresholds )
56  { m_Thresholds = thresholds; }
57 
59  void SetLabelOffset( const TOutput & labelOffset )
60  { m_LabelOffset = labelOffset; }
61 
62  bool operator!=( const ThresholdLabeler & other ) const
63  {
64  if( m_Thresholds != other.m_Thresholds ||
65  m_LabelOffset != other.m_LabelOffset )
66  {
67  return true;
68  }
69  return false;
70  }
71  bool operator==( const ThresholdLabeler & other ) const
72  {
73  return !(*this != other);
74  }
75 
76  inline TOutput operator()( const TInput & A ) const
77  {
78  unsigned int size = m_Thresholds.size();
79  if (size == 0)
80  {
81  return m_LabelOffset;
82  }
83  if (A <= m_Thresholds[0])
84  {
85  return m_LabelOffset;
86  }
87  for (unsigned int i=0; i<size-1; i++)
88  {
89  /* Value is in this class if it equals the upper bound. */
90  if (m_Thresholds[i] < A && A <= m_Thresholds[i+1])
91  {
92  return static_cast<TOutput>(i+1) + m_LabelOffset;
93  }
94  }
95  return static_cast<TOutput>(size) + m_LabelOffset;
96  }
97 
98 private:
99 
101  TOutput m_LabelOffset;
102 };
103 }
104 
105 template <class TInputImage,class TOutputImage>
107  public
108 UnaryFunctorImageFilter<TInputImage,TOutputImage,
109  Functor::ThresholdLabeler<
110  typename TInputImage::PixelType,
111  typename TOutputImage::PixelType> >
112 {
113 public:
116  typedef UnaryFunctorImageFilter<
117  TInputImage,TOutputImage,
119  typename TInputImage::PixelType,
120  typename TOutputImage::PixelType>
124 
126  itkNewMacro(Self);
127 
130 
132  typedef typename TInputImage::PixelType InputPixelType;
133  typedef typename TOutputImage::PixelType OutputPixelType;
134 
136  typedef std::vector<InputPixelType> ThresholdVector;
138  typedef std::vector<RealThresholdType> RealThresholdVector;
139 
140 
142 #ifdef ITK_USE_CONCEPT_CHECKING
143 
144  itkConceptMacro(PixelTypeComparable,
146  itkConceptMacro(OutputPixelTypeComparable,
148  itkConceptMacro(OutputPixelTypeOStreamWritable,
151 #endif
152 
154  void SetThresholds( const ThresholdVector & thresholds )
155  {
156  m_Thresholds = thresholds;
157  m_RealThresholds.clear();
158  typename ThresholdVector::const_iterator itr = m_Thresholds.begin();
159  while( itr != m_Thresholds.end() )
160  {
161  m_RealThresholds.push_back( static_cast< RealThresholdType >( *itr ) );
162  ++itr;
163  }
164  this->Modified();
165  }
166 
169  { return m_Thresholds; }
170 
172  void SetRealThresholds( const RealThresholdVector & thresholds )
173  {
174  m_RealThresholds = thresholds;
175  m_Thresholds.clear();
176  typename RealThresholdVector::const_iterator itr = m_RealThresholds.begin();
177  while( itr != m_RealThresholds.end() )
178  {
179  m_Thresholds.push_back( static_cast< InputPixelType >( *itr ) );
180  ++itr;
181  }
182  this->Modified();
183  }
184 
187  { return m_RealThresholds; }
188 
191  itkGetConstMacro(LabelOffset,OutputPixelType);
192 
193 protected:
196  void PrintSelf(std::ostream& os, Indent indent) const;
197 
200  virtual void BeforeThreadedGenerateData();
201 
202 private:
203  ThresholdLabelerImageFilter(const Self&); //purposely not implemented
204  void operator=(const Self&); //purposely not implemented
205 
209 };
210 
211 } // end namespace itk
212 
213 #ifndef ITK_MANUAL_INSTANTIATION
215 #endif
216 
217 #endif

Generated at Sun May 19 2013 00:10:18 for Orfeo Toolbox with doxygen 1.8.3.1