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  // Make octave compatible with SIFT packed octave (https://github.com/opencv/opencv/issues/4554)
78  int octave = _kpt.octave & 255;
79  octave = octave < 128 ? octave : (-128 | octave);
80  float scale = octave >= 0 ? 1.f/(1 << octave) : (float)(1 << -octave);
81  if(_depth <= 0)
82  {
83  text->setPlainText(QString( "Id = %1\n"
84  "Dir = %3\n"
85  "Hessian = %4\n"
86  "X = %5\n"
87  "Y = %6\n"
88  "Size = %7\n"
89  "Octave = %8\n"
90  "Scale = %9").arg(_id).arg(_kpt.angle).arg(_kpt.response).arg(_kpt.pt.x).arg(_kpt.pt.y).arg(_kpt.size).arg(octave).arg(scale));
91  }
92  else
93  {
94  text->setPlainText(QString( "Id = %1\n"
95  "Dir = %3\n"
96  "Hessian = %4\n"
97  "X = %5\n"
98  "Y = %6\n"
99  "Size = %7\n"
100  "Octave = %8\n"
101  "Scale = %9\n"
102  "Depth = %10 m").arg(_id).arg(_kpt.angle).arg(_kpt.response).arg(_kpt.pt.x).arg(_kpt.pt.y).arg(_kpt.size).arg(octave).arg(scale).arg(_depth));
103  }
104  _placeHolder->setRect(text->boundingRect());
105  }
106 
107 
108  if(_placeHolder->parentItem())
109  {
110  _placeHolder->setParentItem(0); // Make it a to level item
111  }
112  QPen pen = this->pen();
113  this->setPen(QPen(pen.color(), _width+2));
114  _placeHolder->setZValue(this->zValue()+1);
115  _placeHolder->setPos(this->mapFromScene(0,0));
116  _placeHolder->setVisible(true);
117 }
118 
120 {
121  if(_placeHolder)
122  {
123  _placeHolder->setVisible(false);
124  }
125  this->setPen(QPen(pen().color(), _width));
126 }
127 
128 void KeypointItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
129 {
130  QGraphicsScene * scene = this->scene();
131  if(scene && scene->focusItem() == 0)
132  {
133  this->showDescription();
134  }
135  else
136  {
137  this->setPen(QPen(pen().color(), _width+2));
138  }
139  QGraphicsEllipseItem::hoverEnterEvent(event);
140 }
141 
142 void KeypointItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
143 {
144  if(!this->hasFocus())
145  {
146  this->hideDescription();
147  }
148  QGraphicsEllipseItem::hoverEnterEvent(event);
149 }
150 
151 void KeypointItem::focusInEvent ( QFocusEvent * event )
152 {
153  this->showDescription();
154  QGraphicsEllipseItem::focusInEvent(event);
155 }
156 
157 void KeypointItem::focusOutEvent ( QFocusEvent * event )
158 {
159  this->hideDescription();
160  QGraphicsEllipseItem::focusOutEvent(event);
161 }
162 
163 }
void setColor(const QColor &color)
f
x
QGraphicsRectItem * _placeHolder
Definition: KeypointItem.h:63
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
GLM_FUNC_DECL detail::tmat4x4< T, P > scale(detail::tmat4x4< T, P > const &m, detail::tvec3< T, P > const &v)
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 Mon Jan 23 2023 03:37:28