Quantization1DAequiDist0To1.cpp 2.9 KB

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