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: 2003/12/09 15:44:00 $ 00007 Version: $Revision: 1.30 $ 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 const IndexType & GetIndex(const MeasurementVectorType& measurement) const; 00131 00135 const IndexType & GetIndex(const InstanceIdentifier &id) const; 00136 00139 bool IsIndexOutOfBounds(const IndexType &index) const; 00140 00144 InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const ; 00145 00147 unsigned int Size() const ; 00148 00150 SizeType GetSize() const 00151 { return m_Size ; } 00152 00154 SizeValueType GetSize(const unsigned int dimension) const 00155 { 00156 return m_Size[dimension] ; 00157 } 00158 00160 MeasurementType& GetBinMin(const unsigned int dimension, 00161 const unsigned long nbin) 00162 { return m_Min[dimension][nbin] ; } 00163 00165 MeasurementType& GetBinMax(const unsigned int dimension, 00166 const unsigned long nbin) 00167 { return m_Max[dimension][nbin] ; } 00168 00170 void SetBinMin(const unsigned int dimension, const unsigned long nbin, 00171 const MeasurementType min) 00172 { m_Min[dimension][nbin] = min ; } 00173 00175 void SetBinMax(const unsigned int dimension, 00176 unsigned long nbin, const MeasurementType max) 00177 { m_Max[dimension][nbin] = max ; } 00178 00181 MeasurementType& GetBinMinFromValue(const unsigned int dimension, 00182 const float value ) const ; 00183 00186 MeasurementType& GetBinMaxFromValue(const unsigned int dimension, 00187 const float value ) const ; 00188 00190 BinMinVectorType& GetDimensionMins(const unsigned int dimension) const 00191 { return m_Min[dimension] ; } 00192 00194 BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const 00195 { return m_Max[dimension] ; } 00196 00198 BinMinContainerType& GetMins() const 00199 { return m_Min ; } 00200 00202 BinMaxContainerType& GetMaxs() const 00203 { return m_Max ; } 00204 00206 MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType 00207 &measurement) ; 00208 00210 MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType 00211 &measurement) ; 00212 00214 MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index) ; 00215 00217 MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index) ; 00218 00220 FrequencyType GetFrequency(const InstanceIdentifier &id) const 00221 { return m_FrequencyContainer->GetFrequency(id) ; } 00222 00224 FrequencyType GetFrequency(const IndexType &index) const ; 00225 00227 void SetFrequency(const FrequencyType value) ; 00228 00230 void SetFrequency(const InstanceIdentifier &id, const FrequencyType value) 00231 { m_FrequencyContainer->SetFrequency(id, value) ; } 00232 00234 void SetFrequency(const IndexType &index, 00235 const FrequencyType value) ; 00236 00238 void SetFrequency(const MeasurementVectorType &measurement, 00239 const FrequencyType value) ; 00240 00241 00244 void IncreaseFrequency(const InstanceIdentifier &id, 00245 const FrequencyType value) 00246 { m_FrequencyContainer->IncreaseFrequency(id, value) ; } 00247 00250 void IncreaseFrequency(const IndexType &index, 00251 const FrequencyType value) ; 00252 00255 void IncreaseFrequency(const MeasurementVectorType &measurement, 00256 const FrequencyType value) ; 00257 00259 const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const; 00260 00262 const MeasurementVectorType & GetMeasurementVector(const IndexType &index) const; 00263 00265 MeasurementType GetMeasurement(const unsigned long n, 00266 const unsigned int dimension) const ; 00267 00269 FrequencyType GetTotalFrequency() const ; 00270 00272 FrequencyType GetFrequency(const unsigned long n, 00273 const unsigned int dimension) const ; 00274 00289 double Quantile(const unsigned int dimension, const double &p) ; 00290 00293 class Iterator 00294 { 00295 public: 00296 Iterator(){}; 00297 00298 Iterator(Self * histogram) 00299 { 00300 m_Id = 0 ; 00301 m_Histogram = histogram; 00302 } 00303 00304 Iterator(InstanceIdentifier id, Self * histogram) 00305 : m_Id(id), m_Histogram(histogram) 00306 {} 00307 00308 FrequencyType GetFrequency() const 00309 { 00310 return m_Histogram->GetFrequency(m_Id) ; 00311 } 00312 00313 void SetFrequency(const FrequencyType value) 00314 { 00315 m_Histogram->SetFrequency(m_Id, value); 00316 } 00317 00318 InstanceIdentifier GetInstanceIdentifier() const 00319 { return m_Id ; } 00320 00321 const MeasurementVectorType & GetMeasurementVector() const 00322 { 00323 return m_Histogram->GetMeasurementVector(m_Id) ; 00324 } 00325 00326 Iterator& operator++() 00327 { 00328 ++m_Id; 00329 return *this; 00330 } 00331 00332 bool operator!=(const Iterator& it) 00333 { return (m_Id != it.m_Id); } 00334 00335 bool operator==(const Iterator& it) 00336 { return (m_Id == it.m_Id); } 00337 00338 Iterator& operator=(const Iterator& it) 00339 { 00340 m_Id = it.m_Id; 00341 m_Histogram = it.m_Histogram ; 00342 return *this ; 00343 } 00344 00345 Iterator(const Iterator& it) 00346 { 00347 m_Id = it.m_Id; 00348 m_Histogram = it.m_Histogram ; 00349 } 00350 00351 private: 00352 // Iterator pointing DenseFrequencyContainer 00353 InstanceIdentifier m_Id; 00354 00355 // Pointer of DenseFrequencyContainer 00356 Self* m_Histogram ; 00357 } ; // end of iterator class 00358 00359 // Const Iterator 00360 class ConstIterator 00361 { 00362 public: 00363 ConstIterator(){}; 00364 00365 ConstIterator(const Self * histogram) 00366 { 00367 m_Id = 0 ; 00368 m_Histogram = histogram; 00369 } 00370 00371 ConstIterator(InstanceIdentifier id, const Self * histogram) 00372 : m_Id(id), m_Histogram(histogram) 00373 {} 00374 00375 FrequencyType GetFrequency() const 00376 { 00377 return m_Histogram->GetFrequency(m_Id) ; 00378 } 00379 00380 void SetFrequency(const FrequencyType value) 00381 { 00382 m_Histogram->SetFrequency(m_Id, value); 00383 } 00384 00385 InstanceIdentifier GetInstanceIdentifier() const 00386 { return m_Id ; } 00387 00388 const MeasurementVectorType & GetMeasurementVector() const 00389 { 00390 return m_Histogram->GetMeasurementVector(m_Id) ; 00391 } 00392 00393 ConstIterator& operator++() 00394 { 00395 ++m_Id; 00396 return *this; 00397 } 00398 00399 bool operator!=(const ConstIterator& it) 00400 { return (m_Id != it.m_Id); } 00401 00402 bool operator==(const ConstIterator& it) 00403 { return (m_Id == it.m_Id); } 00404 00405 ConstIterator& operator=(const ConstIterator& it) 00406 { 00407 m_Id = it.m_Id; 00408 m_Histogram = it.m_Histogram ; 00409 return *this ; 00410 } 00411 00412 ConstIterator(const ConstIterator & it) 00413 { 00414 m_Id = it.m_Id; 00415 m_Histogram = it.m_Histogram ; 00416 } 00417 00418 private: 00419 // ConstIterator pointing DenseFrequencyContainer 00420 InstanceIdentifier m_Id; 00421 00422 // Pointer of DenseFrequencyContainer 00423 const Self* m_Histogram ; 00424 } ; // end of iterator class 00425 00426 Iterator Begin() 00427 { 00428 Iterator iter(0, this) ; 00429 return iter ; 00430 } 00431 00432 Iterator End() 00433 { 00434 return Iterator(m_OffsetTable[VMeasurementVectorSize], this) ; 00435 } 00436 00437 ConstIterator Begin() const 00438 { 00439 ConstIterator iter(0, this) ; 00440 return iter ; 00441 } 00442 00443 ConstIterator End() const 00444 { 00445 return ConstIterator(m_OffsetTable[VMeasurementVectorSize], this) ; 00446 } 00447 00448 00449 protected: 00450 Histogram() ; 00451 virtual ~Histogram() {} 00452 void PrintSelf(std::ostream& os, Indent indent) const; 00453 00454 // The number of bins for each dimension 00455 SizeType m_Size ; 00456 00457 // lower bound of each bin 00458 std::vector< std::vector<MeasurementType> > m_Min ; 00459 00460 // upper bound of each bin 00461 std::vector< std::vector<MeasurementType> > m_Max ; 00462 00463 private: 00464 Histogram(const Self&); //purposely not implemented 00465 void operator=(const Self&); //purposely not implemented 00466 00467 InstanceIdentifier m_OffsetTable[VMeasurementVectorSize + 1] ; 00468 FrequencyContainerPointer m_FrequencyContainer ; 00469 unsigned int m_NumberOfInstances ; 00470 00471 mutable MeasurementVectorType m_TempMeasurementVector ; 00472 mutable IndexType m_TempIndex ; 00473 00474 } ; // end of class 00475 00476 } // end of namespace Statistics 00477 } // end of namespace itk 00478 00479 #ifndef ITK_MANUAL_INSTANTIATION 00480 #include "itkHistogram.txx" 00481 #endif 00482 00483 #endif

Generated at Sun Apr 1 02:32:40 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000