1 #ifndef CVVISUAL_CVVKEYPOINT
2 #define CVVISUAL_CVVKEYPOINT
3 
4 #include <QGraphicsObject>
5 #include <QPainter>
6 #include <QPointF>
7 #include <QRectF>
8 #include <QStyleOptionGraphicsItem>
9 #include <QWidget>
10 #include <QGraphicsScene>
11 
12 #include "opencv2/core.hpp"
13 #include "opencv2/features2d.hpp"
14 
15 #include "keypointsettings.hpp"
16 #include "../zoomableimage.hpp"
17 
18 namespace cvv
19 {
20 namespace qtutil
21 {
22 
23 class KeyPointSettings;
24 
25 /**
26  * @brief this class represents a Keypoint which is displayed
27  *  a Matchscene.
28  **/
29 class CVVKeyPoint : public QGraphicsObject,public cv::KeyPoint
30 {
31 	Q_OBJECT
32       public:
33 	/**
34 	 * @brief the construor
35 	 * @param key the keypoint with the image point
36 	 * @param image the zoomable image
37 	 */
38 	CVVKeyPoint(const cv::KeyPoint &key,
39 		    qtutil::ZoomableImage *image = nullptr,
40 		    QPen pen = QPen{ Qt::red },
41 		    QBrush brush = QBrush{ Qt::red },
42 		    QGraphicsItem *parent = nullptr);
43 
44 	/**
45 	 * @brief this method maps the imagepoint to the scene
46 	 * @return maps the imagepoint to the scene
47 	 */
imPointInScene() const48 	QPointF imPointInScene() const
49 		{return imagePointInScene_;}
50 
51 	/**
52 	 * @brief boundingRect
53 	 * @return the boundingRect
54 	 */
55     QRectF boundingRect() const CV_OVERRIDE;
56 
57 	/**
58 	 * @brief returns the keypoint
59 	 * @return the keypoint
60 	 */
keyPoint() const61 	cv::KeyPoint keyPoint() const
62 		{return *this;}
63 
64 	/**
65 	 * @brief the paint function.
66 	 */
67 	void paint(QPainter *painter, const QStyleOptionGraphicsItem *,
68            QWidget *) CV_OVERRIDE;
69 
70 	/**
71 	 * @brief returns true if this keypoint is in the visble area of its
72 	 * image
73 	 * @return true if this keypoint is in the visble area of its image
74 	 */
imagePointisVisible()75 	bool imagePointisVisible()
76 		{return image_->visibleArea().contains(pt.x, pt.y);	}
77 
78 	/**
79 	 * @brief if show is true this keypoint will be visible if it is the
80 	 * visibleArea
81 	 * @return the show Value
82 	 */
isShown() const83 	bool isShown() const
84 		{return show_;}
85 
86 	bool operator==(const cv::KeyPoint &o);
87 
getPen() const88 	QPen getPen() const
89 		{return pen_;}
90 
getBrush() const91 	QBrush getBrush() const
92 		{return brush_;	}
93 
94 signals:
95 	/**
96 	 * @brief this signal will be emitted when the imagepoint in the scene
97 	 * has changed
98 	 * @param visible it is true if this keypoint is in the visibleArea
99 	 */
100 	void updatePoint(bool visible);
101 
102       public
103 slots:
104 	/**
105 	 * @brief updates the settings of this KeyPoint
106 	 * @param settings the object which has new settings for this keypoint
107 	 */
108 	void updateSettings(KeyPointSettings &settings);
109 
110 	void setPen(const QPen &pen);
111 
112 	/**
113 	 * @brief updates the brush of this KeyPoint
114 	 * @param brush a new brush
115 	 */
116 	void setBrush(const QBrush &brush);
117 
118 	/**
119 	 * @brief if show is true this keypoint will be visible if it is the
120 	 * visibleArea
121 	 * @param b the new show Value
122 	 */
123 	void setShow(bool b);
124 
125 	/**
126 	 * @brief updates the coordinates and visibleState of this KeyPoint
127 	 * @param visibleArea the visibleArea of the ZoomableImage
128 	 * @param zoom the zoomfactor
129 	 */
130 	void updateImageSet(const QRectF &, const qreal &zoom);
131 
132 	/**
133 	 * @brief this method sets and connects this keypoint which the given
134 	 * ZoomableImage.
135 	 * the ZoomableImage should be in a QGraphicScene and should have same
136 	 * parent
137 	 * @param image the image
138 	 */
139 	void setZoomableImage(ZoomableImage *image);
140 
141       private:
142 	qtutil::ZoomableImage *image_=nullptr;
143 
144 	QPen pen_;
145 	QBrush brush_;
146 	qreal zoom_;
147 	bool show_;
148 
149 	QPointF imagePointInScene_;
150 };
151 }
152 }
153 #endif
154