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

Review/Statistics/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: 2009-05-22 12:55:07 $
00007   Version:   $Revision: 1.2 $
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 namespace itk {
00025 namespace Statistics {
00026 
00049 template< class TSample >
00050 class ITK_EXPORT MembershipSample : public DataObject
00051 {
00052 public:
00054   typedef MembershipSample            Self;
00055   typedef DataObject                  Superclass;
00056   typedef SmartPointer< Self >        Pointer;
00057   typedef SmartPointer< const Self >  ConstPointer;
00058 
00060   itkTypeMacro(MembershipSample, DataObject);
00061   itkNewMacro(Self);
00063 
00066   typedef TSample                                    SampleType;
00067   typedef typename SampleType::MeasurementVectorType MeasurementVectorType;
00068   typedef typename SampleType::MeasurementType       MeasurementType;
00069   typedef typename SampleType::InstanceIdentifier    InstanceIdentifier;
00070   typedef typename SampleType::ConstPointer          SampleConstPointer;
00071 
00072   typedef typename SampleType::AbsoluteFrequencyType         AbsoluteFrequencyType;
00073   typedef typename SampleType::TotalAbsoluteFrequencyType    TotalAbsoluteFrequencyType;
00074   
00075 
00076   typedef unsigned long              ClassLabelType;  
00079   typedef std::vector< ClassLabelType > UniqueClassLabelsType;
00080 
00083   typedef itk::hash_map< InstanceIdentifier, ClassLabelType > ClassLabelHolderType;
00084 
00087   typedef Subsample< SampleType >                   ClassSampleType;
00088   typedef typename ClassSampleType::Pointer         ClassSamplePointer;
00089   typedef typename ClassSampleType::ConstPointer    ClassSampleConstPointer;
00090 
00092   itkSetConstObjectMacro( Sample, SampleType );
00093   itkGetConstObjectMacro( Sample, SampleType );
00095 
00097   void SetNumberOfClasses( unsigned int numberOfClasses );
00098 
00100   itkGetConstMacro( NumberOfClasses, unsigned int );
00101 
00106   void AddInstance(const ClassLabelType &classLabel, const InstanceIdentifier &id);
00107 
00110   unsigned int GetClassLabel(const InstanceIdentifier &id) const;
00111 
00114   const ClassSampleType* GetClassSample(const  ClassLabelType &classLabel) const;
00115 
00118   const ClassLabelHolderType GetClassLabelHolder() const;
00119 
00122   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00123 
00126   MeasurementType GetMeasurement(const InstanceIdentifier &id, 
00127                                   const unsigned int &dimension);
00128 
00130   AbsoluteFrequencyType GetFrequency(const InstanceIdentifier &id) const;
00131 
00133   TotalAbsoluteFrequencyType GetTotalFrequency() const;
00134 
00136   virtual void Graft( const DataObject *thatObject );
00137 
00138 //  void PrintSelf(std::ostream& os, Indent indent) const;  
00139 
00140   class ConstIterator
00141     {
00142     friend class MembershipSample;
00143     public:
00144 
00145     ConstIterator( const Self * sample )
00146       {
00147       *this = sample->Begin();
00148       }
00149 
00150     ConstIterator(const ConstIterator& iter)
00151       {
00152       m_Sample = iter.m_Sample;
00153       m_MembershipSample = iter.m_MembershipSample;
00154       m_InstanceIdentifier = iter.m_InstanceIdentifier;
00155       }
00156 
00157     ConstIterator& operator=(const ConstIterator& iter)
00158       {
00159       m_Sample = iter.m_Sample;
00160       m_MembershipSample = iter.m_MembershipSample;
00161       m_InstanceIdentifier = iter.m_InstanceIdentifier;
00162       return *this;
00163       }
00164 
00165     bool operator!=(const ConstIterator& it) 
00166       {
00167       return (m_InstanceIdentifier != it.m_InstanceIdentifier);
00168       }
00169     
00170     bool operator==(const ConstIterator& it) 
00171       { 
00172       return (m_InstanceIdentifier == it.m_InstanceIdentifier);
00173       }
00174 
00175     ConstIterator& operator++() 
00176       { 
00177       ++m_InstanceIdentifier;
00178       return *this;
00179       }
00180  
00181     AbsoluteFrequencyType GetFrequency() const
00182       {
00183       return  m_Sample->GetFrequency(m_InstanceIdentifier);
00184       }
00185     
00186     const MeasurementVectorType & GetMeasurementVector() const
00187       {
00188       return m_Sample->GetMeasurementVector(m_InstanceIdentifier);
00189       } 
00190     
00191     InstanceIdentifier GetInstanceIdentifier() const   
00192       {
00193       return m_InstanceIdentifier; 
00194       }
00195 
00196     unsigned int   GetClassLabel() const
00197       {
00198       return m_MembershipSample->GetClassLabel( m_InstanceIdentifier );
00199       }
00200  
00201 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00202     protected:
00203 #endif
00204     // Purposely not implemented
00205     ConstIterator();
00206 
00207     // Only to be called from the MembershipSample
00208     ConstIterator(
00209              const Self* memberSample, InstanceIdentifier iid)
00210       :m_Sample(memberSample->GetSample()), m_MembershipSample( memberSample), m_InstanceIdentifier(iid)
00211       {
00212 
00213       }
00214 
00215 
00216     //typename SampleType::ConstIterator m_Iter; 
00217     const TSample*                 m_Sample;
00218     const MembershipSample*        m_MembershipSample;
00219     InstanceIdentifier             m_InstanceIdentifier;
00220     };
00221 
00222   class Iterator: public ConstIterator
00223     {
00224     friend class MembershipSample;
00225 
00226     public:
00227     
00228     Iterator(Self * sample):ConstIterator( sample )
00229       {
00230       }
00231 
00232     Iterator(const Iterator &iter):ConstIterator( iter )
00233       {
00234       }
00235 
00236     Iterator& operator =(const Iterator & iter)
00237       {
00238       this->ConstIterator::operator=( iter );
00239       return *this;
00240       }
00241 
00242 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00243     protected:
00244 #endif
00245     // To ensure const-correctness these method must not be in the public API.
00246     // The are purposly not implemented, since they should never be called.
00247     Iterator();
00248     Iterator(const Self * sample);
00249     Iterator(const ConstIterator & it);
00250     ConstIterator& operator=(const ConstIterator& it);
00251 
00252     // Only to be called from the MembershipSample
00253     Iterator(Self * memberSample,
00254              InstanceIdentifier iid)
00255       :ConstIterator( memberSample, iid )
00256       {} 
00257      
00258     private:
00259     };
00260 
00263   Iterator Begin()
00264     { 
00265     Iterator iter(this, 0);
00266     return iter; 
00267     }
00269 
00272   Iterator  End()
00273     {
00274     Iterator iter(this, m_Sample->Size()); 
00275     return iter; 
00276     }
00278 
00279   ConstIterator Begin() const
00280     { 
00281     ConstIterator iter(this,  0);
00282     return iter; 
00283     }
00284   
00285   ConstIterator  End()  const
00286     {
00287     ConstIterator iter(this, m_Sample->Size()); 
00288     return iter; 
00289     }
00290  
00291 protected:
00292   MembershipSample();
00293   virtual ~MembershipSample() {}
00294   void PrintSelf(std::ostream& os, Indent indent) const;  
00295   
00296 private:
00297   MembershipSample(const Self&); //purposely not implemented
00298   void operator=(const Self&); //purposely not implemented
00299 
00302   int GetInternalClassLabel(const ClassLabelType classLabel ) const;
00303 
00304 
00305   UniqueClassLabelsType                 m_UniqueClassLabels;
00306   ClassLabelHolderType                  m_ClassLabelHolder;
00307   std::vector< ClassSamplePointer >     m_ClassSamples;
00308   SampleConstPointer                    m_Sample;
00309   unsigned int                          m_NumberOfClasses;
00310 
00311 }; // end of class
00312 
00313 
00314 } // end of namespace Statistics 
00315 } // end of namespace itk
00316 
00317 
00318 #ifndef ITK_MANUAL_INSTANTIATION
00319 #include "itkMembershipSample.txx"
00320 #endif
00321 
00322 #endif
00323 

Generated at Thu May 28 10:46:54 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000