PdfPlot.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include "rtabmap/gui/PdfPlot.h"
30 #include "rtabmap/utilite/UCv2Qt.h"
31 #include "rtabmap/core/util3d.h"
32 
33 namespace rtabmap {
34 
35 PdfPlotItem::PdfPlotItem(float dataX, float dataY, float width, int childCount) :
36  UPlotItem(dataX, dataY, width),
37  _img(0),
38  _signaturesRef(0),
39  _text(0)
40 {
41  setLikelihood(dataX, dataY, childCount);
42 }
43 
45 {
46 
47 }
48 
49 void PdfPlotItem::setLikelihood(int id, float value, int childCount)
50 {
51  if(_img && id != this->data().x())
52  {
53  delete _img;
54  _img = 0;
55  }
56  this->setData(QPointF(id, value));
57  _childCount = childCount;
58 }
59 
61 {
62  if(!_text)
63  {
64  _text = new QGraphicsTextItem(this);
65  _text->setVisible(false);
66  }
67  if(shown)
68  {
69  if(!_img && _signaturesRef)
70  {
71  QImage img;
72  QMap<int, Signature>::const_iterator iter = _signaturesRef->find(int(this->data().x()));
73  if(iter != _signaturesRef->constEnd() && !iter.value().sensorData().imageCompressed().empty())
74  {
75  cv::Mat image;
76  iter.value().sensorData().uncompressDataConst(&image, 0, 0);
77  if(!image.empty())
78  {
79  img = uCvMat2QImage(image);
80  QPixmap scaled = QPixmap::fromImage(img).scaledToWidth(128);
81  _img = new QGraphicsPixmapItem(scaled, this);
82  _img->setVisible(false);
83  }
84  }
85  }
86 
87  if(_img)
88  _text->setPos(this->mapFromScene(4+150,0));
89  else
90  _text->setPos(this->mapFromScene(4,0));
91  if(_childCount >= 0)
92  {
93  _text->setPlainText(QString("ID = %1\nValue = %2\nWeight = %3").arg(this->data().x()).arg(this->data().y()).arg(_childCount));
94  }
95  else
96  {
97  _text->setPlainText(QString("ID = %1\nValue = %2").arg(this->data().x()).arg(this->data().y()));
98  }
99  _text->setVisible(true);
100  if(_img)
101  {
102  _img->setPos(this->mapFromScene(4,0));
103  _img->setVisible(true);
104  }
105  }
106  else
107  {
108  _text->setVisible(false);
109  if(_img)
110  _img->setVisible(false);
111  }
113 }
114 
115 
116 
117 
118 
119 PdfPlotCurve::PdfPlotCurve(const QString & name, const QMap<int, Signature> * signaturesMapRef = 0, QObject * parent) :
120  UPlotCurve(name, parent),
121  _signaturesMapRef(signaturesMapRef)
122 {
123 
124 }
125 
127 {
128 
129 }
130 
132 {
134 }
135 
136 void PdfPlotCurve::setData(const QMap<int, float> & dataMap, const QMap<int, int> & weightsMap)
137 {
138  ULOGGER_DEBUG("dataMap=%d, weightsMap=%d", dataMap.size(), weightsMap.size());
139  if(dataMap.size() > 0)
140  {
141  //match the size of the current data
142  int margin = int((_items.size()+1)/2) - dataMap.size();
143 
144  while(margin < 0)
145  {
146  PdfPlotItem * newItem = new PdfPlotItem(0, 0, 2, 0);
148  this->_addValue(newItem);
149  ++margin;
150  }
151 
152  while(margin > 0)
153  {
154  this->removeItem(0);
155  --margin;
156  }
157 
158  ULOGGER_DEBUG("itemsize=%d", _items.size());
159 
160  // update values
161  QList<QGraphicsItem*>::iterator iter = _items.begin();
162  for(QMap<int, float>::const_iterator i=dataMap.begin(); i!=dataMap.end(); ++i)
163  {
164  ((PdfPlotItem*)*iter)->setLikelihood(i.key(), i.value(), weightsMap.value(i.key(), -1));
165  //2 times...
166  ++iter;
167  ++iter;
168  }
169 
170  //reset minMax, this will force the plot to update the axes
171  this->updateMinMax();
172  Q_EMIT dataChanged(this);
173  }
174 }
175 
176 }
int
int
UPlotCurve::_addValue
void _addValue(UPlotItem *data)
Definition: UPlot.cpp:377
name
UPlotItem
Definition: UPlot.h:47
rtabmap::PdfPlotItem::showDescription
virtual void showDescription(bool shown)
Definition: PdfPlot.cpp:60
rtabmap::PdfPlotItem::setSignaturesRef
void setSignaturesRef(const QMap< int, Signature > *signaturesRef)
Definition: PdfPlot.h:46
rtabmap::PdfPlotItem::_text
QGraphicsTextItem * _text
Definition: PdfPlot.h:58
rtabmap_netvlad.img
img
Definition: rtabmap_netvlad.py:78
rtabmap::PdfPlotItem::_signaturesRef
const QMap< int, Signature > * _signaturesRef
Definition: PdfPlot.h:57
y
Matrix3f y
rtabmap::PdfPlotCurve::~PdfPlotCurve
virtual ~PdfPlotCurve()
Definition: PdfPlot.cpp:126
rtabmap::PdfPlotItem
Definition: PdfPlot.h:39
util3d.h
rtabmap::PdfPlotItem::~PdfPlotItem
virtual ~PdfPlotItem()
Definition: PdfPlot.cpp:44
UPlotCurve::removeItem
int removeItem(int index)
Definition: UPlot.cpp:577
ULOGGER_DEBUG
#define ULOGGER_DEBUG(...)
Definition: ULogger.h:53
UPlotCurve::dataChanged
void dataChanged(const UPlotCurve *)
UPlotItem::setData
void setData(const QPointF &data)
Definition: UPlot.cpp:102
rtabmap::PdfPlotItem::_childCount
int _childCount
Definition: PdfPlot.h:56
PdfPlot.h
rtabmap::PdfPlotCurve::setData
void setData(const QMap< int, float > &dataMap, const QMap< int, int > &weightsMap)
Definition: PdfPlot.cpp:136
UPlotItem::data
const QPointF & data() const
Definition: UPlot.h:67
UPlotCurve::_items
QList< QGraphicsItem * > _items
Definition: UPlot.h:240
arg
UCv2Qt.h
x
x
iterator::value
object value
rtabmap::PdfPlotItem::value
float value() const
Definition: PdfPlot.h:48
rtabmap::PdfPlotItem::setLikelihood
void setLikelihood(int id, float value, int childCount)
Definition: PdfPlot.cpp:49
ULogger.h
ULogger class and convenient macros.
UPlotCurve
Definition: UPlot.h:93
rtabmap::PdfPlotCurve::PdfPlotCurve
PdfPlotCurve(const QString &name, const QMap< int, Signature > *signaturesMapRef, QObject *parent=0)
Definition: PdfPlot.cpp:119
iter
iterator iter(handle obj)
UPlotItem::showDescription
virtual void showDescription(bool shown)
Definition: UPlot.cpp:131
rtabmap::PdfPlotItem::_img
QGraphicsPixmapItem * _img
Definition: PdfPlot.h:55
UPlotCurve::updateMinMax
void updateMinMax()
Definition: UPlot.cpp:340
uCvMat2QImage
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack, float depthMin=0, float depthMax=0)
Definition: UCv2Qt.h:47
rtabmap::PdfPlotCurve::_signaturesMapRef
const QMap< int, Signature > * _signaturesMapRef
Definition: PdfPlot.h:74
rtabmap
Definition: CameraARCore.cpp:35
rtabmap::PdfPlotCurve::clear
virtual void clear()
Definition: PdfPlot.cpp:131
UPlotCurve::clear
virtual void clear()
Definition: UPlot.cpp:653
i
int i
rtabmap::PdfPlotItem::PdfPlotItem
PdfPlotItem(float dataX, float dataY, float width, int childCount=-1)
Definition: PdfPlot.cpp:35


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:14