snark
Tools.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SNARK_GRAPHICS_APPLICATIONS_LABELPOINTS_TOOLS_H_
20 #define SNARK_GRAPHICS_APPLICATIONS_LABELPOINTS_TOOLS_H_
21 
22 #include <boost/optional.hpp>
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/date_time/posix_time/posix_time.hpp>
25 #include <qcursor.h>
26 #include <qevent.h>
27 #include <qobject.h>
28 #include <comma/base/types.h>
29 #include <snark/math/interval.h>
30 #include <Eigen/Core>
31 #include <Qt3D/qcolor4ub.h>
32 #include <Qt3D/qglpainter.h>
33 #include "./Icons.h"
34 
35 namespace snark { namespace graphics { namespace View { class Viewer; } } }
36 
37 namespace snark { namespace graphics { namespace View { namespace Tools {
38 
39 QColor4ub colorFromId( comma::uint32 id );
40 
41 class Tool : public QObject
42 {
43  public:
44  Tool( Viewer& viewer, QCursor* cursor );
45  virtual ~Tool() {}
46  void toggle( bool checked );
47  virtual void onMousePress( QMouseEvent* e );
48  virtual void onMouseRelease( QMouseEvent* e );
49  virtual void onMouseMove( QMouseEvent* e );
50  virtual void draw( QGLPainter* painter );
51 
52  protected:
53  Viewer& m_viewer;
54  boost::scoped_ptr< QCursor > m_cursor;
55  virtual void init() {}
56  virtual void reset() {}
57 };
58 
59 struct Navigate : public Tool
60 {
61  Navigate( Viewer& viewer );
62 };
63 
64 class PickId : public Tool
65 {
66  Q_OBJECT
67 
68  public:
69  PickId( Viewer& viewer );
70  void onMousePress( QMouseEvent* e );
71  void shakeColors();
72 
73  signals:
74  void valueChanged( comma::uint32 id );
75 };
76 
77 struct Fill : public Tool
78 {
79  Fill( Viewer& viewer );
80  void onMousePress( QMouseEvent* e );
81 };
82 
83 struct SelectPartition : public Tool
84 {
85  SelectPartition( Viewer& viewer );
86  void onMousePress( QMouseEvent* e );
87  void onMouseRelease( QMouseEvent* e );
88  void onMouseMove( QMouseEvent* e );
89 };
90 
91 struct SelectId : public Tool
92 {
93  SelectId( Viewer& viewer );
94  void onMousePress( QMouseEvent* e );
95  void onMouseRelease( QMouseEvent* e );
96  void onMouseMove( QMouseEvent* e );
97 };
98 
99 class SelectClip : public Tool
100 {
101  public:
102  SelectClip( Viewer& viewer );
103  void onMousePress( QMouseEvent* e );
104  void onMouseRelease( QMouseEvent* e );
105  void onMouseMove( QMouseEvent* e );
106  void draw( QGLPainter* painter );
107 
108  private:
109  boost::optional< QRect > m_rectangle;
110  Eigen::Vector3d m_center;
111  Eigen::Vector3d m_radius;
112 };
113 
114 } } } } // namespace snark { namespace graphics { namespace View { namespace Tools {
115 
116 #endif // SNARK_GRAPHICS_APPLICATIONS_LABELPOINTS_TOOLS_H_