Orfeo Toolbox  3.16
itkHistogram.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkHistogram.h,v $
5  Language: C++
6  Date: $Date: 2009-03-04 15:23:50 $
7  Version: $Revision: 1.50 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkHistogram_h
18 #define __itkHistogram_h
19 
20 #include <vector>
21 
22 #include "itkIndex.h"
23 #include "itkSize.h"
24 #include "itkFixedArray.h"
25 #include "itkSample.h"
28 
29 namespace itk {
30 namespace Statistics {
31 
38 template <typename THistogram>
40 {
41  itkStaticConstMacro(HistogramDimension, unsigned int, THistogram::MeasurementVectorSize);
42 };
43 
80 template < class TMeasurement = float, unsigned int VMeasurementVectorSize = 1,
81  class TFrequencyContainer = DenseFrequencyContainer >
83  : public Sample < FixedArray< TMeasurement, VMeasurementVectorSize > >
84 {
85 public:
86 
87 
89  typedef Histogram Self;
94 
96  itkTypeMacro(Histogram, Sample);
97 
99  itkNewMacro(Self);
100 
102  itkStaticConstMacro(MeasurementVectorSize, unsigned int,
103  VMeasurementVectorSize);
104 
105 
107  typedef TMeasurement MeasurementType;
108 
113  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
114 
116  typedef TFrequencyContainer FrequencyContainerType;
117  typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer;
118 
120  typedef typename FrequencyContainerType::FrequencyType FrequencyType;
121  typedef typename FrequencyContainerType::TotalFrequencyType TotalFrequencyType;
122 
126 
130 
132  typedef std::vector< MeasurementType > BinMinVectorType;
133  typedef std::vector< MeasurementType > BinMaxVectorType;
134  typedef std::vector< BinMinVectorType > BinMinContainerType;
135  typedef std::vector< BinMaxVectorType > BinMaxContainerType;
136 
140  void Initialize(const SizeType &size);
141 
142 
146  void Initialize(const SizeType &size, MeasurementVectorType& lowerBound,
147  MeasurementVectorType& upperBound);
148 
150  void SetToZero();
151 
155  const IndexType & GetIndex(const MeasurementVectorType& measurement) const;
156 
160  bool GetIndex(const MeasurementVectorType & measurement,
161  IndexType & index ) const;
162 
166  const IndexType & GetIndex(const InstanceIdentifier &id) const;
167 
170  itkGetMacro(ClipBinsAtEnds, bool);
171 
174  itkSetMacro(ClipBinsAtEnds, bool);
175 
178  bool IsIndexOutOfBounds(const IndexType &index) const;
179 
183  InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const;
184 
186  unsigned int Size() const;
187 
189  SizeType GetSize() const
190  { return m_Size; }
191 
193  SizeValueType GetSize(const unsigned int dimension) const
194  {
195  return m_Size[dimension];
196  }
197 
199  const MeasurementType& GetBinMin(const unsigned int dimension,
200  const unsigned long nbin) const
201  { return m_Min[dimension][nbin]; }
202 
204  const MeasurementType& GetBinMax(const unsigned int dimension,
205  const unsigned long nbin) const
206  { return m_Max[dimension][nbin]; }
207 
209  void SetBinMin(const unsigned int dimension, const unsigned long nbin,
210  const MeasurementType min)
211  { m_Min[dimension][nbin] = min; }
212 
214  void SetBinMax(const unsigned int dimension,
215  unsigned long nbin, const MeasurementType max)
216  { m_Max[dimension][nbin] = max; }
217 
220  const MeasurementType& GetBinMinFromValue(const unsigned int dimension,
221  const float value ) const;
222 
225  const MeasurementType& GetBinMaxFromValue(const unsigned int dimension,
226  const float value ) const;
227 
229  const BinMinVectorType& GetDimensionMins(const unsigned int dimension) const
230  { return m_Min[dimension]; }
231 
233  const BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const
234  { return m_Max[dimension]; }
235 
237  const BinMinContainerType& GetMins() const
238  { return m_Min; }
239 
241  const BinMaxContainerType& GetMaxs() const
242  { return m_Max; }
243 
245  MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index);
246 
248  MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index);
249 
251  FrequencyType GetFrequency(const InstanceIdentifier &id) const
252  { return m_FrequencyContainer->GetFrequency(id); }
253 
255  FrequencyType GetFrequency(const IndexType &index) const;
256 
258  void SetFrequency(const FrequencyType value);
259 
262  bool SetFrequency(const InstanceIdentifier &id, const FrequencyType value)
263  { return m_FrequencyContainer->SetFrequency(id, value); }
264 
267  bool SetFrequency(const IndexType &index,
268  const FrequencyType value);
269 
272  bool SetFrequency(const MeasurementVectorType &measurement,
273  const FrequencyType value);
274 
275 
279  bool IncreaseFrequency(const InstanceIdentifier &id,
280  const FrequencyType value)
281  { return m_FrequencyContainer->IncreaseFrequency(id, value); }
282 
286  bool IncreaseFrequency(const IndexType &index,
287  const FrequencyType value);
288 
292  bool IncreaseFrequency(const MeasurementVectorType &measurement,
293  const FrequencyType value);
294 
298  const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const;
299 
301  const MeasurementVectorType & GetMeasurementVector(const IndexType &index) const;
302 
305  MeasurementType GetMeasurement(const unsigned long n,
306  const unsigned int dimension) const;
307 
309  TotalFrequencyType GetTotalFrequency() const;
310 
312  FrequencyType GetFrequency(const unsigned long n,
313  const unsigned int dimension) const;
314 
330  double Quantile(const unsigned int dimension, const double &p) const;
331 
332 protected:
333  void PrintSelf(std::ostream& os, Indent indent) const;
334 
335 public:
338  class Iterator
339  {
340  public:
341  Iterator(){};
342 
343  Iterator(Self * histogram)
344  {
345  m_Id = 0;
346  m_Histogram = histogram;
347  }
348 
350  : m_Id(id), m_Histogram(histogram) {}
351 
352  FrequencyType GetFrequency() const
353  {
354  return m_Histogram->GetFrequency(m_Id);
355  }
356 
357  bool SetFrequency(const FrequencyType value)
358  {
359  return m_Histogram->SetFrequency(m_Id, value);
360  }
361 
362  InstanceIdentifier GetInstanceIdentifier() const
363  { return m_Id; }
364 
365  const MeasurementVectorType & GetMeasurementVector() const
366  {
367  return m_Histogram->GetMeasurementVector(m_Id);
368  }
369 
370  Iterator& operator++()
371  {
372  ++m_Id;
373  return *this;
374  }
375 
376  bool operator!=(const Iterator& it)
377  { return (m_Id != it.m_Id); }
378 
379  bool operator==(const Iterator& it)
380  { return (m_Id == it.m_Id); }
381 
382  Iterator& operator=(const Iterator& it)
383  {
384  m_Id = it.m_Id;
385  m_Histogram = it.m_Histogram;
386  return *this;
387  }
388 
389  Iterator(const Iterator& it)
390  {
391  m_Id = it.m_Id;
392  m_Histogram = it.m_Histogram;
393  }
394 
395  private:
396  // Iterator pointing DenseFrequencyContainer
398 
399  // Pointer of DenseFrequencyContainer
401  }; // end of iterator class
402 
403  // Const Iterator
405  {
406  public:
408 
409  ConstIterator(const Self * histogram)
410  {
411  m_Id = 0;
412  m_Histogram = histogram;
413  }
414 
415  ConstIterator(InstanceIdentifier id, const Self * histogram)
416  : m_Id(id), m_Histogram(histogram) {}
417 
418  FrequencyType GetFrequency() const
419  {
420  return m_Histogram->GetFrequency(m_Id);
421  }
422 
423  InstanceIdentifier GetInstanceIdentifier() const
424  { return m_Id; }
425 
426  const MeasurementVectorType & GetMeasurementVector() const
427  {
428  return m_Histogram->GetMeasurementVector(m_Id);
429  }
430 
431  ConstIterator& operator++()
432  {
433  ++m_Id;
434  return *this;
435  }
436 
437  bool operator!=(const ConstIterator& it)
438  { return (m_Id != it.m_Id); }
439 
440  bool operator==(const ConstIterator& it)
441  { return (m_Id == it.m_Id); }
442 
443  ConstIterator& operator=(const ConstIterator& it)
444  {
445  m_Id = it.m_Id;
446  m_Histogram = it.m_Histogram;
447  return *this;
448  }
449 
451  {
452  m_Id = it.m_Id;
453  m_Histogram = it.m_Histogram;
454  }
455 
456  private:
457  // ConstIterator pointing DenseFrequencyContainer
459 
460  // Pointer of DenseFrequencyContainer
462  }; // end of iterator class
463 
464  Iterator Begin()
465  {
466  Iterator iter(0, this);
467  return iter;
468  }
469 
470  Iterator End()
471  {
472  return Iterator(m_OffsetTable[VMeasurementVectorSize], this);
473  }
474 
475  ConstIterator Begin() const
476  {
477  ConstIterator iter(0, this);
478  return iter;
479  }
480 
481  ConstIterator End() const
482  {
483  return ConstIterator(m_OffsetTable[VMeasurementVectorSize], this);
484  }
485 
486  virtual void SetMeasurementVectorSize( const MeasurementVectorSizeType s )
487  {
488  if( s!= VMeasurementVectorSize )
489  {
490  itkExceptionMacro( << "This Histogram class is meant to be used only for "
491  << "fixed length vectors of length " << VMeasurementVectorSize <<
492  ". Cannot set this to " << s);
493  }
494  }
495  MeasurementVectorSizeType GetMeasurementVectorSize() const
496  {
497  return VMeasurementVectorSize;
498  }
499 
500 protected:
501  Histogram();
502  virtual ~Histogram() {}
503 
504  // The number of bins for each dimension
506 
507 private:
508  Histogram(const Self&); //purposely not implemented
509  void operator=(const Self&); //purposely not implemented
510 
511  InstanceIdentifier m_OffsetTable[VMeasurementVectorSize + 1];
513  unsigned int m_NumberOfInstances;
514 
515  // lower bound of each bin
516  std::vector< std::vector<MeasurementType> > m_Min;
517 
518  // upper bound of each bin
519  std::vector< std::vector<MeasurementType> > m_Max;
520 
523 
525 
526 };
527 
528 } // end of namespace Statistics
529 } // end of namespace itk
530 
531 #ifndef ITK_MANUAL_INSTANTIATION
532 #include "itkHistogram.txx"
533 #endif
534 
535 #endif

Generated at Sat Feb 2 2013 23:41:25 for Orfeo Toolbox with doxygen 1.8.1.1