ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkRelabelComponentImageFilter.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 __itkRelabelComponentImageFilter_h
19 #define __itkRelabelComponentImageFilter_h
20 
21 #include "itkInPlaceImageFilter.h"
22 #include "itkImage.h"
23 #include <vector>
24 
25 namespace itk
26 {
78 template< class TInputImage, class TOutputImage >
79 class ITK_EXPORT RelabelComponentImageFilter:
80  public InPlaceImageFilter< TInputImage, TOutputImage >
81 {
82 public:
88 
92  typedef typename Superclass::InputImagePointer InputImagePointer;
93 
98  typedef typename TOutputImage::PixelType OutputPixelType;
99  typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
100  typedef typename TInputImage::PixelType InputPixelType;
101  typedef typename TInputImage::InternalPixelType InputInternalPixelType;
102  itkStaticConstMacro(ImageDimension, unsigned int,
103  TOutputImage::ImageDimension);
104  itkStaticConstMacro(InputImageDimension, unsigned int,
105  TInputImage::ImageDimension);
107 
111  typedef TInputImage InputImageType;
112  typedef TOutputImage OutputImageType;
113  typedef typename TInputImage::IndexType IndexType;
114  typedef typename TInputImage::SizeType SizeType;
115  typedef typename TOutputImage::RegionType RegionType;
116 
122 
127 
131  itkNewMacro(Self);
132 
134  typedef IdentifierType LabelType;
135 
138 
141  itkGetConstMacro(NumberOfObjects, LabelType);
142 
143  typedef std::vector< ObjectSizeType > ObjectSizeInPixelsContainerType;
144  typedef std::vector< float > ObjectSizeInPhysicalUnitsContainerType;
145 
151  itkGetConstMacro(OriginalNumberOfObjects, LabelType);
152 
155  itkSetMacro(NumberOfObjectsToPrint, LabelType);
156  itkGetConstReferenceMacro(NumberOfObjectsToPrint, LabelType);
158 
165  itkSetMacro(MinimumObjectSize, ObjectSizeType);
166 
172  itkGetConstMacro(MinimumObjectSize, ObjectSizeType);
173 
179  const ObjectSizeInPixelsContainerType & GetSizeOfObjectsInPixels() const
180  {
181  // The GetConstReferenceMacro can't be used here becase this container
182  // doesn't have an ostream<< operator overloaded.
183  return this->m_SizeOfObjectsInPixels;
184  }
185 
191  const ObjectSizeInPhysicalUnitsContainerType & GetSizeOfObjectsInPhysicalUnits() const
192  {
193  // The GetConstReferenceMacro can't be used here becase this container
194  // doesn't have an ostream<< operator overloaded.
195  return this->m_SizeOfObjectsInPhysicalUnits;
196  }
197 
201  ObjectSizeType GetSizeOfObjectInPixels(LabelType obj) const
202  {
203  if ( obj > 0 && obj <= m_NumberOfObjects )
204  {
205  return m_SizeOfObjectsInPixels[obj - 1];
206  }
207  else
208  {
209  return 0;
210  }
211  }
213 
217  float GetSizeOfObjectInPhysicalUnits(LabelType obj) const
218  {
219  if ( obj > 0 && obj <= m_NumberOfObjects )
220  {
221  return m_SizeOfObjectsInPhysicalUnits[obj - 1];
222  }
223  else
224  {
225  return 0;
226  }
227  }
229 
230 #ifdef ITK_USE_CONCEPT_CHECKING
231 
232  itkConceptMacro( InputEqualityComparableCheck,
234  itkConceptMacro( UnsignedLongConvertibleToInputCheck,
236  itkConceptMacro( OutputLongConvertibleToUnsignedLongCheck,
238  itkConceptMacro( InputConvertibleToOutputCheck,
240  itkConceptMacro( SameDimensionCheck,
242 
244 #endif
245 
246 protected:
247 
249  m_NumberOfObjects(0), m_NumberOfObjectsToPrint(10),
250  m_OriginalNumberOfObjects(0), m_MinimumObjectSize(0)
251  { this->InPlaceOff(); }
253 
257  void GenerateData();
258 
262  void GenerateInputRequestedRegion();
263 
265  void PrintSelf(std::ostream & os, Indent indent) const;
266 
271  };
272 
273  // put the function objects here for sorting in descending order
275  {
276 public:
277  bool operator()(const RelabelComponentObjectType & a,
278  const RelabelComponentObjectType & b)
279  {
280  if ( a.m_SizeInPixels > b.m_SizeInPixels )
281  {
282  return true;
283  }
284  else if ( a.m_SizeInPixels < b.m_SizeInPixels )
285  {
286  return false;
287  }
288  // size in pixels and physical units are the same, sort based on
289  // original object number
290  else if ( a.m_ObjectNumber < b.m_ObjectNumber )
291  {
292  return true;
293  }
294  else
295  {
296  return false;
297  }
298  }
299  };
300 
301 private:
302  RelabelComponentImageFilter(const Self &); //purposely not implemented
303  void operator=(const Self &); //purposely not implemented
304 
309 
312 };
313 } // end namespace itk
314 
315 #ifndef ITK_MANUAL_INSTANTIATION
316 #include "itkRelabelComponentImageFilter.hxx"
317 #endif
318 
319 #endif
320