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: 2007/02/16 14:53:28 $
00007   Version:   $Revision: 1.29 $
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::MeasurementVectorSizeType MeasurementVectorSizeType;
00064   typedef typename Superclass::MeasurementType MeasurementType;
00065   typedef typename Superclass::FrequencyType FrequencyType ;
00066   typedef typename Superclass::TotalFrequencyType TotalFrequencyType ;
00067   typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
00068   typedef typename Superclass::SearchResultVectorType SearchResultVectorType ;
00069 
00072   typedef MeasurementVectorType ValueType ;
00073 
00074 
00076   typedef std::vector< MeasurementVectorType > InternalDataContainerType ;
00077 
00083   void Resize( unsigned int n ) 
00084   { m_InternalContainer.resize(n) ; }
00085 
00087   void Clear() 
00088   { m_InternalContainer.clear() ; }
00089 
00091   void PushBack( MeasurementVectorType mv )
00092   { m_InternalContainer.push_back( mv ) ; }
00093 
00095   unsigned int Size() const
00096   { return static_cast<unsigned int>( m_InternalContainer.size() ); }
00097 
00100   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00101 
00103   void SetMeasurement(const InstanceIdentifier &id, 
00104                       const unsigned int &dim,
00105                       const MeasurementType &value) ;
00106 
00108   void SetMeasurementVector(const InstanceIdentifier &id, 
00109                             const MeasurementVectorType &mv) ;
00110 
00113   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00114 
00117   TotalFrequencyType GetTotalFrequency() const
00118   { return static_cast<TotalFrequencyType>( m_InternalContainer.size() ); }
00119 
00120   class ConstIterator;
00121  
00122   class Iterator
00123   {
00124 
00125     friend class ConstIterator;
00126 
00127   public:
00128     
00129     Iterator(){}
00130     
00131     Iterator(typename InternalDataContainerType::iterator iter, 
00132              InstanceIdentifier iid)
00133       :m_Iter(iter), m_InstanceIdentifier(iid)
00134     {}
00135     
00136     FrequencyType GetFrequency() const
00137     { return 1 ;}
00138 
00139     const MeasurementVectorType & GetMeasurementVector() const
00140     { return (MeasurementVectorType&) *m_Iter ;} 
00141 
00142     InstanceIdentifier GetInstanceIdentifier() const
00143     { return m_InstanceIdentifier ;}
00144 
00145     Iterator& operator++()
00146     { 
00147       ++m_Iter; 
00148       ++m_InstanceIdentifier; 
00149       return *this;
00150     }
00151     
00152     Iterator& operator--()
00153     { 
00154       --m_Iter ; 
00155       --m_InstanceIdentifier;
00156       return *this ;
00157     }
00158 
00159     bool operator!=(const Iterator &it)
00160     { 
00161       return (m_Iter != it.m_Iter);
00162     }
00163     
00164     bool operator==(const Iterator &it)
00165     { 
00166       return (m_Iter == it.m_Iter);
00167     }
00168     
00169     Iterator& operator =(const Iterator & iter)
00170     { 
00171       m_Iter = iter.m_Iter; 
00172       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00173       return *this ;
00174     }
00175 
00176     Iterator(const Iterator &iter)
00177     {
00178       m_Iter = iter.m_Iter; 
00179       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00180     }
00181     
00182   private:
00183     typename InternalDataContainerType::iterator m_Iter ;
00184     InstanceIdentifier m_InstanceIdentifier ;
00185   } ;
00186 
00187  
00188   class ConstIterator
00189   {
00190   public:
00191     
00192     ConstIterator(){}
00193     
00194     ConstIterator(typename InternalDataContainerType::const_iterator iter, 
00195              InstanceIdentifier iid)
00196       :m_Iter(iter), m_InstanceIdentifier(iid)
00197     {}
00198     
00199     FrequencyType GetFrequency() const
00200     { return 1 ;}
00201 
00202     const MeasurementVectorType & GetMeasurementVector() const
00203     { return static_cast<const MeasurementVectorType&>(*m_Iter) ;} 
00204 
00205     InstanceIdentifier GetInstanceIdentifier() const
00206     { return m_InstanceIdentifier ;}
00207 
00208     ConstIterator& operator++()
00209     { 
00210       ++m_Iter; 
00211       ++m_InstanceIdentifier; 
00212       return *this;
00213     }
00214     
00215     ConstIterator& operator--()
00216     { 
00217       --m_Iter; 
00218       --m_InstanceIdentifier; 
00219       return *this ;
00220     }
00221 
00222     bool operator!=(const ConstIterator &it)
00223     { 
00224       return (m_Iter != it.m_Iter);
00225     }
00226     
00227     bool operator==(const ConstIterator &it)
00228     { 
00229       return (m_Iter == it.m_Iter);
00230     }
00231     
00232     ConstIterator& operator = (const ConstIterator iter)
00233     { 
00234       m_Iter = iter.m_Iter; 
00235       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00236       return *this ;
00237     }
00238 
00239     ConstIterator& operator = (const Iterator & iter)
00240     { 
00241       m_Iter = iter.m_Iter; 
00242       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00243       return *this ;
00244     }
00245 
00246 
00247     ConstIterator(const ConstIterator &iter)
00248     {
00249       m_Iter = iter.m_Iter; 
00250       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00251     }
00252 
00253     ConstIterator(const Iterator &iter)
00254     {
00255       m_Iter = iter.m_Iter; 
00256       m_InstanceIdentifier = iter.m_InstanceIdentifier ;
00257     }
00258     
00259   private:
00260     typename InternalDataContainerType::const_iterator m_Iter ;
00261     InstanceIdentifier m_InstanceIdentifier ;
00262   } ;
00263 
00265   Iterator Begin()
00266   { 
00267     Iterator iter(m_InternalContainer.begin(), 0);
00268     return iter; 
00269   }
00271 
00273   Iterator End()        
00274   {
00275     Iterator iter(m_InternalContainer.end(), m_InternalContainer.size()); 
00276     return iter; 
00277   }
00279 
00281   ConstIterator Begin() const
00282   { 
00283     ConstIterator iter(m_InternalContainer.begin(), 0);
00284     return iter; 
00285   }
00287 
00289   ConstIterator End() const
00290   {
00291     ConstIterator iter(m_InternalContainer.end(), m_InternalContainer.size()); 
00292     return iter; 
00293   }
00295 
00296   virtual MeasurementVectorSizeType GetMeasurementVectorSize() const
00297     {
00298     if ( !this->Superclass::GetMeasurementVectorSize() && this->Size())
00299       { // determined from the length of the first vector in the sample
00300         // at run time
00301       return MeasurementVectorTraits::GetLength(this->GetMeasurementVector(0));
00302       }
00303     return this->Superclass::GetMeasurementVectorSize();
00304     }
00305  
00306 protected:
00307   ListSample() ;
00308   virtual ~ListSample() {}
00309   void PrintSelf(std::ostream& os, Indent indent) const; 
00310   
00311 
00312 private:
00313   ListSample(const Self&) ; //purposely not implemented
00314   void operator=(const Self&) ; //purposely not implemented
00315 
00316   InternalDataContainerType m_InternalContainer ;
00317 
00318 };
00319 
00320 } // end of namespace Statistics 
00321 } // end of namespace itk 
00322 
00323 #ifndef ITK_MANUAL_INSTANTIATION
00324 #include "itkListSample.txx"
00325 #endif
00326 
00327 #endif
00328 

Generated at Sun Sep 23 13:26:08 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000