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: 2005/07/28 18:25:25 $
00007   Version:   $Revision: 1.34 $
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   typedef SmartPointer<const Self> ConstPointer;
00074   
00076   itkTypeMacro(ImageToListAdaptor, ListSampleBase) ;
00077   
00079   itkNewMacro(Self) ;
00080   
00082   typedef TImage ImageType;
00083   typedef typename ImageType::Pointer ImagePointer ;
00084   typedef typename ImageType::ConstPointer ImageConstPointer ;
00085   typedef typename ImageType::IndexType IndexType ;
00086   typedef typename ImageType::PixelType PixelType ;
00087   typedef typename ImageType::PixelContainerConstPointer PixelContainerConstPointer ;
00088   typedef typename ImageType::PixelContainer::ElementIdentifier 
00089   InstanceIdentifier;
00090   
00092   typedef ImageRegionIterator< ImageType > IteratorType ; 
00093   typedef PixelTraits< typename TImage::PixelType > PixelTraitsType ;
00094 
00097   typedef typename PixelTraitsType::ValueType MeasurementType ;
00098   typedef typename Superclass::FrequencyType FrequencyType ;
00099   typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00100 
00102   itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00103                       PixelTraitsType::Dimension);
00104   
00105   virtual void SetMeasurementVectorSize( const MeasurementVectorSizeType s )
00106     {
00107     // Measurement vector size for this class is fixed as the pixel's 
00108     // dimension. This method should throw an exception if the user tries to 
00109     // set the dimension to a different value. 
00110     if( s != MeasurementVectorSize )
00111       {
00112       itkExceptionMacro( << "Measurement vector size for the image adaptor obtained"
00113           << " from the pixel dimension is: " << MeasurementVectorSize << " but you "
00114           << "are setting it to " << s);
00115       }
00116     }
00117 
00118  unsigned int GetMeasurementVectorSize() const 
00119    {
00120    return MeasurementVectorSize;
00121    } 
00122     
00123   
00124 
00125   typedef TMeasurementVector MeasurementVectorType ;
00126   typedef MeasurementVectorType ValueType ;
00127 
00129   void SetImage(const TImage* image) ;
00130 
00132   const TImage* GetImage() const;
00133 
00135   unsigned int Size() const ;
00136 
00137   inline virtual const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00138 
00139   inline FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00140 
00141   FrequencyType GetTotalFrequency() const ;
00142   
00143  
00144   class Iterator
00145   {
00146   public:
00147     
00148     Iterator(){}
00149     
00150     Iterator(InstanceIdentifier id, Pointer pContainer)
00151       :m_Id(id),m_Container(pContainer)
00152     {}
00153     
00154     FrequencyType GetFrequency() const
00155     { return 1 ;}
00156 
00157     const MeasurementVectorType & GetMeasurementVector() const
00158     { return m_Container->GetMeasurementVector(m_Id) ;} 
00159 
00160     InstanceIdentifier GetInstanceIdentifier() const
00161     { return m_Id ;}
00162 
00163     Iterator& operator++()
00164     { ++m_Id ; return *this ;}
00165     
00166     /*Iterator& operator+()
00167     { m_Id += n; return *this ;}*/
00168 
00169     Iterator& operator+(int n)
00170     { m_Id += n; return *this ;}
00171     
00172     Iterator& operator-(int n)
00173     { m_Id -= n; return *this ;}
00174 
00175     bool operator!=(const Iterator &it)
00176     {
00177       if (m_Id != it.m_Id)
00178         {return true ;}
00179 
00180       if (m_Container != it.m_Container)
00181         { return true ;}
00182 
00183       return false ;
00184     }
00185     
00186     bool operator==(const Iterator &it)
00187     { return !(*this != it);}
00188     
00189     Iterator& operator = (const Iterator &iter)
00190     { 
00191       m_Id = iter.m_Id; 
00192       m_Container = iter.m_Container ; 
00193       return *this ;
00194     }
00195 
00196     Iterator(const Iterator &iter)
00197     { 
00198       m_Id = iter.m_Id; 
00199       m_Container = iter.m_Container ; 
00200     }
00201     
00202   private:
00203     InstanceIdentifier m_Id;  // Current id 
00204     Pointer m_Container ;
00205   } ;
00206 
00207 
00208   class ConstIterator
00209   {
00210   public:
00211     
00212     ConstIterator(){}
00213     
00214     ConstIterator(InstanceIdentifier id, ConstPointer pContainer)
00215       :m_Id(id),m_Container(pContainer)
00216     {}
00217     
00218     FrequencyType GetFrequency() const
00219     { return 1 ;}
00220 
00221     const MeasurementVectorType & GetMeasurementVector() const
00222     { return m_Container->GetMeasurementVector(m_Id) ;} 
00223 
00224     InstanceIdentifier GetInstanceIdentifier() const
00225     { return m_Id ;}
00226 
00227     ConstIterator& operator++()
00228     { ++m_Id ; return *this ;}
00229     
00230     /*ConstIterator& operator+()
00231     { m_Id += n; return *this ;}*/
00232 
00233     ConstIterator& operator+(int n)
00234     { m_Id += n; return *this ;}
00235     
00236     ConstIterator& operator-(int n)
00237     { m_Id -= n; return *this ;}
00238 
00239     bool operator!=(const ConstIterator &it)
00240     {
00241       if (m_Id != it.m_Id)
00242         {return true ;}
00243 
00244       if (m_Container != it.m_Container)
00245         { return true ;}
00246 
00247       return false ;
00248     }
00249     
00250     bool operator==(const ConstIterator &it)
00251     { return !(*this != it);}
00252     
00253     ConstIterator& operator = (const ConstIterator &iter)
00254     { 
00255       m_Id = iter.m_Id; 
00256       m_Container = iter.m_Container ; 
00257       return *this ;
00258     }
00259 
00260     ConstIterator(const ConstIterator &iter)
00261     { 
00262       m_Id = iter.m_Id; 
00263       m_Container = iter.m_Container ; 
00264     }
00265     
00266   private:
00267     InstanceIdentifier m_Id;  // Current id 
00268     ConstPointer m_Container ;
00269   } ;
00270 
00271 
00272 
00273   Iterator Begin()
00274   { 
00275     Iterator iter(0, this);
00276     return iter; 
00277   }
00278   
00279   Iterator End()        
00280   {
00281     Iterator iter(this->Size(), this); 
00282     return iter; 
00283   }
00284 
00285   ConstIterator Begin() const
00286   { 
00287     ConstIterator iter(0, this);
00288     return iter; 
00289   }
00290   
00291   ConstIterator End() const
00292   {
00293     ConstIterator iter(this->Size(), this); 
00294     return iter; 
00295   }
00296  
00297 protected:
00298   ImageToListAdaptor() ;
00299   virtual ~ImageToListAdaptor() {}
00300   void PrintSelf(std::ostream& os, Indent indent) const;  
00301 
00302   itkGetConstReferenceMacro(PixelContainer,PixelContainerConstPointer);
00303   itkGetConstReferenceMacro(UseBuffer,bool);
00304   itkGetConstReferenceMacro(ImageBeginIndex,IndexType);
00305   itkGetConstReferenceMacro(ImageEndIndex,IndexType);
00306 
00307 
00308 private:
00309   ImageToListAdaptor(const Self&) ; //purposely not implemented
00310   void operator=(const Self&) ; //purposely not implemented
00311 
00312   PixelContainerConstPointer m_PixelContainer ;
00313   bool m_UseBuffer ;
00314   IndexType m_ImageBeginIndex ;
00315   IndexType m_ImageEndIndex ;
00316 
00317   ImageConstPointer m_Image ;
00318 } ; // end of class ImageToListAdaptor
00319 
00320 } // end of namespace Statistics
00321 } // end of namespace itk
00322 
00323 #ifndef ITK_MANUAL_INSTANTIATION
00324 #include "itkImageToListAdaptor.txx"
00325 #endif
00326 
00327 #endif

Generated at Tue Aug 30 16:44:45 2005 for ITK by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2000