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: 2006/03/22 16:26:44 $
00007   Version:   $Revision: 1.13 $
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 
00071 template <class TInputImage, class TOutputImage>
00072 class ITK_EXPORT RelabelComponentImageFilter : 
00073     public InPlaceImageFilter< TInputImage, TOutputImage > 
00074 {
00075 public:
00079   typedef RelabelComponentImageFilter Self;
00080   typedef InPlaceImageFilter< TInputImage, TOutputImage > Superclass;
00081 
00085   typedef typename Superclass::InputImagePointer InputImagePointer;
00086 
00091   typedef typename TOutputImage::PixelType OutputPixelType;
00092   typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
00093   typedef typename TInputImage::PixelType InputPixelType;
00094   typedef typename TInputImage::InternalPixelType InputInternalPixelType;
00095   itkStaticConstMacro(ImageDimension, unsigned int,
00096                       TOutputImage::ImageDimension); 
00097   itkStaticConstMacro(InputImageDimension, unsigned int,
00098                       TInputImage::ImageDimension);
00100 
00104   typedef TInputImage  InputImageType;
00105   typedef TOutputImage OutputImageType;
00106   typedef   typename TInputImage::IndexType       IndexType;
00107   typedef   typename TInputImage::SizeType        SizeType;
00108   typedef   typename TOutputImage::RegionType     RegionType;
00109 
00113   typedef SmartPointer<Self> Pointer;
00114   typedef SmartPointer<const Self>  ConstPointer;
00115 
00119   itkTypeMacro(RelabelComponentImageFilter, ImageToImageFilter);
00120 
00124   itkNewMacro(Self);
00125 
00128   itkGetMacro(NumberOfObjects, unsigned long);
00129 
00135   itkGetMacro(OriginalNumberOfObjects, unsigned long);
00136 
00139   itkSetMacro(NumberOfObjectsToPrint, unsigned long);
00140   itkGetConstReferenceMacro(NumberOfObjectsToPrint, unsigned long);
00142 
00149   itkSetMacro(MinimumObjectSize, unsigned long);
00150 
00156   itkGetMacro(MinimumObjectSize, unsigned long);
00157 
00163   const std::vector<unsigned long>& GetSizeOfObjectsInPixels() const
00164     { return m_SizeOfObjectsInPixels; }
00165 
00171   const std::vector<float>& GetSizeOfObjectsInPhysicalUnits() const
00172     { return m_SizeOfObjectsInPhysicalUnits; }
00173 
00177   unsigned long GetSizeOfObjectInPixels(unsigned long obj) const
00178     {
00179       if (obj > 0 && obj <= m_NumberOfObjects)
00180         {
00181         return m_SizeOfObjectsInPixels[obj-1];
00182         }
00183       else
00184         {
00185         return 0;
00186         }
00187     }
00189 
00193   float GetSizeOfObjectInPhysicalUnits(unsigned long obj) const
00194     { 
00195       if (obj > 0 && obj <= m_NumberOfObjects)
00196         {
00197         return m_SizeOfObjectsInPhysicalUnits[obj-1];
00198         }
00199       else
00200         {
00201         return 0;
00202         }
00203     }
00205 
00206 #ifdef ITK_USE_CONCEPT_CHECKING
00207 
00208   itkConceptMacro(InputEqualityComparableCheck,
00209     (Concept::EqualityComparable<InputPixelType>));
00210   itkConceptMacro(UnsignedLongConvertibleToInputCheck,
00211     (Concept::Convertible<unsigned long, InputPixelType>));
00212   itkConceptMacro(OutputLongConvertibleToUnsignedLongCheck,
00213     (Concept::Convertible<OutputPixelType, unsigned long>));
00214   itkConceptMacro(InputConvertibleToOutputCheck,
00215     (Concept::Convertible<InputPixelType, OutputPixelType>));
00216   itkConceptMacro(SameDimensionCheck,
00217     (Concept::SameDimension<InputImageDimension, ImageDimension>));
00218 
00220 #endif
00221 
00222 protected:
00223 
00224   RelabelComponentImageFilter()
00225     : m_NumberOfObjects(0), m_NumberOfObjectsToPrint(10),
00226     m_OriginalNumberOfObjects(0), m_MinimumObjectSize(0)
00227     { this->InPlaceOff(); }
00228   virtual ~RelabelComponentImageFilter() {}
00229   RelabelComponentImageFilter(const Self&) {}
00230 
00234   void GenerateData();
00235 
00239   void GenerateInputRequestedRegion();
00240 
00242   void PrintSelf(std::ostream& os, Indent indent) const;
00243 
00244   struct RelabelComponentObjectType
00245   {
00246     unsigned long m_ObjectNumber;
00247     unsigned long m_SizeInPixels;
00248     float m_SizeInPhysicalUnits;
00249   };
00250 
00251   // put the function objects here for sorting in descending order
00252   class RelabelComponentSizeInPixelsComparator
00253   {
00254   public:
00255     bool operator()(const RelabelComponentObjectType&a, 
00256                     const RelabelComponentObjectType &b)
00257       {
00258         if (a.m_SizeInPixels > b.m_SizeInPixels)
00259           {
00260           return true;
00261           }
00262         else if (a.m_SizeInPixels < b.m_SizeInPixels)
00263           {
00264           return false;
00265           }
00266         // size in pixels and physical units are the same, sort based on
00267         // original object number
00268         else if (a.m_ObjectNumber < b.m_ObjectNumber)
00269           {
00270           return true;
00271           }
00272         else
00273           {
00274           return false;
00275           }
00276       }
00277   };
00278 
00279 
00280 private:
00281 
00282   unsigned long m_NumberOfObjects;
00283   unsigned long m_NumberOfObjectsToPrint;
00284   unsigned long m_OriginalNumberOfObjects;
00285   unsigned long m_MinimumObjectSize;
00286   std::vector<unsigned long> m_SizeOfObjectsInPixels;
00287   std::vector<float> m_SizeOfObjectsInPhysicalUnits;
00288 
00289 };
00290   
00291 } // end namespace itk
00292 
00293 #ifndef ITK_MANUAL_INSTANTIATION
00294 #include "itkRelabelComponentImageFilter.txx"
00295 #endif
00296 
00297 #endif
00298 

Generated at Sun Sep 23 14:07:27 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000