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/08/24 15:17:01 $
00007   Version:   $Revision: 1.4 $
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 
00105   typedef itk::Array< long >  IndexType;
00106   typedef typename IndexType::ValueType  IndexValueType;
00107 
00109   typedef itk::Array< long > SizeType ;
00110   typedef typename SizeType::ValueType SizeValueType ;
00111 
00113   typedef std::vector< MeasurementType > BinMinVectorType ;
00114   typedef std::vector< MeasurementType > BinMaxVectorType ;
00115   typedef std::vector< BinMinVectorType > BinMinContainerType ;
00116   typedef std::vector< BinMaxVectorType > BinMaxContainerType ;
00117 
00121   void Initialize(const SizeType &size) ;
00122   
00123 
00127   void Initialize(const SizeType &size, MeasurementVectorType& lowerBound,
00128                   MeasurementVectorType& upperBound) ;
00129 
00131   void SetToZero() ;
00132 
00136   bool GetIndex(const MeasurementVectorType & measurement,
00137                 IndexType & index ) const;
00138   
00142   const IndexType & GetIndex(const InstanceIdentifier &id) const;
00143 
00146   itkGetMacro(ClipBinsAtEnds, bool);
00147 
00150   itkSetMacro(ClipBinsAtEnds, bool);
00151 
00154   bool IsIndexOutOfBounds(const IndexType &index) const;
00155 
00159   InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const ;
00160   
00162   unsigned int Size() const ;
00163 
00165   SizeType GetSize() const
00166   { return m_Size ; }
00167 
00169   SizeValueType GetSize(const unsigned int dimension) const
00170   {
00171     return m_Size[dimension] ; 
00172   }
00173 
00175   const MeasurementType& GetBinMin(const unsigned int dimension, 
00176                              const unsigned long nbin) const
00177   { return m_Min[dimension][nbin] ; }
00178 
00180   const MeasurementType& GetBinMax(const unsigned int dimension,
00181                              const unsigned long nbin) const
00182   { return m_Max[dimension][nbin] ; }
00183   
00185   void SetBinMin(const unsigned int dimension, const unsigned long nbin,
00186                  const MeasurementType min)
00187   { m_Min[dimension][nbin] = min ; }
00188   
00190   void SetBinMax(const unsigned int dimension, 
00191                  unsigned long nbin, const MeasurementType max)
00192   { m_Max[dimension][nbin] = max ; }
00193   
00196   const MeasurementType& GetBinMinFromValue(const unsigned int dimension, 
00197                                       const float value ) const  ;
00198   
00201   const MeasurementType& GetBinMaxFromValue(const unsigned int dimension, 
00202                                       const float value ) const ;
00203   
00205   const BinMinVectorType& GetDimensionMins(const unsigned int dimension) const
00206   { return m_Min[dimension] ; }
00207   
00209   const BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const
00210   {  return m_Max[dimension] ; }
00211   
00213   const BinMinContainerType& GetMins() const
00214   { return m_Min ; }
00215   
00217   const BinMaxContainerType& GetMaxs() const
00218   { return m_Max ; }
00219   
00221   MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType 
00222                                                   &measurement)  ; 
00223   
00225   MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType 
00226                                                   &measurement) ; 
00227   
00229   MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index) ;
00230   
00232   MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index) ; 
00233   
00235   FrequencyType GetFrequency(const InstanceIdentifier &id) const
00236   { return m_FrequencyContainer->GetFrequency(id) ; }
00237 
00239   FrequencyType GetFrequency(const IndexType &index) const ;
00240 
00242   void SetFrequency(const FrequencyType value) ;
00243 
00246   bool SetFrequency(const InstanceIdentifier &id, const FrequencyType value) 
00247   { return m_FrequencyContainer->SetFrequency(id, value) ; }
00248 
00251   bool SetFrequency(const IndexType &index, 
00252                     const FrequencyType value) ;
00253   
00256   bool SetFrequency(const MeasurementVectorType &measurement, 
00257                     const FrequencyType value) ;
00258 
00259 
00263   bool IncreaseFrequency(const InstanceIdentifier &id,
00264                          const FrequencyType value) 
00265   { return m_FrequencyContainer->IncreaseFrequency(id, value) ; }
00266 
00270   bool IncreaseFrequency(const IndexType &index, 
00271                          const FrequencyType value) ;
00272   
00276   bool IncreaseFrequency(const MeasurementVectorType &measurement, 
00277                          const FrequencyType value) ;
00278   
00282   const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
00283   
00285   const MeasurementVectorType & GetMeasurementVector(const IndexType &index) const;
00286   
00289   MeasurementType GetMeasurement(const unsigned long n,
00290                                   const unsigned int dimension) const ;
00291 
00293   FrequencyType GetTotalFrequency() const ;
00294 
00296   FrequencyType GetFrequency(const unsigned long n,
00297                              const unsigned int dimension) const ;
00298 
00314   double Quantile(const unsigned int dimension, const double &p) const;
00315 
00316  protected:
00317   void PrintSelf(std::ostream& os, Indent indent) const;
00318 
00319 public:
00322   class Iterator
00323   {
00324   public:
00325     Iterator(){};
00326     
00327     Iterator(Self * histogram) 
00328     { 
00329       m_Id = 0 ;
00330       m_Histogram = histogram; 
00331     } 
00332     
00333     Iterator(InstanceIdentifier id, Self * histogram)
00334       : m_Id(id), m_Histogram(histogram)
00335     {}
00336     
00337     FrequencyType GetFrequency() const
00338     { 
00339       return  m_Histogram->GetFrequency(m_Id) ;
00340     }
00341     
00342     bool SetFrequency(const FrequencyType value) 
00343     { 
00344       return m_Histogram->SetFrequency(m_Id, value); 
00345     }
00346 
00347     InstanceIdentifier GetInstanceIdentifier() const
00348     { return m_Id ; }
00349 
00350     const MeasurementVectorType & GetMeasurementVector() const
00351     { 
00352       return m_Histogram->GetMeasurementVector(m_Id) ;
00353     } 
00354 
00355     Iterator& operator++() 
00356     { 
00357       ++m_Id; 
00358       return *this;
00359     }
00360     
00361     bool operator!=(const Iterator& it) 
00362     { return (m_Id != it.m_Id); }
00363     
00364     bool operator==(const Iterator& it) 
00365     { return (m_Id == it.m_Id); }
00366     
00367     Iterator& operator=(const Iterator& it)
00368     { 
00369       m_Id  = it.m_Id;
00370       m_Histogram = it.m_Histogram ; 
00371       return *this ;
00372     }
00373 
00374     Iterator(const Iterator& it)
00375     { 
00376       m_Id        = it.m_Id;
00377       m_Histogram = it.m_Histogram ; 
00378     }
00379    
00380   private:
00381     // Iterator pointing DenseFrequencyContainer
00382     InstanceIdentifier m_Id;
00383     
00384     // Pointer of DenseFrequencyContainer
00385     Self* m_Histogram ;
00386   } ; // end of iterator class
00387 
00388   // Const Iterator
00389   class ConstIterator
00390   {
00391   public:
00392     ConstIterator(){};
00393     
00394     ConstIterator(const Self * histogram) 
00395     { 
00396       m_Id = 0 ;
00397       m_Histogram = histogram; 
00398     } 
00399     
00400     ConstIterator(InstanceIdentifier id, const Self * histogram)
00401       : m_Id(id), m_Histogram(histogram)
00402     {}
00403     
00404     FrequencyType GetFrequency() const
00405     { 
00406       return  m_Histogram->GetFrequency(m_Id) ;
00407     }
00408     
00409     bool SetFrequency(const FrequencyType value) 
00410     { 
00411       return m_Histogram->SetFrequency(m_Id, value); 
00412     }
00413 
00414     InstanceIdentifier GetInstanceIdentifier() const
00415     { return m_Id ; }
00416 
00417     const MeasurementVectorType & GetMeasurementVector() const
00418     { 
00419       return m_Histogram->GetMeasurementVector(m_Id) ;
00420     } 
00421 
00422     ConstIterator& operator++() 
00423     { 
00424       ++m_Id; 
00425       return *this;
00426     }
00427     
00428     bool operator!=(const ConstIterator& it) 
00429     { return (m_Id != it.m_Id); }
00430     
00431     bool operator==(const ConstIterator& it) 
00432     { return (m_Id == it.m_Id); }
00433     
00434     ConstIterator& operator=(const ConstIterator& it)
00435     { 
00436       m_Id  = it.m_Id;
00437       m_Histogram = it.m_Histogram ; 
00438       return *this ;
00439     }
00440 
00441     ConstIterator(const ConstIterator & it)
00442     { 
00443       m_Id        = it.m_Id;
00444       m_Histogram = it.m_Histogram ; 
00445     }
00446    
00447   private:
00448     // ConstIterator pointing DenseFrequencyContainer
00449     InstanceIdentifier m_Id;
00450     
00451     // Pointer of DenseFrequencyContainer
00452     const Self* m_Histogram ;
00453   } ; // end of iterator class
00454 
00455   Iterator  Begin()
00456   { 
00457     Iterator iter(0, this) ; 
00458     return iter ;
00459   }
00460            
00461   Iterator  End()        
00462   {
00463     return Iterator(m_OffsetTable[this->GetMeasurementVectorSize()], this) ;
00464   }
00465   
00466   ConstIterator  Begin() const
00467   { 
00468     ConstIterator iter(0, this) ; 
00469     return iter ;
00470   }
00471            
00472   ConstIterator End() const
00473   {
00474     return ConstIterator(m_OffsetTable[this->GetMeasurementVectorSize()], this) ;
00475   }
00476  
00477 
00478 protected:
00479   VariableDimensionHistogram() ;
00480   virtual ~VariableDimensionHistogram() {}
00481 
00485   void SetMeasurementVectorSize( const MeasurementVectorSizeType );
00486 
00487   // The number of bins for each dimension
00488   SizeType m_Size ;
00489   
00490 private:
00491   VariableDimensionHistogram(const Self&); //purposely not implemented
00492   void operator=(const Self&); //purposely not implemented
00493 
00494   Array< InstanceIdentifier > m_OffsetTable;
00495   FrequencyContainerPointer   m_FrequencyContainer ;
00496   unsigned int                m_NumberOfInstances ;
00497 
00498   // lower bound of each bin
00499   std::vector< std::vector<MeasurementType> > m_Min ;
00500   
00501   // upper bound of each bin
00502   std::vector< std::vector<MeasurementType> > m_Max ;
00503   
00504   mutable MeasurementVectorType   m_TempMeasurementVector ;
00505   mutable IndexType               m_TempIndex ;
00506 
00507   bool                            m_ClipBinsAtEnds;
00508 
00509 } ; // end of class
00510 
00511 } // end of namespace Statistics 
00512 } // end of namespace itk 
00513 
00514 #ifndef ITK_MANUAL_INSTANTIATION
00515 #include "itkVariableDimensionHistogram.txx"
00516 #endif
00517 
00518 #endif

Generated at Tue Aug 30 16:46:38 2005 for ITK by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2000