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

Review/Statistics/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: 2010-01-21 22:03:39 $
00007   Version:   $Revision: 1.4 $
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 TSample
00040 {
00041 public:
00043   typedef Subsample                                         Self;
00044   typedef TSample                                           Superclass;
00045   typedef SmartPointer< Self >                              Pointer;
00046   typedef SmartPointer<const Self>                          ConstPointer;
00047 
00049   itkTypeMacro(Subsample, TSample);
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 MeasurementVectorType                   ValueType;
00063 
00064   typedef typename TSample::AbsoluteFrequencyType         AbsoluteFrequencyType;
00065   typedef typename TSample::TotalAbsoluteFrequencyType    TotalAbsoluteFrequencyType;
00066 
00071   typedef std::vector< InstanceIdentifier > InstanceIdentifierHolder;
00072 
00074   virtual const InstanceIdentifierHolder & GetIdHolder () const
00075     {                                                                 \
00076     return this->m_IdHolder;
00077     }
00078 
00080   void SetSample(const TSample* sample);
00081   const TSample* GetSample() const;
00083 
00085   void InitializeWithAllInstances();
00086 
00088   void AddInstance(InstanceIdentifier id);
00089 
00092   InstanceIdentifier Size() const;
00093 
00095   void Clear();
00096 
00099   const MeasurementVectorType & GetMeasurementVector( InstanceIdentifier id) const;
00100 
00102   AbsoluteFrequencyType GetFrequency( InstanceIdentifier id ) const;
00103 
00105   TotalAbsoluteFrequencyType GetTotalFrequency() const;
00106 
00107   void Swap(unsigned int index1, unsigned int index2);
00108   
00109   InstanceIdentifier GetInstanceIdentifier( unsigned int index );
00110   
00111   const MeasurementVectorType & GetMeasurementVectorByIndex(unsigned int index) const;
00112 
00113   AbsoluteFrequencyType GetFrequencyByIndex(unsigned int index) const;
00114 
00116   virtual void Graft( const DataObject *thatObject );
00117 
00118   class ConstIterator
00119     {
00120     friend class Subsample;
00121     public:
00122 
00123     ConstIterator( const Self * sample )
00124       {
00125       *this = sample->Begin();
00126       }
00127 
00128     ConstIterator(const ConstIterator& iter)
00129       {
00130       m_Iter = iter.m_Iter;
00131       m_Subsample = iter.m_Subsample;
00132       m_Sample = iter.m_Sample;
00133       }
00134 
00135     ConstIterator& operator=(const ConstIterator& iter)
00136       {
00137       m_Iter = iter.m_Iter;
00138       m_Subsample = iter.m_Subsample;
00139       m_Sample = iter.m_Sample;
00140       return *this;
00141       }
00142 
00143     bool operator!=(const ConstIterator& it) 
00144       {
00145       return (m_Iter != it.m_Iter);
00146       }
00147     
00148     bool operator==(const ConstIterator& it) 
00149       { 
00150       return (m_Iter == it.m_Iter);
00151       }
00152 
00153     ConstIterator& operator++() 
00154       { 
00155       ++m_Iter;
00156       return *this;
00157       }
00158  
00159     AbsoluteFrequencyType GetFrequency() const
00160       {
00161       return  m_Sample->GetFrequency(*m_Iter);
00162       }
00163     
00164     const MeasurementVectorType & GetMeasurementVector() const
00165       {
00166       return m_Sample->GetMeasurementVector(*m_Iter);
00167       } 
00168     
00169     InstanceIdentifier GetInstanceIdentifier() const   
00170       {
00171       return ( m_Iter - m_Subsample->GetIdHolder().begin() );
00172       }
00173     
00174 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00175     protected:
00176 #endif
00177     // Purposely not implemented
00178     ConstIterator();
00179 
00180     // Only to be called from the Subsample
00181     ConstIterator(typename InstanceIdentifierHolder::const_iterator iter, 
00182              const Self* classSample)
00183       :m_Iter(iter), m_Subsample(classSample), m_Sample(classSample->GetSample())
00184     {}
00185 
00186     // ConstIterator pointing to ImageToListAdaptor
00187     typename InstanceIdentifierHolder::const_iterator m_Iter; 
00188 
00189     // Pointer to Subsample object
00190     const Self*    m_Subsample;
00191     const TSample* m_Sample;
00192 
00193     private:
00194 
00195   };
00196 
00197   class Iterator: public ConstIterator
00198     {
00199     friend class Subsample;
00200 
00201     public:
00202     
00203     Iterator(Self * sample):ConstIterator( sample )
00204       {
00205       }
00206 
00207     Iterator(const Iterator &iter):ConstIterator( iter )
00208       {
00209       }
00210 
00211     Iterator& operator =(const Iterator & iter)
00212       {
00213       this->ConstIterator::operator=( iter );
00214       return *this;
00215       }
00216 
00217 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00218     protected:
00219 #endif
00220     // To ensure const-correctness these method must not be in the public API.
00221     // The are purposly not implemented, since they should never be called.
00222     Iterator();
00223     Iterator(const Self * sample);
00224     Iterator(typename InstanceIdentifierHolder::const_iterator iter, 
00225              const Self* classSample);
00226     Iterator(const ConstIterator & it);
00227     ConstIterator& operator=(const ConstIterator& it);
00228 
00229     // Only to be called from the Subsample
00230     Iterator(typename InstanceIdentifierHolder::iterator iter, 
00231              Self* classSample)
00232       :ConstIterator( iter, classSample )
00233       {}
00234 
00235 
00236   private:
00237   };
00238 
00241   Iterator Begin()
00242     { 
00243     Iterator iter(m_IdHolder.begin(), this);
00244     return iter; 
00245     }
00247 
00250   Iterator  End()
00251     {
00252     Iterator iter(m_IdHolder.end(), this); 
00253     return iter; 
00254     }
00256 
00257   ConstIterator Begin() const
00258     { 
00259     ConstIterator iter(m_IdHolder.begin(), this);
00260     return iter; 
00261     }
00262   
00263   ConstIterator  End()  const
00264     {
00265     ConstIterator iter(m_IdHolder.end(), this); 
00266     return iter; 
00267     }
00268  
00269 protected:
00270   Subsample();
00271   virtual ~Subsample() {}
00272   void PrintSelf(std::ostream& os, Indent indent) const;
00273   
00274 private:
00275   Subsample(const Self&); //purposely not implemented
00276   void operator=(const Self&); //purposely not implemented
00277 
00278   const TSample*              m_Sample;
00279   InstanceIdentifierHolder    m_IdHolder;
00280   unsigned int                m_ActiveDimension;
00281   TotalAbsoluteFrequencyType  m_TotalFrequency;
00282 }; // end of class
00283 
00284 
00285 } // end of namespace Statistics 
00286 } // end of namespace itk
00287 
00288 
00289 #ifndef ITK_MANUAL_INSTANTIATION
00290 #include "itkSubsample.txx"
00291 #endif
00292 
00293 #endif
00294 

Generated at Mon Jul 12 2010 19:59:39 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000