Quantization1DAequiDist0ToMax.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @file Quantization1DAequiDist0ToMax.cpp
  3. * @brief Quantization1DAequiDist0ToMax of one-dimensional signals with selectable interval [0, vMax] (Implementation)
  4. * @author Erik Rodner, Alexander Freytag
  5. * @date 13-10-2015 ( dd-mm-yyyy )
  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. double Quantization1DAequiDist0ToMax::getPrototype ( uint _bin,
  30. const uint & _dim
  31. ) const
  32. {
  33. // _dim will be ignored for this type of quantization. all dimensions are treated equally...
  34. return (this->v_upperBounds[0]*_bin) / (double)(this->ui_numBins-1);
  35. }
  36. uint Quantization1DAequiDist0ToMax::quantize ( double _value,
  37. const uint & _dim
  38. ) const
  39. {
  40. // _dim will be ignored for this type of quantization. all dimensions are treated equally...
  41. if ( _value <= 0.0 )
  42. return 0;
  43. else if ( _value >= this->v_upperBounds[0] )
  44. return this->ui_numBins-1;
  45. else
  46. return static_cast<uint> ( floor( _value/this->v_upperBounds[0] * (this->ui_numBins-1) + 0.5 ) );
  47. }
  48. void Quantization1DAequiDist0ToMax::computeParametersFromData ( const NICE::FeatureMatrix * _fm )
  49. {
  50. double vmax = ( _fm->getLargestValue( ) );
  51. this->v_upperBounds.resize ( 1 );
  52. this->v_upperBounds ( 0 ) = vmax;
  53. }
  54. void Quantization1DAequiDist0ToMax::computeParametersFromData ( const NICE::GMHIKernelRaw * _gm )
  55. {
  56. double vmax = ( _gm->getLargestValue( ) );
  57. this->v_upperBounds.resize ( 1 );
  58. this->v_upperBounds ( 0 ) = vmax;
  59. }
  60. // ---------------------- STORE AND RESTORE FUNCTIONS ----------------------
  61. void Quantization1DAequiDist0ToMax::restore ( std::istream & _is,
  62. int _format
  63. )
  64. {
  65. if ( _is.good() )
  66. {
  67. std::string tmp;
  68. bool b_endOfBlock ( false ) ;
  69. while ( !b_endOfBlock )
  70. {
  71. _is >> tmp; // start of block
  72. if ( this->isEndTag( tmp, "Quantization1DAequiDist0ToMax" ) )
  73. {
  74. b_endOfBlock = true;
  75. continue;
  76. }
  77. tmp = this->removeStartTag ( tmp );
  78. if ( tmp.compare("Quantization") == 0 )
  79. {
  80. // restore parent object
  81. Quantization::restore( _is );
  82. }
  83. else
  84. {
  85. std::cerr << "WARNING -- unexpected Quantization1DAequiDist0ToMax object -- " << tmp << " -- for restoration... aborting" << std::endl;
  86. throw;
  87. }
  88. }
  89. }
  90. else
  91. {
  92. std::cerr << "Quantization1DAequiDist0ToMax::restore -- InStream not initialized - restoring not possible!" << std::endl;
  93. }
  94. }
  95. void Quantization1DAequiDist0ToMax::store ( std::ostream & _os,
  96. int _format
  97. ) const
  98. {
  99. // show starting point
  100. _os << this->createStartTag( "Quantization1DAequiDist0ToMax" ) << std::endl;
  101. // store parent object
  102. Quantization::store( _os );
  103. // done
  104. _os << this->createEndTag( "Quantization1DAequiDist0ToMax" ) << std::endl;
  105. }