00001 00002 #include "GUI/PressureMeter.H" 00003 #include "Image/PixelsTypes.H" 00004 00005 PressureMeter::PressureMeter(int width, int height): 00006 itsWidth(width), 00007 itsHeight(height) 00008 { 00009 } 00010 00011 Image<PixRGB<byte> > PressureMeter::render(int p) 00012 { 00013 itsPressureHist.push_front(p); 00014 if(itsPressureHist.size() > 10) 00015 itsPressureHist.pop_back(); 00016 00017 Image<PixRGB<byte> > pressureImage(itsWidth,itsHeight,ZEROS); 00018 00019 drawCircle(pressureImage,Point2D<int>(itsWidth/2,itsHeight/2), .9*std::min(itsWidth,itsHeight)/2, PixRGB<byte>(0,0,255)); 00020 int avgPressure = 0; 00021 00022 std::list<int>::reverse_iterator it = itsPressureHist.rbegin(); 00023 for(;it != itsPressureHist.rend(); ++it) 00024 { 00025 avgPressure += *it; 00026 } 00027 if(itsPressureHist.size() > 0) 00028 avgPressure /= itsPressureHist.size(); 00029 00030 float drawPercentage = (float)(avgPressure) / 5000.0; 00031 00032 int x = (int)(.9*std::min(itsWidth,itsHeight)/2*cos((drawPercentage*360)*(M_PI/180))); //shift by 90 so that 0 is up 00033 int y = (int)(.9*std::min(itsWidth,itsHeight)/2*sin((drawPercentage*360)*(M_PI/180))); 00034 drawArrow(pressureImage, Point2D<int>(itsWidth/2,itsHeight/2), Point2D<int>(itsWidth/2+x,itsHeight/2+y), PixRGB<byte>(0,255,0)); 00035 00036 return pressureImage; 00037 }