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/01/27 17:00:46 $
00007   Version:   $Revision: 1.16 $
00008 
00009   Copyright (c) 2002 Insight 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 
00028 namespace itk{ 
00029 namespace Statistics{
00030 
00060 template < class TImage >
00061 class ITK_EXPORT ImageToListAdaptor : 
00062     public ListSampleBase< typename TImage::PixelType >
00063 {
00064 public:
00066   typedef ImageToListAdaptor Self;
00067   typedef ListSampleBase< typename TImage::PixelType > Superclass;
00068   typedef SmartPointer< Self > Pointer;
00069   
00071   itkTypeMacro(ImageToListAdaptor, ListSampleBase) ;
00072   
00074   itkNewMacro(Self) ;
00075   
00077   typedef TImage ImageType;
00078   typedef typename ImageType::Pointer ImagePointer ;
00079   typedef typename ImageType::IndexType IndexType ;
00080   typedef typename ImageType::PixelType PixelType ;
00081   typedef typename ImageType::PixelContainerPointer PixelContainerPointer ;
00082   typedef typename ImageType::PixelContainer::ElementIdentifier 
00083   InstanceIdentifier;
00084   
00086   typedef ImageRegionIterator< ImageType > IteratorType ; 
00087   typedef PixelTraits< typename TImage::PixelType > PixelTraitsType ;
00088 
00090   itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00091                       PixelTraitsType::Dimension);
00092 
00095   typedef typename PixelTraitsType::ValueType MeasurementType ;
00096   typedef PixelType MeasurementVectorType;
00097   typedef MeasurementVectorType ValueType ;
00098   typedef typename Superclass::FrequencyType FrequencyType ;
00099 
00101   void SetImage(ImagePointer image) ;
00102 
00104   ImagePointer GetImage() ;
00105 
00107   unsigned int Size() const ;
00108 
00109   unsigned int Size(const unsigned int &dimension) const ;
00110 
00111   unsigned int GetNumberOfInstances() const ;
00112 
00113   void SetMeasurementVector(const InstanceIdentifier id,
00114                             const MeasurementVectorType &measurementVector) ;
00115   
00116   MeasurementVectorType& GetMeasurementVector(const InstanceIdentifier &id) ;
00117 
00118   void SetMeasurement(const InstanceIdentifier &id, 
00119                       const unsigned int &dim,
00120                       const MeasurementType &value) ;
00121 
00122   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00123 
00124   FrequencyType GetTotalFrequency(const unsigned int &dimension) const ;
00125 
00126   class Iterator;
00127   friend class Iterator;
00128   
00129   Iterator Begin()
00130   { 
00131     Iterator iter(0, this);
00132     return iter; 
00133   }
00134   
00135   Iterator End()        
00136   {
00137     Iterator iter(this->Size(), this); 
00138     return iter; 
00139   }
00140   
00141   class Iterator
00142   {
00143   public:
00144     
00145     Iterator(){}
00146     
00147     Iterator(InstanceIdentifier id, Pointer pContainer)
00148       :m_Id(id),m_Container(pContainer)
00149     {}
00150     
00151     FrequencyType GetFrequency() const
00152     { return 1 ;}
00153 
00154     MeasurementVectorType& GetMeasurementVector()
00155     { return m_Container->GetMeasurementVector(m_Id) ;} 
00156 
00157     InstanceIdentifier GetInstanceIdentifier() const
00158     { return m_Id ;}
00159 
00160     Iterator& operator++()
00161     { ++m_Id ; return *this ;}
00162     
00163     Iterator& operator+()
00164     { m_Id += n; return *this ;}
00165 
00166     Iterator& operator+(int n)
00167     { m_Id += n; return *this ;}
00168     
00169     Iterator& operator-(int n)
00170     { m_Id -= n; return *this ;}
00171 
00172     bool operator!=(const Iterator &it)
00173     {
00174       if (m_Id != it.m_Id)
00175         {return true ;}
00176 
00177       if (m_Container != it.m_Container)
00178         { return true ;}
00179 
00180       return false ;
00181     }
00182     
00183     bool operator==(const Iterator &it)
00184     { return !(*this != it);}
00185     
00186     Iterator& operator = (const Iterator &iter)
00187     { 
00188       m_Id = iter.m_Id; 
00189       m_Container = iter.m_Container ; 
00190       return *this ;
00191     }
00192 
00193     Iterator(const Iterator &iter)
00194     { 
00195       m_Id = iter.m_Id; 
00196       m_Container = iter.m_Container ; 
00197     }
00198     
00199   private:
00200     InstanceIdentifier m_Id;  // Current id 
00201     Pointer m_Container ;
00202   } ;
00203   
00204 protected:
00205   ImageToListAdaptor() {}
00206   virtual ~ImageToListAdaptor() {}
00207   void PrintSelf(std::ostream& os, Indent indent) const;  
00208 
00209 private:
00210   ImageToListAdaptor(const Self&) ; //purposely not implemented
00211   void operator=(const Self&) ; //purposely not implemented
00212 
00213   ImagePointer m_Image ;
00214   PixelContainerPointer m_PixelContainer ;
00215 } ; // end of class ImageToListAdaptor
00216 
00217 } // end of namespace Statistics
00218 } // end of namespace itk
00219 
00220 #ifndef ITK_MANUAL_INSTANTIATION
00221 #include "itkImageToListAdaptor.txx"
00222 #endif
00223 
00224 #endif

Generated at Fri May 21 01:14:56 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000