ITK  4.6.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< typename TInputImage, typename TOutputImage >
80  public InPlaceImageFilter< TInputImage, TOutputImage >
81 {
82 public:
88 
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 
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 
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 
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 
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  // Begin concept checking
232  itkConceptMacro( InputEqualityComparableCheck,
234  itkConceptMacro( UnsignedLongConvertibleToInputCheck,
236  itkConceptMacro( OutputLongConvertibleToUnsignedLongCheck,
238  itkConceptMacro( InputConvertibleToOutputCheck,
240  itkConceptMacro( SameDimensionCheck,
242  // End concept checking
243 #endif
244 
245 protected:
246 
250  { this->InPlaceOff(); }
252 
256  void GenerateData();
257 
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:
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 
300 private:
301  RelabelComponentImageFilter(const Self &); //purposely not implemented
302  void operator=(const Self &); //purposely not implemented
303 
308 
311 };
312 } // end namespace itk
313 
314 #ifndef ITK_MANUAL_INSTANTIATION
315 #include "itkRelabelComponentImageFilter.hxx"
316 #endif
317 
318 #endif
const ObjectSizeInPixelsContainerType & GetSizeOfObjectsInPixels() const
Superclass::InputImagePointer InputImagePointer
ObjectSizeInPhysicalUnitsContainerType m_SizeOfObjectsInPhysicalUnits
std::vector< ObjectSizeType > ObjectSizeInPixelsContainerType
virtual void InPlaceOff()
void PrintSelf(std::ostream &os, Indent indent) const
Base class for all process objects that output image data.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
bool operator()(const RelabelComponentObjectType &a, const RelabelComponentObjectType &b)
ObjectSizeType GetSizeOfObjectInPixels(LabelType obj) const
float GetSizeOfObjectInPhysicalUnits(LabelType obj) const
InputImageType::Pointer InputImagePointer
Relabel the components in an image such that consecutive labels are used.
const ObjectSizeInPhysicalUnitsContainerType & GetSizeOfObjectsInPhysicalUnits() const
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
TInputImage::InternalPixelType InputInternalPixelType
Base class for filters that take an image as input and overwrite that image as the output...
#define itkConceptMacro(name, concept)
TOutputImage::InternalPixelType OutputInternalPixelType
ObjectSizeInPixelsContainerType m_SizeOfObjectsInPixels
InPlaceImageFilter< TInputImage, TOutputImage > Superclass