PdfPlot.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "rtabmap/gui/PdfPlot.h"
00029 #include <rtabmap/utilite/ULogger.h>
00030 #include "rtabmap/utilite/UCv2Qt.h"
00031 #include "rtabmap/core/util3d.h"
00032 
00033 namespace rtabmap {
00034 
00035 PdfPlotItem::PdfPlotItem(float dataX, float dataY, float width, int childCount) :
00036         UPlotItem(dataX, dataY, width),
00037         _img(0),
00038         _signaturesRef(0),
00039         _text(0)
00040 {
00041         setLikelihood(dataX, dataY, childCount);
00042 }
00043 
00044 PdfPlotItem::~PdfPlotItem()
00045 {
00046 
00047 }
00048 
00049 void PdfPlotItem::setLikelihood(int id, float value, int childCount)
00050 {
00051         if(_img && id != this->data().x())
00052         {
00053                 delete _img;
00054                 _img = 0;
00055         }
00056         this->setData(QPointF(id, value));
00057         _childCount = childCount;
00058 }
00059 
00060 void PdfPlotItem::showDescription(bool shown)
00061 {
00062         if(!_text)
00063         {
00064                 _text = new QGraphicsTextItem(this);
00065                 _text->setVisible(false);
00066         }
00067         if(shown)
00068         {
00069                 if(!_img && _signaturesRef)
00070                 {
00071                         QImage img;
00072                         QMap<int, Signature>::const_iterator iter = _signaturesRef->find(int(this->data().x()));
00073                         if(iter != _signaturesRef->constEnd() && !iter.value().sensorData().imageCompressed().empty())
00074                         {
00075                                 cv::Mat image;
00076                                 iter.value().sensorData().uncompressDataConst(&image, 0, 0);
00077                                 if(!image.empty())
00078                                 {
00079                                         img = uCvMat2QImage(image);
00080                                         QPixmap scaled = QPixmap::fromImage(img).scaledToWidth(128);
00081                                         _img = new QGraphicsPixmapItem(scaled, this);
00082                                         _img->setVisible(false);
00083                                 }
00084                         }
00085                 }
00086 
00087                 if(_img)
00088                         _text->setPos(this->mapFromScene(4+150,0));
00089                 else
00090                         _text->setPos(this->mapFromScene(4,0));
00091                 if(_childCount >= 0)
00092                 {
00093                         _text->setPlainText(QString("ID = %1\nValue = %2\nWeight = %3").arg(this->data().x()).arg(this->data().y()).arg(_childCount));
00094                 }
00095                 else
00096                 {
00097                         _text->setPlainText(QString("ID = %1\nValue = %2").arg(this->data().x()).arg(this->data().y()));
00098                 }
00099                 _text->setVisible(true);
00100                 if(_img)
00101                 {
00102                         _img->setPos(this->mapFromScene(4,0));
00103                         _img->setVisible(true);
00104                 }
00105         }
00106         else
00107         {
00108                 _text->setVisible(false);
00109                 if(_img)
00110                         _img->setVisible(false);
00111         }
00112         UPlotItem::showDescription(shown);
00113 }
00114 
00115 
00116 
00117 
00118 
00119 PdfPlotCurve::PdfPlotCurve(const QString & name, const QMap<int, Signature> * signaturesMapRef = 0, QObject * parent) :
00120         UPlotCurve(name, parent),
00121         _signaturesMapRef(signaturesMapRef)
00122 {
00123 
00124 }
00125 
00126 PdfPlotCurve::~PdfPlotCurve()
00127 {
00128 
00129 }
00130 
00131 void PdfPlotCurve::clear()
00132 {
00133         UPlotCurve::clear();
00134 }
00135 
00136 void PdfPlotCurve::setData(const QMap<int, float> & dataMap, const QMap<int, int> & weightsMap)
00137 {
00138         ULOGGER_DEBUG("dataMap=%d, weightsMap=%d", dataMap.size(), weightsMap.size());
00139         if(dataMap.size() > 0)
00140         {
00141                 //match the size of the current data
00142                 int margin = int((_items.size()+1)/2) - dataMap.size();
00143 
00144                 while(margin < 0)
00145                 {
00146                         PdfPlotItem * newItem = new PdfPlotItem(0, 0, 2, 0);
00147                         newItem->setSignaturesRef(_signaturesMapRef);
00148                         this->_addValue(newItem);
00149                         ++margin;
00150                 }
00151 
00152                 while(margin > 0)
00153                 {
00154                         this->removeItem(0);
00155                         --margin;
00156                 }
00157 
00158                 ULOGGER_DEBUG("itemsize=%d", _items.size());
00159 
00160                 // update values
00161                 QList<QGraphicsItem*>::iterator iter = _items.begin();
00162                 for(QMap<int, float>::const_iterator i=dataMap.begin(); i!=dataMap.end(); ++i)
00163                 {
00164                         ((PdfPlotItem*)*iter)->setLikelihood(i.key(),  i.value(), weightsMap.value(i.key(), -1));
00165                         //2 times...
00166                         ++iter;
00167                         ++iter;
00168                 }
00169 
00170                 //reset minMax, this will force the plot to update the axes
00171                 this->updateMinMax();
00172                 emit dataChanged(this);
00173         }
00174 }
00175 
00176 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:17