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

itkImageToListAdaptor.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageToListAdaptor.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:29:45 $
00007   Version:   $Revision: 1.23 $
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 __itkImageToListAdaptor_h
00018 #define __itkImageToListAdaptor_h
00019 
00020 #include <typeinfo>
00021 
00022 #include "itkImage.h"
00023 #include "itkPixelTraits.h"
00024 #include "itkListSampleBase.h"
00025 #include "itkSmartPointer.h"
00026 #include "itkImageRegionIterator.h"
00027 #include "itkFixedArray.h"
00028 #include "itkMacro.h"
00029 
00030 namespace itk{ 
00031 namespace Statistics{
00032 
00062 template < class TImage,
00063            class TMeasurementVector = 
00064            ITK_TYPENAME TImage::PixelType >
00065 class ITK_EXPORT ImageToListAdaptor : 
00066     public ListSampleBase< TMeasurementVector >
00067 {
00068 public:
00070   typedef ImageToListAdaptor Self;
00071   typedef ListSampleBase< TMeasurementVector > Superclass;
00072   typedef SmartPointer< Self > Pointer;
00073   
00075   itkTypeMacro(ImageToListAdaptor, ListSampleBase) ;
00076   
00078   itkNewMacro(Self) ;
00079   
00081   typedef TImage ImageType;
00082   typedef typename ImageType::Pointer ImagePointer ;
00083   typedef typename ImageType::IndexType IndexType ;
00084   typedef typename ImageType::PixelType PixelType ;
00085   typedef typename ImageType::PixelContainerPointer PixelContainerPointer ;
00086   typedef typename ImageType::PixelContainer::ElementIdentifier 
00087   InstanceIdentifier;
00088   
00090   typedef ImageRegionIterator< ImageType > IteratorType ; 
00091   typedef PixelTraits< typename TImage::PixelType > PixelTraitsType ;
00092 
00094   itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00095                       PixelTraitsType::Dimension);
00096 
00099   typedef typename PixelTraitsType::ValueType MeasurementType ;
00100   typedef typename Superclass::FrequencyType FrequencyType ;
00101 
00102   typedef TMeasurementVector MeasurementVectorType ;
00103   typedef MeasurementVectorType ValueType ;
00104 
00106   void SetImage(TImage* image) ;
00107 
00109   TImage* GetImage() ;
00110 
00112   unsigned int Size() const ;
00113 
00114   inline virtual MeasurementVectorType GetMeasurementVector(const InstanceIdentifier &id) ;
00115 
00116   inline FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00117 
00118   FrequencyType GetTotalFrequency() const ;
00119 
00120   class Iterator;
00121   friend class Iterator;
00122   
00123   Iterator Begin()
00124   { 
00125     Iterator iter(0, this);
00126     return iter; 
00127   }
00128   
00129   Iterator End()        
00130   {
00131     Iterator iter(this->Size(), this); 
00132     return iter; 
00133   }
00134   
00135   class Iterator
00136   {
00137   public:
00138     
00139     Iterator(){}
00140     
00141     Iterator(InstanceIdentifier id, Pointer pContainer)
00142       :m_Id(id),m_Container(pContainer)
00143     {}
00144     
00145     FrequencyType GetFrequency() const
00146     { return 1 ;}
00147 
00148     MeasurementVectorType GetMeasurementVector()
00149     { return m_Container->GetMeasurementVector(m_Id) ;} 
00150 
00151     InstanceIdentifier GetInstanceIdentifier() const
00152     { return m_Id ;}
00153 
00154     Iterator& operator++()
00155     { ++m_Id ; return *this ;}
00156     
00157     Iterator& operator+()
00158     { m_Id += n; return *this ;}
00159 
00160     Iterator& operator+(int n)
00161     { m_Id += n; return *this ;}
00162     
00163     Iterator& operator-(int n)
00164     { m_Id -= n; return *this ;}
00165 
00166     bool operator!=(const Iterator &it)
00167     {
00168       if (m_Id != it.m_Id)
00169         {return true ;}
00170 
00171       if (m_Container != it.m_Container)
00172         { return true ;}
00173 
00174       return false ;
00175     }
00176     
00177     bool operator==(const Iterator &it)
00178     { return !(*this != it);}
00179     
00180     Iterator& operator = (const Iterator &iter)
00181     { 
00182       m_Id = iter.m_Id; 
00183       m_Container = iter.m_Container ; 
00184       return *this ;
00185     }
00186 
00187     Iterator(const Iterator &iter)
00188     { 
00189       m_Id = iter.m_Id; 
00190       m_Container = iter.m_Container ; 
00191     }
00192     
00193   private:
00194     InstanceIdentifier m_Id;  // Current id 
00195     Pointer m_Container ;
00196   } ;
00197   
00198 protected:
00199   ImageToListAdaptor() ;
00200   virtual ~ImageToListAdaptor() {}
00201   void PrintSelf(std::ostream& os, Indent indent) const;  
00202 
00203   PixelContainerPointer m_PixelContainer ;
00204   bool m_UseBuffer ;
00205   typename TImage::IndexType m_ImageBeginIndex ;
00206   typename TImage::IndexType m_ImageEndIndex ;
00207 
00208 private:
00209   ImageToListAdaptor(const Self&) ; //purposely not implemented
00210   void operator=(const Self&) ; //purposely not implemented
00211 
00212   ImagePointer m_Image ;
00213 } ; // end of class ImageToListAdaptor
00214 
00215 } // end of namespace Statistics
00216 } // end of namespace itk
00217 
00218 #ifndef ITK_MANUAL_INSTANTIATION
00219 #include "itkImageToListAdaptor.txx"
00220 #endif
00221 
00222 #endif

Generated at Tue Sep 16 11:32:01 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000