rviz_scene_publisher.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2020, Iori Yanokura
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #include "rviz_scene_publisher.h"
37 #include <rviz/display_context.h>
38 #include <rviz/view_manager.h>
39 #include <rviz/display_group.h>
40 #include <rviz/display.h>
41 #include <rviz/render_panel.h>
42 #include <QImage>
43 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
44 #include <QScreen>
45 #include <QGuiApplication>
46 #endif
47 #include <boost/filesystem.hpp>
48 
49 namespace jsk_rviz_plugins
50 {
52  Display(), it_(nh_), image_id_(0)
53  {
55  "topic_name", "/rviz/image",
56  "topic_name", this, SLOT(updateTopicName()));
57  }
58 
60  {
61  delete topic_name_property_;
62  }
63 
65  {
68  }
69 
71  {
73  }
74 
76  {
79  }
80 
81  void RvizScenePublisher::update(float wall_dt, float ros_dt)
82  {
84 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
85  QPixmap screenshot
86  = QGuiApplication::primaryScreen()->grabWindow(context_->getViewManager()->getRenderPanel()->winId());
87 #else
88  QPixmap screenshot
89  = QPixmap::grabWindow(context_->getViewManager()->getRenderPanel()->winId());
90 #endif
91  QImage src = screenshot.toImage().convertToFormat(QImage::Format_RGB888); // RGB
92  cv::Mat image(src.height(), src.width(), CV_8UC3,
93  (uchar*)src.bits(), src.bytesPerLine()); // RGB
94 
95  sensor_msgs::Image img_msg;
96  std_msgs::Header header;
97  header.stamp = ros::Time::now();
98  header.seq = image_id_++;
100  img_bridge.toImageMsg(img_msg);
101  publisher_.publish(img_msg);
102  }
103 }
104 
105 
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
DisplayContext * context_
virtual ViewManager * getViewManager() const =0
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
std::string getStdString()
image_transport::Publisher publisher_
virtual void update(float wall_dt, float ros_dt)
image_transport::ImageTransport it_
void publish(const sensor_msgs::Image &message) const
virtual void queueRender()=0
static Time now()
RenderPanel * getRenderPanel() const
sensor_msgs::ImagePtr toImageMsg() const


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18