Orfeo Toolbox  3.16
itkVariableDimensionHistogram.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkVariableDimensionHistogram.h,v $
5  Language: C++
6  Date: $Date: 2009-03-04 20:26:56 $
7  Version: $Revision: 1.8 $
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 __itkVariableDimensionHistogram_h
18 #define __itkVariableDimensionHistogram_h
19 
20 #include <vector>
21 
22 #include "itkIndex.h"
23 #include "itkSize.h"
24 #include "itkArray.h"
25 #include "itkSample.h"
28 
29 namespace itk {
30 namespace Statistics {
31 
66 template < class TMeasurement = float,
67  class TFrequencyContainer = DenseFrequencyContainer >
69  : public Sample < Array< TMeasurement > >
70 {
71 public:
72 
78 
80  itkTypeMacro(VariableDimensionHistogram, Sample);
81 
83  itkNewMacro(Self);
84 
86  typedef TMeasurement MeasurementType;
87 
91  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
93 
95  typedef TFrequencyContainer FrequencyContainerType;
96  typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer;
97 
99  typedef typename FrequencyContainerType::FrequencyType FrequencyType;
100  typedef typename FrequencyContainerType::TotalFrequencyType TotalFrequencyType;
101 
105 
109 
111  typedef std::vector< MeasurementType > BinMinVectorType;
112  typedef std::vector< MeasurementType > BinMaxVectorType;
113  typedef std::vector< BinMinVectorType > BinMinContainerType;
114  typedef std::vector< BinMaxVectorType > BinMaxContainerType;
115 
119  void Initialize(const SizeType &size);
120 
121 
125  void Initialize(const SizeType &size, MeasurementVectorType& lowerBound,
126  MeasurementVectorType& upperBound);
127 
129  void SetToZero();
130 
134  bool GetIndex(const MeasurementVectorType & measurement,
135  IndexType & index ) const;
136 
140  const IndexType & GetIndex(const InstanceIdentifier &ident) const;
141 
144  itkGetMacro(ClipBinsAtEnds, bool);
145 
148  itkSetMacro(ClipBinsAtEnds, bool);
149 
152  bool IsIndexOutOfBounds(const IndexType &index) const;
153 
157  InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const;
158 
160  unsigned int Size() const;
161 
163  SizeType GetSize() const
164  { return m_Size; }
165 
167  SizeValueType GetSize(const unsigned int dimension) const
168  {
169  return m_Size[dimension];
170  }
171 
173  const MeasurementType& GetBinMin(const unsigned int dimension,
174  const unsigned long nbin) const
175  { return m_Min[dimension][nbin]; }
176 
178  const MeasurementType& GetBinMax(const unsigned int dimension,
179  const unsigned long nbin) const
180  { return m_Max[dimension][nbin]; }
181 
183  void SetBinMin(const unsigned int dimension, const unsigned long nbin,
184  const MeasurementType min)
185  { m_Min[dimension][nbin] = min; }
186 
188  void SetBinMax(const unsigned int dimension,
189  unsigned long nbin, const MeasurementType max)
190  { m_Max[dimension][nbin] = max; }
191 
194  const MeasurementType& GetBinMinFromValue(const unsigned int dimension,
195  const float value ) const;
196 
199  const MeasurementType& GetBinMaxFromValue(const unsigned int dimension,
200  const float value ) const;
201 
203  const BinMinVectorType& GetDimensionMins(const unsigned int dimension) const
204  { return m_Min[dimension]; }
205 
207  const BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const
208  { return m_Max[dimension]; }
209 
211  const BinMinContainerType& GetMins() const
212  { return m_Min; }
214  const BinMaxContainerType& GetMaxs() const
215  { return m_Max; }
216 
218  MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType
219  &measurement);
220 
222  MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType
223  &measurement);
224 
226  MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index);
227 
229  MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index);
230 
232  FrequencyType GetFrequency(const InstanceIdentifier &ident) const
233  { return m_FrequencyContainer->GetFrequency(ident); }
234 
236  FrequencyType GetFrequency(const IndexType &index) const;
237 
239  void SetFrequency(const FrequencyType value);
240 
243  bool SetFrequency(const InstanceIdentifier &ident, const FrequencyType value)
244  { return m_FrequencyContainer->SetFrequency(ident, value); }
245 
248  bool SetFrequency(const IndexType &index,
249  const FrequencyType value);
250 
253  bool SetFrequency(const MeasurementVectorType &measurement,
254  const FrequencyType value);
255 
256 
260  bool IncreaseFrequency(const InstanceIdentifier &ident,
261  const FrequencyType value)
262  { return m_FrequencyContainer->IncreaseFrequency(ident, value); }
263 
267  bool IncreaseFrequency(const IndexType &index,
268  const FrequencyType value);
269 
273  bool IncreaseFrequency(const MeasurementVectorType &measurement,
274  const FrequencyType value);
275 
279  const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &ident) const;
280 
282  const MeasurementVectorType & GetMeasurementVector(const IndexType &index) const;
283 
286  MeasurementType GetMeasurement(const unsigned long n,
287  const unsigned int dimension) const;
288 
290  TotalFrequencyType GetTotalFrequency() const;
291 
293  FrequencyType GetFrequency(const unsigned long n,
294  const unsigned int dimension) const;
295 
311  double Quantile(const unsigned int dimension, const double &p) const;
312 
313 protected:
314  void PrintSelf(std::ostream& os, Indent indent) const;
315 
316 public:
319  class Iterator
320  {
321  public:
322  Iterator(){};
323 
324  Iterator(Self * histogram)
325  {
326  m_Id = 0;
327  m_Histogram = histogram;
328  }
329 
330  Iterator(InstanceIdentifier ident, Self * histogram)
331  : m_Id(ident), m_Histogram(histogram) {}
332 
333  FrequencyType GetFrequency() const
334  {
335  return m_Histogram->GetFrequency(m_Id);
336  }
337 
338  bool SetFrequency(const FrequencyType value)
339  {
340  return m_Histogram->SetFrequency(m_Id, value);
341  }
342 
343  InstanceIdentifier GetInstanceIdentifier() const
344  { return m_Id; }
345 
346  const MeasurementVectorType & GetMeasurementVector() const
347  {
348  return m_Histogram->GetMeasurementVector(m_Id);
349  }
350 
351  Iterator& operator++()
352  {
353  ++m_Id;
354  return *this;
355  }
356 
357  bool operator!=(const Iterator& it)
358  { return (m_Id != it.m_Id); }
359 
360  bool operator==(const Iterator& it)
361  { return (m_Id == it.m_Id); }
362 
363  Iterator& operator=(const Iterator& it)
364  {
365  m_Id = it.m_Id;
366  m_Histogram = it.m_Histogram;
367  return *this;
368  }
369 
370  Iterator(const Iterator& it)
371  {
372  m_Id = it.m_Id;
373  m_Histogram = it.m_Histogram;
374  }
375 
376  private:
377  // Iterator pointing DenseFrequencyContainer
379 
380  // Pointer of DenseFrequencyContainer
382  }; // end of iterator class
383 
384  // Const Iterator
386  {
387  public:
389 
390  ConstIterator(const Self * histogram)
391  {
392  m_Id = 0;
393  m_Histogram = histogram;
394  }
395 
396  ConstIterator(InstanceIdentifier ident, const Self * histogram)
397  : m_Id(ident), m_Histogram(histogram) {}
398 
399  FrequencyType GetFrequency() const
400  {
401  return m_Histogram->GetFrequency(m_Id);
402  }
403 
404  bool SetFrequency(const FrequencyType value)
405  {
406  return m_Histogram->SetFrequency(m_Id, value);
407  }
408 
409  InstanceIdentifier GetInstanceIdentifier() const
410  { return m_Id; }
411 
412  const MeasurementVectorType & GetMeasurementVector() const
413  {
414  return m_Histogram->GetMeasurementVector(m_Id);
415  }
416 
417  ConstIterator& operator++()
418  {
419  ++m_Id;
420  return *this;
421  }
422 
423  bool operator!=(const ConstIterator& it)
424  { return (m_Id != it.m_Id); }
425 
426  bool operator==(const ConstIterator& it)
427  { return (m_Id == it.m_Id); }
428 
429  ConstIterator& operator=(const ConstIterator& it)
430  {
431  m_Id = it.m_Id;
432  m_Histogram = it.m_Histogram;
433  return *this;
434  }
435 
437  {
438  m_Id = it.m_Id;
439  m_Histogram = it.m_Histogram;
440  }
441 
442  private:
443  // ConstIterator pointing DenseFrequencyContainer
445 
446  // Pointer of DenseFrequencyContainer
448  }; // end of iterator class
449 
450  Iterator Begin()
451  {
452  Iterator iter(0, this);
453  return iter;
454  }
455 
456  Iterator End()
457  {
458  return Iterator(m_OffsetTable[this->GetMeasurementVectorSize()], this);
459  }
460 
461  ConstIterator Begin() const
462  {
463  ConstIterator iter(0, this);
464  return iter;
465  }
466 
467  ConstIterator End() const
468  {
469  return ConstIterator(m_OffsetTable[this->GetMeasurementVectorSize()], this);
470  }
471 
472 protected:
475 
479  void SetMeasurementVectorSize( const MeasurementVectorSizeType );
480 
481  // The number of bins for each dimension
483 
484 private:
485  VariableDimensionHistogram(const Self&); //purposely not implemented
486  void operator=(const Self&); //purposely not implemented
487 
490  unsigned int m_NumberOfInstances;
491 
492  // lower bound of each bin
493  std::vector< std::vector<MeasurementType> > m_Min;
494 
495  // upper bound of each bin
496  std::vector< std::vector<MeasurementType> > m_Max;
497 
500 
502 
503 }; // end of class
504 
505 } // end of namespace Statistics
506 } // end of namespace itk
507 
508 #ifndef ITK_MANUAL_INSTANTIATION
510 #endif
511 
512 #endif

Generated at Sun Feb 3 2013 00:11:21 for Orfeo Toolbox with doxygen 1.8.1.1