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: 2002/09/25 20:50:20 $
00007   Version:   $Revision: 1.20 $
00008 
00009   Copyright (c) 2002 Insight 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 
00050 template< class TSample >
00051 class ITK_EXPORT MembershipSample : 
00052     public Sample< typename TSample::MeasurementVectorType >
00053 {
00054 public:
00056   typedef MembershipSample Self;
00057   typedef Sample< typename TSample::MeasurementVectorType > Superclass ;
00058   typedef SmartPointer< Self > Pointer ;
00059 
00061   itkTypeMacro(MembershipSample, Sample);
00062   itkNewMacro(Self) ;
00063   
00066   typedef typename TSample::MeasurementVectorType MeasurementVectorType;
00067   typedef typename TSample::MeasurementType MeasurementType;
00068   typedef typename TSample::InstanceIdentifier InstanceIdentifier;
00069   typedef typename TSample::FrequencyType FrequencyType ;
00070   //    typedef typename TSample::SizeType SizeType ;
00071   //    typedef typename TSample::SizeValueType SizeValueType ;
00072   
00074   itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00075                       TSample::MeasurementVectorSize);
00076   
00079   typedef std::vector< unsigned int > UniqueClassLabelsType ;
00080 
00083   typedef itk::hash_map< InstanceIdentifier, unsigned int> ClassLabelHolderType ;
00084   
00087   typedef Subsample< TSample > ClassSampleType ;
00088   
00090   void SetSample(TSample* sample) ;
00091   
00092   TSample* GetSample() ;
00093   
00094   void SetNumberOfClasses(unsigned int numberOfClasses) ;
00095   
00096   unsigned int GetNumberOfClasses() const ;
00097 
00098   unsigned int GetNumberOfInstances() const ;
00099 
00100   void AddInstance(const unsigned int &classLabel, const InstanceIdentifier &id) ;
00101   
00102   unsigned int GetClassLabel(const InstanceIdentifier &id) const ;
00103 
00104   int GetInternalClassLabel(const unsigned int classLabel ) const ;
00105 
00106   unsigned int GetClassSampleSize(const unsigned int &classLabel) const ;
00107 
00108   ClassSampleType* GetClassSample(const unsigned int &classLabel) ;
00109   
00110   ClassLabelHolderType* GetClassLabels()
00111   { return &m_ClassLabelHolder ; }
00112 
00114   unsigned int Size(void) const ;
00115   
00117   unsigned int Size(const unsigned int &dimension) const;
00118   
00121   MeasurementVectorType& GetMeasurementVector(const InstanceIdentifier &id) ;
00122   
00125   MeasurementType& GetMeasurement(const InstanceIdentifier &id, 
00126                                   const unsigned int &dimension) ;
00127 
00129   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00130   
00132   FrequencyType GetTotalFrequency(const unsigned int &d) const ;
00133 
00134   void Resize(unsigned int n) 
00135   {
00136     m_ClassLabelHolder.resize(n) ;
00137   }
00138 
00139   class Iterator;
00140   friend class Iterator;
00141   
00142   Iterator Begin()
00143   { 
00144     Iterator iter(0, this) ;
00145     return iter; 
00146   }
00147   
00148   Iterator  End()        
00149   {
00150     Iterator iter(this->Size(), this) ; 
00151     return iter; 
00152   }
00153   
00154   class Iterator
00155   {
00156   public:
00157     Iterator(InstanceIdentifier id, Self* membershipSample)
00158       :m_Id(id), m_MembershipSample(membershipSample),
00159        m_Sample(membershipSample->GetSample())
00160     {}
00161     
00162     FrequencyType GetFrequency() const
00163     { return  m_Sample->GetFrequency(m_Id) ; }
00164     
00165     MeasurementVectorType& GetMeasurementVector()
00166     { return m_Sample->GetMeasurementVector(m_Id) ; } 
00167     
00168     InstanceIdentifier GetInstanceIdentifier() const
00169     { return m_Id ; }
00170 
00171     unsigned int GetClassLabel() const
00172     { return m_MembershipSample->GetClassLabel(m_Id) ; }
00173 
00174     Iterator& operator++() 
00175     { 
00176       ++m_Id ;
00177       return *this ;
00178     }
00179     
00180     bool operator!=(const Iterator& it) 
00181     { 
00182       if (m_Id != it.m_Id || 
00183           m_MembershipSample != it.m_MembershipSample ||
00184           m_Sample != it.m_Sample)
00185         {
00186           return true ;
00187         }
00188       else
00189         {
00190           return false ;
00191         }
00192     }
00193 
00194     bool operator==(const Iterator& it) 
00195     { 
00196       if (m_Id == it.m_Id && 
00197           m_MembershipSample == it.m_MembershipSample &&
00198           m_Sample == it.m_Sample)
00199         {
00200           return true ;
00201         }
00202       else
00203         {
00204           return false ;
00205         }
00206     }
00207     
00208     Iterator& operator=(const Iterator& it)
00209     {
00210       m_Id = it.m_Id;
00211       m_MembershipSample = it.m_MembershipSample ;
00212       m_Sample = it.m_Sample ;
00213       return *this ;
00214     }
00215 
00216     Iterator(const Iterator& it)
00217     {
00218       m_Id = it.m_Id;
00219       m_MembershipSample = it.m_MembershipSample ;
00220       m_Sample = it.m_Sample ;
00221     }
00222     
00223   private:
00224     // identifier for the instance
00225     InstanceIdentifier m_Id ;  
00226     // Pointer to MemebershipSample object
00227     Self* m_MembershipSample ;
00228     TSample* m_Sample ;
00229   } ;
00230 
00231 protected:
00232   MembershipSample() ;
00233   virtual ~MembershipSample() {}
00234   void PrintSelf(std::ostream& os, Indent indent) const;  
00235   
00236 private:
00237   MembershipSample(const Self&) ; //purposely not implemented
00238   void operator=(const Self&) ; //purposely not implemented
00239 
00240   TSample*                        m_Sample ;
00241   unsigned int                    m_CurrentClassLabel ;
00242   UniqueClassLabelsType           m_UniqueClassLabels ;
00243   ClassLabelHolderType            m_ClassLabelHolder ;
00244   unsigned int                    m_NumberOfClasses ;
00245   std::vector< unsigned int >     m_ClassSampleSizes ;
00246   std::vector< typename ClassSampleType::Pointer > m_ClassSamples ;
00247 } ; // end of class
00248 
00249 
00250 } // end of namespace Statistics 
00251 } // end of namespace itk
00252 
00253 
00254 #ifndef ITK_MANUAL_INSTANTIATION
00255 #include "itkMembershipSample.txx"
00256 #endif
00257 
00258 #endif
00259 
00260 
00261 
00262 
00263 
00264 
00265 

Generated at Fri May 21 01:15:02 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000