PdfPlot.cpp
Go to the documentation of this file.
1 // Taken from RTAB-Map library r606 [www.rtabmap.googlecode.com]
2 
3 /*
4  * Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke
5  *
6  * This file is part of RTAB-Map.
7  *
8  * RTAB-Map is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * RTAB-Map is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with RTAB-Map. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "PdfPlot.h"
24 
25 namespace rtabmap {
26 
27 PdfPlotItem::PdfPlotItem(float dataX, float dataY, float width, int childCount) :
28  UPlotItem(dataX, dataY, width),
29  _img(0),
30  _imagesRef(0)
31 {
32  setLikelihood(dataX, dataY, childCount);
33  _text = new QGraphicsTextItem(this);
34  _text->setVisible(false);
35 }
36 
38 {
39 
40 }
41 
42 void PdfPlotItem::setLikelihood(int id, float value, int childCount)
43 {
44  if(_img && id != this->data().x())
45  {
46  delete _img;
47  _img = 0;
48  }
49  this->setData(QPointF(id, value));
50  _childCount = childCount;
51 }
52 
54 {
55  if(shown)
56  {
57  if(!_img && _imagesRef)
58  {
59  QImage img;
60  QMap<int, QByteArray>::const_iterator iter = _imagesRef->find(int(this->data().x()));
61  if(iter != _imagesRef->constEnd())
62  {
63  if(img.loadFromData(iter.value(), "JPEG"))
64  {
65  QPixmap scaled = QPixmap::fromImage(img).scaledToWidth(128);
66  _img = new QGraphicsPixmapItem(scaled, this);
67  _img->setVisible(false);
68  }
69  }
70  }
71 
72  if(_img)
73  _text->setPos(this->mapFromScene(4+150,0));
74  else
75  _text->setPos(this->mapFromScene(4,0));
76  if(_childCount >= 0)
77  {
78  _text->setPlainText(QString("ID = %1\nValue = %2\nWeight = %3").arg(this->data().x()).arg(this->data().y()).arg(_childCount));
79  }
80  else
81  {
82  _text->setPlainText(QString("ID = %1\nValue = %2").arg(this->data().x()).arg(this->data().y()));
83  }
84  _text->setVisible(true);
85  if(_img)
86  {
87  _img->setPos(this->mapFromScene(4,0));
88  _img->setVisible(true);
89  }
90  }
91  else
92  {
93  _text->setVisible(false);
94  if(_img)
95  _img->setVisible(false);
96  }
98 }
99 
100 
101 
102 
103 
104 PdfPlotCurve::PdfPlotCurve(const QString & name, const QMap<int, QByteArray> * imagesMapRef = 0, QObject * parent) :
105  UPlotCurve(name, parent),
106  _imagesMapRef(imagesMapRef)
107 {
108 
109 }
110 
112 {
113 
114 }
115 
117 {
119 }
120 
121 void PdfPlotCurve::setData(const QMap<int, int> & dataMap, const QMap<int, int> & weightsMap)
122 {
123  ULOGGER_DEBUG("dataMap=%d, weightsMap=%d", dataMap.size(), weightsMap.size());
124  if(dataMap.size() > 0)
125  {
126  //match the size of the current data
127  int margin = int((_items.size()+1)/2) - dataMap.size();
128 
129  while(margin < 0)
130  {
131  PdfPlotItem * newItem = new PdfPlotItem(0, 0, 2, 0);
132  newItem->setImagesRef(_imagesMapRef);
133  this->_addValue(newItem);
134  ++margin;
135  }
136 
137  while(margin > 0)
138  {
139  this->removeItem(0);
140  --margin;
141  }
142 
143  ULOGGER_DEBUG("itemsize=%d", _items.size());
144 
145  // update values
146  QList<QGraphicsItem*>::iterator iter = _items.begin();
147  for(QMap<int, int>::const_iterator i=dataMap.begin(); i!=dataMap.end(); ++i)
148  {
149  UASSERT(iter!= _items.end());
150  ((PdfPlotItem*)*iter)->setLikelihood(i.key(), i.value(), weightsMap.value(i.key(),-1));
151  //2 times...
152  ++iter;
153  ++iter;
154  }
155  //reset minMax, this will force the plot to update the axes
156  this->updateMinMax();
157  Q_EMIT dataChanged(this);
158  }
159 }
160 
161 }
PdfPlotCurve(const QString &name, const QMap< int, QByteArray > *imagesMapRef, QObject *parent=0)
Definition: PdfPlot.cpp:104
float value() const
Definition: PdfPlot.h:38
void setLikelihood(int id, float value, int childCount)
Definition: PdfPlot.cpp:42
void setImagesRef(const QMap< int, QByteArray > *imagesRef)
Definition: PdfPlot.h:36
int removeItem(int index)
Definition: UPlot.cpp:560
void updateMinMax()
Definition: UPlot.cpp:328
virtual ~PdfPlotCurve()
Definition: PdfPlot.cpp:111
QGraphicsPixmapItem * _img
Definition: PdfPlot.h:46
void setData(const QMap< int, int > &dataMap, const QMap< int, int > &weightsMap)
Definition: PdfPlot.cpp:121
#define UASSERT(condition)
virtual void showDescription(bool shown)
Definition: UPlot.cpp:128
PdfPlotItem(float dataX, float dataY, float width, int childCount=-1)
Definition: PdfPlot.cpp:27
#define ULOGGER_DEBUG(...)
Definition: ULogger.h:54
void _addValue(UPlotItem *data)
Definition: UPlot.cpp:365
const QMap< int, QByteArray > * _imagesMapRef
Definition: PdfPlot.h:64
QList< QGraphicsItem * > _items
Definition: UPlot.h:232
virtual void showDescription(bool shown)
Definition: PdfPlot.cpp:53
virtual void clear()
Definition: UPlot.cpp:636
QGraphicsTextItem * _text
Definition: PdfPlot.h:45
ULogger class and convenient macros.
void setData(const QPointF &data)
Definition: UPlot.cpp:99
const QPointF & data() const
Definition: UPlot.h:67
const QMap< int, QByteArray > * _imagesRef
Definition: PdfPlot.h:48
virtual ~PdfPlotItem()
Definition: PdfPlot.cpp:37
virtual void clear()
Definition: PdfPlot.cpp:116
void dataChanged(const UPlotCurve *)


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Mon Dec 12 2022 03:20:09