MIRA
PolygonTool2D.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_POLYGONTOOL2D_H_
48 #define _MIRA_POLYGONTOOL2D_H_
49 
51 
52 #include <QGraphicsPolygonItem>
53 #include <geometry/Polygon.h>
54 
55 namespace mira {
56 
58 
59 class PathPointItem : public QAbstractGraphicsShapeItem
60 {
61 public:
62  PathPointItem(qreal radius = 2.0, QGraphicsItem* parent = NULL);
63  virtual ~PathPointItem();
64 
65  virtual QRectF boundingRect() const;
66 
67 protected: // Override these to customize the look of the handle
68  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*);
69 
70  const qreal RADIUS;
71 };
72 
74 
76 {
78  ("Name", "Polygon")
79  ("Category", "Interact")
80  ("Description", "Define a polygon in the 2D view")
81  ("Default", "false")
82  ("Order", "400"))
83 
84 public:
85  PolygonTool2D();
86  virtual ~PolygonTool2D();
87 
88  template<typename Reflector> void reflect(Reflector& r) {
90  }
91 
92  Polygon2f polygon() const;
93  QPen pen() const;
94  QBrush brush() const;
95 
96  void setPen(QPen pen);
97  void setBrush(QBrush brush);
98 
99 public:
100  virtual void onMousePressed(QMouseEvent* e);
101  virtual void onMouseReleased(QMouseEvent* e);
102 
103  virtual void activate();
104  virtual void deactivate();
105  virtual void reset();
106 
107  virtual QIcon getIcon();
108 
109 protected:
110  virtual void init(IVisualizationSite* site);
111  virtual QGraphicsItem* setupScene(QGraphicsScene* mgr);
112 
113 protected:
115  virtual void onNewPolygon(const Polygon2f& polygon) {};
116 
117 protected:
118  void updatePenAndBrush();
119 
120  QGraphicsItemGroup* mItem;
121  QGraphicsPolygonItem* mPolygonItem;
122  QVector<PathPointItem*> mPointItems;
123 
124  QPen mPen;
125  QBrush mBrush;
126 
127  QVector<QPointF> mPathPoints;
128 };
129 
131 
132 }
133 
134 #endif
virtual ~PathPointItem()
virtual QRectF boundingRect() const
Definition: PolygonTool2D.h:75
QPen mPen
Definition: PolygonTool2D.h:124
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
QGraphicsPolygonItem * mPolygonItem
Definition: PolygonTool2D.h:121
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
The primary interface between a Visualization and the container of the visualization (e...
Definition: Visualization.h:65
QVector< QPointF > mPathPoints
Definition: PolygonTool2D.h:127
QBrush mBrush
Definition: PolygonTool2D.h:125
#define MIRA_META_OBJECT(classIdentifier, MetaInfo)
Use this MACRO instead of MIRA_OBJECT if you like to add meta information to your class...
Definition: FactoryMacros.h:204
QGraphicsItemGroup * mItem
Definition: PolygonTool2D.h:120
Declaration of VisualizationTool2D.
QVector< PathPointItem * > mPointItems
Definition: PolygonTool2D.h:122
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:137
#define MIRA_GUI_VISUALIZATION_EXPORT
Definition: GuiVisualizationExports.h:61
virtual void onNewPolygon(const Polygon2f &polygon)
overwrite this method to be notified whenever the user clicks right mouse button
Definition: PolygonTool2D.h:115
Simple Wrapper for Boost::geometry polygon.
PathPointItem(qreal radius=2.0, QGraphicsItem *parent=NULL)
const qreal RADIUS
Definition: PolygonTool2D.h:70
Definition: VisualizationTool2D.h:59
boost::geometry::model::ring< Point2f > Polygon2f
A 2D polygon with 32 bit floating precision.
Definition: Polygon.h:131
Definition: PolygonTool2D.h:59