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/or 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  {
54  topic_name_property_ = new rviz::StringProperty(
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 
rviz::DisplayContext::queueRender
virtual void queueRender()=0
display_group.h
cv_bridge::CvImage::toImageMsg
sensor_msgs::ImagePtr toImageMsg() const
jsk_rviz_plugins::RvizScenePublisher
Definition: rviz_scene_publisher.h:85
jsk_rviz_plugins::RvizScenePublisher::onEnable
virtual void onEnable()
Definition: rviz_scene_publisher.cpp:102
display.h
jsk_rviz_plugins::RvizScenePublisher::topic_name_
std::string topic_name_
Definition: rviz_scene_publisher.h:133
sensor_msgs::image_encodings::RGB8
const std::string RGB8
image_transport::ImageTransport::advertise
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
rviz::DisplayContext::getViewManager
virtual ViewManager * getViewManager() const=0
rviz::Display
jsk_rviz_plugins::RvizScenePublisher::updateTopicName
void updateTopicName()
Definition: rviz_scene_publisher.cpp:107
class_list_macros.h
jsk_rviz_plugins::RvizScenePublisher::RvizScenePublisher
RvizScenePublisher()
Definition: rviz_scene_publisher.cpp:83
rviz::ViewManager::getRenderPanel
RenderPanel * getRenderPanel() const
render_panel.h
rviz::StringProperty
rviz::StringProperty::getStdString
std::string getStdString()
jsk_rviz_plugins::RvizScenePublisher::image_id_
int image_id_
Definition: rviz_scene_publisher.h:134
polygon_array_sample.header
header
Definition: polygon_array_sample.py:58
image_transport::Publisher::publish
void publish(const sensor_msgs::Image &message) const
view_manager.h
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
rviz::Display::context_
DisplayContext * context_
rviz_scene_publisher.h
cv_bridge::CvImage
jsk_rviz_plugins::RvizScenePublisher::it_
image_transport::ImageTransport it_
Definition: rviz_scene_publisher.h:136
rviz::RenderPanel
jsk_rviz_plugins::RvizScenePublisher::onInitialize
virtual void onInitialize()
Definition: rviz_scene_publisher.cpp:96
jsk_rviz_plugins::RvizScenePublisher::publisher_
image_transport::Publisher publisher_
Definition: rviz_scene_publisher.h:137
jsk_rviz_plugins::RvizScenePublisher::~RvizScenePublisher
virtual ~RvizScenePublisher()
Definition: rviz_scene_publisher.cpp:91
jsk_rviz_plugins::RvizScenePublisher::update
virtual void update(float wall_dt, float ros_dt)
Definition: rviz_scene_publisher.cpp:113
jsk_rviz_plugins
Definition: __init__.py:1
ros::Time::now
static Time now()
jsk_rviz_plugins::RvizScenePublisher::topic_name_property_
rviz::StringProperty * topic_name_property_
Definition: rviz_scene_publisher.h:132
display_context.h


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Jun 1 2024 02:47:16