/******************************************************* * * DESCRIPTION: Uniform and Non-uniform quantizers classes * * AUTHOR: Mariana C. D'Abreu * * EMAIL: mdabreu@dc.uba.ar * ********************************************************/ #ifndef _QUANTIZER_H #define _QUANTIZER_H #include #include "realprec.h" #include "mathincl.h" #include "defaults.h" #define UNIFORM_METHOD "uniform" #define INTERVALS_METHOD "intervals" /***************************** * * Class : Quantizer * ******************************/ class Quantizer { public: static Quantizer *create( const string &method ); virtual ~Quantizer() {}; virtual string className () const = 0; static bool validMethod( const string &method ); static string validMethodsAsString(); //--- Getters y setters ---// virtual int paramCount() const = 0; virtual string getParam ( const int n ) const = 0; virtual Quantizer &setParam ( const int n, const string &value ) = 0; double precision() const { return TOL; } Quantizer &precision( const double precision ) { TOL = precision; return *this; } //--- Funcion de cuantificacion ---// virtual RealValue quantize ( const RealValue &value ) = 0; virtual void printInfo ( ostream &out ) const = 0; protected: Quantizer() { this->TOL = RealPrecision::Tol.precision(); } private: double TOL; }; /***************************** * * Class : UniformQuantizer * ******************************/ class UniformQuantizer : public Quantizer { public: UniformQuantizer(); virtual string className () const { return "UniformQuantizer"; } virtual int paramCount() const { return 3; } virtual RealValue getQuantum () const { return quantum; } virtual RealValue getUpperSatValue () const { return upperSatValue; } virtual RealValue getLowerSatValue () const { return lowerSatValue; } virtual Quantizer &setQuantum ( const RealValue &value ); virtual Quantizer &setUpperSatValue ( const RealValue &value ) { upperSatValue = value; return *this; } virtual Quantizer &setLowerSatValue ( const RealValue &value ) { lowerSatValue = value; return *this; } virtual string getParam ( const int n ) const; virtual Quantizer &setParam ( const int n, const string &value ); virtual RealValue quantize ( const RealValue &value ); virtual void printInfo ( ostream &out ) const; private: RealValue quantum; RealValue upperSatValue; RealValue lowerSatValue; }; inline UniformQuantizer::UniformQuantizer() { quantum = DEFAULT_QUANTUM; upperSatValue = M_INFINITO; lowerSatValue = M_MINFINITO; } /***************************** * * Class : IntervalsQuantizer * ******************************/ class IntervalsQuantizer : public Quantizer { public: string className () const { return "IntervalsQuantizer"; } int paramCount() const { return 1; } string getParam ( const int n ) const; Quantizer &setParam ( const int n, const string &value ); RealValue quantize( const RealValue &value ); void printInfo ( ostream &out ) const; static const int MAX_INTERVALS; static const char INTERVAL_SEPARATOR; private: bool initIntervals ( const string &strInt ); const RealValue &findInterval ( const RealValue &value ); int number; RealValue *intervals; }; #endif