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
00066 template < class TMeasurement = float,
00067 class TFrequencyContainer = DenseFrequencyContainer >
00068 class ITK_EXPORT VariableDimensionHistogram
00069 : public Sample < Array< TMeasurement > >
00070 {
00071 public:
00072
00074 typedef VariableDimensionHistogram Self;
00075 typedef Sample< Array< TMeasurement > > Superclass;
00076 typedef SmartPointer<Self> Pointer;
00077 typedef SmartPointer<const Self> ConstPointer;
00078
00080 itkTypeMacro(VariableDimensionHistogram, Sample);
00081
00083 itkNewMacro(Self);
00084
00086 typedef TMeasurement MeasurementType;
00087
00089 typedef typename Superclass::MeasurementVectorType MeasurementVectorType;
00090 typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
00091 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
00092 typedef MeasurementVectorType ValueType;
00093
00095 typedef TFrequencyContainer FrequencyContainerType;
00096 typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer;
00097
00099 typedef typename FrequencyContainerType::FrequencyType FrequencyType;
00100 typedef typename FrequencyContainerType::TotalFrequencyType TotalFrequencyType;
00101
00103 typedef itk::Array< long > IndexType;
00104 typedef typename IndexType::ValueType IndexValueType;
00105
00107 typedef itk::Array< long > SizeType;
00108 typedef typename SizeType::ValueType SizeValueType;
00109
00111 typedef std::vector< MeasurementType > BinMinVectorType;
00112 typedef std::vector< MeasurementType > BinMaxVectorType;
00113 typedef std::vector< BinMinVectorType > BinMinContainerType;
00114 typedef std::vector< BinMaxVectorType > BinMaxContainerType;
00115
00119 void Initialize(const SizeType &size);
00120
00121
00125 void Initialize(const SizeType &size, MeasurementVectorType& lowerBound,
00126 MeasurementVectorType& upperBound);
00127
00129 void SetToZero();
00130
00134 bool GetIndex(const MeasurementVectorType & measurement,
00135 IndexType & index ) const;
00136
00140 const IndexType & GetIndex(const InstanceIdentifier &ident) const;
00141
00144 itkGetMacro(ClipBinsAtEnds, bool);
00145
00148 itkSetMacro(ClipBinsAtEnds, bool);
00149
00152 bool IsIndexOutOfBounds(const IndexType &index) const;
00153
00157 InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const;
00158
00160 unsigned int Size() const;
00161
00163 SizeType GetSize() const
00164 { return m_Size; }
00165
00167 SizeValueType GetSize(const unsigned int dimension) const
00168 {
00169 return m_Size[dimension];
00170 }
00171
00173 const MeasurementType& GetBinMin(const unsigned int dimension,
00174 const unsigned long nbin) const
00175 { return m_Min[dimension][nbin]; }
00176
00178 const MeasurementType& GetBinMax(const unsigned int dimension,
00179 const unsigned long nbin) const
00180 { return m_Max[dimension][nbin]; }
00181
00183 void SetBinMin(const unsigned int dimension, const unsigned long nbin,
00184 const MeasurementType min)
00185 { m_Min[dimension][nbin] = min; }
00186
00188 void SetBinMax(const unsigned int dimension,
00189 unsigned long nbin, const MeasurementType max)
00190 { m_Max[dimension][nbin] = max; }
00191
00194 const MeasurementType& GetBinMinFromValue(const unsigned int dimension,
00195 const float value ) const;
00196
00199 const MeasurementType& GetBinMaxFromValue(const unsigned int dimension,
00200 const float value ) const;
00201
00203 const BinMinVectorType& GetDimensionMins(const unsigned int dimension) const
00204 { return m_Min[dimension]; }
00205
00207 const BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const
00208 { return m_Max[dimension]; }
00209
00211 const BinMinContainerType& GetMins() const
00212 { return m_Min; }
00213
00215 const BinMaxContainerType& GetMaxs() const
00216 { return m_Max; }
00217
00219 MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType
00220 &measurement);
00221
00223 MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType
00224 &measurement);
00225
00227 MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index);
00228
00230 MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index);
00231
00233 FrequencyType GetFrequency(const InstanceIdentifier &ident) const
00234 { return m_FrequencyContainer->GetFrequency(ident); }
00235
00237 FrequencyType GetFrequency(const IndexType &index) const;
00238
00240 void SetFrequency(const FrequencyType value);
00241
00244 bool SetFrequency(const InstanceIdentifier &ident, const FrequencyType value)
00245 { return m_FrequencyContainer->SetFrequency(ident, value); }
00246
00249 bool SetFrequency(const IndexType &index,
00250 const FrequencyType value);
00251
00254 bool SetFrequency(const MeasurementVectorType &measurement,
00255 const FrequencyType value);
00256
00257
00261 bool IncreaseFrequency(const InstanceIdentifier &ident,
00262 const FrequencyType value)
00263 { return m_FrequencyContainer->IncreaseFrequency(ident, value); }
00264
00268 bool IncreaseFrequency(const IndexType &index,
00269 const FrequencyType value);
00270
00274 bool IncreaseFrequency(const MeasurementVectorType &measurement,
00275 const FrequencyType value);
00276
00280 const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &ident) const;
00281
00283 const MeasurementVectorType & GetMeasurementVector(const IndexType &index) const;
00284
00287 MeasurementType GetMeasurement(const unsigned long n,
00288 const unsigned int dimension) const;
00289
00291 TotalFrequencyType GetTotalFrequency() const;
00292
00294 FrequencyType GetFrequency(const unsigned long n,
00295 const unsigned int dimension) const;
00296
00312 double Quantile(const unsigned int dimension, const double &p) const;
00314
00315 protected:
00316 void PrintSelf(std::ostream& os, Indent indent) const;
00317
00318 public:
00321 class Iterator
00322 {
00323 public:
00324 Iterator(){};
00325
00326 Iterator(Self * histogram)
00327 {
00328 m_Id = 0;
00329 m_Histogram = histogram;
00330 }
00331
00332 Iterator(InstanceIdentifier ident, Self * histogram)
00333 : m_Id(ident), m_Histogram(histogram) {}
00334
00335 FrequencyType GetFrequency() const
00336 {
00337 return m_Histogram->GetFrequency(m_Id);
00338 }
00339
00340 bool SetFrequency(const FrequencyType value)
00341 {
00342 return m_Histogram->SetFrequency(m_Id, value);
00343 }
00344
00345 InstanceIdentifier GetInstanceIdentifier() const
00346 { return m_Id; }
00347
00348 const MeasurementVectorType & GetMeasurementVector() const
00349 {
00350 return m_Histogram->GetMeasurementVector(m_Id);
00351 }
00352
00353 Iterator& operator++()
00354 {
00355 ++m_Id;
00356 return *this;
00357 }
00358
00359 bool operator!=(const Iterator& it)
00360 { return (m_Id != it.m_Id); }
00361
00362 bool operator==(const Iterator& it)
00363 { return (m_Id == it.m_Id); }
00364
00365 Iterator& operator=(const Iterator& it)
00366 {
00367 m_Id = it.m_Id;
00368 m_Histogram = it.m_Histogram;
00369 return *this;
00370 }
00371
00372 Iterator(const Iterator& it)
00373 {
00374 m_Id = it.m_Id;
00375 m_Histogram = it.m_Histogram;
00376 }
00377
00378 private:
00379
00380 InstanceIdentifier m_Id;
00381
00382
00383 Self* m_Histogram;
00384 };
00385
00386
00387 class ConstIterator
00388 {
00389 public:
00390 ConstIterator(){};
00391
00392 ConstIterator(const Self * histogram)
00393 {
00394 m_Id = 0;
00395 m_Histogram = histogram;
00396 }
00397
00398 ConstIterator(InstanceIdentifier ident, const Self * histogram)
00399 : m_Id(ident), m_Histogram(histogram) {}
00400
00401 FrequencyType GetFrequency() const
00402 {
00403 return m_Histogram->GetFrequency(m_Id);
00404 }
00405
00406 bool SetFrequency(const FrequencyType value)
00407 {
00408 return m_Histogram->SetFrequency(m_Id, value);
00409 }
00410
00411 InstanceIdentifier GetInstanceIdentifier() const
00412 { return m_Id; }
00413
00414 const MeasurementVectorType & GetMeasurementVector() const
00415 {
00416 return m_Histogram->GetMeasurementVector(m_Id);
00417 }
00418
00419 ConstIterator& operator++()
00420 {
00421 ++m_Id;
00422 return *this;
00423 }
00424
00425 bool operator!=(const ConstIterator& it)
00426 { return (m_Id != it.m_Id); }
00427
00428 bool operator==(const ConstIterator& it)
00429 { return (m_Id == it.m_Id); }
00430
00431 ConstIterator& operator=(const ConstIterator& it)
00432 {
00433 m_Id = it.m_Id;
00434 m_Histogram = it.m_Histogram;
00435 return *this;
00436 }
00437
00438 ConstIterator(const ConstIterator & it)
00439 {
00440 m_Id = it.m_Id;
00441 m_Histogram = it.m_Histogram;
00442 }
00443
00444 private:
00445
00446 InstanceIdentifier m_Id;
00447
00448
00449 const Self* m_Histogram;
00450 };
00451
00452 Iterator Begin()
00453 {
00454 Iterator iter(0, this);
00455 return iter;
00456 }
00457
00458 Iterator End()
00459 {
00460 return Iterator(m_OffsetTable[this->GetMeasurementVectorSize()], this);
00461 }
00462
00463 ConstIterator Begin() const
00464 {
00465 ConstIterator iter(0, this);
00466 return iter;
00467 }
00468
00469 ConstIterator End() const
00470 {
00471 return ConstIterator(m_OffsetTable[this->GetMeasurementVectorSize()], this);
00472 }
00473
00474 protected:
00475 VariableDimensionHistogram();
00476 virtual ~VariableDimensionHistogram() {}
00477
00481 void SetMeasurementVectorSize( const MeasurementVectorSizeType );
00482
00483
00484 SizeType m_Size;
00485
00486 private:
00487 VariableDimensionHistogram(const Self&);
00488 void operator=(const Self&);
00489
00490 Array< InstanceIdentifier > m_OffsetTable;
00491 FrequencyContainerPointer m_FrequencyContainer;
00492 unsigned int m_NumberOfInstances;
00493
00494
00495 std::vector< std::vector<MeasurementType> > m_Min;
00496
00497
00498 std::vector< std::vector<MeasurementType> > m_Max;
00499
00500 mutable MeasurementVectorType m_TempMeasurementVector;
00501 mutable IndexType m_TempIndex;
00502
00503 bool m_ClipBinsAtEnds;
00504
00505 };
00506
00507 }
00508 }
00509
00510 #ifndef ITK_MANUAL_INSTANTIATION
00511 #include "itkVariableDimensionHistogram.txx"
00512 #endif
00513
00514 #endif
00515