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::QGraphPainter
QGraphPainter(QWidget *parent=0, const char *name=0, WFlags f=0)
Definition: qgraphpainter.cpp:28
QGraphPainter::valueAdded
void valueAdded(double)
Definition: qgraphpainter.cpp:48
QGraphPainter::setRange
void setRange(double min, double max)
Definition: qgraphpainter.cpp:71
QGraphPainter::start
void start(int period)
Definition: qgraphpainter.cpp:89
QGraphPainter::setYReference
void setYReference(double y)
Definition: qgraphpainter.cpp:57
qgraphpainter.h
QGraphPainter::autoscale
bool autoscale
Definition: qgraphpainter.h:57
QGraphPainter::setAutoscale
void setAutoscale(bool a)
Definition: qgraphpainter.cpp:76
QGraphPainter::timerEvent
virtual void timerEvent(QTimerEvent *te)
Definition: qgraphpainter.cpp:84
QGraphPainter::max
double max
Definition: qgraphpainter.h:55
QGraphPainter::~QGraphPainter
virtual ~QGraphPainter()
Definition: qgraphpainter.cpp:40
QGraphPainter::title
QString title
Definition: qgraphpainter.h:62
QGraphPainter::m_pixmap
QPixmap * m_pixmap
Definition: qgraphpainter.h:61
QGraphPainter::values
DoubleDeque values
Definition: qgraphpainter.h:56
QGraphPainter::timer
int timer
Definition: qgraphpainter.h:59
QGraphPainter::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: qgraphpainter.cpp:36
QGraphPainter::disableYReference
void disableYReference()
Definition: qgraphpainter.cpp:62
QGraphPainter::reference
double reference
Definition: qgraphpainter.h:55
QGraphPainter::setTitle
void setTitle(const char *title)
Definition: qgraphpainter.cpp:67
QGraphPainter::clear
void clear()
Definition: qgraphpainter.cpp:44
QGraphPainter::m_useYReference
bool m_useYReference
Definition: qgraphpainter.h:58
QGraphPainter::paintEvent
virtual void paintEvent(QPaintEvent *paintevent)
Definition: qgraphpainter.cpp:95
QGraphPainter::getAutoscale
bool getAutoscale() const
Definition: qgraphpainter.cpp:80
QGraphPainter::min
double min
Definition: qgraphpainter.h:55


openslam_gmapping
Author(s): Cyrill Stachniss, Udo Frese, Giorgio Grisetti, Wolfram Burgard
autogenerated on Thu Oct 19 2023 02:25:51