map_canvas.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
30 #ifndef MAPVIZ_MAP_CANVAS_H_
31 #define MAPVIZ_MAP_CANVAS_H_
32 
33 // C++ standard libraries
34 #include <cstring>
35 #include <list>
36 #include <string>
37 #include <vector>
38 
39 #include <boost/shared_ptr.hpp>
40 
41 // QT libraries
42 #include <QGLWidget>
43 #include <QMouseEvent>
44 #include <QWheelEvent>
45 #include <QColor>
46 #include <QTimer>
47 
48 // ROS libraries
49 #include <ros/ros.h>
50 #include <tf/transform_datatypes.h>
51 #include <tf/transform_listener.h>
52 
53 #include <mapviz/mapviz_plugin.h>
54 
55 namespace mapviz
56 {
57  class MapCanvas : public QGLWidget
58  {
59  Q_OBJECT
60 
61  public:
62  explicit MapCanvas(QWidget *parent = 0);
63  ~MapCanvas();
64 
66 
67  void AddPlugin(MapvizPluginPtr plugin, int order);
68  void RemovePlugin(MapvizPluginPtr plugin);
69  void SetFixedFrame(const std::string& frame);
70  void SetTargetFrame(const std::string& frame);
71  void ToggleFixOrientation(bool on);
72  void ToggleRotate90(bool on);
73  void ToggleEnableAntialiasing(bool on);
74  void UpdateView();
75  void ReorderDisplays();
76  void ResetLocation();
77  QPointF MapGlCoordToFixedFrame(const QPointF& point);
78  QPointF FixedFrameToMapGlCoord(const QPointF& point);
79 
80  double frameRate() const;
81 
82  float ViewScale() const { return view_scale_; }
83  float OffsetX() const { return offset_x_; }
84  float OffsetY() const { return offset_y_; }
85 
86 
87  void setCanvasAbleToMove(bool assigning)
88  {
89  canvas_able_to_move_ = assigning;
90  }
91 
92  void leaveEvent(QEvent* e);
93 
94  void SetViewScale(float scale)
95  {
96  view_scale_ = scale;
97  UpdateView();
98  }
99 
100  void SetOffsetX(float x)
101  {
102  offset_x_ = x;
103  UpdateView();
104  }
105 
106  void SetOffsetY(float y)
107  {
108  offset_y_ = y;
109  UpdateView();
110  }
111 
112  void SetBackground(const QColor& color)
113  {
114  bg_color_ = color;
115  update();
116  }
117 
118  void CaptureFrames(bool enabled)
119  {
120  capture_frames_ = enabled;
121  update();
122  }
123 
131  bool CopyCaptureBuffer(uchar* buffer)
132  {
133  if (!capture_buffer_.empty())
134  {
135  memcpy(&buffer[0], &capture_buffer_[0], capture_buffer_.size());
136  return true;
137  }
138 
139  return false;
140  }
141 
148  bool CopyCaptureBuffer(std::vector<uint8_t>& buffer)
149  {
150  buffer.clear();
151  if (!capture_buffer_.empty())
152  {
153  buffer.resize(capture_buffer_.size());
154  memcpy(&buffer[0], &capture_buffer_[0], buffer.size());
155 
156  return true;
157  }
158 
159  return false;
160  }
161 
162  void CaptureFrame(bool force = false);
163 
164  Q_SIGNALS:
165  void Hover(double x, double y, double scale);
166 
167  public Q_SLOTS:
168  void setFrameRate(const double fps);
169 
170  protected:
171  void initializeGL();
172  void initGlBlending();
173  void pushGlMatrices();
174  void popGlMatrices();
175  void resizeGL(int w, int h);
176  void paintEvent(QPaintEvent* event);
177  void wheelEvent(QWheelEvent* e);
178  void mousePressEvent(QMouseEvent* e);
179  void mouseReleaseEvent(QMouseEvent* e);
180  void mouseMoveEvent(QMouseEvent* e);
181  void keyPressEvent(QKeyEvent* e);
182 
183  void Recenter();
184  void TransformTarget(QPainter* painter);
185  void Zoom(float factor);
186 
187  void InitializePixelBuffers();
188 
189  bool canvas_able_to_move_ = true;
192  GLuint pixel_buffer_ids_[2];
195 
200 
202 
203  QColor bg_color_;
204 
205  Qt::MouseButton mouse_button_;
207  int mouse_x_;
208  int mouse_y_;
209  // Used when right-click dragging to zoom
211 
215 
216  // Offset based on previous mouse drags
217  double offset_x_;
218  double offset_y_;
219 
220  // Offset based on current mouse drag
221  double drag_x_;
222  double drag_y_;
223 
224  // The center of the view
227 
228  // View scale in meters per pixel
229  float view_scale_;
230 
231  // The bounds of the view
232  float view_left_;
233  float view_right_;
234  float view_top_;
236 
237  // The bounds of the scene
238  float scene_left_;
240  float scene_top_;
242 
243  std::string fixed_frame_;
244  std::string target_frame_;
245 
248  QTransform qtransform_;
249  std::list<MapvizPluginPtr> plugins_;
250 
251  std::vector<uint8_t> capture_buffer_;
252  };
253 }
254 
255 #endif // MAPVIZ_MAP_CANVAS_H_
mapviz::MapCanvas::scene_bottom_
float scene_bottom_
Definition: map_canvas.h:241
mapviz::MapCanvas::UpdateView
void UpdateView()
Definition: map_canvas.cpp:560
mapviz::MapCanvas::CopyCaptureBuffer
bool CopyCaptureBuffer(uchar *buffer)
Definition: map_canvas.h:131
mapviz::MapCanvas::InitializePixelBuffers
void InitializePixelBuffers()
Definition: map_canvas.cpp:108
mapviz::MapCanvas::tf_
boost::shared_ptr< tf::TransformListener > tf_
Definition: map_canvas.h:246
mapviz::MapCanvas::target_frame_
std::string target_frame_
Definition: map_canvas.h:244
mapviz::MapCanvas::drag_x_
double drag_x_
Definition: map_canvas.h:221
mapviz::MapCanvas::FixedFrameToMapGlCoord
QPointF FixedFrameToMapGlCoord(const QPointF &point)
Definition: map_canvas.cpp:346
mapviz::MapCanvas::resizeGL
void resizeGL(int w, int h)
Definition: map_canvas.cpp:178
mapviz::MapCanvas::offset_y_
double offset_y_
Definition: map_canvas.h:218
mapviz::MapCanvas::enable_antialiasing_
bool enable_antialiasing_
Definition: map_canvas.h:199
mapviz::MapCanvas::ToggleRotate90
void ToggleRotate90(bool on)
Definition: map_canvas.cpp:436
mapviz
Definition: color_button.h:36
mapviz::MapCanvas::scene_left_
float scene_left_
Definition: map_canvas.h:238
mapviz::MapCanvas::Recenter
void Recenter()
Definition: map_canvas.cpp:587
mapviz::MapCanvas::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *e)
Definition: map_canvas.cpp:351
mapviz::MapCanvas::view_top_
float view_top_
Definition: map_canvas.h:234
mapviz::MapCanvas::view_scale_
float view_scale_
Definition: map_canvas.h:229
mapviz::MapCanvas::SetBackground
void SetBackground(const QColor &color)
Definition: map_canvas.h:112
mapviz::MapCanvas::MapGlCoordToFixedFrame
QPointF MapGlCoordToFixedFrame(const QPointF &point)
Definition: map_canvas.cpp:340
mapviz::MapCanvas::transform_
tf::StampedTransform transform_
Definition: map_canvas.h:247
boost::shared_ptr< tf::TransformListener >
mapviz::MapCanvas::mousePressEvent
void mousePressEvent(QMouseEvent *e)
Definition: map_canvas.cpp:320
mapviz::MapCanvas::fix_orientation_
bool fix_orientation_
Definition: map_canvas.h:197
mapviz::MapCanvas::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e)
Definition: map_canvas.cpp:361
mapviz::MapCanvas::CaptureFrame
void CaptureFrame(bool force=false)
Definition: map_canvas.cpp:183
mapviz::MapCanvas::OffsetY
float OffsetY() const
Definition: map_canvas.h:84
ros.h
mapviz::MapCanvas::initGlBlending
void initGlBlending()
Definition: map_canvas.cpp:170
mapviz::MapCanvas::RemovePlugin
void RemovePlugin(MapvizPluginPtr plugin)
Definition: map_canvas.cpp:456
mapviz::MapCanvas::initializeGL
void initializeGL()
Definition: map_canvas.cpp:133
mapviz::MapCanvas::mouse_hover_x_
int mouse_hover_x_
Definition: map_canvas.h:213
mapviz::MapCanvas::setCanvasAbleToMove
void setCanvasAbleToMove(bool assigning)
Definition: map_canvas.h:87
mapviz::MapCanvas::mouse_x_
int mouse_x_
Definition: map_canvas.h:207
mapviz::MapCanvas::mouse_pressed_
bool mouse_pressed_
Definition: map_canvas.h:206
mapviz::MapCanvas::InitializeTf
void InitializeTf(boost::shared_ptr< tf::TransformListener > tf)
Definition: map_canvas.cpp:103
tf::StampedTransform
mapviz::MapCanvas::pushGlMatrices
void pushGlMatrices()
Definition: map_canvas.cpp:285
mapviz::MapCanvas::~MapCanvas
~MapCanvas()
Definition: map_canvas.cpp:95
mapviz::MapCanvas::offset_x_
double offset_x_
Definition: map_canvas.h:217
mapviz::MapCanvas::OffsetX
float OffsetX() const
Definition: map_canvas.h:83
mapviz::MapCanvas::qtransform_
QTransform qtransform_
Definition: map_canvas.h:248
mapviz::MapCanvas::Zoom
void Zoom(float factor)
Definition: map_canvas.cpp:314
mapviz::MapCanvas::mouse_hover_y_
int mouse_hover_y_
Definition: map_canvas.h:214
mapviz::MapCanvas::SetOffsetX
void SetOffsetX(float x)
Definition: map_canvas.h:100
mapviz::MapCanvas::mouse_button_
Qt::MouseButton mouse_button_
Definition: map_canvas.h:205
mapviz::MapCanvas::mouse_previous_y_
int mouse_previous_y_
Definition: map_canvas.h:210
mapviz::MapCanvas::mouse_hovering_
bool mouse_hovering_
Definition: map_canvas.h:212
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
mapviz::MapCanvas::setFrameRate
void setFrameRate(const double fps)
Definition: map_canvas.cpp:596
mapviz::MapCanvas::view_center_x_
float view_center_x_
Definition: map_canvas.h:225
mapviz::MapCanvas::plugins_
std::list< MapvizPluginPtr > plugins_
Definition: map_canvas.h:249
mapviz::MapCanvas::SetFixedFrame
void SetFixedFrame(const std::string &frame)
Definition: map_canvas.cpp:411
mapviz::MapCanvas::pixel_buffer_size_
int32_t pixel_buffer_size_
Definition: map_canvas.h:191
mapviz::MapCanvas::ReorderDisplays
void ReorderDisplays()
Definition: map_canvas.cpp:582
mapviz::MapCanvas::popGlMatrices
void popGlMatrices()
Definition: map_canvas.cpp:296
mapviz::MapCanvas::wheelEvent
void wheelEvent(QWheelEvent *e)
Definition: map_canvas.cpp:307
mapviz::MapCanvas::rotate_90_
bool rotate_90_
Definition: map_canvas.h:198
buffer
string buffer
mapviz::MapCanvas::TransformTarget
void TransformTarget(QPainter *painter)
Definition: map_canvas.cpp:464
mapviz::MapCanvas::view_right_
float view_right_
Definition: map_canvas.h:233
mapviz::MapCanvas::scene_top_
float scene_top_
Definition: map_canvas.h:240
mapviz::MapCanvas::ResetLocation
void ResetLocation()
Definition: map_canvas.cpp:576
mapviz::MapCanvas::bg_color_
QColor bg_color_
Definition: map_canvas.h:203
mapviz::MapCanvas::pixel_buffer_index_
int32_t pixel_buffer_index_
Definition: map_canvas.h:193
mapviz::MapCanvas::view_left_
float view_left_
Definition: map_canvas.h:232
transform_listener.h
mapviz::MapCanvas::SetOffsetY
void SetOffsetY(float y)
Definition: map_canvas.h:106
mapviz::MapCanvas
Definition: map_canvas.h:57
mapviz::MapCanvas::leaveEvent
void leaveEvent(QEvent *e)
Definition: map_canvas.cpp:405
transform_datatypes.h
mapviz::MapCanvas::ToggleFixOrientation
void ToggleFixOrientation(bool on)
Definition: map_canvas.cpp:431
mapviz::MapCanvas::SetViewScale
void SetViewScale(float scale)
Definition: map_canvas.h:94
mapviz::MapCanvas::fixed_frame_
std::string fixed_frame_
Definition: map_canvas.h:243
mapviz::MapCanvas::capture_frames_
bool capture_frames_
Definition: map_canvas.h:194
mapviz_plugin.h
mapviz::MapCanvas::ViewScale
float ViewScale() const
Definition: map_canvas.h:82
mapviz::MapCanvas::paintEvent
void paintEvent(QPaintEvent *event)
Definition: map_canvas.cpp:219
mapviz::MapCanvas::CaptureFrames
void CaptureFrames(bool enabled)
Definition: map_canvas.h:118
mapviz::MapCanvas::scene_right_
float scene_right_
Definition: map_canvas.h:239
mapviz::MapCanvas::has_pixel_buffers_
bool has_pixel_buffers_
Definition: map_canvas.h:190
mapviz::MapCanvas::view_bottom_
float view_bottom_
Definition: map_canvas.h:235
mapviz::MapCanvas::mouse_y_
int mouse_y_
Definition: map_canvas.h:208
mapviz::MapCanvas::CopyCaptureBuffer
bool CopyCaptureBuffer(std::vector< uint8_t > &buffer)
Definition: map_canvas.h:148
tf
mapviz::MapCanvas::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Definition: map_canvas.cpp:331
mapviz::MapCanvas::view_center_y_
float view_center_y_
Definition: map_canvas.h:226
mapviz::MapCanvas::ToggleEnableAntialiasing
void ToggleEnableAntialiasing(bool on)
Definition: map_canvas.cpp:441
mapviz::MapCanvas::pixel_buffer_ids_
GLuint pixel_buffer_ids_[2]
Definition: map_canvas.h:192
mapviz::MapCanvas::initialized_
bool initialized_
Definition: map_canvas.h:196
mapviz::MapCanvas::SetTargetFrame
void SetTargetFrame(const std::string &frame)
Definition: map_canvas.cpp:421
mapviz::MapCanvas::frame_rate_timer_
QTimer frame_rate_timer_
Definition: map_canvas.h:201
mapviz::MapCanvas::canvas_able_to_move_
bool canvas_able_to_move_
Definition: map_canvas.h:189
mapviz::MapCanvas::Hover
void Hover(double x, double y, double scale)
mapviz::MapCanvas::AddPlugin
void AddPlugin(MapvizPluginPtr plugin, int order)
Definition: map_canvas.cpp:451
mapviz::MapCanvas::capture_buffer_
std::vector< uint8_t > capture_buffer_
Definition: map_canvas.h:251
mapviz::MapCanvas::frameRate
double frameRate() const
Definition: map_canvas.cpp:606
mapviz::MapCanvas::drag_y_
double drag_y_
Definition: map_canvas.h:222
mapviz::MapCanvas::MapCanvas
MapCanvas(QWidget *parent=0)
Definition: map_canvas.cpp:50


mapviz
Author(s): Marc Alban
autogenerated on Sun Sep 8 2024 02:27:09