snark
view.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 
20 
21 #ifndef SNARK_GRAPHICS_GL_VIEW_H_
22 #define SNARK_GRAPHICS_GL_VIEW_H_
23 
24 #include <boost/optional.hpp>
25 #include <boost/thread.hpp>
26 #include <Eigen/Core>
27 #include <Qt3D/qglview.h>
28 #include <QMouseEvent>
29 #include "./coordinates.h"
30 
31 namespace snark { namespace graphics { namespace qt3d {
32 
34 class view : public QGLView
35 {
36  Q_OBJECT
37 public:
38  view( const QColor4ub& background_color, double fov,bool z_up, bool orthographic = false );
39  virtual ~view() {}
40 
41 private slots:
42  void hide_coordinates() { m_show_coordinates = false; update(); }
43 
44 protected:
45  void updateZFar();
46  void updateView( const QVector3D& min, const QVector3D& max );
47  void lookAtCenter();
48  void draw_coordinates( QGLPainter* painter );
49  void mousePressEvent( QMouseEvent *e );
50  void mouseReleaseEvent( QMouseEvent *e );
51  void mouseMoveEvent( QMouseEvent *e );
52  void wheelEvent( QWheelEvent *e );
53  QVector3D unproject( float x, float y, float depth );
54  boost::optional< QVector3D > getPoint( const QPoint& point2d );
55  void mouseDoubleClickEvent( QMouseEvent *e );
56 
57  const QColor4ub m_background_color;
58  QVector3D m_sceneCenter;
59  bool m_z_up;
60  boost::optional< Eigen::Vector3d > m_offset;
61 
62 private:
63  boost::optional< QPoint > m_startPan;
64  boost::optional< QPoint > m_startRotate;
65  double m_sceneRadius;
66  QVector3D m_revolve;
67  boost::optional< coordinates > m_coordinates;
68  bool m_show_coordinates;
69 };
70 
71 } } } // namespace snark { namespace graphics { namespace gt3d {
72 
73 #endif /*SNARK_GRAPHICS_GL_VIEW_H_*/