src
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
{
51
RvizScenePublisher::RvizScenePublisher
():
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
59
RvizScenePublisher::~RvizScenePublisher
()
60
{
61
delete
topic_name_property_
;
62
}
63
64
void
RvizScenePublisher::onInitialize
()
65
{
66
updateTopicName
();
67
context_
->
queueRender
();
68
}
69
70
void
RvizScenePublisher::onEnable
()
71
{
72
context_
->
queueRender
();
73
}
74
75
void
RvizScenePublisher::updateTopicName
()
76
{
77
topic_name_
=
topic_name_property_
->
getStdString
();
78
publisher_
=
it_
.
advertise
(
topic_name_
, 1);
79
}
80
81
void
RvizScenePublisher::update
(
float
wall_dt,
float
ros_dt)
82
{
83
rviz::RenderPanel
* panel =
context_
->
getViewManager
()->
getRenderPanel
();
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_
++;
99
cv_bridge::CvImage
img_bridge =
cv_bridge::CvImage
(header,
sensor_msgs::image_encodings::RGB8
, image);
100
img_bridge.
toImageMsg
(img_msg);
101
publisher_
.
publish
(img_msg);
102
}
103
}
104
105
106
#include <
pluginlib/class_list_macros.h
>
107
PLUGINLIB_EXPORT_CLASS
(
jsk_rviz_plugins::RvizScenePublisher
,
rviz::Display
)
jsk_rviz_plugins::RvizScenePublisher::updateTopicName
void updateTopicName()
Definition:
rviz_scene_publisher.cpp:75
sensor_msgs::image_encodings::RGB8
const std::string RGB8
jsk_rviz_plugins::RvizScenePublisher::image_id_
int image_id_
Definition:
rviz_scene_publisher.h:70
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
rviz::Display::context_
DisplayContext * context_
rviz::RenderPanel
rviz::DisplayContext::getViewManager
virtual ViewManager * getViewManager() const=0
jsk_rviz_plugins
Definition:
__init__.py:1
image_transport::ImageTransport::advertise
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
rviz::StringProperty::getStdString
std::string getStdString()
rviz_scene_publisher.h
display.h
display_context.h
rviz::Display
jsk_rviz_plugins::RvizScenePublisher::publisher_
image_transport::Publisher publisher_
Definition:
rviz_scene_publisher.h:73
jsk_rviz_plugins::RvizScenePublisher::~RvizScenePublisher
virtual ~RvizScenePublisher()
Definition:
rviz_scene_publisher.cpp:59
cv_bridge::CvImage::toImageMsg
sensor_msgs::ImagePtr toImageMsg() const
jsk_rviz_plugins::RvizScenePublisher::update
virtual void update(float wall_dt, float ros_dt)
Definition:
rviz_scene_publisher.cpp:81
jsk_rviz_plugins::RvizScenePublisher::it_
image_transport::ImageTransport it_
Definition:
rviz_scene_publisher.h:72
class_list_macros.h
jsk_rviz_plugins::RvizScenePublisher::onInitialize
virtual void onInitialize()
Definition:
rviz_scene_publisher.cpp:64
cv_bridge::CvImage
rviz::ViewManager::getRenderPanel
RenderPanel * getRenderPanel() const
polygon_array_sample.header
header
Definition:
polygon_array_sample.py:58
jsk_rviz_plugins::RvizScenePublisher::topic_name_property_
rviz::StringProperty * topic_name_property_
Definition:
rviz_scene_publisher.h:68
image_transport::Publisher::publish
void publish(const sensor_msgs::Image &message) const
rviz::StringProperty
render_panel.h
rviz::DisplayContext::queueRender
virtual void queueRender()=0
jsk_rviz_plugins::RvizScenePublisher::onEnable
virtual void onEnable()
Definition:
rviz_scene_publisher.cpp:70
jsk_rviz_plugins::RvizScenePublisher::RvizScenePublisher
RvizScenePublisher()
Definition:
rviz_scene_publisher.cpp:51
ros::Time::now
static Time now()
view_manager.h
display_group.h
jsk_rviz_plugins::RvizScenePublisher
Definition:
rviz_scene_publisher.h:53
jsk_rviz_plugins::RvizScenePublisher::topic_name_
std::string topic_name_
Definition:
rviz_scene_publisher.h:69
jsk_rviz_plugins
Author(s): Kei Okada
, Yohei Kakiuchi
, Shohei Fujii
, Ryohei Ueda
autogenerated on Thu Jun 1 2023 02:45:58