KeypointItem.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 
29 
30 #include <QtGui/QPen>
31 #include <QtGui/QBrush>
32 #include <QGraphicsScene>
34 
35 namespace rtabmap {
36 
37 KeypointItem::KeypointItem(int id, const cv::KeyPoint & kpt, float depth, const QColor & color, QGraphicsItem * parent) :
38  QGraphicsEllipseItem(kpt.pt.x-(kpt.size==0?3.0f:kpt.size)/2.0f, kpt.pt.y-(kpt.size==0?3.0f:kpt.size)/2.0f, kpt.size==0?3.0f:kpt.size, kpt.size==0?3.0f:kpt.size, parent),
39  _id(id),
40  _kpt(kpt),
41  _placeHolder(0),
42  _depth(depth)
43 {
44  this->setColor(color);
45  this->setAcceptHoverEvents(true);
46  this->setFlag(QGraphicsItem::ItemIsFocusable, true);
47  _width = pen().width();
48 }
49 
51 {
52  delete _placeHolder;
53 }
54 
55 void KeypointItem::setColor(const QColor & color)
56 {
57  this->setPen(QPen(color));
58  this->setBrush(QBrush(color));
59 }
60 
62 {
63  if(!_placeHolder)
64  {
65  _placeHolder = new QGraphicsRectItem (this);
66  _placeHolder->setVisible(false);
67  if(qGray(pen().color().rgb() > 255/2))
68  {
69  _placeHolder->setBrush(QBrush(QColor ( 0,0,0, 170 )));
70  }
71  else
72  {
73  _placeHolder->setBrush(QBrush(QColor ( 255, 255, 255, 170 )));
74  }
75  QGraphicsTextItem * text = new QGraphicsTextItem(_placeHolder);
76  text->setDefaultTextColor(this->pen().color().rgb());
77  if(_depth <= 0)
78  {
79  text->setPlainText(QString( "Id = %1\n"
80  "Dir = %3\n"
81  "Hessian = %4\n"
82  "X = %5\n"
83  "Y = %6\n"
84  "Size = %7\n"
85  "Octave = %8").arg(_id).arg(_kpt.angle).arg(_kpt.response).arg(_kpt.pt.x).arg(_kpt.pt.y).arg(_kpt.size).arg(_kpt.octave));
86  }
87  else
88  {
89  text->setPlainText(QString( "Id = %1\n"
90  "Dir = %3\n"
91  "Hessian = %4\n"
92  "X = %5\n"
93  "Y = %6\n"
94  "Size = %7\n"
95  "Octave = %8\n"
96  "Depth = %9 m").arg(_id).arg(_kpt.angle).arg(_kpt.response).arg(_kpt.pt.x).arg(_kpt.pt.y).arg(_kpt.size).arg(_kpt.octave).arg(_depth));
97  }
98  _placeHolder->setRect(text->boundingRect());
99  }
100 
101 
102  if(_placeHolder->parentItem())
103  {
104  _placeHolder->setParentItem(0); // Make it a to level item
105  }
106  QPen pen = this->pen();
107  this->setPen(QPen(pen.color(), _width+2));
108  _placeHolder->setZValue(this->zValue()+1);
109  _placeHolder->setPos(this->mapFromScene(0,0));
110  _placeHolder->setVisible(true);
111 }
112 
114 {
115  if(_placeHolder)
116  {
117  _placeHolder->setVisible(false);
118  }
119  this->setPen(QPen(pen().color(), _width));
120 }
121 
122 void KeypointItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
123 {
124  QGraphicsScene * scene = this->scene();
125  if(scene && scene->focusItem() == 0)
126  {
127  this->showDescription();
128  }
129  else
130  {
131  this->setPen(QPen(pen().color(), _width+2));
132  }
133  QGraphicsEllipseItem::hoverEnterEvent(event);
134 }
135 
136 void KeypointItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
137 {
138  if(!this->hasFocus())
139  {
140  this->hideDescription();
141  }
142  QGraphicsEllipseItem::hoverEnterEvent(event);
143 }
144 
145 void KeypointItem::focusInEvent ( QFocusEvent * event )
146 {
147  this->showDescription();
148  QGraphicsEllipseItem::focusInEvent(event);
149 }
150 
151 void KeypointItem::focusOutEvent ( QFocusEvent * event )
152 {
153  this->hideDescription();
154  QGraphicsEllipseItem::focusOutEvent(event);
155 }
156 
157 }
void setColor(const QColor &color)
f
QGraphicsRectItem * _placeHolder
Definition: KeypointItem.h:63
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
virtual void focusOutEvent(QFocusEvent *event)
KeypointItem(int id, const cv::KeyPoint &kpt, float depth=0, const QColor &color=Qt::green, QGraphicsItem *parent=0)
virtual void focusInEvent(QFocusEvent *event)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
ULogger class and convenient macros.


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31