qmappainter.h
Go to the documentation of this file.
00001 #ifndef QMAPPAINTER_H
00002 #define QMAPPAINTER_H
00003 
00004 #include <qpainter.h>
00005 #include <qpixmap.h>
00006 #include <qstring.h>
00007 #include <qwidget.h>
00008 #include <utils/gvalues.h>
00009 #include <utils/point.h>
00010 
00011 class QMapPainter :  public QWidget{
00012         public:
00013                 QMapPainter( QWidget * parent = 0, const char * name = 0, WFlags f = 0);
00014                 virtual ~QMapPainter();
00015         public:
00016                 template < typename Cell >
00017                 void setPixmap(unsigned int xsize, unsigned int ysize, Cell** values);
00018                 template < typename Iterator >
00019                 void drawPoints(const Iterator& begin, const Iterator& end, unsigned char r,  unsigned char g, unsigned char b);
00020                 void start(int period);
00021         protected:
00022                 virtual void timerEvent(QTimerEvent * te);
00023                 virtual void resizeEvent(QResizeEvent *);
00024                 int timer;
00025                 virtual void paintEvent ( QPaintEvent *paintevent );
00026                 QPixmap * m_pixmap;
00027 };
00028 
00029 template <typename Cell>
00030 void QMapPainter::setPixmap(unsigned int xsize, unsigned int ysize, Cell** values){
00031         QSize s(xsize, ysize);
00032         m_pixmap->resize(s);
00033         m_pixmap->fill(Qt::white);
00034         QPainter painter(m_pixmap);
00035         for (unsigned int x=0; x<(unsigned int)xsize; x++)
00036                 for (unsigned int y=0; y<(unsigned int)ysize; y++){
00037                         double v=(double) values[x][y];
00038                         
00039                         if (v>=0){
00040                                 unsigned int grayVal=(unsigned char) (255-(unsigned char)(255*v));
00041                                 painter.setPen(QColor(grayVal, grayVal, grayVal));
00042                         } else {
00043                                 painter.setPen(QColor(255, 100, 100));
00044                         }
00045                         painter.drawPoint(x,ysize-y);
00046                 }
00047 }
00048 
00049 template < typename Iterator >
00050 void QMapPainter::drawPoints(const Iterator& begin, const Iterator& end, unsigned char r,  unsigned char g, unsigned char b){
00051         QPainter painter(m_pixmap);
00052         painter.setPen(QColor(r,g,b));
00053         for (Iterator it=begin; it!=end; it++){
00054                 GMapping::IntPoint p=(GMapping::IntPoint)*it;
00055                 painter.drawPoint(p.x, height()-p.y);
00056         }
00057 }
00058 
00059 #endif
00060 


openslam_gmapping
Author(s): Giorgio Grisetti, Cyrill Stachniss, Wolfram Burgard
autogenerated on Fri Aug 28 2015 11:56:21