Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkRelabelComponentImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkRelabelComponentImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-04-27 22:58:48 $
00007   Version:   $Revision: 1.17 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkRelabelComponentImageFilter_h
00018 #define __itkRelabelComponentImageFilter_h
00019 
00020 #include "itkInPlaceImageFilter.h"
00021 #include "itkImage.h"
00022 #include <vector>
00023 
00024 namespace itk
00025 {
00026 
00073 template <class TInputImage, class TOutputImage>
00074 class ITK_EXPORT RelabelComponentImageFilter : 
00075     public InPlaceImageFilter< TInputImage, TOutputImage > 
00076 {
00077 public:
00081   typedef RelabelComponentImageFilter                     Self;
00082   typedef InPlaceImageFilter< TInputImage, TOutputImage > Superclass;
00083 
00087   typedef typename Superclass::InputImagePointer InputImagePointer;
00088 
00093   typedef typename TOutputImage::PixelType         OutputPixelType;
00094   typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
00095   typedef typename TInputImage::PixelType          InputPixelType;
00096   typedef typename TInputImage::InternalPixelType  InputInternalPixelType;
00097   itkStaticConstMacro(ImageDimension, unsigned int,
00098                       TOutputImage::ImageDimension); 
00099   itkStaticConstMacro(InputImageDimension, unsigned int,
00100                       TInputImage::ImageDimension);
00102 
00106   typedef TInputImage                             InputImageType;
00107   typedef TOutputImage                            OutputImageType;
00108   typedef   typename TInputImage::IndexType       IndexType;
00109   typedef   typename TInputImage::SizeType        SizeType;
00110   typedef   typename TOutputImage::RegionType     RegionType;
00111 
00115   typedef SmartPointer<Self>        Pointer;
00116   typedef SmartPointer<const Self>  ConstPointer;
00117 
00121   itkTypeMacro(RelabelComponentImageFilter, ImageToImageFilter);
00122 
00126   itkNewMacro(Self);
00127 
00129   typedef unsigned long int    LabelType;
00130 
00132   typedef unsigned long int    ObjectSizeType;
00133 
00136   itkGetConstMacro(NumberOfObjects, LabelType);
00137 
00143   itkGetConstMacro(OriginalNumberOfObjects, LabelType);
00144 
00147   itkSetMacro(NumberOfObjectsToPrint, LabelType);
00148   itkGetConstReferenceMacro(NumberOfObjectsToPrint, LabelType);
00150 
00157   itkSetMacro(MinimumObjectSize, ObjectSizeType);
00158 
00164   itkGetConstMacro(MinimumObjectSize, ObjectSizeType);
00165 
00171   const std::vector<ObjectSizeType>& GetSizeOfObjectsInPixels() const
00172     { return m_SizeOfObjectsInPixels; }
00173 
00179   const std::vector<float>& GetSizeOfObjectsInPhysicalUnits() const
00180     { return m_SizeOfObjectsInPhysicalUnits; }
00181 
00185   ObjectSizeType GetSizeOfObjectInPixels( LabelType obj ) const
00186     {
00187     if (obj > 0 && obj <= m_NumberOfObjects)
00188       {
00189       return m_SizeOfObjectsInPixels[obj-1];
00190       }
00191     else
00192       {
00193       return 0;
00194       }
00195     }
00197 
00201   float GetSizeOfObjectInPhysicalUnits( LabelType obj ) const
00202     { 
00203     if (obj > 0 && obj <= m_NumberOfObjects)
00204       {
00205       return m_SizeOfObjectsInPhysicalUnits[obj-1];
00206       }
00207     else
00208       {
00209       return 0;
00210       }
00211     }
00213 
00214 #ifdef ITK_USE_CONCEPT_CHECKING
00215 
00216   itkConceptMacro(InputEqualityComparableCheck,
00217     (Concept::EqualityComparable<InputPixelType>));
00218   itkConceptMacro(UnsignedLongConvertibleToInputCheck,
00219     (Concept::Convertible<LabelType, InputPixelType>));
00220   itkConceptMacro(OutputLongConvertibleToUnsignedLongCheck,
00221     (Concept::Convertible<OutputPixelType, LabelType>));
00222   itkConceptMacro(InputConvertibleToOutputCheck,
00223     (Concept::Convertible<InputPixelType, OutputPixelType>));
00224   itkConceptMacro(SameDimensionCheck,
00225     (Concept::SameDimension<InputImageDimension, ImageDimension>));
00226 
00228 #endif
00229 
00230 protected:
00231 
00232   RelabelComponentImageFilter()
00233     : m_NumberOfObjects(0), m_NumberOfObjectsToPrint(10),
00234     m_OriginalNumberOfObjects(0), m_MinimumObjectSize(0)
00235     { this->InPlaceOff(); }
00236   virtual ~RelabelComponentImageFilter() {}
00237   RelabelComponentImageFilter(const Self&) {}
00238 
00242   void GenerateData();
00243 
00247   void GenerateInputRequestedRegion();
00248 
00250   void PrintSelf(std::ostream& os, Indent indent) const;
00251 
00252   struct RelabelComponentObjectType
00253     {
00254     LabelType       m_ObjectNumber;
00255     ObjectSizeType  m_SizeInPixels;
00256     float           m_SizeInPhysicalUnits;
00257     };
00258 
00259   // put the function objects here for sorting in descending order
00260   class RelabelComponentSizeInPixelsComparator
00261     {
00262     public:
00263       bool operator()(const RelabelComponentObjectType&a, 
00264                       const RelabelComponentObjectType &b)
00265       {
00266       if (a.m_SizeInPixels > b.m_SizeInPixels)
00267         {
00268         return true;
00269         }
00270       else if (a.m_SizeInPixels < b.m_SizeInPixels)
00271         {
00272         return false;
00273         }
00274       // size in pixels and physical units are the same, sort based on
00275       // original object number
00276       else if (a.m_ObjectNumber < b.m_ObjectNumber)
00277         {
00278         return true;
00279         }
00280       else
00281         {
00282         return false;
00283         }
00284       }
00285   };
00286   
00287 
00288 private:
00289 
00290   LabelType       m_NumberOfObjects;
00291   LabelType       m_NumberOfObjectsToPrint;
00292   LabelType       m_OriginalNumberOfObjects;
00293   ObjectSizeType  m_MinimumObjectSize;
00294 
00295   std::vector<ObjectSizeType> m_SizeOfObjectsInPixels;
00296   std::vector<float>          m_SizeOfObjectsInPhysicalUnits;
00297 
00298 };
00299   
00300 } // end namespace itk
00301 
00302 #ifndef ITK_MANUAL_INSTANTIATION
00303 #include "itkRelabelComponentImageFilter.txx"
00304 #endif
00305 
00306 #endif
00307 

Generated at Tue Sep 15 04:41:08 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000