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

itkListSample.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkListSample.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/02/26 23:20:32 $
00007   Version:   $Revision: 1.11 $
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 __itkListSample_h
00018 #define __itkListSample_h
00019 
00020 #include "itkObjectFactory.h"
00021 #include "itkMacro.h"
00022 #include "itkListSampleBase.h"
00023 #include "itkFixedArray.h"
00024 #include "itkSmartPointer.h"
00025 
00026 #include <vector>
00027 
00028 namespace itk{ 
00029 namespace Statistics{
00030 
00041 template< class TMeasurementVector >
00042 class ITK_EXPORT ListSample : public ListSampleBase< TMeasurementVector >
00043 {
00044 public:
00046   typedef ListSample  Self;
00047   typedef ListSampleBase< TMeasurementVector > Superclass;
00048   typedef SmartPointer< Self > Pointer;
00049 
00051   itkTypeMacro(ListSample, ListSampleBase);
00052 
00054   itkNewMacro(Self) ;
00055   
00060   typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
00061   typedef typename Superclass::MeasurementType MeasurementType;
00062   typedef typename Superclass::FrequencyType FrequencyType ;
00063   typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
00064 
00066   itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00067                       Superclass::MeasurementVectorSize);
00068 
00070   typedef std::vector< MeasurementVectorType > InternalDataContainerType ;
00071 
00076   void Resize( unsigned int n ) 
00077   { m_InternalContainer.resize(n) ; }
00078 
00080   void PushBack( MeasurementVectorType &mv )
00081   { m_InternalContainer.push_back( mv ) ; }
00082 
00084   unsigned int Size() const
00085   { return static_cast<unsigned int>( m_InternalContainer.size() ); }
00086 
00091   unsigned int Size(const unsigned int &) const
00092   { return static_cast<unsigned int>( m_InternalContainer.size() ); }
00093 
00095   unsigned int GetNumberOfInstances() const 
00096   { return static_cast<unsigned int>( m_InternalContainer.size() ); }
00097 
00100   MeasurementVectorType& GetMeasurementVector(const InstanceIdentifier &id) ;
00101 
00104   void SetMeasurement(const InstanceIdentifier &id, 
00105                       const unsigned int &dim,
00106                       const MeasurementType &value) ;
00107 
00110   void SetMeasurementVector(const InstanceIdentifier &id, 
00111                             const MeasurementVectorType &mv) ;
00112 
00114   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00115 
00117   FrequencyType GetTotalFrequency(const unsigned int &) const
00118   { return static_cast<FrequencyType>( m_InternalContainer.size() ); }
00119 
00121   class Iterator;
00122   friend class Iterator;
00123   
00125   Iterator Begin()
00126   { 
00127     Iterator iter(m_InternalContainer.begin(), 0);
00128     return iter; 
00129   }
00130   
00132   Iterator End()        
00133   {
00134     Iterator iter(m_InternalContainer.end(), m_InternalContainer.size()); 
00135     return iter; 
00136   }
00137   
00138   class Iterator
00139   {
00140   public:
00141     
00142     Iterator(){}
00143     
00144     Iterator(typename InternalDataContainerType::iterator iter, 
00145              InstanceIdentifier iid)
00146       :m_Iter(iter), m_InstanceIdentifier(iid)
00147     {}
00148     
00149     FrequencyType GetFrequency() const
00150     { return 1 ;}
00151 
00152     MeasurementVectorType& GetMeasurementVector()
00153     { return (MeasurementVectorType&) *m_Iter ;} 
00154 
00155     InstanceIdentifier GetInstanceIdentifier() const
00156     { return m_InstanceIdentifier() ;}
00157 
00158     Iterator& operator++()
00159     { ++m_Iter ; ++m_InstanceIdentifier ; return *this ;}
00160     
00161     Iterator& operator--()
00162     { 
00163       --m_Iter ; 
00164 
00165       if ( m_InstanceIdentifier > 1 )
00166         m_InstanceIdentifier; 
00167       
00168       return *this ;
00169     }
00170 
00171     bool operator!=(const Iterator &it)
00172     { return (m_Iter != it.m_Iter) ;}
00173     
00174     bool operator==(const Iterator &it)
00175     { return (m_Iter == it.m_Iter) ;}
00176     
00177     Iterator& operator = (const Iterator &iter)
00178     { 
00179       m_Iter = iter.m_Iter; 
00180       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00181       return iter ;
00182     }
00183 
00184     Iterator(const Iterator &iter)
00185     {
00186       m_Iter = iter.m_Iter; 
00187       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00188     }
00189     
00190   private:
00191     typename InternalDataContainerType::iterator m_Iter ;
00192     InstanceIdentifier m_InstanceIdentifier ;
00193   } ;
00194 
00195 protected:
00196   ListSample() ;
00197   virtual ~ListSample() {}
00198   void PrintSelf(std::ostream& os, Indent indent) const; 
00199   
00200 private:
00201   ListSample(const Self&) ; //purposely not implemented
00202   void operator=(const Self&) ; //purposely not implemented
00203 
00204   InternalDataContainerType m_InternalContainer ;
00205 };
00206 
00207 } // end of namespace Statistics 
00208 } // end of namespace itk 
00209 
00210 #ifndef ITK_MANUAL_INSTANTIATION
00211 #include "itkListSample.txx"
00212 #endif
00213 
00214 #endif

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