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

itkHistogram.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkHistogram.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/09/11 00:15:14 $
00007   Version:   $Revision: 1.36 $
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 __itkHistogram_h
00018 #define __itkHistogram_h
00019 
00020 #include <vector>
00021 
00022 #include "itkIndex.h"
00023 #include "itkSize.h"
00024 #include "itkFixedArray.h"
00025 #include "itkSample.h"
00026 #include "itkDenseFrequencyContainer.h"
00027 #include "itkSparseFrequencyContainer.h"
00028 
00029 namespace itk{
00030 namespace Statistics{
00031 
00063 template < class TMeasurement = float, unsigned int VMeasurementVectorSize = 1,
00064            class TFrequencyContainer = DenseFrequencyContainer< float > > 
00065 class ITK_EXPORT Histogram 
00066   : public Sample < FixedArray< TMeasurement, VMeasurementVectorSize > >
00067 {
00068 public:
00070   typedef Histogram  Self ;
00071   typedef Sample< FixedArray< TMeasurement, VMeasurementVectorSize > > Superclass ;
00072   typedef SmartPointer<Self> Pointer ;
00073   typedef SmartPointer<const Self> ConstPointer ;
00074 
00076   itkTypeMacro(Histogram, Sample) ;
00077 
00079   itkNewMacro(Self) ;
00080 
00082   itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00083                       VMeasurementVectorSize);
00084  
00086   typedef TMeasurement MeasurementType ;
00087 
00089   typedef typename Superclass::MeasurementVectorType MeasurementVectorType ;
00090   typedef typename Superclass::InstanceIdentifier InstanceIdentifier ;
00091   typedef MeasurementVectorType ValueType ;
00092 
00094   typedef TFrequencyContainer FrequencyContainerType ;
00095   typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer ;
00096 
00098   typedef typename FrequencyContainerType::FrequencyType FrequencyType ;
00099 
00101   typedef itk::Index< VMeasurementVectorSize >  IndexType;
00102   typedef typename IndexType::IndexValueType  IndexValueType;
00103 
00105   typedef itk::Size< VMeasurementVectorSize > SizeType ;
00106   typedef typename SizeType::SizeValueType SizeValueType ;
00107 
00109   typedef std::vector< MeasurementType > BinMinVectorType ;
00110   typedef std::vector< MeasurementType > BinMaxVectorType ;
00111   typedef std::vector< BinMinVectorType > BinMinContainerType ;
00112   typedef std::vector< BinMaxVectorType > BinMaxContainerType ;
00113 
00118   void Initialize(const SizeType &size) ;
00119   
00120 
00126   void Initialize(const SizeType &size, MeasurementVectorType& lowerBound,
00127                   MeasurementVectorType& upperBound) ;
00128 
00130   void SetToZero() ;
00131 
00135   const IndexType & GetIndex(const MeasurementVectorType& measurement) const;
00136 
00139   bool GetIndex(const MeasurementVectorType & measurement,
00140                 IndexType & index ) const;
00141   
00145   const IndexType & GetIndex(const InstanceIdentifier &id) const;
00146 
00149   bool IsIndexOutOfBounds(const IndexType &index) const;
00150 
00154   InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const ;
00155   
00157   unsigned int Size() const ;
00158 
00160   SizeType GetSize() const
00161   { return m_Size ; }
00162 
00164   SizeValueType GetSize(const unsigned int dimension) const
00165   {
00166     return m_Size[dimension] ; 
00167   }
00168 
00170   const MeasurementType& GetBinMin(const unsigned int dimension, 
00171                              const unsigned long nbin) const
00172   { return m_Min[dimension][nbin] ; }
00173   
00175   const MeasurementType& GetBinMax(const unsigned int dimension,
00176                              const unsigned long nbin) const
00177   { return m_Max[dimension][nbin] ; }
00178   
00180   void SetBinMin(const unsigned int dimension, const unsigned long nbin,
00181                  const MeasurementType min)
00182   { m_Min[dimension][nbin] = min ; }
00183   
00185   void SetBinMax(const unsigned int dimension, 
00186                  unsigned long nbin, const MeasurementType max)
00187   { m_Max[dimension][nbin] = max ; }
00188   
00191   MeasurementType& GetBinMinFromValue(const unsigned int dimension, 
00192                                       const float value ) const  ;
00193   
00196   MeasurementType& GetBinMaxFromValue(const unsigned int dimension, 
00197                                       const float value ) const ;
00198   
00200   BinMinVectorType& GetDimensionMins(const unsigned int dimension) const
00201   { return m_Min[dimension] ; }
00202   
00204   BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const
00205   {  return m_Max[dimension] ; }
00206   
00208   BinMinContainerType& GetMins() const
00209   { return m_Min ; }
00210   
00212   BinMaxContainerType& GetMaxs() const
00213   { return m_Max ; }
00214   
00216   MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType 
00217                                                   &measurement)  ; 
00218   
00220   MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType 
00221                                                   &measurement) ; 
00222   
00224   MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index) ;
00225   
00227   MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index) ; 
00228   
00230   FrequencyType GetFrequency(const InstanceIdentifier &id) const
00231   { return m_FrequencyContainer->GetFrequency(id) ; }
00232 
00234   FrequencyType GetFrequency(const IndexType &index) const ;
00235 
00237   void SetFrequency(const FrequencyType value) ;
00238 
00241   bool SetFrequency(const InstanceIdentifier &id, const FrequencyType value) 
00242   { return m_FrequencyContainer->SetFrequency(id, value) ; }
00243 
00246   bool SetFrequency(const IndexType &index, 
00247                     const FrequencyType value) ;
00248   
00251   bool SetFrequency(const MeasurementVectorType &measurement, 
00252                     const FrequencyType value) ;
00253 
00254 
00257   bool IncreaseFrequency(const InstanceIdentifier &id,
00258                          const FrequencyType value) 
00259   { return m_FrequencyContainer->IncreaseFrequency(id, value) ; }
00260 
00263   bool IncreaseFrequency(const IndexType &index, 
00264                          const FrequencyType value) ;
00265   
00268   bool IncreaseFrequency(const MeasurementVectorType &measurement, 
00269                          const FrequencyType value) ;
00270   
00272   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00273   
00275   const MeasurementVectorType & GetMeasurementVector(const IndexType &index) const;
00276   
00278   MeasurementType GetMeasurement(const unsigned long n,
00279                                   const unsigned int dimension) const ;
00280 
00282   FrequencyType GetTotalFrequency() const ;
00283 
00285   FrequencyType GetFrequency(const unsigned long n,
00286                              const unsigned int dimension) const ;
00287 
00302   double Quantile(const unsigned int dimension, const double &p) const;
00303 
00306   class Iterator
00307   {
00308   public:
00309     Iterator(){};
00310     
00311     Iterator(Self * histogram) 
00312     { 
00313       m_Id = 0 ;
00314       m_Histogram = histogram; 
00315     } 
00316     
00317     Iterator(InstanceIdentifier id, Self * histogram)
00318       : m_Id(id), m_Histogram(histogram)
00319     {}
00320     
00321     FrequencyType GetFrequency() const
00322     { 
00323       return  m_Histogram->GetFrequency(m_Id) ;
00324     }
00325     
00326     bool SetFrequency(const FrequencyType value) 
00327     { 
00328       return m_Histogram->SetFrequency(m_Id, value); 
00329     }
00330 
00331     InstanceIdentifier GetInstanceIdentifier() const
00332     { return m_Id ; }
00333 
00334     const MeasurementVectorType & GetMeasurementVector() const
00335     { 
00336       return m_Histogram->GetMeasurementVector(m_Id) ;
00337     } 
00338 
00339     Iterator& operator++() 
00340     { 
00341       ++m_Id; 
00342       return *this;
00343     }
00344     
00345     bool operator!=(const Iterator& it) 
00346     { return (m_Id != it.m_Id); }
00347     
00348     bool operator==(const Iterator& it) 
00349     { return (m_Id == it.m_Id); }
00350     
00351     Iterator& operator=(const Iterator& it)
00352     { 
00353       m_Id  = it.m_Id;
00354       m_Histogram = it.m_Histogram ; 
00355       return *this ;
00356     }
00357 
00358     Iterator(const Iterator& it)
00359     { 
00360       m_Id        = it.m_Id;
00361       m_Histogram = it.m_Histogram ; 
00362     }
00363    
00364   private:
00365     // Iterator pointing DenseFrequencyContainer
00366     InstanceIdentifier m_Id;
00367     
00368     // Pointer of DenseFrequencyContainer
00369     Self* m_Histogram ;
00370   } ; // end of iterator class
00371 
00372   // Const Iterator
00373   class ConstIterator
00374   {
00375   public:
00376     ConstIterator(){};
00377     
00378     ConstIterator(const Self * histogram) 
00379     { 
00380       m_Id = 0 ;
00381       m_Histogram = histogram; 
00382     } 
00383     
00384     ConstIterator(InstanceIdentifier id, const Self * histogram)
00385       : m_Id(id), m_Histogram(histogram)
00386     {}
00387     
00388     FrequencyType GetFrequency() const
00389     { 
00390       return  m_Histogram->GetFrequency(m_Id) ;
00391     }
00392     
00393     bool SetFrequency(const FrequencyType value) 
00394     { 
00395       return m_Histogram->SetFrequency(m_Id, value); 
00396     }
00397 
00398     InstanceIdentifier GetInstanceIdentifier() const
00399     { return m_Id ; }
00400 
00401     const MeasurementVectorType & GetMeasurementVector() const
00402     { 
00403       return m_Histogram->GetMeasurementVector(m_Id) ;
00404     } 
00405 
00406     ConstIterator& operator++() 
00407     { 
00408       ++m_Id; 
00409       return *this;
00410     }
00411     
00412     bool operator!=(const ConstIterator& it) 
00413     { return (m_Id != it.m_Id); }
00414     
00415     bool operator==(const ConstIterator& it) 
00416     { return (m_Id == it.m_Id); }
00417     
00418     ConstIterator& operator=(const ConstIterator& it)
00419     { 
00420       m_Id  = it.m_Id;
00421       m_Histogram = it.m_Histogram ; 
00422       return *this ;
00423     }
00424 
00425     ConstIterator(const ConstIterator & it)
00426     { 
00427       m_Id        = it.m_Id;
00428       m_Histogram = it.m_Histogram ; 
00429     }
00430    
00431   private:
00432     // ConstIterator pointing DenseFrequencyContainer
00433     InstanceIdentifier m_Id;
00434     
00435     // Pointer of DenseFrequencyContainer
00436     const Self* m_Histogram ;
00437   } ; // end of iterator class
00438 
00439   Iterator  Begin()
00440   { 
00441     Iterator iter(0, this) ; 
00442     return iter ;
00443   }
00444            
00445   Iterator  End()        
00446   {
00447     return Iterator(m_OffsetTable[VMeasurementVectorSize], this) ;
00448   }
00449   
00450   ConstIterator  Begin() const
00451   { 
00452     ConstIterator iter(0, this) ; 
00453     return iter ;
00454   }
00455            
00456   ConstIterator End() const
00457   {
00458     return ConstIterator(m_OffsetTable[VMeasurementVectorSize], this) ;
00459   }
00460  
00461 
00462 protected:
00463   Histogram() ;
00464   virtual ~Histogram() {}
00465   void PrintSelf(std::ostream& os, Indent indent) const;
00466 
00467   // The number of bins for each dimension
00468   SizeType m_Size ;
00469   
00470 private:
00471   Histogram(const Self&); //purposely not implemented
00472   void operator=(const Self&); //purposely not implemented
00473 
00474   InstanceIdentifier          m_OffsetTable[VMeasurementVectorSize + 1] ;
00475   FrequencyContainerPointer   m_FrequencyContainer ;
00476   unsigned int                m_NumberOfInstances ;
00477 
00478   // lower bound of each bin
00479   std::vector< std::vector<MeasurementType> > m_Min ;
00480   
00481   // upper bound of each bin
00482   std::vector< std::vector<MeasurementType> > m_Max ;
00483   
00484   mutable MeasurementVectorType   m_TempMeasurementVector ;
00485   mutable IndexType               m_TempIndex ;
00486 
00487 } ; // end of class
00488 
00489 } // end of namespace Statistics 
00490 } // end of namespace itk 
00491 
00492 #ifndef ITK_MANUAL_INSTANTIATION
00493 #include "itkHistogram.txx"
00494 #endif
00495 
00496 #endif

Generated at Tue Mar 29 23:53:46 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000