Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

HistogramBars.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // Author: Richard van Balen
00003 #ifndef Impala_Application_TagsLife_HistogramBars_h
00004 #define Impala_Application_TagsLife_HistogramBars_h
00005 
00006 namespace Impala {
00007 namespace Application {
00008 namespace TagsLife {
00009 
00010 #ifndef OglGui_Window_h
00011 #include "OglGui/Window.h"
00012 #endif
00013 
00014 class HistogramBars :    public OglGui::Window
00015 {
00016 public:
00017     typedef OglGui::Window          Window;
00018 
00019     HistogramBars(Window* parent, int x, int y, int w, int h) :
00020         Window(parent,x,y,w,h)
00021     {
00022         Init(w,h);
00023     }
00024 
00025     void Clear()
00026     {
00027         mStartBar = mEndBar = -1;
00028         mMaxFreq = 0;
00029         mHistogram.clear();
00030     }
00031 
00032     void AddToHistogram(int val)
00033     {
00034         if (val > mMaxFreq)
00035             mMaxFreq = val;
00036 
00037         mHistogram.push_back(val);
00038     }
00039 
00040     void HighLightInterval(int startBar, int endBar)
00041     {
00042         mStartBar = startBar;
00043         mEndBar   = endBar;
00044     }
00045 
00046     void SetColors(int normalColor, int highlightColor)
00047     {
00048         mNormalColor    = normalColor;
00049         mHighlightColor = highlightColor;
00050     }
00051 
00052     virtual void DisplayFunc()
00053     {
00054         OGC oldOGC;
00055         OGCSave(&oldOGC);
00056 
00057         Window::DisplayFunc();
00058 
00059         int     nrBars = mHistogram.size();
00060         ILOG_VAR(Impala.Application.TagsLife.HistogramBars);
00061         float   slotSz = W() / (float) nrBars;
00062         float   barSz  = (slotSz > 2) ? slotSz / 2 : 1;
00063 
00064         for (int i=0; i<nrBars; i++)
00065         {
00066             int x = i * slotSz;
00067             bool highLight = (i >= mStartBar && i <= mEndBar);
00068             ULONG color = (highLight ? mHighlightColor : mNormalColor);
00069             SetSolidFillColor(color);
00070             int barH = (mHistogram[i] / (float) mMaxFreq) * H();
00071             FillRectangle(x+slotSz/4,0,barSz,barH);
00072         }
00073         OGCRestore(&oldOGC);
00074     }
00075 
00076 private:
00077     void Init(int w, int h)
00078     {
00079         mStartBar = mEndBar = -1;
00080         mNormalColor = oglRED;
00081         mHighlightColor = 0xff800000;
00082         mMaxFreq = 0;
00083     }
00084 
00085     std::vector<int>    mHistogram;
00086     ULONG               mNormalColor;
00087     ULONG               mHighlightColor;
00088     int                 mStartBar;
00089     int                 mEndBar;
00090     int                 mMaxFreq;
00091 };
00092 
00093 } // namespace HistogramBars
00094 } // namespace Application
00095 } // namespace Impala
00096 
00097 #endif

Generated on Fri Mar 19 09:30:39 2010 for ImpalaSrc by  doxygen 1.5.1