CompassMeter.C

00001 
00002 #include "GUI/CompassMeter.H"
00003 #include "Image/PixelsTypes.H"
00004 
00005 CompassMeter::CompassMeter(int width, int height):
00006   itsWidth(width),
00007   itsHeight(height),
00008   itsCurrentHeading(0),
00009   itsDesiredHeading(0)
00010 {
00011 }
00012 
00013 Image<PixRGB<byte> > CompassMeter::render(short h)
00014 {
00015   itsCurrentHeading = h;
00016 
00017   itsHeadingHist.push_front(h);
00018   if(itsHeadingHist.size() > 10)
00019     itsHeadingHist.pop_back();
00020 
00021   Image<PixRGB<byte> > compassImage(itsWidth,itsHeight,ZEROS);
00022 
00023   drawCircle(compassImage,Point2D<int>(itsWidth/2,itsHeight/2), .9*std::min(itsWidth,itsHeight)/2, PixRGB<byte>(255,0,0));
00024 
00025   std::list<short>::reverse_iterator it = itsHeadingHist.rbegin();
00026   float opacity=0;
00027   float opacity_step =1/float(itsHeadingHist.size());
00028   for(;it != itsHeadingHist.rend(); ++it)
00029     {
00030       //LINFO("Opacity:%f, Step: %f", opacity, opacity_step);
00031       int x = (int)(.9*std::min(itsWidth,itsHeight)/2*cos((*it-90)*(M_PI/180))); //shift by 90 so that 0 is up
00032       int y = (int)(.9*std::min(itsWidth,itsHeight)/2*sin((*it-90)*(M_PI/180)));
00033       drawArrow(compassImage,
00034                 Point2D<int>(itsWidth/2,itsHeight/2),
00035                 Point2D<int>(itsWidth/2+x,itsHeight/2+y),
00036                 PixRGB<byte>(0,255*opacity*.5,255*opacity*.5));
00037       opacity+=opacity_step;
00038     }
00039 
00040   int x = (int)(.9*std::min(itsWidth,itsHeight)/2*cos((*(itsHeadingHist.begin())-90)*(M_PI/180))); //shift by 90 so that 0 is up
00041   int y = (int)(.9*std::min(itsWidth,itsHeight)/2*sin((*(itsHeadingHist.begin())-90)*(M_PI/180)));
00042   drawArrow(compassImage, Point2D<int>(itsWidth/2,itsHeight/2), Point2D<int>(itsWidth/2+x,itsHeight/2+y), PixRGB<byte>(0,255,0));
00043 
00044   return compassImage;
00045 }
Generated on Sun May 8 08:40:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3