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


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