snark
label_points/Viewer.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_VIEWER_H_
20 #define SNARK_GRAPHICS_APPLICATIONS_LABELPOINTS_VIEWER_H_
21 
22 #ifdef WIN32
23 #include <WinSock2.h>
24 #define BOOST_FILESYSTEM_VERSION 3
25 #endif
26 
27 #include <cmath>
28 #include <iostream>
29 #include <sstream>
30 #include <limits>
31 #include <math.h>
32 #include <boost/filesystem/operations.hpp>
33 #include <boost/lexical_cast.hpp>
34 #include <boost/scoped_ptr.hpp>
35 #include <boost/optional.hpp>
36 #include <comma/string/string.h>
37 
38 #include <snark/graphics/qt3d/view.h>
39 
40 #include "./Dataset.h"
41 #include "./PointWithId.h"
42 #include "./Tools.h"
43 
44 namespace snark { namespace graphics { namespace View {
45 
46 static const long double pi_ = 3.14159265358979323846l;
47 
48 class Viewer : public qt3d::view
49 {
50  Q_OBJECT
51 
52  public:
53  Tools::Navigate navigate;
54  Tools::PickId pickId;
55  Tools::SelectPartition selectPartition;
56  Tools::SelectId selectId;
57  Tools::SelectClip selectClip;
58  Tools::Fill fill;
59 
60  Viewer( const std::vector< comma::csv::options >& options
61  , bool labelDuplicated
62  , const QColor4ub& background_color
63  , bool orthographic = false, double fieldOfView = pi_ / 4 );
64 
65  void show( std::size_t i, bool visible ); // quick and dirty
66  void setWritable( std::size_t i, bool writable ); // quick and dirty
67  void save();
68  void reload();
69  const std::vector< boost::shared_ptr< Dataset > >& datasets() const;
70  Dataset& dataset( std::size_t index ); // quick and dirty
71  const Dataset& dataset( std::size_t index ) const; // quick and dirty
72 
73  public slots:
74  void handleId( comma::uint32 id );
75 
76  signals:
77  void initialized();
78 
79  protected:
80  void saveStateToFile();
81  void initializeGL( QGLPainter *painter );
82  void paintGL( QGLPainter *painter );
83  void mousePressEvent( QMouseEvent* e );
84  void mouseReleaseEvent( QMouseEvent* e );
85  void mouseMoveEvent( QMouseEvent* e );
86  boost::optional< std::pair< Eigen::Vector3d, comma::uint32 > > pointSelection( const QPoint& point, bool writableOnly = false );
87 
88  private:
89  friend class Tools::Tool; // quick and dirty
90  friend class Tools::PickId; // quick and dirty
91  friend struct Tools::SelectPartition; // quick and dirty
92  friend struct Tools::SelectId; // quick and dirty
93  friend class Tools::SelectClip; // quick and dirty
94  friend struct Tools::Fill; // quick and dirty
95  void setCamera();
96 
97  Tools::Tool* m_currentTool;
98  std::vector< boost::shared_ptr< Dataset > > m_datasets;
99  boost::optional< comma::uint32 > m_id;
100  const QColor4ub m_background_color;
101  std::vector< comma::csv::options > m_options;
102  bool m_labelDuplicated;
103  bool m_orthographic;
104  double m_fieldOfView;
105  boost::optional< QPoint > m_startPan;
106  boost::optional< QPoint > m_startRotate;
107  double m_sceneRadius;
108 };
109 
110 } } } // namespace snark { namespace graphics { namespace View {
111 
112 #endif // SNARK_GRAPHICS_APPLICATIONS_LABELPOINTS_VIEWER_H_