QuantizationNDAequiDist0ToMax.cpp 3.1 KB

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