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

itkSubsample.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSubsample.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/08/17 17:57:22 $
00007   Version:   $Revision: 1.31 $
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 __itkSubsample_h
00018 #define __itkSubsample_h
00019 
00020 #include "itkSample.h"
00021 #include "itkMacro.h"
00022 #include "itkObjectFactory.h"
00023 
00024 namespace itk{ 
00025 namespace Statistics{
00026 
00037 template< class TSample >
00038 class ITK_EXPORT Subsample : 
00039     public Sample< typename TSample::MeasurementVectorType >
00040 {
00041 public:
00043   typedef Subsample Self;
00044   typedef Sample< typename TSample::MeasurementVectorType > Superclass ;
00045   typedef SmartPointer< Self > Pointer ;
00046   typedef SmartPointer<const Self> ConstPointer;
00047 
00049   itkTypeMacro(Subsample, Sample);
00050 
00052   itkNewMacro(Self) ;
00053 
00055   typedef typename TSample::Pointer SamplePointer ;
00056 
00059   typedef typename TSample::MeasurementVectorType MeasurementVectorType;
00060   typedef typename TSample::MeasurementType MeasurementType;
00061   typedef typename TSample::InstanceIdentifier InstanceIdentifier;
00062   typedef typename TSample::FrequencyType FrequencyType ;
00063   typedef typename TSample::TotalFrequencyType TotalFrequencyType ;
00064   typedef MeasurementVectorType ValueType ;
00065 
00070   typedef std::vector< InstanceIdentifier > InstanceIdentifierHolder ;
00071 
00073   void SetSample(const TSample* sample)
00074     { 
00075     m_Sample = sample ; 
00076     this->SetMeasurementVectorSize( m_Sample->GetMeasurementVectorSize() );
00077     }
00079 
00080   const TSample* GetSample() const
00081   { return m_Sample ; } 
00082 
00083 
00084   void InitializeWithAllInstances()
00085   {
00086     m_IdHolder.resize(m_Sample->Size()) ;
00087     typename InstanceIdentifierHolder::iterator idIter = m_IdHolder.begin() ;
00088     typename TSample::ConstIterator iter = m_Sample->Begin() ;
00089     typename TSample::ConstIterator last = m_Sample->End() ;
00090     m_TotalFrequency = NumericTraits< FrequencyType >::Zero ;
00091     while (iter != last)
00092       {
00093       *idIter++ = iter.GetInstanceIdentifier() ;
00094       m_TotalFrequency += iter.GetFrequency() ;
00095       ++iter ;
00096       }
00097   }
00098 
00099   void AddInstance(InstanceIdentifier id)
00100   { 
00101     m_IdHolder.push_back(id) ; 
00102     m_TotalFrequency += m_Sample->GetFrequency(id) ;
00103   }
00104 
00107   unsigned int Size() const
00108   { 
00109     return static_cast<unsigned int>( m_IdHolder.size() );
00110   }
00111 
00112   void Clear()
00113   { 
00114     m_IdHolder.clear() ;
00115     m_TotalFrequency = NumericTraits< FrequencyType >::Zero ;
00116   }
00117 
00120   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const
00121   { return m_Sample->GetMeasurementVector(id) ; }
00122 
00124   FrequencyType GetFrequency(const InstanceIdentifier &id) const
00125   { return m_Sample->GetFrequency(id) ; }
00126 
00128   TotalFrequencyType GetTotalFrequency() const
00129   { return m_TotalFrequency ; }
00130 
00131   void Swap(int index1, int index2) ;
00132   
00133   MeasurementVectorType GetMeasurementVectorByIndex(int index) const ;
00134 
00135   FrequencyType GetFrequencyByIndex(int index) const;
00136 
00137   InstanceIdentifier GetInstanceIdentifier(int index) const;
00138 
00139   class ConstIterator;
00140  
00141   class Iterator
00142   {
00143     friend class ConstIterator;
00144 
00145   public:
00146     Iterator(typename InstanceIdentifierHolder::iterator iter, 
00147              Self* classSample)
00148       :m_Iter(iter), m_Subsample(classSample),
00149        m_Sample(classSample->GetSample())
00150     {}
00151     
00152     FrequencyType GetFrequency() const
00153     { return  m_Sample->GetFrequency(*m_Iter) ; }
00154     
00155     const MeasurementVectorType & GetMeasurementVector() const
00156     { return m_Sample->GetMeasurementVector(*m_Iter) ; } 
00157     
00158     InstanceIdentifier GetInstanceIdentifier() const   
00159     { return *m_Iter ; }
00160     
00161     Iterator& operator++() 
00162     { 
00163       ++m_Iter ;
00164       return *this ;
00165     }
00166     
00167     //Iterator& operator+()
00168     //{ m_Iter += n; return *this ;}
00169 
00170     Iterator& operator+(int n)
00171     { m_Iter += n; return *this ;}
00172     
00173     Iterator& operator-(int n)
00174     { m_Iter -= n; return *this ;}
00175 
00176     bool operator!=(const Iterator& it) 
00177     { return (m_Iter != it.m_Iter) ; }
00178     
00179     bool operator==(const Iterator& it) 
00180     { return (m_Iter == it.m_Iter) ; }
00181     
00182     Iterator& operator=(const Iterator& iter)
00183     {
00184       m_Iter = iter.m_Iter;
00185       m_Subsample = iter.m_Subsample ;
00186       m_Sample = iter.m_Sample ;
00187       return *this ;
00188     }
00189 
00190     Iterator(const Iterator& iter)
00191     {
00192       m_Iter = iter.m_Iter;
00193       m_Subsample = iter.m_Subsample ;
00194       m_Sample = iter.m_Sample ;
00195     }
00196     
00197   private:
00198     // Iterator pointing to ImageToListAdaptor
00199     typename InstanceIdentifierHolder::iterator m_Iter ;  
00200     // Pointer to Subsample object
00201     Self* m_Subsample ;
00202     const TSample* m_Sample ;
00203   } ;
00204 
00205 
00206  
00207   class ConstIterator
00208   {
00209   public:
00210     ConstIterator(typename InstanceIdentifierHolder::const_iterator iter, 
00211              const Self* classSample)
00212       :m_Iter(iter), m_Subsample(classSample),
00213        m_Sample(classSample->GetSample())
00214     {}
00215     
00216     FrequencyType GetFrequency() const
00217     { return  m_Sample->GetFrequency(*m_Iter) ; }
00218     
00219     const MeasurementVectorType & GetMeasurementVector() const
00220     { return m_Sample->GetMeasurementVector(*m_Iter) ; } 
00221     
00222     InstanceIdentifier GetInstanceIdentifier() const   
00223     { return *m_Iter ; }
00224     
00225     ConstIterator& operator++() 
00226     { 
00227       ++m_Iter ;
00228       return *this ;
00229     }
00230     
00231     //ConstIterator& operator+()
00232     //{ m_Iter += n; return *this ;}
00233 
00234     ConstIterator& operator+(int n)
00235     { m_Iter += n; return *this ;}
00236     
00237     ConstIterator& operator-(int n)
00238     { m_Iter -= n; return *this ;}
00239 
00240     bool operator!=(const ConstIterator& it) 
00241     { return (m_Iter != it.m_Iter) ; }
00242     
00243     bool operator==(const ConstIterator& it) 
00244     { return (m_Iter == it.m_Iter) ; }
00245     
00246     ConstIterator& operator=(const ConstIterator& iter)
00247     {
00248       m_Iter = iter.m_Iter;
00249       m_Subsample = iter.m_Subsample ;
00250       m_Sample = iter.m_Sample ;
00251       return *this ;
00252     }
00253 
00254     ConstIterator& operator=(const Iterator& iter)
00255     {
00256       m_Iter = iter.m_Iter;
00257       m_Subsample = iter.m_Subsample ;
00258       m_Sample = iter.m_Sample ;
00259       return *this ;
00260     }
00261 
00262     ConstIterator(const ConstIterator& iter)
00263     {
00264       m_Iter = iter.m_Iter;
00265       m_Subsample = iter.m_Subsample ;
00266       m_Sample = iter.m_Sample ;
00267     }
00268 
00269     ConstIterator(const Iterator& iter)
00270     {
00271       m_Iter = iter.m_Iter;
00272       m_Subsample = iter.m_Subsample ;
00273       m_Sample = iter.m_Sample ;
00274     }
00275     
00276   private:
00277     // ConstIterator pointing to ImageToListAdaptor
00278     typename InstanceIdentifierHolder::const_iterator m_Iter ;  
00279     // Pointer to Subsample object
00280     const Self* m_Subsample ;
00281     const TSample* m_Sample ;
00282   } ;
00283 
00284 
00285 
00286   Iterator Begin()
00287   { 
00288     Iterator iter(m_IdHolder.begin(), this) ;
00289     return iter; 
00290   }
00291   
00292   Iterator  End()        
00293   {
00294     Iterator iter(m_IdHolder.end(), this) ; 
00295     return iter; 
00296   }
00297 
00298   ConstIterator Begin() const
00299   { 
00300     ConstIterator iter(m_IdHolder.begin(), this) ;
00301     return iter; 
00302   }
00303   
00304   ConstIterator  End()  const
00305   {
00306     ConstIterator iter(m_IdHolder.end(), this) ; 
00307     return iter; 
00308   }
00309  
00310 protected:
00311   Subsample() ;
00312   virtual ~Subsample() {}
00313   void PrintSelf(std::ostream& os, Indent indent) const;
00314   
00315 private:
00316   Subsample(const Self&) ; //purposely not implemented
00317   void operator=(const Self&) ; //purposely not implemented
00318 
00319   const TSample*              m_Sample ;
00320   InstanceIdentifierHolder    m_IdHolder ;
00321   unsigned int                m_ActiveDimension ;
00322   FrequencyType m_TotalFrequency ;
00323 } ; // end of class
00324 
00325 
00326 } // end of namespace Statistics 
00327 } // end of namespace itk
00328 
00329 
00330 #ifndef ITK_MANUAL_INSTANTIATION
00331 #include "itkSubsample.txx"
00332 #endif
00333 
00334 #endif
00335 
00336 
00337 
00338 
00339 
00340 
00341 
00342 

Generated at Tue Jul 29 22:42:09 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000