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: 2007-10-05 10:31:58 $
00007   Version:   $Revision: 1.14 $
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 
00130   itkGetMacro(NumberOfObjects, unsigned long);
00131 
00137   itkGetMacro(OriginalNumberOfObjects, unsigned long);
00138 
00141   itkSetMacro(NumberOfObjectsToPrint, unsigned long);
00142   itkGetConstReferenceMacro(NumberOfObjectsToPrint, unsigned long);
00144 
00151   itkSetMacro(MinimumObjectSize, unsigned long);
00152 
00158   itkGetMacro(MinimumObjectSize, unsigned long);
00159 
00165   const std::vector<unsigned long>& GetSizeOfObjectsInPixels() const
00166     { return m_SizeOfObjectsInPixels; }
00167 
00173   const std::vector<float>& GetSizeOfObjectsInPhysicalUnits() const
00174     { return m_SizeOfObjectsInPhysicalUnits; }
00175 
00179   unsigned long GetSizeOfObjectInPixels(unsigned long obj) const
00180     {
00181       if (obj > 0 && obj <= m_NumberOfObjects)
00182         {
00183         return m_SizeOfObjectsInPixels[obj-1];
00184         }
00185       else
00186         {
00187         return 0;
00188         }
00189     }
00191 
00195   float GetSizeOfObjectInPhysicalUnits(unsigned long obj) const
00196     { 
00197       if (obj > 0 && obj <= m_NumberOfObjects)
00198         {
00199         return m_SizeOfObjectsInPhysicalUnits[obj-1];
00200         }
00201       else
00202         {
00203         return 0;
00204         }
00205     }
00207 
00208 #ifdef ITK_USE_CONCEPT_CHECKING
00209 
00210   itkConceptMacro(InputEqualityComparableCheck,
00211     (Concept::EqualityComparable<InputPixelType>));
00212   itkConceptMacro(UnsignedLongConvertibleToInputCheck,
00213     (Concept::Convertible<unsigned long, InputPixelType>));
00214   itkConceptMacro(OutputLongConvertibleToUnsignedLongCheck,
00215     (Concept::Convertible<OutputPixelType, unsigned long>));
00216   itkConceptMacro(InputConvertibleToOutputCheck,
00217     (Concept::Convertible<InputPixelType, OutputPixelType>));
00218   itkConceptMacro(SameDimensionCheck,
00219     (Concept::SameDimension<InputImageDimension, ImageDimension>));
00220 
00222 #endif
00223 
00224 protected:
00225 
00226   RelabelComponentImageFilter()
00227     : m_NumberOfObjects(0), m_NumberOfObjectsToPrint(10),
00228     m_OriginalNumberOfObjects(0), m_MinimumObjectSize(0)
00229     { this->InPlaceOff(); }
00230   virtual ~RelabelComponentImageFilter() {}
00231   RelabelComponentImageFilter(const Self&) {}
00232 
00236   void GenerateData();
00237 
00241   void GenerateInputRequestedRegion();
00242 
00244   void PrintSelf(std::ostream& os, Indent indent) const;
00245 
00246   struct RelabelComponentObjectType
00247   {
00248     unsigned long m_ObjectNumber;
00249     unsigned long m_SizeInPixels;
00250     float m_SizeInPhysicalUnits;
00251   };
00252 
00253   // put the function objects here for sorting in descending order
00254   class RelabelComponentSizeInPixelsComparator
00255   {
00256   public:
00257     bool operator()(const RelabelComponentObjectType&a, 
00258                     const RelabelComponentObjectType &b)
00259       {
00260         if (a.m_SizeInPixels > b.m_SizeInPixels)
00261           {
00262           return true;
00263           }
00264         else if (a.m_SizeInPixels < b.m_SizeInPixels)
00265           {
00266           return false;
00267           }
00268         // size in pixels and physical units are the same, sort based on
00269         // original object number
00270         else if (a.m_ObjectNumber < b.m_ObjectNumber)
00271           {
00272           return true;
00273           }
00274         else
00275           {
00276           return false;
00277           }
00278       }
00279   };
00280 
00281 
00282 private:
00283 
00284   unsigned long m_NumberOfObjects;
00285   unsigned long m_NumberOfObjectsToPrint;
00286   unsigned long m_OriginalNumberOfObjects;
00287   unsigned long m_MinimumObjectSize;
00288   std::vector<unsigned long> m_SizeOfObjectsInPixels;
00289   std::vector<float> m_SizeOfObjectsInPhysicalUnits;
00290 
00291 };
00292   
00293 } // end namespace itk
00294 
00295 #ifndef ITK_MANUAL_INSTANTIATION
00296 #include "itkRelabelComponentImageFilter.txx"
00297 #endif
00298 
00299 #endif
00300 

Generated at Mon Apr 14 14:16:24 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000