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

itkMembershipSample.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMembershipSample.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/09/30 17:24:45 $
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 __itkMembershipSample_h
00018 #define __itkMembershipSample_h
00019 
00020 #include "itk_hash_map.h"
00021 #include "itkSample.h"
00022 #include "itkSubsample.h"
00023 
00024 #include "itkExceptionObject.h"
00025 
00026 namespace itk{ 
00027 namespace Statistics{
00028 
00056 template< class TSample >
00057 class ITK_EXPORT MembershipSample : 
00058     public Sample< typename TSample::MeasurementVectorType >
00059 {
00060 public:
00062   typedef MembershipSample Self;
00063   typedef Sample< typename TSample::MeasurementVectorType > Superclass ;
00064   typedef SmartPointer< Self > Pointer ;
00065   typedef SmartPointer< const Self > ConstPointer ;
00066 
00068   itkTypeMacro(MembershipSample, Sample);
00069   itkNewMacro(Self) ;
00070   
00073   typedef typename TSample::MeasurementVectorType MeasurementVectorType;
00074   typedef typename TSample::MeasurementType MeasurementType;
00075   typedef typename TSample::InstanceIdentifier InstanceIdentifier;
00076   typedef typename TSample::FrequencyType FrequencyType ;
00077   typedef typename TSample::TotalFrequencyType TotalFrequencyType ;
00078   
00079   
00082   typedef std::vector< unsigned int > UniqueClassLabelsType ;
00083 
00086   typedef itk::hash_map< InstanceIdentifier, unsigned int> ClassLabelHolderType ;
00087   
00090   typedef Subsample< TSample > ClassSampleType ;
00091   typedef typename ClassSampleType::Pointer         ClassSamplePointer;
00092   typedef typename ClassSampleType::ConstPointer    ClassSampleConstPointer;
00093   
00095   void SetSample(const TSample* sample) ;
00096 
00098   const TSample* GetSample() const;
00099   
00101   void SetNumberOfClasses(unsigned int numberOfClasses) ;
00102   
00104   unsigned int GetNumberOfClasses() const ;
00105 
00110   void AddInstance(const unsigned int &classLabel, const InstanceIdentifier &id) ;
00113   unsigned int GetClassLabel(const InstanceIdentifier &id) const ;
00114 
00117   int GetInternalClassLabel(const unsigned int classLabel ) const ;
00118 
00121   unsigned int GetClassSampleSize(const unsigned int &classLabel) const ;
00122 
00125   const ClassSampleType* GetClassSample(const unsigned int &classLabel) const ;
00126   
00129   ClassLabelHolderType* GetClassLabels()
00130   { return &m_ClassLabelHolder ; }
00131 
00133   unsigned int Size(void) const ;
00134   
00137   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00138   
00141   MeasurementType GetMeasurement(const InstanceIdentifier &id, 
00142                                   const unsigned int &dimension) ;
00143 
00145   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00146   
00148   TotalFrequencyType GetTotalFrequency() const ;
00149 
00150   void Resize(unsigned int n) 
00151   {
00152     m_ClassLabelHolder.resize(n) ;
00153   }
00154 
00155  
00156   class ConstIterator
00157   {
00158   public:
00159     ConstIterator(InstanceIdentifier id, const Self* membershipSample)
00160       :m_Id(id), m_MembershipSample(membershipSample),
00161        m_Sample(membershipSample->GetSample())
00162     {}
00163     
00164     FrequencyType GetFrequency() const
00165     { return  m_Sample->GetFrequency(m_Id) ; }
00166     
00167     const MeasurementVectorType & GetMeasurementVector() const
00168     { return m_Sample->GetMeasurementVector(m_Id) ; } 
00169     
00170     InstanceIdentifier GetInstanceIdentifier() const
00171     { return m_Id ; }
00172 
00173     void SetClassLabel(unsigned int classLabel)
00174     { m_MembershipSample->AddInstance(classLabel, m_Id) ; }
00175 
00176     unsigned int GetClassLabel() const
00177     { return m_MembershipSample->GetClassLabel(m_Id) ; }
00178 
00179     ConstIterator& operator++() 
00180     { 
00181       ++m_Id ;
00182       return *this ;
00183     }
00184     
00185     bool operator!=(const ConstIterator& it) 
00186     { 
00187       if (m_Id != it.m_Id || 
00188           m_MembershipSample != it.m_MembershipSample ||
00189           m_Sample != it.m_Sample)
00190         {
00191         return true ;
00192         }
00193       else
00194         {
00195         return false ;
00196         }
00197     }
00198 
00199     bool operator==(const ConstIterator& it) 
00200     { 
00201       if (m_Id == it.m_Id && 
00202           m_MembershipSample == it.m_MembershipSample &&
00203           m_Sample == it.m_Sample)
00204         {
00205         return true ;
00206         }
00207       else
00208         {
00209         return false ;
00210         }
00211     }
00212     
00213     ConstIterator& operator=(const ConstIterator& it)
00214     {
00215       m_Id = it.m_Id;
00216       m_MembershipSample = it.m_MembershipSample ;
00217       m_Sample = it.m_Sample ;
00218       return *this ;
00219     }
00220 
00221     ConstIterator(const ConstIterator& it)
00222     {
00223       m_Id = it.m_Id;
00224       m_MembershipSample = it.m_MembershipSample ;
00225       m_Sample = it.m_Sample ;
00226     }
00227     
00228   private:
00229     // identifier for the instance
00230     InstanceIdentifier m_Id ;  
00231     // Pointer to MemebershipSample object
00232     const Self* m_MembershipSample ;
00233     const TSample* m_Sample ;
00234   } ;
00235 
00236   ConstIterator Begin() const
00237   { 
00238     ConstIterator iter(0, this) ;
00239     return iter; 
00240   }
00241   
00242   ConstIterator  End() const        
00243   {
00244     ConstIterator iter(this->Size(), this) ; 
00245     return iter; 
00246   }
00247  
00248 protected:
00249   MembershipSample() ;
00250   virtual ~MembershipSample() {}
00251   void PrintSelf(std::ostream& os, Indent indent) const;  
00252   
00253 private:
00254   MembershipSample(const Self&) ; //purposely not implemented
00255   void operator=(const Self&) ; //purposely not implemented
00256 
00257   const TSample*                  m_Sample ;
00258   unsigned int                    m_CurrentClassLabel ;
00259   UniqueClassLabelsType           m_UniqueClassLabels ;
00260   ClassLabelHolderType            m_ClassLabelHolder ;
00261   unsigned int                    m_NumberOfClasses ;
00262   std::vector< unsigned int >     m_ClassSampleSizes ;
00263   std::vector< ClassSamplePointer > m_ClassSamples ;
00264 } ; // end of class
00265 
00266 
00267 } // end of namespace Statistics 
00268 } // end of namespace itk
00269 
00270 
00271 #ifndef ITK_MANUAL_INSTANTIATION
00272 #include "itkMembershipSample.txx"
00273 #endif
00274 
00275 #endif
00276 
00277 
00278 
00279 
00280 
00281 
00282 

Generated at Wed May 24 23:39:56 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000