ITK  4.2.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 protected:
246 
248  m_NumberOfObjects(0), m_NumberOfObjectsToPrint(10),
249  m_OriginalNumberOfObjects(0), m_MinimumObjectSize(0)
250  { this->InPlaceOff(); }
252 
256  void GenerateData();
257 
261  void GenerateInputRequestedRegion();
262 
264  void PrintSelf(std::ostream & os, Indent indent) const;
265 
270  };
271 
272  // put the function objects here for sorting in descending order
274  {
275 public:
276  bool operator()(const RelabelComponentObjectType & a,
277  const RelabelComponentObjectType & b)
278  {
279  if ( a.m_SizeInPixels > b.m_SizeInPixels )
280  {
281  return true;
282  }
283  else if ( a.m_SizeInPixels < b.m_SizeInPixels )
284  {
285  return false;
286  }
287  // size in pixels and physical units are the same, sort based on
288  // original object number
289  else if ( a.m_ObjectNumber < b.m_ObjectNumber )
290  {
291  return true;
292  }
293  else
294  {
295  return false;
296  }
297  }
298  };
299 private:
300  RelabelComponentImageFilter(const Self &); //purposely not implemented
301  void operator=(const Self &); //purposely not implemented
302 
307 
310 };
311 } // end namespace itk
312 
313 #ifndef ITK_MANUAL_INSTANTIATION
314 #include "itkRelabelComponentImageFilter.hxx"
315 #endif
316 
317 #endif
318