1 #include "cvvkeypoint.hpp"
2
3 namespace cvv
4 {
5 namespace qtutil
6 {
7
CVVKeyPoint(const cv::KeyPoint & key,qtutil::ZoomableImage * image,QPen pen,QBrush brush,QGraphicsItem * parent)8 CVVKeyPoint::CVVKeyPoint(const cv::KeyPoint &key, qtutil::ZoomableImage *image,
9 QPen pen, QBrush brush, QGraphicsItem *parent)
10 : QGraphicsObject{ parent }, cv::KeyPoint{ key }, image_{ image }, pen_{ pen },
11 brush_{ brush }, show_{ true }
12 {
13 //setFlag(QGraphicsItem::ItemIsSelectable, true);
14 //setSelected(true);
15 setToolTip(QString
16 { "KeyPoint size: %1 \n angle %2 \n response %3 " }
17 .arg(size)
18 .arg(angle)
19 .arg(response));
20 if (image != nullptr)
21 {
22 updateImageSet(image->visibleArea(), image->zoom());
23 connect(image, SIGNAL(updateArea(QRectF, qreal)), this,
24 SLOT(updateImageSet(QRectF, qreal)));
25 }
26 }
27
paint(QPainter * painter,const QStyleOptionGraphicsItem *,QWidget *)28 void CVVKeyPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
29 QWidget *)
30 {
31 painter->setPen(pen_);
32 painter->setBrush(brush_);
33 painter->drawEllipse(boundingRect());
34 }
35
setZoomableImage(ZoomableImage * image)36 void CVVKeyPoint::setZoomableImage(ZoomableImage *image)
37 {
38 image_ = image;
39 updateImageSet(image->visibleArea(), image->zoom());
40 connect(image, SIGNAL(updateArea(QRectF, qreal)), this,
41 SLOT(updateImageSet(const QRectF &, const qreal &)));
42 }
43
operator ==(const cv::KeyPoint & o)44 bool CVVKeyPoint::operator==(const cv::KeyPoint &o)
45 {
46 return o.pt == pt && o.size == size &&
47 o.angle == angle && o.response == response &&
48 o.octave == octave && o.class_id == class_id;
49 }
50
updateSettings(KeyPointSettings & settings)51 void CVVKeyPoint::updateSettings(KeyPointSettings &settings)
52 {
53 settings.setSettings(*this);
54 }
55
56
57
setPen(const QPen & pen)58 void CVVKeyPoint::setPen(const QPen &pen)
59 {
60 pen_ = pen;
61 update();
62 }
63
setBrush(const QBrush & brush)64 void CVVKeyPoint::setBrush(const QBrush &brush)
65 {
66 brush_ = brush;
67 update();
68 }
69
setShow(bool b)70 void CVVKeyPoint::setShow(bool b)
71 {
72 show_ = b;
73 if(image_){
74 setVisible(show_&imagePointisVisible());
75 }
76 }
77
boundingRect() const78 QRectF CVVKeyPoint::boundingRect() const
79 {
80 // TODO throw image==nullptr
81 return QRectF{
82 QPointF{ imPointInScene().x() - 3, imPointInScene().y() - 3 },
83 QPointF{ imPointInScene().x() + 3, imPointInScene().y() + 3 }
84 };
85 }
86
updateImageSet(const QRectF &,const qreal & zoom)87 void CVVKeyPoint::updateImageSet(const QRectF &, const qreal &zoom)
88 {
89 imagePointInScene_=image_->mapImagePointToParent(
90 QPointF{ pt.x, pt.y });
91
92 bool isInVisibleArea=imagePointisVisible();
93 setVisible(show_ && isInVisibleArea);
94 emit updatePoint(isInVisibleArea);
95 zoom_ = zoom;
96 prepareGeometryChange();
97 // update();
98 }
99 }
100 }
101