PdfPlot.cpp
Go to the documentation of this file.
00001 // Taken from RTAB-Map library r606 [www.rtabmap.googlecode.com]
00002 
00003 /*
00004  * Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke
00005  *
00006  * This file is part of RTAB-Map.
00007  *
00008  * RTAB-Map is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * RTAB-Map is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with RTAB-Map.  If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 #include "PdfPlot.h"
00023 
00024 #define ULOGGER_DEBUG(A, ...)
00025 
00026 namespace rtabmap {
00027 
00028 PdfPlotItem::PdfPlotItem(float dataX, float dataY, float width, int childCount) :
00029         UPlotItem(dataX, dataY, width),
00030         _img(0),
00031         _imagesRef(0)
00032 {
00033         setLikelihood(dataX, dataY, childCount);
00034         _text = new QGraphicsTextItem(this);
00035         _text->setVisible(false);
00036 }
00037 
00038 PdfPlotItem::~PdfPlotItem()
00039 {
00040 
00041 }
00042 
00043 void PdfPlotItem::setLikelihood(int id, float value, int childCount)
00044 {
00045         if(_img && id != this->data().x())
00046         {
00047                 delete _img;
00048                 _img = 0;
00049         }
00050         this->setData(QPointF(id, value));
00051         _childCount = childCount;
00052 }
00053 
00054 void PdfPlotItem::showDescription(bool shown)
00055 {
00056         if(shown)
00057         {
00058                 if(!_img && _imagesRef)
00059                 {
00060                         QImage img;
00061                         QMap<int, QByteArray>::const_iterator iter = _imagesRef->find(int(this->data().x()));
00062                         if(iter != _imagesRef->constEnd())
00063                         {
00064                                 if(img.loadFromData(iter.value(), "JPEG"))
00065                                 {
00066                                         QPixmap scaled = QPixmap::fromImage(img).scaledToWidth(128);
00067                                         _img = new QGraphicsPixmapItem(scaled, this);
00068                                         _img->setVisible(false);
00069                                 }
00070                         }
00071                 }
00072 
00073                 if(_img)
00074                         _text->setPos(this->mapFromScene(4+150,0));
00075                 else
00076                         _text->setPos(this->mapFromScene(4,0));
00077                 if(_childCount >= 0)
00078                 {
00079                         _text->setPlainText(QString("ID = %1\nValue = %2\nWeight = %3").arg(this->data().x()).arg(this->data().y()).arg(_childCount));
00080                 }
00081                 else
00082                 {
00083                         _text->setPlainText(QString("ID = %1\nValue = %2").arg(this->data().x()).arg(this->data().y()));
00084                 }
00085                 _text->setVisible(true);
00086                 if(_img)
00087                 {
00088                         _img->setPos(this->mapFromScene(4,0));
00089                         _img->setVisible(true);
00090                 }
00091         }
00092         else
00093         {
00094                 _text->setVisible(false);
00095                 if(_img)
00096                         _img->setVisible(false);
00097         }
00098         UPlotItem::showDescription(shown);
00099 }
00100 
00101 
00102 
00103 
00104 
00105 PdfPlotCurve::PdfPlotCurve(const QString & name, const QMap<int, QByteArray> * imagesMapRef = 0, QObject * parent) :
00106         UPlotCurve(name, parent),
00107         _imagesMapRef(imagesMapRef)
00108 {
00109 
00110 }
00111 
00112 PdfPlotCurve::~PdfPlotCurve()
00113 {
00114 
00115 }
00116 
00117 void PdfPlotCurve::clear()
00118 {
00119         UPlotCurve::clear();
00120 }
00121 
00122 void PdfPlotCurve::setData(const QMap<int, int> & dataMap, const QMap<int, int> & weightsMap)
00123 {
00124         ULOGGER_DEBUG("dataMap=%d, weightsMap=%d", dataMap.size(), weightsMap.size());
00125         if(dataMap.size() > 0)
00126         {
00127                 //match the size of the current data
00128                 int margin = int((_items.size()+1)/2) - dataMap.size();
00129 
00130                 while(margin < 0)
00131                 {
00132                         PdfPlotItem * newItem = new PdfPlotItem(0, 0, 2, 0);
00133                         newItem->setImagesRef(_imagesMapRef);
00134                         this->_addValue(newItem);
00135                         ++margin;
00136                 }
00137 
00138                 while(margin > 0)
00139                 {
00140                         this->removeItem(0);
00141                         --margin;
00142                 }
00143 
00144                 ULOGGER_DEBUG("itemsize=%d", _items.size());
00145 
00146                 // update values
00147                 QList<QGraphicsItem*>::iterator iter = _items.begin();
00148                 QMap<int, int>::const_iterator j=weightsMap.begin();
00149                 for(QMap<int, int>::const_iterator i=dataMap.begin(); i!=dataMap.end(); ++i, ++j)
00150                 {
00151                         ((PdfPlotItem*)*iter)->setLikelihood(i.key(),  i.value(), j!=weightsMap.end()?j.value():-1);
00152                         //2 times...
00153                         ++iter;
00154                         ++iter;
00155                 }
00156 
00157                 //reset minMax, this will force the plot to update the axes
00158                 this->updateMinMax();
00159                 Q_EMIT dataChanged(this);
00160         }
00161 }
00162 
00163 }


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Fri Feb 12 2016 01:18:17