Orfeo Toolbox  4.0
itkThresholdLabelerImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkThresholdLabelerImageFilter_h
19 #define __itkThresholdLabelerImageFilter_h
20 
21 #include "itkUnaryFunctorImageFilter.h"
22 #include "itkConceptChecking.h"
23 
24 namespace itk
25 {
42 namespace Functor
43 {
44 template< typename TInput, typename TOutput >
46 {
47 public:
50 
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 
72  bool operator==(const ThresholdLabeler & other) const
73  {
74  return !( *this != other );
75  }
76 
77  inline TOutput operator()(const TInput & A) const
78  {
79  unsigned int size = m_Thresholds.size();
80 
81  if ( size == 0 )
82  {
83  return m_LabelOffset;
84  }
85  if ( A <= m_Thresholds[0] )
86  {
87  return m_LabelOffset;
88  }
89  for ( unsigned int i = 0; i < size - 1; i++ )
90  {
91  /* Value is in this class if it equals the upper bound. */
92  if ( m_Thresholds[i] < A && A <= m_Thresholds[i + 1] )
93  {
94  return static_cast< TOutput >( i + 1 ) + m_LabelOffset;
95  }
96  }
97  return static_cast< TOutput >( size ) + m_LabelOffset;
98  }
99 
100 private:
101 
103  TOutput m_LabelOffset;
104 };
105 }
106 
107 template< typename TInputImage, typename TOutputImage >
109  public
110  UnaryFunctorImageFilter< TInputImage, TOutputImage,
111  Functor::ThresholdLabeler<
112  typename TInputImage::PixelType,
113  typename TOutputImage::PixelType > >
114 {
115 public:
118  typedef UnaryFunctorImageFilter<
119  TInputImage, TOutputImage,
121  typename TInputImage::PixelType,
122  typename TOutputImage::PixelType >
124 
127 
129  itkNewMacro(Self);
130 
133 
135  typedef typename TInputImage::PixelType InputPixelType;
136  typedef typename TOutputImage::PixelType OutputPixelType;
137 
139  typedef std::vector< InputPixelType > ThresholdVector;
141  typedef std::vector< RealThresholdType > RealThresholdVector;
142 
144 #ifdef ITK_USE_CONCEPT_CHECKING
145  // Begin concept checking
146  itkConceptMacro( PixelTypeComparable,
148  itkConceptMacro( OutputPixelTypeComparable,
150  itkConceptMacro( OutputPixelTypeOStreamWritable,
152  // End concept checking
153 #endif
154 
156  void SetThresholds(const ThresholdVector & thresholds)
157  {
158  m_Thresholds = thresholds;
159  m_RealThresholds.clear();
160  typename ThresholdVector::const_iterator itr = m_Thresholds.begin();
161  while ( itr != m_Thresholds.end() )
162  {
163  m_RealThresholds.push_back( static_cast< RealThresholdType >( *itr ) );
164  ++itr;
165  }
166  this->Modified();
167  }
168 
171  { return m_Thresholds; }
172 
174  void SetRealThresholds(const RealThresholdVector & thresholds)
175  {
176  m_RealThresholds = thresholds;
177  m_Thresholds.clear();
178  typename RealThresholdVector::const_iterator itr = m_RealThresholds.begin();
179  while ( itr != m_RealThresholds.end() )
180  {
181  m_Thresholds.push_back( static_cast< InputPixelType >( *itr ) );
182  ++itr;
183  }
184  this->Modified();
185  }
186 
189  { return m_RealThresholds; }
190 
192  itkSetClampMacro( LabelOffset, OutputPixelType, NumericTraits< OutputPixelType >::Zero,
194  itkGetConstMacro(LabelOffset, OutputPixelType);
195 
196 protected:
199  void PrintSelf(std::ostream & os, Indent indent) const;
200 
203  virtual void BeforeThreadedGenerateData();
204 
205 private:
206  ThresholdLabelerImageFilter(const Self &); //purposely not implemented
207  void operator=(const Self &); //purposely not implemented
208 
212 };
213 } // end namespace itk
214 
215 #ifndef ITK_MANUAL_INSTANTIATION
217 #endif
218 
219 #endif

Generated at Sat Mar 8 2014 15:37:44 for Orfeo Toolbox with doxygen 1.8.3.1