SimpleMeter.C

00001 
00002 #include "GUI/SimpleMeter.H"
00003 #include "Image/PixelsTypes.H"
00004 
00005 SimpleMeter::SimpleMeter(int width, int height, double min, double max, double lowThresh, double medThresh)
00006 {
00007 
00008         itsWidth                  = width;
00009         itsHeight          = height;
00010         itsMin                          = min;
00011         itsMax                          = max;
00012         itsLowThresh = itsHeight - (lowThresh - itsMin)*itsHeight/(itsMax - itsMin);
00013         itsMedThresh = itsHeight - (medThresh - itsMin)*itsHeight/(itsMax - itsMin);
00014 }
00015 
00016 SimpleMeter::SimpleMeter(int width, int height, double min, double max)
00017 {
00018 
00019         itsWidth                  = width;
00020         itsHeight          = height;
00021         itsMin                          = min;
00022         itsMax                          = max;
00023 
00024         int lowThresh = (int)((itsMax - itsMin)/2.0 + itsMin);
00025         int medThresh = (int)((itsMax - itsMin)*2.0/3.0 + itsMin);
00026 
00027         itsLowThresh = itsHeight - (lowThresh - itsMin)*itsHeight/(itsMax - itsMin);
00028         itsMedThresh = itsHeight - (medThresh - itsMin)*itsHeight/(itsMax - itsMin);
00029 }
00030 
00031 Image<PixRGB<byte> > SimpleMeter::render(double val)
00032 {
00033         Image<PixRGB<byte> > meter(itsWidth, itsHeight, ZEROS);
00034         int valY;
00035         if(val < itsMin)
00036                 valY = 0;
00037         else if(val > itsMax)
00038                 valY = itsHeight;
00039         else
00040         {
00041                 valY = (int)((val - itsMin)*(itsHeight)/(itsMax - itsMin));
00042         }
00043 
00044         for(int y=itsHeight-1; y>1; y -= 3)
00045         {
00046                 PixRGB<byte> Color;
00047                 if(y > itsLowThresh)
00048                         Color = PixRGB<byte>(0,255,0);
00049                 else if(y < itsLowThresh && y > itsMedThresh)
00050                         Color = PixRGB<byte>(255,255,0);
00051                 else
00052                         Color = PixRGB<byte>(255,0,0);
00053 
00054                 float alpha = .4;
00055                 if(y > itsHeight-valY)
00056                         alpha = 1;
00057                 drawLine(meter, Point2D<int>(0, y), Point2D<int>(itsWidth-1,y),PixRGB<byte>(Color*alpha),1);
00058 
00059         }
00060 
00061         return meter;
00062 }
00063 
Generated on Sun May 8 08:40:41 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3