qgraphpainter.cpp
Go to the documentation of this file.
1 /*****************************************************************
2  *
3  * This file is part of the GMAPPING project
4  *
5  * GMAPPING Copyright (c) 2004 Giorgio Grisetti,
6  * Cyrill Stachniss, and Wolfram Burgard
7  *
8  * This software is licensed under the "Creative Commons
9  * License (Attribution-NonCommercial-ShareAlike 2.0)"
10  * and is copyrighted by Giorgio Grisetti, Cyrill Stachniss,
11  * and Wolfram Burgard.
12  *
13  * Further information on this license can be found at:
14  * http://creativecommons.org/licenses/by-nc-sa/2.0/
15  *
16  * GMAPPING is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied
18  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19  * PURPOSE.
20  *
21  *****************************************************************/
22 
23 
24 #include <iostream>
25 #include "qgraphpainter.h"
26 #include "moc_qgraphpainter.cpp"
27 using namespace std;
28 
29 QGraphPainter::QGraphPainter( QWidget * parent, const char * name, WFlags f):
30  QWidget(parent, name, f|WRepaintNoErase|WResizeNoErase){
31  m_pixmap=new QPixmap(size());
32  m_pixmap->fill(Qt::white);
33  autoscale=false;
34  m_useYReference = false;
35 }
36 
37 void QGraphPainter::resizeEvent(QResizeEvent * sizeev){
38  m_pixmap->resize(sizeev->size());
39 }
40 
42  delete m_pixmap;
43 }
44 
46  values.clear();
47 }
48 
50  values.push_back(v);
51 }
52 
53 void QGraphPainter::valueAdded(double v, double _min, double _max){
54  setRange(_min, _max);
55  values.push_back(v);
56 }
57 
59  m_useYReference = true;
60  reference=y;
61 }
62 
64  m_useYReference = false;
65 }
66 
67 
68 void QGraphPainter::setTitle(const char* t){
69  title=t;
70 }
71 
72 void QGraphPainter::setRange(double _min, double _max){
73  min=_min;
74  max=_max;
75 }
76 
78  autoscale=a;
79 }
80 
82  return autoscale;
83 }
84 
85 void QGraphPainter::timerEvent(QTimerEvent * te) {
86  if (te->timerId()==timer)
87  update();
88 }
89 
90 void QGraphPainter::start(int period){
91  timer=startTimer(period);
92 }
93 
94 
95 
96 void QGraphPainter::paintEvent ( QPaintEvent * ){
97  m_pixmap->fill(Qt::white);
98  QPainter painter(m_pixmap);
99  double _min=MAXDOUBLE, _max=-MAXDOUBLE;
100  if (autoscale){
101  for (unsigned int i=0; i<(unsigned int)width() && i<values.size(); i++){
102  _min=_min<values[i]?_min:values[i];
103  _max=_max>values[i]?_max:values[i];
104  }
105  } else {
106  _min=min;
107  _max=max;
108  }
109 
110 
111  painter.setPen(Qt::black);
112  painter.drawRect(0, 0, width(), height());
113  const int boundary=2;
114  int xoffset=40;
115  double scale=((double)height()-2*boundary-2)/(_max-_min);
116 
117  if (m_useYReference) {
118  painter.setPen(Qt::green);
119  painter.drawLine(xoffset+boundary/2, height()-(int)(scale*(reference-_min)),
120  width()-boundary/2, height()-(int)(scale*(reference-_min)));
121  }
122  painter.setPen(Qt::blue);
123  unsigned int start=0;
124  if (values.size()>(unsigned int)width()-2*boundary-xoffset)
125  start=values.size()-width()+2*boundary+xoffset;
126  int oldv=0;
127  if ((unsigned int)width()-2*boundary-xoffset>1 && values.size()>1)
128  oldv = (int)(scale*(values[1+start]-_min)) + boundary;
129 
130  for (unsigned int i=1; i<(unsigned int)width()-2*boundary-xoffset && i<values.size(); i++){
131  int v=(int)(scale*(values[i+start]-_min)) + boundary;
132  painter.drawLine(i-1+boundary+xoffset, height()-boundary-oldv,
133  xoffset+i+boundary, height()-boundary-v);
134  oldv=v;
135  }
136  painter.setPen(Qt::black);
137  painter.drawText( 3, height()/2, title);
138  QFont sansFont( "Helvetica [Cronyx]", 6);
139  painter.setFont(sansFont);
140  bitBlt(this,0,0,m_pixmap,0,0,m_pixmap->width(),m_pixmap->height(),CopyROP);
141 }
142 
void setRange(double min, double max)
virtual void timerEvent(QTimerEvent *te)
virtual ~QGraphPainter()
void disableYReference()
double reference
Definition: qgraphpainter.h:56
void setYReference(double y)
bool m_useYReference
Definition: qgraphpainter.h:59
DoubleDeque values
Definition: qgraphpainter.h:57
virtual void resizeEvent(QResizeEvent *)
QPixmap * m_pixmap
Definition: qgraphpainter.h:62
#define MAXDOUBLE
Definition: gvalues.h:4
void valueAdded(double)
void setAutoscale(bool a)
void setTitle(const char *title)
QGraphPainter(QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0)
bool getAutoscale() const
virtual void paintEvent(QPaintEvent *paintevent)
void start(int period)


openslam_gmapping
Author(s): Giorgio Grisetti, Cyrill Stachniss, Wolfram Burgard
autogenerated on Mon Jun 10 2019 14:04:22