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

itkVariableDimensionHistogram.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVariableDimensionHistogram.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/09/30 17:40:35 $
00007   Version:   $Revision: 1.6 $
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 __itkVariableDimensionHistogram_h
00018 #define __itkVariableDimensionHistogram_h
00019 
00020 #include <vector>
00021 
00022 #include "itkIndex.h"
00023 #include "itkSize.h"
00024 #include "itkArray.h"
00025 #include "itkSample.h"
00026 #include "itkDenseFrequencyContainer.h"
00027 #include "itkSparseFrequencyContainer.h"
00028 
00029 namespace itk{
00030 namespace Statistics{
00031 
00069 template < class TMeasurement = float, 
00070            class TFrequencyContainer = DenseFrequencyContainer > 
00071 class ITK_EXPORT VariableDimensionHistogram 
00072   : public Sample < Array< TMeasurement > >
00073 {
00074 public:
00075 
00077   typedef VariableDimensionHistogram  Self ;
00078   typedef Sample< Array< TMeasurement > > Superclass ;
00079   typedef SmartPointer<Self> Pointer ;
00080   typedef SmartPointer<const Self> ConstPointer ;
00081 
00083   itkTypeMacro(VariableDimensionHistogram, Sample) ;
00084 
00086   itkNewMacro(Self) ;
00087 
00089   typedef TMeasurement MeasurementType ;
00090 
00092   typedef typename Superclass::MeasurementVectorType MeasurementVectorType ;
00093   typedef typename Superclass::InstanceIdentifier InstanceIdentifier ;
00094   typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType ;
00095   typedef MeasurementVectorType ValueType ;
00096 
00098   typedef TFrequencyContainer FrequencyContainerType ;
00099   typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer ;
00100 
00102   typedef typename FrequencyContainerType::FrequencyType FrequencyType ;
00103   typedef typename FrequencyContainerType::TotalFrequencyType TotalFrequencyType ;
00104 
00106   typedef itk::Array< long >  IndexType;
00107   typedef typename IndexType::ValueType  IndexValueType;
00108 
00110   typedef itk::Array< long > SizeType ;
00111   typedef typename SizeType::ValueType SizeValueType ;
00112 
00114   typedef std::vector< MeasurementType > BinMinVectorType ;
00115   typedef std::vector< MeasurementType > BinMaxVectorType ;
00116   typedef std::vector< BinMinVectorType > BinMinContainerType ;
00117   typedef std::vector< BinMaxVectorType > BinMaxContainerType ;
00118 
00122   void Initialize(const SizeType &size) ;
00123   
00124 
00128   void Initialize(const SizeType &size, MeasurementVectorType& lowerBound,
00129                   MeasurementVectorType& upperBound) ;
00130 
00132   void SetToZero() ;
00133 
00137   bool GetIndex(const MeasurementVectorType & measurement,
00138                 IndexType & index ) const;
00139   
00143   const IndexType & GetIndex(const InstanceIdentifier &id) const;
00144 
00147   itkGetMacro(ClipBinsAtEnds, bool);
00148 
00151   itkSetMacro(ClipBinsAtEnds, bool);
00152 
00155   bool IsIndexOutOfBounds(const IndexType &index) const;
00156 
00160   InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const ;
00161   
00163   unsigned int Size() const ;
00164 
00166   SizeType GetSize() const
00167   { return m_Size ; }
00168 
00170   SizeValueType GetSize(const unsigned int dimension) const
00171   {
00172     return m_Size[dimension] ; 
00173   }
00174 
00176   const MeasurementType& GetBinMin(const unsigned int dimension, 
00177                              const unsigned long nbin) const
00178   { return m_Min[dimension][nbin] ; }
00179 
00181   const MeasurementType& GetBinMax(const unsigned int dimension,
00182                              const unsigned long nbin) const
00183   { return m_Max[dimension][nbin] ; }
00184   
00186   void SetBinMin(const unsigned int dimension, const unsigned long nbin,
00187                  const MeasurementType min)
00188   { m_Min[dimension][nbin] = min ; }
00189   
00191   void SetBinMax(const unsigned int dimension, 
00192                  unsigned long nbin, const MeasurementType max)
00193   { m_Max[dimension][nbin] = max ; }
00194   
00197   const MeasurementType& GetBinMinFromValue(const unsigned int dimension, 
00198                                       const float value ) const  ;
00199   
00202   const MeasurementType& GetBinMaxFromValue(const unsigned int dimension, 
00203                                       const float value ) const ;
00204   
00206   const BinMinVectorType& GetDimensionMins(const unsigned int dimension) const
00207   { return m_Min[dimension] ; }
00208   
00210   const BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const
00211   {  return m_Max[dimension] ; }
00212   
00214   const BinMinContainerType& GetMins() const
00215   { return m_Min ; }
00216   
00218   const BinMaxContainerType& GetMaxs() const
00219   { return m_Max ; }
00220   
00222   MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType 
00223                                                   &measurement)  ; 
00224   
00226   MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType 
00227                                                   &measurement) ; 
00228   
00230   MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index) ;
00231   
00233   MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index) ; 
00234   
00236   FrequencyType GetFrequency(const InstanceIdentifier &id) const
00237   { return m_FrequencyContainer->GetFrequency(id) ; }
00238 
00240   FrequencyType GetFrequency(const IndexType &index) const ;
00241 
00243   void SetFrequency(const FrequencyType value) ;
00244 
00247   bool SetFrequency(const InstanceIdentifier &id, const FrequencyType value) 
00248   { return m_FrequencyContainer->SetFrequency(id, value) ; }
00249 
00252   bool SetFrequency(const IndexType &index, 
00253                     const FrequencyType value) ;
00254   
00257   bool SetFrequency(const MeasurementVectorType &measurement, 
00258                     const FrequencyType value) ;
00259 
00260 
00264   bool IncreaseFrequency(const InstanceIdentifier &id,
00265                          const FrequencyType value) 
00266   { return m_FrequencyContainer->IncreaseFrequency(id, value) ; }
00267 
00271   bool IncreaseFrequency(const IndexType &index, 
00272                          const FrequencyType value) ;
00273   
00277   bool IncreaseFrequency(const MeasurementVectorType &measurement, 
00278                          const FrequencyType value) ;
00279   
00283   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00284   
00286   const MeasurementVectorType & GetMeasurementVector(const IndexType &index) const;
00287   
00290   MeasurementType GetMeasurement(const unsigned long n,
00291                                   const unsigned int dimension) const ;
00292 
00294   TotalFrequencyType GetTotalFrequency() const ;
00295 
00297   FrequencyType GetFrequency(const unsigned long n,
00298                              const unsigned int dimension) const ;
00299 
00315   double Quantile(const unsigned int dimension, const double &p) const;
00316 
00317  protected:
00318   void PrintSelf(std::ostream& os, Indent indent) const;
00319 
00320 public:
00323   class Iterator
00324   {
00325   public:
00326     Iterator(){};
00327     
00328     Iterator(Self * histogram) 
00329     { 
00330       m_Id = 0 ;
00331       m_Histogram = histogram; 
00332     } 
00333     
00334     Iterator(InstanceIdentifier id, Self * histogram)
00335       : m_Id(id), m_Histogram(histogram)
00336     {}
00337     
00338     FrequencyType GetFrequency() const
00339     { 
00340       return  m_Histogram->GetFrequency(m_Id) ;
00341     }
00342     
00343     bool SetFrequency(const FrequencyType value) 
00344     { 
00345       return m_Histogram->SetFrequency(m_Id, value); 
00346     }
00347 
00348     InstanceIdentifier GetInstanceIdentifier() const
00349     { return m_Id ; }
00350 
00351     const MeasurementVectorType & GetMeasurementVector() const
00352     { 
00353       return m_Histogram->GetMeasurementVector(m_Id) ;
00354     } 
00355 
00356     Iterator& operator++() 
00357     { 
00358       ++m_Id; 
00359       return *this;
00360     }
00361     
00362     bool operator!=(const Iterator& it) 
00363     { return (m_Id != it.m_Id); }
00364     
00365     bool operator==(const Iterator& it) 
00366     { return (m_Id == it.m_Id); }
00367     
00368     Iterator& operator=(const Iterator& it)
00369     { 
00370       m_Id  = it.m_Id;
00371       m_Histogram = it.m_Histogram ; 
00372       return *this ;
00373     }
00374 
00375     Iterator(const Iterator& it)
00376     { 
00377       m_Id        = it.m_Id;
00378       m_Histogram = it.m_Histogram ; 
00379     }
00380    
00381   private:
00382     // Iterator pointing DenseFrequencyContainer
00383     InstanceIdentifier m_Id;
00384     
00385     // Pointer of DenseFrequencyContainer
00386     Self* m_Histogram ;
00387   } ; // end of iterator class
00388 
00389   // Const Iterator
00390   class ConstIterator
00391   {
00392   public:
00393     ConstIterator(){};
00394     
00395     ConstIterator(const Self * histogram) 
00396     { 
00397       m_Id = 0 ;
00398       m_Histogram = histogram; 
00399     } 
00400     
00401     ConstIterator(InstanceIdentifier id, const Self * histogram)
00402       : m_Id(id), m_Histogram(histogram)
00403     {}
00404     
00405     FrequencyType GetFrequency() const
00406     { 
00407       return  m_Histogram->GetFrequency(m_Id) ;
00408     }
00409     
00410     bool SetFrequency(const FrequencyType value) 
00411     { 
00412       return m_Histogram->SetFrequency(m_Id, value); 
00413     }
00414 
00415     InstanceIdentifier GetInstanceIdentifier() const
00416     { return m_Id ; }
00417 
00418     const MeasurementVectorType & GetMeasurementVector() const
00419     { 
00420       return m_Histogram->GetMeasurementVector(m_Id) ;
00421     } 
00422 
00423     ConstIterator& operator++() 
00424     { 
00425       ++m_Id; 
00426       return *this;
00427     }
00428     
00429     bool operator!=(const ConstIterator& it) 
00430     { return (m_Id != it.m_Id); }
00431     
00432     bool operator==(const ConstIterator& it) 
00433     { return (m_Id == it.m_Id); }
00434     
00435     ConstIterator& operator=(const ConstIterator& it)
00436     { 
00437       m_Id  = it.m_Id;
00438       m_Histogram = it.m_Histogram ; 
00439       return *this ;
00440     }
00441 
00442     ConstIterator(const ConstIterator & it)
00443     { 
00444       m_Id        = it.m_Id;
00445       m_Histogram = it.m_Histogram ; 
00446     }
00447    
00448   private:
00449     // ConstIterator pointing DenseFrequencyContainer
00450     InstanceIdentifier m_Id;
00451     
00452     // Pointer of DenseFrequencyContainer
00453     const Self* m_Histogram ;
00454   } ; // end of iterator class
00455 
00456   Iterator  Begin()
00457   { 
00458     Iterator iter(0, this) ; 
00459     return iter ;
00460   }
00461            
00462   Iterator  End()        
00463   {
00464     return Iterator(m_OffsetTable[this->GetMeasurementVectorSize()], this) ;
00465   }
00466   
00467   ConstIterator  Begin() const
00468   { 
00469     ConstIterator iter(0, this) ; 
00470     return iter ;
00471   }
00472            
00473   ConstIterator End() const
00474   {
00475     return ConstIterator(m_OffsetTable[this->GetMeasurementVectorSize()], this) ;
00476   }
00477  
00478 
00479 protected:
00480   VariableDimensionHistogram() ;
00481   virtual ~VariableDimensionHistogram() {}
00482 
00486   void SetMeasurementVectorSize( const MeasurementVectorSizeType );
00487 
00488   // The number of bins for each dimension
00489   SizeType m_Size ;
00490   
00491 private:
00492   VariableDimensionHistogram(const Self&); //purposely not implemented
00493   void operator=(const Self&); //purposely not implemented
00494 
00495   Array< InstanceIdentifier > m_OffsetTable;
00496   FrequencyContainerPointer   m_FrequencyContainer ;
00497   unsigned int                m_NumberOfInstances ;
00498 
00499   // lower bound of each bin
00500   std::vector< std::vector<MeasurementType> > m_Min ;
00501   
00502   // upper bound of each bin
00503   std::vector< std::vector<MeasurementType> > m_Max ;
00504   
00505   mutable MeasurementVectorType   m_TempMeasurementVector ;
00506   mutable IndexType               m_TempIndex ;
00507 
00508   bool                            m_ClipBinsAtEnds;
00509 
00510 } ; // end of class
00511 
00512 } // end of namespace Statistics 
00513 } // end of namespace itk 
00514 
00515 #ifndef ITK_MANUAL_INSTANTIATION
00516 #include "itkVariableDimensionHistogram.txx"
00517 #endif
00518 
00519 #endif

Generated at Thu May 25 00:10:46 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000