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/09/10 14:29:45 $ 00007 Version: $Revision: 1.28 $ 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 00075 itkTypeMacro(Histogram, Sample) ; 00076 00078 itkNewMacro(Self) ; 00079 00081 itkStaticConstMacro(MeasurementVectorSize, unsigned int, 00082 VMeasurementVectorSize); 00083 00085 typedef TMeasurement MeasurementType ; 00086 00088 typedef typename Superclass::MeasurementVectorType MeasurementVectorType ; 00089 typedef typename Superclass::InstanceIdentifier InstanceIdentifier ; 00090 typedef MeasurementVectorType ValueType ; 00091 00093 typedef TFrequencyContainer FrequencyContainerType ; 00094 typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer ; 00095 00097 typedef typename FrequencyContainerType::FrequencyType FrequencyType ; 00098 00100 typedef itk::Index< VMeasurementVectorSize > IndexType; 00101 typedef typename IndexType::IndexValueType IndexValueType; 00102 00104 typedef itk::Size< VMeasurementVectorSize > SizeType ; 00105 typedef typename SizeType::SizeValueType SizeValueType ; 00106 00108 typedef std::vector< MeasurementType > BinMinVectorType ; 00109 typedef std::vector< MeasurementType > BinMaxVectorType ; 00110 typedef std::vector< BinMinVectorType > BinMinContainerType ; 00111 typedef std::vector< BinMaxVectorType > BinMaxContainerType ; 00112 00117 void Initialize(const SizeType &size) ; 00118 00119 00125 void Initialize(const SizeType &size, MeasurementVectorType& lowerBound, 00126 MeasurementVectorType& upperBound) ; 00127 00129 IndexType& GetIndex(const MeasurementVectorType& measurement) ; 00130 00134 IndexType& GetIndex(const InstanceIdentifier &id) ; 00135 00138 bool IsIndexOutOfBounds(const IndexType &index) const; 00139 00143 InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const ; 00144 00146 unsigned int Size() const ; 00147 00149 SizeType GetSize() const 00150 { return m_Size ; } 00151 00153 SizeValueType GetSize(const unsigned int dimension) const 00154 { 00155 return m_Size[dimension] ; 00156 } 00157 00159 MeasurementType& GetBinMin(const unsigned int dimension, 00160 const unsigned long nbin) 00161 { return m_Min[dimension][nbin] ; } 00162 00164 MeasurementType& GetBinMax(const unsigned int dimension, 00165 const unsigned long nbin) 00166 { return m_Max[dimension][nbin] ; } 00167 00169 void SetBinMin(const unsigned int dimension, const unsigned long nbin, 00170 const MeasurementType min) 00171 { m_Min[dimension][nbin] = min ; } 00172 00174 void SetBinMax(const unsigned int dimension, 00175 unsigned long nbin, const MeasurementType max) 00176 { m_Max[dimension][nbin] = max ; } 00177 00180 MeasurementType& GetBinMinFromValue(const unsigned int dimension, 00181 const float value ) const ; 00182 00185 MeasurementType& GetBinMaxFromValue(const unsigned int dimension, 00186 const float value ) const ; 00187 00189 BinMinVectorType& GetDimensionMins(const unsigned int dimension) const 00190 { return m_Min[dimension] ; } 00191 00193 BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const 00194 { return m_Max[dimension] ; } 00195 00197 BinMinContainerType& GetMins() const 00198 { return m_Min ; } 00199 00201 BinMaxContainerType& GetMaxs() const 00202 { return m_Max ; } 00203 00205 MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType 00206 &measurement) ; 00207 00209 MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType 00210 &measurement) ; 00211 00213 MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index) ; 00214 00216 MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index) ; 00217 00219 FrequencyType GetFrequency(const InstanceIdentifier &id) const 00220 { return m_FrequencyContainer->GetFrequency(id) ; } 00221 00223 FrequencyType GetFrequency(const IndexType &index) const ; 00224 00226 void SetFrequency(const FrequencyType value) ; 00227 00229 void SetFrequency(const InstanceIdentifier &id, const FrequencyType value) 00230 { m_FrequencyContainer->SetFrequency(id, value) ; } 00231 00233 void SetFrequency(const IndexType &index, 00234 const FrequencyType value) ; 00235 00237 void SetFrequency(const MeasurementVectorType &measurement, 00238 const FrequencyType value) ; 00239 00240 00243 void IncreaseFrequency(const InstanceIdentifier &id, 00244 const FrequencyType value) 00245 { m_FrequencyContainer->IncreaseFrequency(id, value) ; } 00246 00249 void IncreaseFrequency(const IndexType &index, 00250 const FrequencyType value) ; 00251 00254 void IncreaseFrequency(const MeasurementVectorType &measurement, 00255 const FrequencyType value) ; 00256 00258 MeasurementVectorType GetMeasurementVector(const InstanceIdentifier &id) ; 00259 00261 MeasurementVectorType GetMeasurementVector(const IndexType &index) ; 00262 00264 MeasurementType GetMeasurement(const unsigned long n, 00265 const unsigned int dimension) const ; 00266 00268 FrequencyType GetTotalFrequency() const ; 00269 00271 FrequencyType GetFrequency(const unsigned long n, 00272 const unsigned int dimension) const ; 00273 00288 double Quantile(const unsigned int dimension, const double &p) ; 00289 00291 class Iterator ; 00292 friend class Iterator ; 00293 00294 Iterator Begin() 00295 { 00296 Iterator iter(0, this) ; 00297 return iter ; 00298 } 00299 00300 Iterator End() 00301 { 00302 return Iterator(m_OffsetTable[VMeasurementVectorSize], this) ; 00303 } 00304 00305 00306 class Iterator 00307 { 00308 public: 00309 Iterator(){}; 00310 00311 Iterator(Pointer histogram) 00312 { 00313 m_Id = 0 ; 00314 m_Histogram = histogram; 00315 } 00316 00317 Iterator(InstanceIdentifier id, Pointer 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 void SetFrequency(const FrequencyType value) 00327 { 00328 m_Histogram->SetFrequency(m_Id, value); 00329 } 00330 00331 InstanceIdentifier GetInstanceIdentifier() const 00332 { return m_Id ; } 00333 00334 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 protected: 00373 Histogram() ; 00374 virtual ~Histogram() {} 00375 void PrintSelf(std::ostream& os, Indent indent) const; 00376 00377 // The number of bins for each dimension 00378 SizeType m_Size ; 00379 00380 // lower bound of each bin 00381 std::vector< std::vector<MeasurementType> > m_Min ; 00382 00383 // upper bound of each bin 00384 std::vector< std::vector<MeasurementType> > m_Max ; 00385 00386 private: 00387 Histogram(const Self&); //purposely not implemented 00388 void operator=(const Self&); //purposely not implemented 00389 00390 InstanceIdentifier m_OffsetTable[VMeasurementVectorSize + 1] ; 00391 FrequencyContainerPointer m_FrequencyContainer ; 00392 unsigned int m_NumberOfInstances ; 00393 MeasurementVectorType m_TempMeasurementVector ; 00394 IndexType m_TempIndex ; 00395 } ; // end of class 00396 00397 } // end of namespace Statistics 00398 } // end of namespace itk 00399 00400 #ifndef ITK_MANUAL_INSTANTIATION 00401 #include "itkHistogram.txx" 00402 #endif 00403 00404 #endif

Generated at Sat Mar 31 02:20:29 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000