cvvpointmatch.cpp 1.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include <QBrush>

#include "cvvpointmatch.hpp"

namespace cvv
{
namespace qtutil
{

CVVPointMatch::CVVPointMatch(CVVKeyPoint *left_key, CVVKeyPoint *right_key,
                             const cv::DMatch &match, bool isLeftKey,
                             qreal radius, const QPen &pen, const QBrush &brush,
                             QGraphicsItem *parent)
    : CVVMatch{ left_key, right_key, match, pen, parent },
      isLeftKey_{ isLeftKey },
      radius_{ std::min(radius * match.distance, 10.0) }, brush_{ brush }
{
	if (isLeftKey_)
	{
		right_key_visible_ = true;
		setVisible(left_key_visible_);
	}
	else
	{
		left_key_visible_ = true;
		setVisible(right_key_visible_);
	}
}

QRectF CVVPointMatch::boundingRect() const
{
	QPointF point =
	    (isLeftKey_ ? leftImPointInScene() : rightImPointInScene());
	return QRectF{ QPointF{ point.x() - radius_, point.y() - radius_ },
		       QPointF{ point.x() + radius_, point.y() + radius_ } };
}

void CVVPointMatch::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
                          QWidget *)
{
	painter->setPen(pen_);
	painter->setBrush(brush_);
	painter->drawEllipse(boundingRect());
}

void CVVPointMatch::updateRightKey(bool visible)
{
	if (!isLeftKey_)
	{
		CVVMatch::updateRightKey(visible);
	}
}

void CVVPointMatch::updateLeftKey(bool visible)
{
	if (isLeftKey_)
	{
		CVVMatch::updateLeftKey(visible);
	}
}
}
}