src
VoronoiSegmentDisplay.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012, Willow Garage, Inc.
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* * Neither the name of the Willow Garage, Inc. nor the names of its
14
* contributors may be used to endorse or promote products derived from
15
* this software without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
* POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30
#include <OGRE/OgreSceneNode.h>
31
#include <OGRE/OgreSceneManager.h>
32
33
#include <
tf/transform_listener.h
>
34
35
#include <
rviz/visualization_manager.h
>
36
#include <
rviz/properties/color_property.h
>
37
#include <
rviz/properties/float_property.h
>
38
#include <
rviz/properties/int_property.h
>
39
#include <
rviz/frame_manager.h
>
40
41
42
#include <
tuw_multi_robot_rviz/VoronoiSegmentDisplay.h
>
43
#include <
tuw_multi_robot_rviz/VoronoiSegmentVisual.h
>
44
45
namespace
tuw_multi_robot_rviz
46
{
47
48
49
// The constructor must have no arguments, so we can't give the
50
// constructor the parameters it needs to fully initialize.
51
VoronoiSegmentDisplay::VoronoiSegmentDisplay
() {
52
color_path_property_
=
new
rviz::ColorProperty
(
"Path Color"
, QColor ( 50, 51, 204 ),
53
"Color to draw the path."
,
54
this
, SLOT (
updatePathColor
() ) );
55
56
scale_path_property_
=
new
rviz::FloatProperty
(
"Path Scale"
, 1,
57
"Scale of the path points."
,
58
this
, SLOT (
updatePathScale
() ) );
59
scale_path_property_
->
setMin
( 0 );
60
scale_path_property_
->
setMax
( 1 );
61
62
63
history_length_property_
=
new
rviz::IntProperty
(
"History Length"
, 1,
64
"Number of prior measurements to display."
,
65
this
, SLOT (
updateHistoryLength
() ) );
66
history_length_property_
->
setMin
( 1 );
67
history_length_property_
->
setMax
( 100000 );
68
}
69
70
// After the top-level rviz::Display::initialize() does its own setup,
71
// it calls the subclass's onInitialize() function. This is where we
72
// instantiate all the workings of the class. We make sure to also
73
// call our immediate super-class's onInitialize() function, since it
74
// does important stuff setting up the message filter.
75
//
76
// Note that "MFDClass" is a typedef of
77
// ``MessageFilterDisplay<message type>``, to save typing that long
78
// templated class name every time you need to refer to the
79
// superclass.
80
void
VoronoiSegmentDisplay::onInitialize
() {
81
MFDClass::onInitialize
();
82
updateHistoryLength
();
83
}
84
85
VoronoiSegmentDisplay::~VoronoiSegmentDisplay
() {
86
}
87
88
// Clear the visuals by deleting their objects.
89
void
VoronoiSegmentDisplay::reset
() {
90
MFDClass::reset
();
91
visuals_
.clear();
92
}
93
94
// Set the current color values for each visual.
95
void
VoronoiSegmentDisplay::updatePathColor
() {
96
Ogre::ColourValue color =
color_path_property_
->
getOgreColor
();
97
for
(
auto
& visualsI:
visuals_
) { visualsI->setPathColor ( color ); }
98
}
99
100
// Set the number of past visuals to show.
101
void
VoronoiSegmentDisplay::updateHistoryLength
() {
102
visuals_
.rset_capacity (
history_length_property_
->
getInt
() );
103
}
104
105
void
VoronoiSegmentDisplay::updatePathScale
()
106
{
107
float
scale =
scale_path_property_
->
getFloat
();
108
for
(
auto
& visualsI:
visuals_
) { visualsI->setPathScale ( scale ); }
109
}
110
111
// This is our callback to handle an incoming message.
112
void
VoronoiSegmentDisplay::processMessage
(
const
tuw_multi_robot_msgs::Graph::ConstPtr& msg ) {
113
// Here we call the rviz::FrameManager to get the transform from the
114
// fixed frame to the frame in the header of this Imu message. If
115
// it fails, we can't do anything else so we return.
116
Ogre::Quaternion orientation;
117
Ogre::Vector3 position;
118
if
( !
context_
->
getFrameManager
()->
getTransform
( msg->header.frame_id,
119
msg->header.stamp,
120
position, orientation ) ) {
121
ROS_DEBUG
(
"Error transforming from frame '%s' to frame '%s'"
,
122
msg->header.frame_id.c_str(), qPrintable (
fixed_frame_
) );
123
return
;
124
}
125
126
// We are keeping a circular buffer of visual pointers. This gets
127
// the next one, or creates and stores it if the buffer is not full
128
boost::shared_ptr<VoronoiSegmentVisual>
visual;
129
if
(
visuals_
.full() ) {
130
visual =
visuals_
.front();
131
}
else
{
132
visual.reset (
new
VoronoiSegmentVisual
(
context_
->
getSceneManager
(),
scene_node_
) );
133
}
134
135
// Now set or update the contents of the chosen visual.
136
visual->setMessage ( msg );
137
visual->setFramePosition ( position );
138
visual->setFrameOrientation ( orientation );
139
140
visual->setPathColor (
color_path_property_
->
getOgreColor
() );
141
142
// And send it to the end of the circular buffer
143
visuals_
.push_back ( visual );
144
}
145
146
147
}
// end namespace rviz_plugin_tutorials
148
149
// Tell pluginlib about this class. It is important to do this in
150
// global scope, outside our package's namespace.
151
#include <
pluginlib/class_list_macros.h
>
152
PLUGINLIB_EXPORT_CLASS
(
tuw_multi_robot_rviz::VoronoiSegmentDisplay
,
rviz::Display
)
153
// END_TUTORIAL
tuw_multi_robot_rviz::VoronoiSegmentDisplay::updatePathColor
void updatePathColor()
Definition:
VoronoiSegmentDisplay.cpp:95
tuw_multi_robot_rviz::VoronoiSegmentDisplay::updatePathScale
void updatePathScale()
Definition:
VoronoiSegmentDisplay.cpp:105
rviz::IntProperty::setMin
void setMin(int min)
rviz::MessageFilterDisplay::reset
void reset() override
tuw_multi_robot_rviz::VoronoiSegmentDisplay::scale_path_property_
rviz::FloatProperty * scale_path_property_
Definition:
VoronoiSegmentDisplay.h:126
boost::shared_ptr
rviz::FloatProperty::setMax
void setMax(float max)
int_property.h
frame_manager.h
tuw_multi_robot_rviz
Definition:
MultiRobotGoalSelector.h:61
tuw_multi_robot_rviz::VoronoiSegmentDisplay::color_path_property_
rviz::ColorProperty * color_path_property_
Definition:
VoronoiSegmentDisplay.h:124
tuw_multi_robot_rviz::VoronoiSegmentDisplay::history_length_property_
rviz::IntProperty * history_length_property_
Definition:
VoronoiSegmentDisplay.h:127
tuw_multi_robot_rviz::VoronoiSegmentDisplay::reset
virtual void reset()
Definition:
VoronoiSegmentDisplay.cpp:89
rviz::Display::fixed_frame_
QString fixed_frame_
tuw_multi_robot_rviz::VoronoiSegmentDisplay::visuals_
boost::circular_buffer< boost::shared_ptr< VoronoiSegmentVisual > > visuals_
Definition:
VoronoiSegmentDisplay.h:120
tuw_multi_robot_rviz::VoronoiSegmentVisual
Definition:
VoronoiSegmentVisual.h:62
tuw_multi_robot_rviz::VoronoiSegmentDisplay::~VoronoiSegmentDisplay
virtual ~VoronoiSegmentDisplay()
Definition:
VoronoiSegmentDisplay.cpp:85
tuw_multi_robot_rviz::VoronoiSegmentDisplay::VoronoiSegmentDisplay
VoronoiSegmentDisplay()
Definition:
VoronoiSegmentDisplay.cpp:51
rviz::FloatProperty::setMin
void setMin(float min)
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const=0
float_property.h
rviz::ColorProperty
visualization_manager.h
rviz::Display
VoronoiSegmentDisplay.h
rviz::FloatProperty
class_list_macros.h
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::FloatProperty::getFloat
virtual float getFloat() const
ROS_DEBUG
#define ROS_DEBUG(...)
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
tuw_multi_robot_rviz::VoronoiSegmentDisplay::processMessage
void processMessage(const tuw_multi_robot_msgs::Graph::ConstPtr &msg)
Definition:
VoronoiSegmentDisplay.cpp:112
rviz::IntProperty::setMax
void setMax(int max)
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const=0
VoronoiSegmentVisual.h
transform_listener.h
rviz::MessageFilterDisplay::onInitialize
void onInitialize() override
rviz::FrameManager::getTransform
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
tuw_multi_robot_rviz::VoronoiSegmentDisplay::onInitialize
virtual void onInitialize()
Definition:
VoronoiSegmentDisplay.cpp:80
rviz::Display::context_
DisplayContext * context_
tuw_multi_robot_rviz::VoronoiSegmentDisplay
Definition:
VoronoiSegmentDisplay.h:87
rviz::IntProperty::getInt
virtual int getInt() const
color_property.h
rviz::ColorProperty::getOgreColor
Ogre::ColourValue getOgreColor() const
tuw_multi_robot_rviz::VoronoiSegmentDisplay::updateHistoryLength
void updateHistoryLength()
Definition:
VoronoiSegmentDisplay.cpp:101
rviz::IntProperty
tuw_multi_robot_rviz
Author(s): Benjamin Binder
autogenerated on Wed Mar 2 2022 01:10:08