src
target_visualizer_display.cpp
Go to the documentation of this file.
1
// -*- mode: c++; -*-
2
/*********************************************************************
3
* Software License Agreement (BSD License)
4
*
5
* Copyright (c) 2014, JSK Lab
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
#include <
rviz/view_manager.h
>
36
#include <
rviz/render_panel.h
>
37
#include <
rviz/uniform_string_stream.h
>
38
#include <OGRE/OgreCamera.h>
39
#include <OGRE/OgreMaterialManager.h>
40
#include "
target_visualizer_display.h
"
41
#include <OGRE/OgreManualObject.h>
42
43
namespace
jsk_rviz_plugins
44
{
45
const
float
arrow_animation_duration
= 1.0;
46
const
double
minimum_font_size
= 0.2;
47
48
TargetVisualizerDisplay::TargetVisualizerDisplay
():
49
message_recieved_(false)
50
{
51
target_name_property_ =
new
rviz::StringProperty
(
52
"target name"
,
"target"
,
53
"name of the target"
,
54
this
, SLOT(updateTargetName())
55
);
56
radius_property_ =
new
rviz::FloatProperty
(
57
"radius"
, 1.0,
58
"radius of the target mark"
,
59
this
, SLOT(updateRadius()));
60
radius_property_->setMin(0.0);
61
alpha_property_ =
new
rviz::FloatProperty
(
62
"alpha"
, 0.8,
63
"0 is fully transparent, 1.0 is fully opaque."
,
64
this
, SLOT(updateAlpha()));
65
alpha_property_->setMin(0.0);
66
alpha_property_->setMax(1.0);
67
color_property_ =
new
rviz::ColorProperty
(
68
"color"
, QColor(25, 255, 240),
69
"color of the target"
,
70
this
, SLOT(updateColor()));
71
shape_type_property_ =
new
rviz::EnumProperty
(
72
"type"
,
"Simple Circle"
,
73
"Shape to display the pose as"
,
74
this
, SLOT(updateShapeType()));
75
shape_type_property_->addOption(
"Simple Circle"
, SimpleCircle);
76
shape_type_property_->addOption(
"Decoreted Circle"
, GISCircle);
77
}
78
79
TargetVisualizerDisplay::~TargetVisualizerDisplay
()
80
{
81
delete
target_name_property_
;
82
delete
alpha_property_
;
83
delete
color_property_
;
84
delete
radius_property_
;
85
}
86
87
void
TargetVisualizerDisplay::onEnable
()
88
{
89
subscribe
();
90
visualizer_
->setEnable(
false
);
// keep false, it will be true
91
// in side of processMessae callback.
92
}
93
94
void
TargetVisualizerDisplay::processMessage
(
95
const
geometry_msgs::PoseStamped::ConstPtr& msg)
96
{
97
boost::mutex::scoped_lock
lock
(
mutex_
);
98
message_recieved_
=
true
;
99
visualizer_
->setEnable(
isEnabled
());
100
if
(!
isEnabled
()) {
101
return
;
102
}
103
Ogre::Quaternion orientation;
104
Ogre::Vector3 position;
105
if
(!
context_
->
getFrameManager
()->
transform
(
msg
->header,
106
msg
->pose,
107
position, orientation))
108
{
109
std::ostringstream oss;
110
oss <<
"Error transforming pose"
;
111
oss <<
" from frame '"
<<
msg
->header.frame_id <<
"'"
;
112
oss <<
" to frame '"
<< qPrintable(
fixed_frame_
) <<
"'"
;
113
ROS_ERROR_STREAM
(oss.str());
114
setStatus
(
rviz::StatusProperty::Error
,
"Transform"
, QString::fromStdString(oss.str()));
115
return
;
116
}
117
visualizer_
->setPosition(position);
118
}
119
120
121
void
TargetVisualizerDisplay::update
(
float
wall_dt,
float
ros_dt)
122
{
123
if
(!
message_recieved_
) {
124
return
;
125
}
126
visualizer_
->setOrientation(
context_
);
127
visualizer_
->update(wall_dt, ros_dt);
128
}
129
130
void
TargetVisualizerDisplay::onInitialize
()
131
{
132
visualizer_initialized_
=
false
;
133
MFDClass::onInitialize
();
134
scene_node_
=
scene_manager_
->getRootSceneNode()->createChildSceneNode();
135
136
updateRadius
();
137
updateShapeType
();
138
// updateTargetName();
139
// updateColor();
140
// updateAlpha();
141
}
142
143
void
TargetVisualizerDisplay::reset
()
144
{
145
MFDClass::reset
();
146
message_recieved_
=
false
;
147
if
(
visualizer_
) {
148
visualizer_
->setEnable(
false
);
149
}
150
}
151
152
void
TargetVisualizerDisplay::updateTargetName
()
153
{
154
boost::mutex::scoped_lock
lock
(
mutex_
);
155
target_name_
=
target_name_property_
->
getStdString
();
156
if
(
visualizer_
) {
157
visualizer_
->setText(
target_name_
);
158
}
159
}
160
161
void
TargetVisualizerDisplay::updateRadius
()
162
{
163
boost::mutex::scoped_lock
lock
(
mutex_
);
164
radius_
=
radius_property_
->
getFloat
();
165
if
(
visualizer_
) {
166
visualizer_
->setSize(
radius_
);
167
}
168
}
169
170
void
TargetVisualizerDisplay::updateAlpha
()
171
{
172
boost::mutex::scoped_lock
lock
(
mutex_
);
173
alpha_
=
alpha_property_
->
getFloat
();
174
if
(
visualizer_
) {
175
visualizer_
->setAlpha(
alpha_
);
176
}
177
}
178
179
void
TargetVisualizerDisplay::updateColor
()
180
{
181
boost::mutex::scoped_lock
lock
(
mutex_
);
182
color_
=
color_property_
->
getColor
();
183
if
(
visualizer_
) {
184
visualizer_
->setColor(
color_
);
185
}
186
}
187
188
void
TargetVisualizerDisplay::updateShapeType
()
189
{
190
if
(!
visualizer_initialized_
||
191
current_type_
!=
shape_type_property_
->
getOptionInt
()) {
192
{
193
boost::mutex::scoped_lock
lock
(
mutex_
);
194
if
(
shape_type_property_
->
getOptionInt
() ==
SimpleCircle
) {
195
current_type_
=
SimpleCircle
;
196
// simple circle
197
visualizer_
.reset(
new
SimpleCircleFacingVisualizer
(
198
scene_manager_
,
199
scene_node_
,
200
context_
,
201
radius_
));
202
}
203
else
{
204
current_type_
=
GISCircle
;
205
// GIS
206
GISCircleVisualizer
* v =
new
GISCircleVisualizer
(
207
scene_manager_
,
208
scene_node_
,
209
radius_
);
210
v->
setAnonymous
(
false
);
211
visualizer_
.reset(v);
212
}
213
visualizer_initialized_
=
true
;
214
}
215
updateTargetName
();
216
updateColor
();
217
updateAlpha
();
218
}
219
}
220
}
221
222
#include <
pluginlib/class_list_macros.h
>
223
PLUGINLIB_EXPORT_CLASS
(
jsk_rviz_plugins::TargetVisualizerDisplay
,
rviz::Display
)
224
rviz::EnumProperty::getOptionInt
virtual int getOptionInt()
rviz::Display::isEnabled
bool isEnabled() const
rviz::ColorProperty::getColor
virtual QColor getColor() const
rviz::MessageFilterDisplay< MessageType >::reset
void reset() override
msg
msg
jsk_rviz_plugins::TargetVisualizerDisplay::color_
QColor color_
Definition:
target_visualizer_display.h:157
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
jsk_rviz_plugins::TargetVisualizerDisplay::update
void update(float wall_dt, float ros_dt)
Definition:
target_visualizer_display.cpp:153
rviz::StatusProperty::Error
Error
jsk_rviz_plugins::TargetVisualizerDisplay::reset
virtual void reset()
Definition:
target_visualizer_display.cpp:175
target_visualizer_display.h
jsk_rviz_plugins::TargetVisualizerDisplay::alpha_property_
rviz::FloatProperty * alpha_property_
Definition:
target_visualizer_display.h:148
jsk_rviz_plugins::TargetVisualizerDisplay::message_recieved_
bool message_recieved_
Definition:
target_visualizer_display.h:159
rviz_mouse_point_to_tablet.lock
lock
Definition:
rviz_mouse_point_to_tablet.py:11
jsk_rviz_plugins::SimpleCircleFacingVisualizer
Definition:
facing_visualizer.h:181
jsk_rviz_plugins::TargetVisualizerDisplay::updateAlpha
void updateAlpha()
Definition:
target_visualizer_display.cpp:202
rviz::Display::fixed_frame_
QString fixed_frame_
rviz::MessageFilterDisplay< geometry_msgs::PoseStamped >::subscribe
virtual void subscribe()
jsk_rviz_plugins::TargetVisualizerDisplay::current_type_
ShapeType current_type_
Definition:
target_visualizer_display.h:160
jsk_rviz_plugins::TargetVisualizerDisplay::mutex_
boost::mutex mutex_
Definition:
target_visualizer_display.h:154
rviz::ColorProperty
rviz::Display
rviz::EnumProperty
rviz::FloatProperty
jsk_rviz_plugins::TargetVisualizerDisplay::visualizer_initialized_
bool visualizer_initialized_
Definition:
target_visualizer_display.h:161
class_list_macros.h
rviz::Display::setStatus
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
jsk_rviz_plugins::TargetVisualizerDisplay::updateTargetName
void updateTargetName()
Definition:
target_visualizer_display.cpp:184
rviz::FloatProperty::getFloat
virtual float getFloat() const
jsk_rviz_plugins::GISCircleVisualizer::setAnonymous
virtual void setAnonymous(bool anonymous)
Definition:
facing_visualizer.cpp:709
render_panel.h
jsk_rviz_plugins::TargetVisualizerDisplay::SimpleCircle
@ SimpleCircle
Definition:
target_visualizer_display.h:137
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
jsk_rviz_plugins::TargetVisualizerDisplay::onInitialize
virtual void onInitialize()
Definition:
target_visualizer_display.cpp:162
rviz::StringProperty
rviz::StringProperty::getStdString
std::string getStdString()
jsk_rviz_plugins::TargetVisualizerDisplay::GISCircle
@ GISCircle
Definition:
target_visualizer_display.h:138
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const=0
jsk_rviz_plugins::TargetVisualizerDisplay::radius_
double radius_
Definition:
target_visualizer_display.h:158
jsk_rviz_plugins::TargetVisualizerDisplay::updateShapeType
void updateShapeType()
Definition:
target_visualizer_display.cpp:220
jsk_rviz_plugins::TargetVisualizerDisplay::updateRadius
void updateRadius()
Definition:
target_visualizer_display.cpp:193
jsk_rviz_plugins::arrow_animation_duration
const float arrow_animation_duration
Definition:
facing_visualizer.cpp:79
view_manager.h
rviz::MessageFilterDisplay< MessageType >::onInitialize
void onInitialize() override
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
rviz::Display::context_
DisplayContext * context_
jsk_rviz_plugins::TargetVisualizerDisplay::visualizer_
FacingObject::Ptr visualizer_
Definition:
target_visualizer_display.h:152
jsk_rviz_plugins::TargetVisualizerDisplay::TargetVisualizerDisplay
TargetVisualizerDisplay()
Definition:
target_visualizer_display.cpp:80
jsk_rviz_plugins::TargetVisualizerDisplay::target_name_property_
rviz::StringProperty * target_name_property_
Definition:
target_visualizer_display.h:147
jsk_rviz_plugins::TargetVisualizerDisplay::processMessage
void processMessage(const geometry_msgs::PoseStamped::ConstPtr &msg)
Definition:
target_visualizer_display.cpp:126
rviz::FrameManager::transform
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
jsk_rviz_plugins::TargetVisualizerDisplay::~TargetVisualizerDisplay
virtual ~TargetVisualizerDisplay()
Definition:
target_visualizer_display.cpp:111
jsk_rviz_plugins::TargetVisualizerDisplay::onEnable
virtual void onEnable()
Definition:
target_visualizer_display.cpp:119
jsk_rviz_plugins::TargetVisualizerDisplay::alpha_
double alpha_
Definition:
target_visualizer_display.h:156
jsk_rviz_plugins::TargetVisualizerDisplay::shape_type_property_
rviz::EnumProperty * shape_type_property_
Definition:
target_visualizer_display.h:151
jsk_rviz_plugins::TargetVisualizerDisplay::color_property_
rviz::ColorProperty * color_property_
Definition:
target_visualizer_display.h:149
jsk_rviz_plugins::GISCircleVisualizer
Definition:
facing_visualizer.h:252
jsk_rviz_plugins::minimum_font_size
const double minimum_font_size
Definition:
facing_visualizer.cpp:78
jsk_rviz_plugins::TargetVisualizerDisplay::target_name_
std::string target_name_
Definition:
target_visualizer_display.h:155
jsk_rviz_plugins
Definition:
__init__.py:1
jsk_rviz_plugins::TargetVisualizerDisplay::radius_property_
rviz::FloatProperty * radius_property_
Definition:
target_visualizer_display.h:150
jsk_rviz_plugins::TargetVisualizerDisplay
Definition:
target_visualizer_display.h:96
uniform_string_stream.h
jsk_rviz_plugins::TargetVisualizerDisplay::updateColor
void updateColor()
Definition:
target_visualizer_display.cpp:211
jsk_rviz_plugins
Author(s): Kei Okada
, Yohei Kakiuchi
, Shohei Fujii
, Ryohei Ueda
autogenerated on Fri Dec 13 2024 03:49:57