00001
00002
00003 #ifndef histoH
00004 #define histoH
00005
00006
00007 #include <Classes.hpp>
00008 #include <Controls.hpp>
00009 #include <ExtCtrls.hpp>
00010 #include <assert.h>
00011 #include <math.h>
00012
00013 #define MAX(x,y) (((x)>(y)) ? (x) : (y))
00014
00022 class THistogram {
00023
00024 private:
00028 int *_histo;
00029 int _size;
00030 int _max;
00031 bool _maxDirty;
00032 bool _drawAverage;
00033 bool _horizontal;
00034 TColor _fg, _bg;
00035 float _histoZoom;
00036 float _valZoom;
00037
00038 float _histoPos;
00039 float _valPos;
00040 int _logType;
00041
00042 void __fastcall __drawLine(TPaintBox *pb, int val, int line);
00043 float __fastcall MYLOG(float val)
00044 {
00045 switch(_logType)
00046 {
00047 case 1:
00048 return log(val);
00049 case 2:
00050 return log10(val);
00051 default:
00052 return val;
00053 }
00054 }
00055
00056 public:
00057 THistogram(int size);
00058 ~THistogram() {
00059 delete [] _histo;
00060 }
00061
00062 __property bool drawAverage = { read=_drawAverage, write=_drawAverage };
00063 __property bool horizontal = { read=_horizontal, write=_horizontal };
00064 __property TColor foreground = { read=_fg, write=_fg };
00065 __property TColor background = { read=_bg, write=_bg };
00066 __property float histoZoom = { read=_histoZoom, write=_histoZoom };
00067 __property float valZoom = { read=_valZoom, write=_valZoom };
00068 __property float histoPos = { read=_histoPos, write=_histoPos };
00069 __property float valPos = { read=_valPos, write=_valPos };
00070 __property int logType = { read=_logType, write=_logType };
00071 __property int size = { read=_size, write=_size };
00072
00078 void __fastcall drawTo(TPaintBox *pb);
00079
00086 float __fastcall getHPP(TPaintBox *pb);
00093 float __fastcall getVPP(TPaintBox *pb);
00094
00101 float __fastcall getHMaxZoom(TControl *pb);
00102
00103 int __fastcall calcMax()
00104 {
00105 if (_maxDirty) {
00106 for(int i=0; i<_size; ++i)
00107 _max=MAX(_max, _histo[i]);
00108 _maxDirty = false;
00109 }
00110 return _max;
00111 }
00112
00113 int &operator[](int n) {
00114
00115 if (n<0 || n>=_size) {
00116 return _histo[0];
00117 } else {
00118 _maxDirty = true;
00119 return _histo[n];
00120 }
00121 }
00122 };
00123
00124 #endif