qmappainter.h
Go to the documentation of this file.
1 #ifndef QMAPPAINTER_H
2 #define QMAPPAINTER_H
3 
4 #include <qpainter.h>
5 #include <qpixmap.h>
6 #include <qstring.h>
7 #include <qwidget.h>
9 #include <gmapping/utils/point.h>
10 
11 class QMapPainter : public QWidget{
12  public:
13  QMapPainter( QWidget * parent = 0, const char * name = 0, WFlags f = 0);
14  virtual ~QMapPainter();
15  public:
16  template < typename Cell >
17  void setPixmap(unsigned int xsize, unsigned int ysize, Cell** values);
18  template < typename Iterator >
19  void drawPoints(const Iterator& begin, const Iterator& end, unsigned char r, unsigned char g, unsigned char b);
20  void start(int period);
21  protected:
22  virtual void timerEvent(QTimerEvent * te);
23  virtual void resizeEvent(QResizeEvent *);
24  int timer;
25  virtual void paintEvent ( QPaintEvent *paintevent );
26  QPixmap * m_pixmap;
27 };
28 
29 template <typename Cell>
30 void QMapPainter::setPixmap(unsigned int xsize, unsigned int ysize, Cell** values){
31  QSize s(xsize, ysize);
32  m_pixmap->resize(s);
33  m_pixmap->fill(Qt::white);
34  QPainter painter(m_pixmap);
35  for (unsigned int x=0; x<(unsigned int)xsize; x++)
36  for (unsigned int y=0; y<(unsigned int)ysize; y++){
37  double v=(double) values[x][y];
38 
39  if (v>=0){
40  unsigned int grayVal=(unsigned char) (255-(unsigned char)(255*v));
41  painter.setPen(QColor(grayVal, grayVal, grayVal));
42  } else {
43  painter.setPen(QColor(255, 100, 100));
44  }
45  painter.drawPoint(x,ysize-y);
46  }
47 }
48 
49 template < typename Iterator >
50 void QMapPainter::drawPoints(const Iterator& begin, const Iterator& end, unsigned char r, unsigned char g, unsigned char b){
51  QPainter painter(m_pixmap);
52  painter.setPen(QColor(r,g,b));
53  for (Iterator it=begin; it!=end; it++){
55  painter.drawPoint(p.x, height()-p.y);
56  }
57 }
58 
59 #endif
60 
void setPixmap(unsigned int xsize, unsigned int ysize, Cell **values)
Definition: qmappainter.h:30
void start(int period)
Definition: qmappainter.cpp:24
point< int > IntPoint
Definition: point.h:201
QPixmap * m_pixmap
Definition: qmappainter.h:26
virtual void resizeEvent(QResizeEvent *)
Definition: qmappainter.cpp:10
virtual ~QMapPainter()
Definition: qmappainter.cpp:14
virtual void timerEvent(QTimerEvent *te)
Definition: qmappainter.cpp:19
void drawPoints(const Iterator &begin, const Iterator &end, unsigned char r, unsigned char g, unsigned char b)
Definition: qmappainter.h:50
virtual void paintEvent(QPaintEvent *paintevent)
Definition: qmappainter.cpp:29
QMapPainter(QWidget *parent=0, const char *name=0, WFlags f=0)
Definition: qmappainter.cpp:4


openslam_gmapping
Author(s): Cyrill Stachniss, Udo Frese, Giorgio Grisetti, Wolfram Burgard
autogenerated on Mon Feb 28 2022 22:59:20