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) ;
00071 
00074   typedef typename TSample::MeasurementVectorType MeasurementVectorType;
00075   typedef typename TSample::MeasurementType MeasurementType;
00076   typedef typename TSample::InstanceIdentifier InstanceIdentifier;
00077   typedef typename TSample::FrequencyType FrequencyType ;
00078   typedef typename TSample::TotalFrequencyType TotalFrequencyType ;
00079 
00080   
00083   typedef std::vector< unsigned int > UniqueClassLabelsType ;
00084 
00087   typedef itk::hash_map< InstanceIdentifier, unsigned int> ClassLabelHolderType ;
00088 
00091   typedef Subsample< TSample > ClassSampleType ;
00092   typedef typename ClassSampleType::Pointer         ClassSamplePointer;
00093   typedef typename ClassSampleType::ConstPointer    ClassSampleConstPointer;
00094 
00096   void SetSample(const TSample* sample) ;
00097 
00099   const TSample* GetSample() const;
00100 
00102   void SetNumberOfClasses(unsigned int numberOfClasses) ;
00103 
00105   unsigned int GetNumberOfClasses() const ;
00106 
00111   void AddInstance(const unsigned int &classLabel, const InstanceIdentifier &id) ;
00112 
00115   unsigned int GetClassLabel(const InstanceIdentifier &id) const ;
00116 
00119   int GetInternalClassLabel(const unsigned int classLabel ) const ;
00120 
00123   unsigned int GetClassSampleSize(const unsigned int &classLabel) const ;
00124 
00127   const ClassSampleType* GetClassSample(const unsigned int &classLabel) const ;
00128 
00131   ClassLabelHolderType* GetClassLabels()
00132   { return &m_ClassLabelHolder ; }
00133 
00135   unsigned int Size(void) const ;
00136 
00139   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00140 
00143   MeasurementType GetMeasurement(const InstanceIdentifier &id, 
00144                                   const unsigned int &dimension) ;
00145 
00147   FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00148 
00150   TotalFrequencyType GetTotalFrequency() const ;
00151 
00152   void Resize(unsigned int n) 
00153   {
00154     m_ClassLabelHolder.resize(n) ;
00155   }
00156 
00157  
00158   class ConstIterator
00159   {
00160   public:
00161     ConstIterator(InstanceIdentifier id, const Self* membershipSample)
00162       :m_Id(id), m_MembershipSample(membershipSample),
00163        m_Sample(membershipSample->GetSample())
00164     {}
00165     
00166     FrequencyType GetFrequency() const
00167     { return  m_Sample->GetFrequency(m_Id) ; }
00168     
00169     const MeasurementVectorType & GetMeasurementVector() const
00170     { return m_Sample->GetMeasurementVector(m_Id) ; } 
00171     
00172     InstanceIdentifier GetInstanceIdentifier() const
00173     { return m_Id ; }
00174 
00175     void SetClassLabel(unsigned int classLabel)
00176     { m_MembershipSample->AddInstance(classLabel, m_Id) ; }
00177 
00178     unsigned int GetClassLabel() const
00179     { return m_MembershipSample->GetClassLabel(m_Id) ; }
00180 
00181     ConstIterator& operator++() 
00182     { 
00183       ++m_Id ;
00184       return *this ;
00185     }
00186     
00187     bool operator!=(const ConstIterator& it) 
00188     { 
00189       if (m_Id != it.m_Id || 
00190           m_MembershipSample != it.m_MembershipSample ||
00191           m_Sample != it.m_Sample)
00192         {
00193         return true ;
00194         }
00195       else
00196         {
00197         return false ;
00198         }
00199     }
00200 
00201     bool operator==(const ConstIterator& it) 
00202     { 
00203       if (m_Id == it.m_Id && 
00204           m_MembershipSample == it.m_MembershipSample &&
00205           m_Sample == it.m_Sample)
00206         {
00207         return true ;
00208         }
00209       else
00210         {
00211         return false ;
00212         }
00213     }
00214     
00215     ConstIterator& operator=(const ConstIterator& it)
00216     {
00217       m_Id = it.m_Id;
00218       m_MembershipSample = it.m_MembershipSample ;
00219       m_Sample = it.m_Sample ;
00220       return *this ;
00221     }
00222 
00223     ConstIterator(const ConstIterator& it)
00224     {
00225       m_Id = it.m_Id;
00226       m_MembershipSample = it.m_MembershipSample ;
00227       m_Sample = it.m_Sample ;
00228     }
00229     
00230   private:
00231     // identifier for the instance
00232     InstanceIdentifier m_Id ;  
00233     // Pointer to MemebershipSample object
00234     const Self* m_MembershipSample ;
00235     const TSample* m_Sample ;
00236   } ;
00237 
00238   ConstIterator Begin() const
00239   { 
00240     ConstIterator iter(0, this) ;
00241     return iter; 
00242   }
00243   
00244   ConstIterator  End() const        
00245   {
00246     ConstIterator iter(this->Size(), this) ; 
00247     return iter; 
00248   }
00249  
00250 protected:
00251   MembershipSample() ;
00252   virtual ~MembershipSample() {}
00253   void PrintSelf(std::ostream& os, Indent indent) const;  
00254   
00255 private:
00256   MembershipSample(const Self&) ; //purposely not implemented
00257   void operator=(const Self&) ; //purposely not implemented
00258 
00259   const TSample*                  m_Sample ;
00260   unsigned int                    m_CurrentClassLabel ;
00261   UniqueClassLabelsType           m_UniqueClassLabels ;
00262   ClassLabelHolderType            m_ClassLabelHolder ;
00263   unsigned int                    m_NumberOfClasses ;
00264   std::vector< unsigned int >     m_ClassSampleSizes ;
00265   std::vector< ClassSamplePointer > m_ClassSamples ;
00266 } ; // end of class
00267 
00268 
00269 } // end of namespace Statistics 
00270 } // end of namespace itk
00271 
00272 
00273 #ifndef ITK_MANUAL_INSTANTIATION
00274 #include "itkMembershipSample.txx"
00275 #endif
00276 
00277 #endif
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 

Generated at Sat Feb 28 13:00:11 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000