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

Review/Statistics/itkSample.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSample.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-05-02 05:43:58 $
00007   Version:   $Revision: 1.1 $
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 __itkSample_h
00018 #define __itkSample_h
00019 
00020 #include "itkMacro.h"
00021 #include "itkPoint.h"
00022 #include "itkSize.h"
00023 #include "itkDataObject.h"
00024 #include "itkFixedArray.h"
00025 #include "itkMeasurementVectorTraits.h"
00026 #include "itkNumericTraits.h"
00027 #include <vector> // for the size_type declaration
00028 
00029 
00030 namespace itk { 
00031 namespace Statistics {
00032 
00062 template < class TMeasurementVector >
00063 class ITK_EXPORT Sample : public DataObject
00064 {
00065 public:
00067   typedef Sample                        Self;  
00068   typedef DataObject                    Superclass;
00069   typedef SmartPointer< Self >          Pointer;
00070   typedef SmartPointer<const Self >     ConstPointer;
00071 
00073   itkTypeMacro(Sample, DataObject);
00074 
00076   typedef TMeasurementVector MeasurementVectorType;
00077 
00080   typedef typename MeasurementVectorTraitsTypes< 
00081     MeasurementVectorType >::ValueType   MeasurementType;
00082 
00084   typedef MeasurementVectorTraits::AbsoluteFrequencyType       AbsoluteFrequencyType;
00085 
00087   typedef NumericTraits<AbsoluteFrequencyType>::AccumulateType TotalAbsoluteFrequencyType;
00088 
00091   typedef typename MeasurementVectorTraits::InstanceIdentifier  InstanceIdentifier;
00092 
00094   typedef unsigned int  MeasurementVectorSizeType;
00095 
00097   virtual InstanceIdentifier Size() const = 0;
00098 
00101   virtual const MeasurementVectorType & 
00102     GetMeasurementVector( InstanceIdentifier id) const = 0;
00103 
00106   virtual AbsoluteFrequencyType GetFrequency( InstanceIdentifier id ) const = 0;
00107 
00109   virtual TotalAbsoluteFrequencyType GetTotalFrequency() const = 0;
00110 
00111   
00113   virtual void SetMeasurementVectorSize( MeasurementVectorSizeType s )
00114     {
00115     // Test whether the vector type is resizable or not
00116     MeasurementVectorType m;
00117     if( MeasurementVectorTraits::IsResizable( m ) )
00118       {
00119       // then this is a resizable vector type
00120       //
00121       // if the new size is the same as the previou size, just return
00122       if( s == this->m_MeasurementVectorSize )
00123         {
00124         return;
00125         }
00126       else
00127         {
00128         // If the new size is different from the current size, then
00129         // only change the measurement vector size if the container is empty.
00130         if( this->Size() )
00131           {
00132           itkExceptionMacro("Attempting to change the measurement \
00133           vector size of a non-empty Sample");
00134           }
00135         else
00136           {
00137           this->m_MeasurementVectorSize = s;
00138           this->Modified();
00139           }
00140         }
00141       }
00142     else
00143       {
00144       // If this is a non-resizable vector type
00145       MeasurementVectorType m3;
00146       MeasurementVectorSizeType defaultLength = MeasurementVectorTraits::GetLength( m3 );
00147       // and the new length is different from the default one, then throw an exception
00148       if( defaultLength != s )
00149         {
00150         itkExceptionMacro("Attempting to change the measurement \
00151                            vector size of a non-resizable vector type");
00152         }
00153       }
00154     }
00156 
00158   itkGetConstMacro( MeasurementVectorSize, MeasurementVectorSizeType );
00159 
00161   virtual void Graft( const DataObject *thatObject )
00162     {
00163     this->Superclass::Graft(thatObject);
00164 
00165     const Self *thatConst = dynamic_cast< const Self * >(thatObject);
00166     if (thatConst)
00167       {
00168       this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
00169       }
00170     }
00171   
00172 protected:
00173   Sample()
00174     {
00175     m_MeasurementVectorSize = MeasurementVectorTraits::GetLength( 
00176                                         MeasurementVectorType() );
00177     }
00178 
00179   virtual ~Sample() {}
00180 
00181   void PrintSelf(std::ostream& os, Indent indent) const
00182     {
00183     Superclass::PrintSelf(os,indent);
00184     os << indent << "Length of measurement vectors in the sample: " << 
00185       m_MeasurementVectorSize << std::endl;
00186     }
00187 
00188 
00189   
00190 private:
00191   Sample(const Self&); //purposely not implemented
00192   void operator=(const Self&); //purposely not implemented
00193 
00194   MeasurementVectorSizeType m_MeasurementVectorSize;
00195 }; // end of class
00196 
00197 } // end of namespace Statistics
00198 } // end of namespace itk
00199 
00200 #endif
00201 

Generated at Thu May 28 11:26:22 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000