Quantization1DAequiDist0ToMax.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @file Quantization1DAequiDist0ToMax.cpp
  3. * @brief Quantization1DAequiDist0ToMax of one-dimensional signals with a standard range of [0,1] (Implementation)
  4. * @author Erik Rodner, Alexander Freytag
  5. * @date 01/09/2012
  6. */
  7. #include <iostream>
  8. #include "Quantization1DAequiDist0ToMax.h"
  9. using namespace NICE;
  10. Quantization1DAequiDist0ToMax::Quantization1DAequiDist0ToMax( )
  11. {
  12. this->ui_numBins = 1;
  13. }
  14. Quantization1DAequiDist0ToMax::Quantization1DAequiDist0ToMax(
  15. uint _numBins,
  16. NICE::Vector * _upperBounds
  17. )
  18. {
  19. this->ui_numBins = _numBins;
  20. this->v_upperBounds.resize ( 1 );
  21. if ( (_upperBounds != NULL) && (_upperBounds->size() > 0) )
  22. this->v_upperBounds(0) = *_upperBounds(0);
  23. else
  24. this->v_upperBounds(0) = 1.0;
  25. }
  26. Quantization1DAequiDist0ToMax::~Quantization1DAequiDist0ToMax()
  27. {
  28. }
  29. uint Quantization1DAequiDist0ToMax::size() const
  30. {
  31. return this->ui_numBins;
  32. }
  33. double Quantization1DAequiDist0ToMax::getPrototype (uint _bin) const
  34. {
  35. return _bin / (double)(this->ui_numBins-1);
  36. }
  37. uint Quantization1DAequiDist0ToMax::quantize ( double _value,
  38. const uint & _dim
  39. ) const
  40. {
  41. // _dim will be ignored for this type of quantization. all dimensions are treated equally...
  42. if ( _value <= 0.0 )
  43. return 0;
  44. else if ( _value >= 1.0 )
  45. return this->ui_numBins-1;
  46. else
  47. return (uint)( _value * (this->ui_numBins-1) + 0.5 );
  48. }
  49. // ---------------------- STORE AND RESTORE FUNCTIONS ----------------------
  50. void Quantization1DAequiDist0ToMax::restore ( std::istream & _is,
  51. int _format
  52. )
  53. {
  54. if ( _is.good() )
  55. {
  56. std::string tmp;
  57. bool b_endOfBlock ( false ) ;
  58. while ( !b_endOfBlock )
  59. {
  60. _is >> tmp; // start of block
  61. if ( this->isEndTag( tmp, "Quantization1DAequiDist0ToMax" ) )
  62. {
  63. b_endOfBlock = true;
  64. continue;
  65. }
  66. tmp = this->removeStartTag ( tmp );
  67. if ( tmp.compare("Quantization") == 0 )
  68. {
  69. // restore parent object
  70. Quantization::restore(is);
  71. }
  72. else
  73. {
  74. std::cerr << "WARNING -- unexpected Quantization1DAequiDist0ToMax object -- " << tmp << " -- for restoration... aborting" << std::endl;
  75. throw;
  76. }
  77. _is >> tmp; // end of block
  78. tmp = this->removeEndTag ( tmp );
  79. }
  80. }
  81. else
  82. {
  83. std::cerr << "Quantization1DAequiDist0ToMax::restore -- InStream not initialized - restoring not possible!" << std::endl;
  84. }
  85. }
  86. void Quantization1DAequiDist0ToMax::store ( std::ostream & _os,
  87. int _format
  88. ) const
  89. {
  90. // show starting point
  91. _os << this->createStartTag( "Quantization1DAequiDist0ToMax" ) << std::endl;
  92. // store parent object
  93. Quantization::store(os);
  94. // done
  95. _os << this->createEndTag( "Quantization1DAequiDist0ToMax" ) << std::endl;
  96. }