Orfeo Toolbox  4.2
itkHistogram.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkHistogram_h
19 #define __itkHistogram_h
20 
21 #include <vector>
22 
23 #include "itkArray.h"
24 #include "itkSample.h"
27 
28 namespace itk
29 {
30 namespace Statistics
31 {
32 
75 template< typename TMeasurement = float,
76  typename TFrequencyContainer = DenseFrequencyContainer2 >
77 class Histogram:
78  public Sample< Array< TMeasurement > >
79 {
80 public:
81 
82  // This type serves as the indirect definition of MeasurementVectorType
84 
86  typedef Histogram Self;
90 
92  itkTypeMacro(Histogram, Sample);
93 
95  itkNewMacro(Self);
96 
98  typedef TMeasurement MeasurementType;
99 
104 
106 
108  typedef TFrequencyContainer FrequencyContainerType;
109  typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer;
110 
112  typedef typename FrequencyContainerType::AbsoluteFrequencyType AbsoluteFrequencyType;
113  typedef typename FrequencyContainerType::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
114  typedef typename FrequencyContainerType::RelativeFrequencyType RelativeFrequencyType;
115  typedef typename FrequencyContainerType::TotalRelativeFrequencyType TotalRelativeFrequencyType;
116 
120 
124 
126  typedef std::vector< MeasurementType > BinMinVectorType;
127  typedef std::vector< MeasurementType > BinMaxVectorType;
128  typedef std::vector< BinMinVectorType > BinMinContainerType;
129  typedef std::vector< BinMaxVectorType > BinMaxContainerType;
130 
134  void Initialize(const SizeType & size);
135 
139  void Initialize(const SizeType & size, MeasurementVectorType & lowerBound,
140  MeasurementVectorType & upperBound);
141 
143  void SetToZero();
144 
148  itkLegacyMacro(const IndexType & GetIndex(const MeasurementVectorType & measurement) const);
149 
153  bool GetIndex(const MeasurementVectorType & measurement,
154  IndexType & index) const;
155 
159  const IndexType & GetIndex(InstanceIdentifier id) const;
160 
163  itkGetConstMacro(ClipBinsAtEnds, bool);
164 
167  itkSetMacro(ClipBinsAtEnds, bool);
168 
171  bool IsIndexOutOfBounds(const IndexType & index) const;
172 
177 
179  InstanceIdentifier Size() const;
180 
182  const SizeType & GetSize() const;
183 
185  SizeValueType GetSize(unsigned int dimension) const;
186 
188  const MeasurementType & GetBinMin(unsigned int dimension,
189  InstanceIdentifier nbin) const;
190 
192  const MeasurementType & GetBinMax(unsigned int dimension,
193  InstanceIdentifier nbin) const;
194 
196  void SetBinMin(unsigned int dimension, InstanceIdentifier nbin,
197  MeasurementType min);
198 
200  void SetBinMax(unsigned int dimension,
202 
205  const MeasurementType & GetBinMinFromValue(unsigned int dimension,
206  float value) const;
207 
210  const MeasurementType & GetBinMaxFromValue(unsigned int dimension,
211  float value) const;
212 
214  const BinMinVectorType & GetDimensionMins(unsigned int dimension) const;
215 
217  const BinMaxVectorType & GetDimensionMaxs(unsigned int dimension) const;
218 
220  const BinMinContainerType & GetMins() const;
221 
223  const BinMaxContainerType & GetMaxs() const;
224 
226  const MeasurementVectorType & GetHistogramMinFromIndex(const IndexType & index) const;
227 
229  const MeasurementVectorType & GetHistogramMaxFromIndex(const IndexType & index) const;
230 
233 
235  AbsoluteFrequencyType GetFrequency(const IndexType & index) const;
236 
239 
243 
246  bool SetFrequencyOfIndex(const IndexType & index,
247  AbsoluteFrequencyType value);
248 
251  bool SetFrequencyOfMeasurement(const MeasurementVectorType & measurement,
252  AbsoluteFrequencyType value);
253 
258 
262  bool IncreaseFrequencyOfIndex(const IndexType & index,
263  AbsoluteFrequencyType value);
264 
273  const MeasurementVectorType & measurement,
274  AbsoluteFrequencyType value);
275 #ifdef ITKV3_COMPATIBILITY
276  //In ITKv4 the member functions are given unique names to dis-ambiguate
277  //the intended behavior. Make aliases of the overloaded calls
278  //for ITKv3 backwards compatibility.
279  bool IncreaseFrequency(const IndexType & index,
280  AbsoluteFrequencyType value)
281  {
282  return IncreaseFrequencyOfIndex(index,value);
283  }
284 
285  bool IncreaseFrequency(
286  const MeasurementVectorType & measurement,
287  AbsoluteFrequencyType value)
288  {
289  return IncreaseFrequencyOfMeasurement(measurement,value);
290  }
291 
292 #endif
293 
298 
300  const MeasurementVectorType & GetMeasurementVector(const IndexType & index) const;
301 
305  unsigned int dimension) const;
306 
309 
312  unsigned int dimension) const;
313 
329  double Quantile(unsigned int dimension, double p) const;
330 
332  double Mean(unsigned int dimension) const;
333 
335  virtual void Graft(const DataObject *);
336 
337 protected:
338  void PrintSelf(std::ostream & os, Indent indent) const;
339 
340 public:
341 
347  {
348 public:
349 
350  friend class Histogram;
351 
352  ConstIterator(const Self *histogram)
353  {
354  m_Id = 0;
355  m_Histogram = histogram;
356  }
357 
359  {
360  m_Id = it.m_Id;
362  }
363 
365  {
366  m_Id = it.m_Id;
368  return *this;
369  }
370 
372  {
373  return m_Histogram->GetFrequency(m_Id);
374  }
375 
377  {
378  return m_Id;
379  }
380 
382  {
383  return m_Histogram->GetMeasurementVector(m_Id);
384  }
385 
386  const IndexType & GetIndex() const
387  {
388  return m_Histogram->GetIndex(m_Id);
389  }
390 
392  {
393  ++m_Id;
394  return *this;
395  }
396 
397  bool operator!=(const ConstIterator & it)
398  {
399  return ( m_Id != it.m_Id );
400  }
401 
402  bool operator==(const ConstIterator & it)
403  {
404  return ( m_Id == it.m_Id );
405  }
406 
407 protected:
408  // This method is purposely not implemented
409  ConstIterator();
410 
411  ConstIterator(InstanceIdentifier id, const Self *histogram):
412  m_Id(id), m_Histogram(histogram)
413  {}
414 
415  // ConstIterator pointing DenseFrequencyContainer
417 
418  // Pointer of DenseFrequencyContainer
420  }; // end of iterator class
421 
426  class Iterator:public ConstIterator
427  {
428 public:
429 
430  Iterator(Self *histogram):ConstIterator(histogram)
431  {}
432 
434  ConstIterator(id, histogram)
435  {}
436 
438  {}
439 
441  {
442  this->ConstIterator::operator=(it);
443  return *this;
444  }
445 
447  {
448  Self *histogram = const_cast< Self * >( this->m_Histogram );
449 
450  return histogram->SetFrequency(this->m_Id, value);
451  }
452 
453 protected:
454  // To ensure const-correctness these method must not be in the public API.
455  // The are purposly not implemented, since they should never be called.
456  Iterator();
457  Iterator(const Self *histogram);
458  Iterator(InstanceIdentifier id, const Self *histogram);
459  Iterator(const ConstIterator & it);
460  ConstIterator & operator=(const ConstIterator & it);
461 
462 private:
463  }; // end of iterator class
464 
466  {
467  Iterator iter(0, this);
468 
469  return iter;
470  }
471 
473  {
474  return Iterator(m_OffsetTable[this->GetMeasurementVectorSize()], this);
475  }
476 
478  {
479  ConstIterator iter(0, this);
480 
481  return iter;
482  }
483 
485  {
487  }
488 
489 protected:
490  Histogram();
491  virtual ~Histogram() {}
492 
493  // The number of bins for each dimension
495 
496 private:
497  Histogram(const Self &); //purposely not implemented
498  void operator=(const Self &); //purposely not implemented
499 
500  typedef std::vector< InstanceIdentifier > OffsetTableType;
503  unsigned int m_NumberOfInstances;
504 
505  // This method is provided here just to avoid a "hidden" warning
506  // related to the virtual method available in DataObject.
507  virtual void Initialize() {}
508 
509  // lower bound of each bin
510  std::vector< std::vector< MeasurementType > > m_Min;
511 
512  // upper bound of each bin
513  std::vector< std::vector< MeasurementType > > m_Max;
514 
517 
519 };
520 } // end of namespace Statistics
521 } // end of namespace itk
522 
523 #ifndef ITK_MANUAL_INSTANTIATION
524 #include "itkHistogram.hxx"
525 #endif
526 
527 #endif

Generated at Sat Aug 30 2014 14:49:04 for Orfeo Toolbox with doxygen 1.8.3.1