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: 2005/07/26 15:54:59 $
00007   Version:   $Revision: 1.24 $
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 __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 
00045 template< class TMeasurementVector >
00046 class ITK_EXPORT ListSample : public ListSampleBase< TMeasurementVector >
00047 {
00048 public:
00050   typedef ListSample  Self;
00051   typedef ListSampleBase< TMeasurementVector > Superclass;
00052   typedef SmartPointer< Self > Pointer;
00053   typedef SmartPointer<const Self> ConstPointer;
00054 
00056   itkTypeMacro(ListSample, ListSampleBase);
00057 
00059   itkNewMacro(Self) ;
00060   
00062   typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
00063   typedef typename Superclass::MeasurementType MeasurementType;
00064   typedef typename Superclass::FrequencyType FrequencyType ;
00065   typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
00066   typedef typename Superclass::SearchResultVectorType SearchResultVectorType ;
00067 
00070   typedef MeasurementVectorType ValueType ;
00071 
00072 
00074   typedef std::vector< MeasurementVectorType > InternalDataContainerType ;
00075 
00081   void Resize( unsigned int n ) 
00082   { m_InternalContainer.resize(n) ; }
00083 
00085   void Clear() 
00086   { m_InternalContainer.clear() ; }
00087 
00089   void PushBack( MeasurementVectorType mv )
00090   { m_InternalContainer.push_back( mv ) ; }
00091 
00093   unsigned int Size() const
00094   { return static_cast<unsigned int>( m_InternalContainer.size() ); }
00095 
00098   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00099 
00101   void SetMeasurement(const InstanceIdentifier &id, 
00102                       const unsigned int &dim,
00103                       const MeasurementType &value) ;
00104 
00106   void SetMeasurementVector(const InstanceIdentifier &id, 
00107                             const MeasurementVectorType &mv) ;
00108 
00111   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00112 
00115   FrequencyType GetTotalFrequency() const
00116   { return static_cast<FrequencyType>( m_InternalContainer.size() ); }
00117 
00118   class ConstIterator;
00119  
00120   class Iterator
00121   {
00122 
00123     friend class ConstIterator;
00124 
00125   public:
00126     
00127     Iterator(){}
00128     
00129     Iterator(typename InternalDataContainerType::iterator iter, 
00130              InstanceIdentifier iid)
00131       :m_Iter(iter), m_InstanceIdentifier(iid)
00132     {}
00133     
00134     FrequencyType GetFrequency() const
00135     { return 1 ;}
00136 
00137     const MeasurementVectorType & GetMeasurementVector() const
00138     { return (MeasurementVectorType&) *m_Iter ;} 
00139 
00140     InstanceIdentifier GetInstanceIdentifier() const
00141     { return m_InstanceIdentifier ;}
00142 
00143     Iterator& operator++()
00144     { ++m_Iter ; ++m_InstanceIdentifier ; return *this ;}
00145     
00146     Iterator& operator--()
00147     { 
00148       --m_Iter ; 
00149 
00150       if ( m_InstanceIdentifier > 1 )
00151         m_InstanceIdentifier; 
00152       
00153       return *this ;
00154     }
00155 
00156     bool operator!=(const Iterator &it)
00157     { return (m_Iter != it.m_Iter) ;}
00158     
00159     bool operator==(const Iterator &it)
00160     { return (m_Iter == it.m_Iter) ;}
00161     
00162     Iterator& operator = (const Iterator & iter)
00163     { 
00164       m_Iter = iter.m_Iter; 
00165       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00166       return *this ;
00167     }
00168 
00169     Iterator(const Iterator &iter)
00170     {
00171       m_Iter = iter.m_Iter; 
00172       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00173     }
00174     
00175   private:
00176     typename InternalDataContainerType::iterator m_Iter ;
00177     InstanceIdentifier m_InstanceIdentifier ;
00178   } ;
00179 
00180  
00181   class ConstIterator
00182   {
00183   public:
00184     
00185     ConstIterator(){}
00186     
00187     ConstIterator(typename InternalDataContainerType::const_iterator iter, 
00188              InstanceIdentifier iid)
00189       :m_Iter(iter), m_InstanceIdentifier(iid)
00190     {}
00191     
00192     FrequencyType GetFrequency() const
00193     { return 1 ;}
00194 
00195     const MeasurementVectorType & GetMeasurementVector() const
00196     { return (MeasurementVectorType&) *m_Iter ;} 
00197 
00198     InstanceIdentifier GetInstanceIdentifier() const
00199     { return m_InstanceIdentifier ;}
00200 
00201     ConstIterator& operator++()
00202     { ++m_Iter ; ++m_InstanceIdentifier ; return *this ;}
00203     
00204     ConstIterator& operator--()
00205     { 
00206       --m_Iter ; 
00207 
00208       if ( m_InstanceIdentifier > 1 )
00209         m_InstanceIdentifier; 
00210       
00211       return *this ;
00212     }
00213 
00214     bool operator!=(const ConstIterator &it)
00215     { return (m_Iter != it.m_Iter) ;}
00216     
00217     bool operator==(const ConstIterator &it)
00218     { return (m_Iter == it.m_Iter) ;}
00219     
00220     ConstIterator& operator = (const ConstIterator iter)
00221     { 
00222       m_Iter = iter.m_Iter; 
00223       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00224       return *this ;
00225     }
00226 
00227     ConstIterator& operator = (const Iterator & iter)
00228     { 
00229       m_Iter = iter.m_Iter; 
00230       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00231       return *this ;
00232     }
00233 
00234 
00235     ConstIterator(const ConstIterator &iter)
00236     {
00237       m_Iter = iter.m_Iter; 
00238       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00239     }
00240 
00241     ConstIterator(const Iterator &iter)
00242     {
00243       m_Iter = iter.m_Iter; 
00244       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00245     }
00246     
00247   private:
00248     typename InternalDataContainerType::const_iterator m_Iter ;
00249     InstanceIdentifier m_InstanceIdentifier ;
00250   } ;
00251 
00253   Iterator Begin()
00254   { 
00255     Iterator iter(m_InternalContainer.begin(), 0);
00256     return iter; 
00257   }
00258   
00260   Iterator End()        
00261   {
00262     Iterator iter(m_InternalContainer.end(), m_InternalContainer.size()); 
00263     return iter; 
00264   }
00265 
00267   ConstIterator Begin() const
00268   { 
00269     ConstIterator iter(m_InternalContainer.begin(), 0);
00270     return iter; 
00271   }
00272   
00274   ConstIterator End() const
00275   {
00276     ConstIterator iter(m_InternalContainer.end(), m_InternalContainer.size()); 
00277     return iter; 
00278   }
00279  
00280 protected:
00281   ListSample() ;
00282   virtual ~ListSample() {}
00283   void PrintSelf(std::ostream& os, Indent indent) const; 
00284   
00285 
00286 private:
00287   ListSample(const Self&) ; //purposely not implemented
00288   void operator=(const Self&) ; //purposely not implemented
00289 
00290   InternalDataContainerType m_InternalContainer ;
00291 
00292 };
00293 
00294 } // end of namespace Statistics 
00295 } // end of namespace itk 
00296 
00297 #ifndef ITK_MANUAL_INSTANTIATION
00298 #include "itkListSample.txx"
00299 #endif
00300 
00301 #endif

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