Main Page Alphabetical List Compound List File List Compound Members Related Pages

# histo.cpp

    00001 //---------------------------------------------------------------------------
    00002
    00003
    00004 #pragma hdrstop
    00005
    00006 #include "histo.h"
    00007
    00008 //---------------------------------------------------------------------------
    00009
    00010 #pragma package(smart_init)
    00011
    00012 THistogram::THistogram(int size)
    00013 :
    00014         _size(size),
    00015         _max(0),
    00016         _maxDirty(true),
    00017         _drawAverage(false),
    00018         _horizontal(true),
    00019         _fg(clLtGray),
    00020         _bg(clWhite),
    00021         _histoZoom(1.0),
    00022         _valZoom(1.0),
    00023         _histoPos(0.0),
    00024         _valPos(0.0),
    00025         _logType(2)
    00026 {
    00027         _histo = new int[size];
    00028         memset((void*)_histo, 0, _size*sizeof(int));
    00029 }
    00030
    00031 void __fastcall THistogram::__drawLine(TPaintBox *pb, int val, int line)
    00032 {
    00033         if (val != 0)
    00034         {
    00035                 TCanvas *c = pb->Canvas;
    00036                 float _vpp = getVPP(pb);
    00037                 int len = (int)(MYLOG(val)/_vpp);
    00038                 c->Pen->Color = _fg;
    00039                 if (_horizontal) {
    00040                         c->MoveTo(line, pb->Height-len);
    00041                         c->LineTo(line, pb->Height);
    00042                 } else {
    00043                         c->MoveTo(pb->Width-len, line);
    00044                         c->LineTo(pb->Width, line);
    00045                 }
    00046         }
    00047 }
    00048
    00049 float __fastcall THistogram::getHPP(TPaintBox *pb)
    00050 {
    00051         int w = _horizontal ? pb->Width : pb->Height;
    00052         if (w == 0) return 1.0;
    00053         else        return ((float)_size/(float)w);
    00054         //else        return ((float)_size/(float)w/_histoZoom);
    00055 }
    00056
    00057 float __fastcall THistogram::getVPP(TPaintBox *pb)
    00058 {
    00059         int h = _horizontal ? pb->Height : pb->Width;
    00060         if (h == 0) return 1.0;
    00061         else        return (MYLOG(calcMax())/(float)h);
    00062         //else        return (MYLOG(calcMax())/(float)h/_valZoom);
    00063 }
    00064
    00065 float __fastcall THistogram::getHMaxZoom(TControl *pb)
    00066 {
    00067         int w = _horizontal ? pb->Width : pb->Height;
    00068         //return (((float)_size/2.0)+1.0)/(float)w;
    00069         return ((float)_size/(float)w);
    00070 }
    00071
    00072 void __fastcall THistogram::drawTo(TPaintBox *pb)
    00073 {
    00074         //float _hpp = getHPP(pb);
    00075
    00076         //int count = 0;
    00077         //long int valSum = 0;
    00078         //int valMax = 0;
    00079         TCanvas *c = pb->Canvas;
    00080
    00081         c->FillRect(pb->ClientRect);
    00082         pb->Color = _bg;
    00083
    00084         /*
    00085         for(int i = 1; i<4096; ++i)     // do not pay attantion on number of
    00086                                         // zeros.
    00087         {
    00088                 if (!(i%(int)_hpp)) {
    00089                         if (_drawAverage)
    00090                                 __drawLine(pb, (float)valSum/(float)count,
    00091                                            i/(int)_hpp);
    00092                         else
    00093                                 __drawLine(pb, (float)valMax,
    00094                                            i/(int)_hpp);
    00095                         count = 1;
    00096                         valSum = _histo[i];
    00097                         valMax = _histo[i];
    00098                 } else {
    00099                         count++;
    00100                         valSum += _histo[i];
    00101                         valMax = MAX(valMax, _histo[i]);
    00102                 }
    00103         }
    00104         */
    00105         int max;
    00106         if (_horizontal) max=pb->Width;
    00107         else             max=pb->Height;
    00108         for(int i = 1; i<max; ++i)
    00109         {
    00110                 int j = (int)((float)(i-1)*getHPP(pb));
    00111                 int end = (int)((float)i*getHPP(pb));
    00112                 //int dist = end-i;
    00113                 int sum = 0;
    00114                 for(; j<end; ++j)
    00115                         sum = MAX(sum, _histo[j]);
    00116                 //__drawLine(pb, (float)sum/(float)dist,i);
    00117                 __drawLine(pb, sum,i);
    00118
    00119         }
    00120 }