itkVariableDimensionHistogram.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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;
00317
00318 protected:
00319 void PrintSelf(std::ostream& os, Indent indent) const;
00320
00321 public:
00324 class Iterator
00325 {
00326 public:
00327 Iterator(){};
00328
00329 Iterator(Self * histogram)
00330 {
00331 m_Id = 0 ;
00332 m_Histogram = histogram;
00333 }
00334
00335 Iterator(InstanceIdentifier id, Self * histogram)
00336 : m_Id(id), m_Histogram(histogram)
00337 {}
00338
00339 FrequencyType GetFrequency() const
00340 {
00341 return m_Histogram->GetFrequency(m_Id) ;
00342 }
00343
00344 bool SetFrequency(const FrequencyType value)
00345 {
00346 return m_Histogram->SetFrequency(m_Id, value);
00347 }
00348
00349 InstanceIdentifier GetInstanceIdentifier() const
00350 { return m_Id ; }
00351
00352 const MeasurementVectorType & GetMeasurementVector() const
00353 {
00354 return m_Histogram->GetMeasurementVector(m_Id) ;
00355 }
00356
00357 Iterator& operator++()
00358 {
00359 ++m_Id;
00360 return *this;
00361 }
00362
00363 bool operator!=(const Iterator& it)
00364 { return (m_Id != it.m_Id); }
00365
00366 bool operator==(const Iterator& it)
00367 { return (m_Id == it.m_Id); }
00368
00369 Iterator& operator=(const Iterator& it)
00370 {
00371 m_Id = it.m_Id;
00372 m_Histogram = it.m_Histogram ;
00373 return *this ;
00374 }
00375
00376 Iterator(const Iterator& it)
00377 {
00378 m_Id = it.m_Id;
00379 m_Histogram = it.m_Histogram ;
00380 }
00381
00382 private:
00383
00384 InstanceIdentifier m_Id;
00385
00386
00387 Self* m_Histogram ;
00388 } ;
00389
00390
00391 class ConstIterator
00392 {
00393 public:
00394 ConstIterator(){};
00395
00396 ConstIterator(const Self * histogram)
00397 {
00398 m_Id = 0 ;
00399 m_Histogram = histogram;
00400 }
00401
00402 ConstIterator(InstanceIdentifier id, const Self * histogram)
00403 : m_Id(id), m_Histogram(histogram)
00404 {}
00405
00406 FrequencyType GetFrequency() const
00407 {
00408 return m_Histogram->GetFrequency(m_Id) ;
00409 }
00410
00411 bool SetFrequency(const FrequencyType value)
00412 {
00413 return m_Histogram->SetFrequency(m_Id, value);
00414 }
00415
00416 InstanceIdentifier GetInstanceIdentifier() const
00417 { return m_Id ; }
00418
00419 const MeasurementVectorType & GetMeasurementVector() const
00420 {
00421 return m_Histogram->GetMeasurementVector(m_Id) ;
00422 }
00423
00424 ConstIterator& operator++()
00425 {
00426 ++m_Id;
00427 return *this;
00428 }
00429
00430 bool operator!=(const ConstIterator& it)
00431 { return (m_Id != it.m_Id); }
00432
00433 bool operator==(const ConstIterator& it)
00434 { return (m_Id == it.m_Id); }
00435
00436 ConstIterator& operator=(const ConstIterator& it)
00437 {
00438 m_Id = it.m_Id;
00439 m_Histogram = it.m_Histogram ;
00440 return *this ;
00441 }
00442
00443 ConstIterator(const ConstIterator & it)
00444 {
00445 m_Id = it.m_Id;
00446 m_Histogram = it.m_Histogram ;
00447 }
00448
00449 private:
00450
00451 InstanceIdentifier m_Id;
00452
00453
00454 const Self* m_Histogram ;
00455 } ;
00456
00457 Iterator Begin()
00458 {
00459 Iterator iter(0, this) ;
00460 return iter ;
00461 }
00462
00463 Iterator End()
00464 {
00465 return Iterator(m_OffsetTable[this->GetMeasurementVectorSize()], this) ;
00466 }
00467
00468 ConstIterator Begin() const
00469 {
00470 ConstIterator iter(0, this) ;
00471 return iter ;
00472 }
00473
00474 ConstIterator End() const
00475 {
00476 return ConstIterator(m_OffsetTable[this->GetMeasurementVectorSize()], this) ;
00477 }
00478
00479
00480 protected:
00481 VariableDimensionHistogram() ;
00482 virtual ~VariableDimensionHistogram() {}
00483
00487 void SetMeasurementVectorSize( const MeasurementVectorSizeType );
00488
00489
00490 SizeType m_Size ;
00491
00492 private:
00493 VariableDimensionHistogram(const Self&);
00494 void operator=(const Self&);
00495
00496 Array< InstanceIdentifier > m_OffsetTable;
00497 FrequencyContainerPointer m_FrequencyContainer ;
00498 unsigned int m_NumberOfInstances ;
00499
00500
00501 std::vector< std::vector<MeasurementType> > m_Min ;
00502
00503
00504 std::vector< std::vector<MeasurementType> > m_Max ;
00505
00506 mutable MeasurementVectorType m_TempMeasurementVector ;
00507 mutable IndexType m_TempIndex ;
00508
00509 bool m_ClipBinsAtEnds;
00510
00511 } ;
00512
00513 }
00514 }
00515
00516 #ifndef ITK_MANUAL_INSTANTIATION
00517 #include "itkVariableDimensionHistogram.txx"
00518 #endif
00519
00520 #endif
00521