qgraphpainter.cpp
Go to the documentation of this file.
00001 /*****************************************************************
00002  *
00003  * This file is part of the GMAPPING project
00004  *
00005  * GMAPPING Copyright (c) 2004 Giorgio Grisetti, 
00006  * Cyrill Stachniss, and Wolfram Burgard
00007  *
00008  * This software is licensed under the "Creative Commons 
00009  * License (Attribution-NonCommercial-ShareAlike 2.0)" 
00010  * and is copyrighted by Giorgio Grisetti, Cyrill Stachniss, 
00011  * and Wolfram Burgard.
00012  * 
00013  * Further information on this license can be found at:
00014  * http://creativecommons.org/licenses/by-nc-sa/2.0/
00015  * 
00016  * GMAPPING is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied 
00018  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00019  * PURPOSE.  
00020  *
00021  *****************************************************************/
00022 
00023 
00024 #include <iostream>
00025 #include "qgraphpainter.h"
00026 #include "moc_qgraphpainter.cpp"
00027 using namespace std;
00028 
00029 QGraphPainter::QGraphPainter( QWidget * parent, const char * name, WFlags f):
00030         QWidget(parent, name, f|WRepaintNoErase|WResizeNoErase){
00031         m_pixmap=new QPixmap(size());
00032         m_pixmap->fill(Qt::white);
00033         autoscale=false;
00034         m_useYReference = false;
00035 }
00036 
00037 void QGraphPainter::resizeEvent(QResizeEvent * sizeev){
00038         m_pixmap->resize(sizeev->size());
00039 }
00040 
00041 QGraphPainter::~QGraphPainter(){
00042         delete m_pixmap;
00043 }
00044 
00045 void QGraphPainter::clear(){
00046         values.clear();
00047 }
00048 
00049 void QGraphPainter::valueAdded(double v){
00050         values.push_back(v);
00051 }
00052 
00053 void QGraphPainter::valueAdded(double v, double _min, double _max){
00054         setRange(_min, _max);
00055         values.push_back(v);
00056 }
00057 
00058 void QGraphPainter::setYReference(double y){
00059   m_useYReference = true;
00060         reference=y;
00061 }
00062 
00063 void QGraphPainter::disableYReference(){
00064   m_useYReference = false;
00065 }
00066 
00067 
00068 void QGraphPainter::setTitle(const char* t){
00069         title=t;
00070 }
00071 
00072 void QGraphPainter::setRange(double _min, double _max){
00073         min=_min;
00074         max=_max;
00075 }
00076 
00077 void QGraphPainter::setAutoscale(bool a) {
00078         autoscale=a;
00079 }
00080 
00081 bool QGraphPainter::getAutoscale() const {
00082         return autoscale;
00083 }
00084 
00085 void QGraphPainter::timerEvent(QTimerEvent * te) {
00086         if (te->timerId()==timer) 
00087                 update();
00088 }
00089 
00090 void QGraphPainter::start(int period){
00091         timer=startTimer(period);
00092 }
00093 
00094 
00095 
00096 void QGraphPainter::paintEvent ( QPaintEvent * ){
00097         m_pixmap->fill(Qt::white);
00098         QPainter painter(m_pixmap);
00099         double _min=MAXDOUBLE, _max=-MAXDOUBLE;
00100         if (autoscale){
00101                 for (unsigned int i=0; i<(unsigned int)width() && i<values.size(); i++){
00102                         _min=_min<values[i]?_min:values[i];
00103                         _max=_max>values[i]?_max:values[i];
00104                 }
00105         } else {
00106                 _min=min;
00107                 _max=max;
00108         }
00109         
00110 
00111         painter.setPen(Qt::black);
00112         painter.drawRect(0, 0, width(), height());
00113         const int boundary=2;
00114         int xoffset=40;
00115         double scale=((double)height()-2*boundary-2)/(_max-_min);
00116 
00117         if (m_useYReference) {
00118           painter.setPen(Qt::green);
00119           painter.drawLine(xoffset+boundary/2, height()-(int)(scale*(reference-_min)), 
00120                            width()-boundary/2, height()-(int)(scale*(reference-_min)));
00121         }
00122         painter.setPen(Qt::blue);
00123         unsigned int start=0;
00124         if (values.size()>(unsigned int)width()-2*boundary-xoffset)
00125                 start=values.size()-width()+2*boundary+xoffset;
00126         int oldv=0;
00127         if ((unsigned int)width()-2*boundary-xoffset>1 && values.size()>1)
00128           oldv = (int)(scale*(values[1+start]-_min)) + boundary;
00129         
00130         for (unsigned int i=1; i<(unsigned int)width()-2*boundary-xoffset && i<values.size(); i++){
00131                 int v=(int)(scale*(values[i+start]-_min)) + boundary;
00132                 painter.drawLine(i-1+boundary+xoffset, height()-boundary-oldv, 
00133                                  xoffset+i+boundary, height()-boundary-v);
00134                 oldv=v;
00135         }
00136         painter.setPen(Qt::black);
00137         painter.drawText( 3, height()/2, title);
00138         QFont sansFont( "Helvetica [Cronyx]", 6);       
00139         painter.setFont(sansFont);
00140         bitBlt(this,0,0,m_pixmap,0,0,m_pixmap->width(),m_pixmap->height(),CopyROP);
00141 }
00142 


openslam_gmapping
Author(s): Giorgio Grisetti, Cyrill Stachniss, Wolfram Burgard
autogenerated on Thu Jun 6 2019 19:25:13