47 return a->DrawOrder() < b->DrawOrder();
51 QGLWidget(QGLFormat(QGL::SampleBuffers), parent),
52 has_pixel_buffers_(false),
53 pixel_buffer_size_(0),
54 pixel_buffer_index_(0),
55 capture_frames_(false),
57 fix_orientation_(false),
59 enable_antialiasing_(true),
60 mouse_button_(Qt::NoButton),
61 mouse_pressed_(false),
65 mouse_hovering_(false),
85 setMouseTracking(
true);
92 setFocusPolicy(Qt::StrongFocus);
112 int32_t buffer_size = width() * height() * 4;
123 glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, buffer_size, 0, GL_STREAM_READ_ARB);
125 glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, buffer_size, 0, GL_STREAM_READ_ARB);
126 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
135 GLenum err = glewInit();
138 ROS_ERROR(
"Error: %s\n", glewGetErrorString(err));
143 std::string extensions = (
const char*)glGetString(GL_EXTENSIONS);
144 has_pixel_buffers_ = extensions.find(
"GL_ARB_pixel_buffer_object") != std::string::npos;
147 glClearColor(0.58
f, 0.56
f, 0.5
f, 1);
150 glEnable(GL_MULTISAMPLE);
151 glEnable(GL_POINT_SMOOTH);
152 glEnable(GL_LINE_SMOOTH);
153 glEnable(GL_POLYGON_SMOOTH);
154 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
155 glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
156 glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
160 glDisable(GL_MULTISAMPLE);
161 glDisable(GL_POINT_SMOOTH);
162 glDisable(GL_LINE_SMOOTH);
163 glDisable(GL_POLYGON_SMOOTH);
173 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
174 glDepthFunc(GL_NEVER);
175 glDisable(GL_DEPTH_TEST);
186 glPixelStorei(GL_PACK_ALIGNMENT, 4);
196 glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, 0);
198 GLubyte*
data =
reinterpret_cast<GLubyte*
>(glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB));
205 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
207 glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
211 int32_t buffer_size = width() * height() * 4;
215 glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, &
capture_buffer_[0]);
227 p.setRenderHints(QPainter::Antialiasing |
228 QPainter::TextAntialiasing |
229 QPainter::SmoothPixmapTransform |
230 QPainter::HighQualityAntialiasing,
232 p.beginNativePainting();
236 glMatrixMode(GL_MODELVIEW);
241 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
259 std::list<MapvizPluginPtr>::iterator it;
269 if ((*it)->SupportsPainting())
271 p.endNativePainting();
273 p.beginNativePainting();
280 glMatrixMode(GL_MODELVIEW);
282 p.endNativePainting();
287 glMatrixMode(GL_TEXTURE);
289 glMatrixMode(GL_PROJECTION);
291 glMatrixMode(GL_MODELVIEW);
293 glPushAttrib(GL_ALL_ATTRIB_BITS);
299 glMatrixMode(GL_MODELVIEW);
301 glMatrixMode(GL_PROJECTION);
303 glMatrixMode(GL_TEXTURE);
309 float numDegrees = e->delta() / -8;
311 Zoom(numDegrees / 10.0);
333 std::list<MapvizPluginPtr>::iterator it;
342 bool invertible =
true;
343 return qtransform_.inverted(&invertible).map(point);
369 case Qt::MiddleButton:
376 case Qt::RightButton:
380 Zoom(((
float)diff) / 10.0
f);
392 double x = center_x + (e->x() - width() / 2.0) *
view_scale_;
393 double y = center_y + (height() / 2.0 - e->y()) *
view_scale_;
408 Q_EMIT
Hover(0, 0, 0);
414 std::list<MapvizPluginPtr>::iterator it;
417 (*it)->SetTargetFrame(frame);
445 format.setSwapInterval(1);
448 this->setFormat(format);
453 std::list<MapvizPluginPtr>::iterator it;
456 (*it)->SetUseLatestTransforms(on);
493 bool success =
false;
511 double roll, pitch, yaw;
514 glRotatef(-yaw * 57.2957795, 0, 0, 1);
527 qtransform_ = qtransform_.scale(1, -1);
528 painter->setWorldTransform(qtransform_,
false);
575 glViewport(0, 0, width(), height());
576 glMatrixMode(GL_PROJECTION);
580 qtransform_ = QTransform::fromTranslate(width() / 2.0, height() / 2.0).
608 ROS_ERROR(
"Invalid frame rate: %f", fps);
static const long double _half_pi
void mouseMoveEvent(QMouseEvent *e)
QPointF MapGlCoordToFixedFrame(const QPointF &point)
void RemovePlugin(MapvizPluginPtr plugin)
void setFrameRate(const double fps)
void TransformTarget(QPainter *painter)
void CaptureFrame(bool force=false)
void resizeGL(int w, int h)
std::vector< uint8_t > capture_buffer_
boost::shared_ptr< tf::TransformListener > tf_
void keyPressEvent(QKeyEvent *e)
void leaveEvent(QEvent *e)
void InitializeTf(boost::shared_ptr< tf::TransformListener > tf)
Qt::MouseButton mouse_button_
tf::StampedTransform transform_
void ToggleEnableAntialiasing(bool on)
TFSIMD_FORCE_INLINE const tfScalar & getY() const
void SetFixedFrame(const std::string &frame)
TFSIMD_FORCE_INLINE const tfScalar & y() const
int32_t pixel_buffer_index_
bool compare_plugins(MapvizPluginPtr a, MapvizPluginPtr b)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
bool canvas_able_to_move_
int32_t pixel_buffer_size_
bool enable_antialiasing_
void wheelEvent(QWheelEvent *e)
void mouseReleaseEvent(QMouseEvent *e)
#define ROS_ERROR_THROTTLE(rate,...)
GLuint pixel_buffer_ids_[2]
static Quaternion createQuaternionFromYaw(double yaw)
QPointF FixedFrameToMapGlCoord(const QPointF &point)
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
void InitializePixelBuffers()
TFSIMD_FORCE_INLINE const tfScalar & x() const
void ToggleRotate90(bool on)
void Hover(double x, double y, double scale)
std::string target_frame_
void ToggleUseLatestTransforms(bool on)
void SetTargetFrame(const std::string &frame)
std::list< MapvizPluginPtr > plugins_
TFSIMD_FORCE_INLINE const tfScalar & getX() const
void ToggleFixOrientation(bool on)
void paintEvent(QPaintEvent *event)
void SetViewScale(float scale)
void mousePressEvent(QMouseEvent *e)
void AddPlugin(MapvizPluginPtr plugin, int order)
MapCanvas(QWidget *parent=0)