DepthMeter.C

00001 
00002 #include "GUI/DepthMeter.H"
00003 #include "Image/PixelsTypes.H"
00004 #include "Util/StringConversions.H"
00005 
00006 DepthMeter::DepthMeter(int width, int height):
00007   itsWidth(width),
00008   itsHeight(height),
00009   itsCurrentDepth(0)
00010 {
00011 
00012 }
00013 
00014 Image<PixRGB<byte> > DepthMeter::render(int d)
00015 {
00016   itsCurrentDepth = d;
00017   itsDepthHist.push_front(d);
00018   if(itsDepthHist.size() > 5)
00019     itsDepthHist.pop_back();
00020 
00021   int avgDepth = 0;
00022 
00023   std::list<int>::reverse_iterator it = itsDepthHist.rbegin();
00024   for(;it != itsDepthHist.rend(); ++it)
00025     {
00026       avgDepth += *it;
00027     }
00028   if(itsDepthHist.size() > 0)
00029     avgDepth /= itsDepthHist.size();
00030 
00031   int minDrawDepth = avgDepth - itsHeight/2;
00032 
00033   Image<PixRGB<byte> > depthImage(itsWidth,itsHeight,ZEROS);
00034 
00035   int drawHeight = 0;
00036 
00037   // draw tick marks
00038   while(drawHeight < itsHeight)
00039     {
00040       if((minDrawDepth %100 ) % 13 == 0)
00041         {
00042           drawLine(depthImage,
00043                    Point2D<int>((int)(.38*(float)itsWidth),drawHeight),
00044                    Point2D<int>((int)(.62*(float)itsWidth),drawHeight),
00045                    PixRGB<byte>(100,100,100));
00046         }
00047 
00048       if(minDrawDepth % 25 == 0)
00049         {
00050           if(minDrawDepth % 100 == 0 ||
00051              minDrawDepth % 100 == 50)
00052             {
00053               drawLine(depthImage, Point2D<int>((int)(.1*(float)itsWidth),drawHeight),
00054                        Point2D<int>((int)(.9*(float)itsWidth),drawHeight),
00055                        PixRGB<byte>(200,200,200));
00056             }
00057           else if(minDrawDepth % 100 == 25 ||
00058                   minDrawDepth % 100 == 75)
00059             {
00060               writeText(depthImage,
00061                         Point2D<int>(0,drawHeight-12),
00062                         toStr<int>(minDrawDepth / 100).c_str(),
00063                         PixRGB<byte>(20,253,0),
00064                         PixRGB<byte>(0,0,0),
00065                         SimpleFont::FIXED(14));
00066 
00067               writeText(depthImage,
00068                         Point2D<int>((int)(.75*(float)itsWidth + 8),drawHeight-6),
00069                         toStr<int>(minDrawDepth % 100).c_str(),
00070                         PixRGB<byte>(20,253,0),
00071                         PixRGB<byte>(0,0,0),
00072                         SimpleFont::FIXED(8));
00073 
00074               drawLine(depthImage,
00075                        Point2D<int>((int)(.25*(float)itsWidth),drawHeight),
00076                        Point2D<int>((int)(.75*(float)itsWidth),drawHeight),
00077                        PixRGB<byte>(100,100,100));
00078             }
00079 
00080           if(drawHeight + 13 < itsHeight)
00081             {
00082               drawLine(depthImage,
00083                        Point2D<int>((int)(.38*(float)itsWidth),drawHeight + 13),
00084                        Point2D<int>((int)(.62*(float)itsWidth),drawHeight+13),
00085                        PixRGB<byte>(100,100,100));
00086             }
00087 
00088           drawHeight += 25;
00089           minDrawDepth += 25;
00090         }
00091       else
00092         {
00093           drawHeight++;
00094           minDrawDepth++;
00095         }
00096     }
00097 
00098   // draw current depth line as horizontal over middle of image
00099   drawLine(depthImage, Point2D<int>(0,(itsHeight/2-2)), Point2D<int>(itsWidth,(itsHeight/2 - 2)), PixRGB<byte>(255,0,0));
00100   drawLine(depthImage, Point2D<int>(0,(itsHeight/2+2)), Point2D<int>(itsWidth,(itsHeight/2 + 2)), PixRGB<byte>(255,0,0));
00101 
00102   return depthImage;
00103 }
00104 
Generated on Sun May 8 08:40:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3