snark
Reader.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_APPLICATIONS_VIEWPOINTS_READER_H_
22 #define SNARK_GRAPHICS_APPLICATIONS_VIEWPOINTS_READER_H_
23 
24 #include <deque>
25 #include <fstream>
26 #include <iostream>
27 #include <cmath>
28 #include <sstream>
29 #include <boost/scoped_ptr.hpp>
30 #include <boost/thread.hpp>
31 #include <comma/base/types.h>
32 #include <comma/csv/options.h>
33 #include <comma/csv/stream.h>
34 #include <comma/io/file_descriptor.h>
35 #include <comma/io/stream.h>
36 #include <comma/sync/synchronized.h>
37 #include <snark/math/interval.h>
38 #include "./Coloured.h"
39 #include "./PointWithId.h"
40 #include <snark/graphics/qt3d/vertex_buffer.h>
41 #include <Qt3D/qglview.h>
42 
43 class QGLAbstractScene;
44 
45 namespace snark { namespace graphics { namespace View {
46 
47 class Viewer;
48 
49 class Reader
50 {
51  public:
52  const std::size_t size;
53  const unsigned int pointSize;
54  const comma::csv::options options;
55 
56  Reader( QGLView& viewer, comma::csv::options& options, std::size_t size, coloured* c, unsigned int pointSize, const std::string& label, const QVector3D& offset = QVector3D( 0, 0, 0 ) );
57 
58  virtual ~Reader() {}
59 
60  virtual void start() = 0;
61  virtual void update( const Eigen::Vector3d& offset ) = 0;
62  virtual const Eigen::Vector3d& somePoint() const = 0;
63  virtual bool readOnce() = 0;
64  virtual void render( QGLPainter *painter ) = 0;
65  virtual bool empty() const = 0;
66 
67  void show( bool s );
68  bool show() const;
69  bool isShutdown() const;
70  bool isStdIn() const { return m_isStdIn; }
71  void shutdown();
72  void read();
73 
74  protected:
75  void updatePoint( const Eigen::Vector3d& offset );
76  void drawLabel( QGLPainter* painter, const QVector3D& position, const std::string& label );
77  void drawLabel( QGLPainter* painter, const QVector3D& position );
78 
79  friend class Viewer;
80  QGLView& m_viewer;
81  boost::optional< snark::math::closed_interval< float, 3 > > m_extents;
82  unsigned int m_num_points;
83  boost::scoped_ptr< coloured > m_colored;
84  bool m_shutdown;
85  bool m_isStdIn;
86  bool m_show;
87  comma::io::istream m_istream;
88  boost::scoped_ptr< boost::thread > m_thread;
89  mutable boost::mutex m_mutex;
90  boost::optional< Eigen::Vector3d > m_point;
91  boost::optional< Eigen::Vector3d > m_orientation;
92  QColor4ub m_color;
93  QVector3D m_translation;
94  QQuaternion m_quaternion;
95  std::string m_label;
96  QVector3D m_offset;
97 
98  private:
99  void drawText( QGLPainter *painter, const QString& string, const QColor4ub& color );
100 };
101 
102 } } } // namespace snark { namespace graphics { namespace View {
103 
104 #endif /*SNARK_GRAPHICS_APPLICATIONS_VIEWPOINTS_READER_H_*/