2011-12-02 18:34:08 +00:00
|
|
|
/*
|
2014-08-06 13:43:29 +00:00
|
|
|
Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2014-08-11 15:49:53 +00:00
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
2014-08-06 13:43:29 +00:00
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-10-25 15:48:19 +00:00
|
|
|
|
|
|
|
|
#include "KeypointItem.h"
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QPen>
|
|
|
|
|
#include <QtGui/QBrush>
|
|
|
|
|
#include <QtGui/QGraphicsScene>
|
|
|
|
|
|
2014-08-06 13:43:29 +00:00
|
|
|
namespace find_object {
|
|
|
|
|
|
2015-06-24 18:07:52 -04:00
|
|
|
KeypointItem::KeypointItem(int id, qreal x, qreal y, int r, const cv::KeyPoint & kpt, int wordID, const QColor & color, QGraphicsItem * parent) :
|
2011-10-25 15:48:19 +00:00
|
|
|
QGraphicsEllipseItem(x, y, r, r, parent),
|
2012-04-04 18:15:51 +00:00
|
|
|
placeHolder_(0),
|
2015-06-24 18:07:52 -04:00
|
|
|
id_(id),
|
|
|
|
|
kpt_(kpt),
|
|
|
|
|
wordID_(wordID)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
|
|
|
|
this->setPen(QPen(color));
|
|
|
|
|
this->setBrush(QBrush(color));
|
|
|
|
|
this->setAcceptsHoverEvents(true);
|
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
|
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KeypointItem::~KeypointItem()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeypointItem::setColor(const QColor & color)
|
|
|
|
|
{
|
|
|
|
|
this->setPen(QPen(color));
|
|
|
|
|
this->setBrush(QBrush(color));
|
2012-04-04 18:15:51 +00:00
|
|
|
if(placeHolder_)
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
QList<QGraphicsItem *> items = placeHolder_->children();
|
2011-10-25 15:48:19 +00:00
|
|
|
if(items.size())
|
|
|
|
|
{
|
|
|
|
|
((QGraphicsTextItem *)items.front())->setDefaultTextColor(this->pen().color().rgb());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeypointItem::showDescription()
|
|
|
|
|
{
|
2014-05-13 17:47:59 +00:00
|
|
|
if(!placeHolder_ || !placeHolder_->isVisible())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2014-05-13 17:47:59 +00:00
|
|
|
if(!placeHolder_)
|
|
|
|
|
{
|
2015-06-24 18:07:52 -04:00
|
|
|
QString info = QString( "Keypoint = %1\n"
|
|
|
|
|
"Word = %2\n"
|
|
|
|
|
"Response = %3\n"
|
|
|
|
|
"Angle = %4\n"
|
|
|
|
|
"X = %5\n"
|
|
|
|
|
"Y = %6\n"
|
|
|
|
|
"Size = %7").arg(id_).arg(wordID_).arg(kpt_.response).arg(kpt_.angle).arg(kpt_.pt.x).arg(kpt_.pt.y).arg(kpt_.size);
|
|
|
|
|
|
2014-05-13 17:47:59 +00:00
|
|
|
placeHolder_ = new QGraphicsRectItem();
|
|
|
|
|
placeHolder_->setVisible(false);
|
|
|
|
|
this->scene()->addItem(placeHolder_);
|
|
|
|
|
placeHolder_->setBrush(QBrush(QColor ( 0, 0, 0, 170 ))); // Black transparent background
|
|
|
|
|
QGraphicsTextItem * text = new QGraphicsTextItem(placeHolder_);
|
|
|
|
|
text->setDefaultTextColor(this->pen().color().rgb());
|
2015-06-24 18:07:52 -04:00
|
|
|
text->setPlainText(info);
|
2014-05-13 17:47:59 +00:00
|
|
|
placeHolder_->setRect(text->boundingRect());
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
|
|
|
|
|
|
2014-05-13 17:47:59 +00:00
|
|
|
QPen pen = this->pen();
|
|
|
|
|
this->setPen(QPen(pen.color(), pen.width()+2));
|
|
|
|
|
placeHolder_->setZValue(this->zValue()+1);
|
|
|
|
|
placeHolder_->setPos(this->mapToScene(0,0));
|
|
|
|
|
placeHolder_->setVisible(true);
|
|
|
|
|
}
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeypointItem::hideDescription()
|
|
|
|
|
{
|
2014-05-13 17:47:59 +00:00
|
|
|
if(placeHolder_ && placeHolder_->isVisible())
|
2011-10-25 15:48:19 +00:00
|
|
|
{
|
2012-04-04 18:15:51 +00:00
|
|
|
placeHolder_->setVisible(false);
|
2014-05-13 17:47:59 +00:00
|
|
|
this->setPen(QPen(pen().color(), pen().width()-2));
|
2011-10-25 15:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeypointItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
|
|
|
|
|
{
|
2014-05-13 17:47:59 +00:00
|
|
|
this->showDescription();
|
2011-10-25 15:48:19 +00:00
|
|
|
QGraphicsEllipseItem::hoverEnterEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeypointItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
|
|
|
|
|
{
|
|
|
|
|
if(!this->hasFocus())
|
|
|
|
|
{
|
|
|
|
|
this->hideDescription();
|
|
|
|
|
}
|
|
|
|
|
QGraphicsEllipseItem::hoverEnterEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeypointItem::focusInEvent ( QFocusEvent * event )
|
|
|
|
|
{
|
|
|
|
|
this->showDescription();
|
|
|
|
|
QGraphicsEllipseItem::focusInEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeypointItem::focusOutEvent ( QFocusEvent * event )
|
|
|
|
|
{
|
|
|
|
|
this->hideDescription();
|
|
|
|
|
QGraphicsEllipseItem::focusOutEvent(event);
|
|
|
|
|
}
|
2014-08-06 13:43:29 +00:00
|
|
|
|
|
|
|
|
} // namespace find_object
|