src
rviz
default_plugin
tools
point_tool.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2013, 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 <OgreRay.h>
31
#include <OgreVector3.h>
32
33
#include "
rviz/viewport_mouse_event.h
"
34
#include "
rviz/load_resource.h
"
35
#include "
rviz/render_panel.h
"
36
#include "
rviz/display_context.h
"
37
#include "
rviz/selection/selection_manager.h
"
38
#include "
rviz/view_controller.h
"
39
40
#include "
rviz/default_plugin/tools/point_tool.h
"
41
42
#include "
rviz/properties/bool_property.h
"
43
#include "
rviz/properties/string_property.h
"
44
45
#include <geometry_msgs/PointStamped.h>
46
47
#include <sstream>
48
49
namespace
rviz
50
{
51
PointTool::PointTool
() :
Tool
()
52
{
53
shortcut_key_
=
'c'
;
54
55
topic_property_
=
56
new
StringProperty
(
"Topic"
,
"/clicked_point"
,
"The topic on which to publish points."
,
57
getPropertyContainer
(), SLOT(
updateTopic
()),
this
);
58
59
auto_deactivate_property_
=
60
new
BoolProperty
(
"Single click"
,
true
,
"Switch away from this tool after one click."
,
61
getPropertyContainer
(), SLOT(
updateAutoDeactivate
()),
this
);
62
63
updateTopic
();
64
}
65
66
PointTool::~PointTool
()
67
{
68
}
69
70
void
PointTool::onInitialize
()
71
{
72
hit_cursor_
=
cursor_
;
73
std_cursor_
=
getDefaultCursor
();
74
}
75
76
void
PointTool::activate
()
77
{
78
}
79
80
void
PointTool::deactivate
()
81
{
82
}
83
84
void
PointTool::updateTopic
()
85
{
86
try
87
{
88
pub_
=
nh_
.
advertise
<geometry_msgs::PointStamped>(
topic_property_
->
getStdString
(), 1);
89
}
90
catch
(
const
ros::Exception
& e)
91
{
92
ROS_ERROR_STREAM_NAMED
(
"PointTool"
, e.what());
93
}
94
}
95
96
void
PointTool::updateAutoDeactivate
()
97
{
98
}
99
100
int
PointTool::processMouseEvent
(
ViewportMouseEvent
& event)
101
{
102
int
flags = 0;
103
104
Ogre::Vector3 pos;
105
bool
success =
context_
->
getSelectionManager
()->
get3DPoint
(event.
viewport
, event.
x
, event.
y
, pos);
106
setCursor
(success ?
hit_cursor_
:
std_cursor_
);
107
108
if
(success)
109
{
110
std::ostringstream
s
;
111
s <<
"<b>Left-Click:</b> Select this point."
;
112
s.precision(3);
113
s <<
" ["
<< pos.x <<
","
<< pos.y <<
","
<< pos.z <<
"]"
;
114
setStatus
(s.str().c_str());
115
116
if
(event.
leftUp
())
117
{
118
geometry_msgs::PointStamped ps;
119
ps.point.x = pos.x;
120
ps.point.y = pos.y;
121
ps.point.z = pos.z;
122
ps.header.frame_id =
context_
->
getFixedFrame
().toStdString();
123
ps.header.stamp =
ros::Time::now
();
124
pub_
.
publish
(ps);
125
126
if
(
auto_deactivate_property_
->
getBool
())
127
{
128
flags |=
Finished
;
129
}
130
}
131
}
132
else
133
{
134
setStatus
(
"Move over an object to select the target point."
);
135
}
136
137
return
flags;
138
}
139
140
}
// namespace rviz
141
142
#include <
pluginlib/class_list_macros.hpp
>
143
PLUGINLIB_EXPORT_CLASS
(
rviz::PointTool
,
rviz::Tool
)
rviz::Tool::Finished
Definition:
tool.h:103
selection_manager.h
rviz::Tool
Definition:
tool.h:56
ROS_ERROR_STREAM_NAMED
#define ROS_ERROR_STREAM_NAMED(name, args)
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition:
viewport_mouse_event.h:145
rviz::Tool::getPropertyContainer
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition:
tool.h:76
s
XmlRpcServer s
rviz::getDefaultCursor
QCursor getDefaultCursor(bool)
Definition:
load_resource.cpp:96
view_controller.h
bool_property.h
rviz::Tool::shortcut_key_
char shortcut_key_
Definition:
tool.h:209
load_resource.h
rviz::PointTool::onInitialize
void onInitialize() override
Definition:
point_tool.cpp:70
rviz::PointTool::~PointTool
~PointTool() override
Definition:
point_tool.cpp:66
rviz
Definition:
add_display_dialog.cpp:54
rviz::ViewportMouseEvent::x
int x
Definition:
viewport_mouse_event.h:147
rviz::PointTool::topic_property_
StringProperty * topic_property_
Definition:
point_tool.h:76
rviz::StringProperty::getStdString
std::string getStdString()
Definition:
string_property.h:50
display_context.h
class_list_macros.hpp
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
viewport_mouse_event.h
rviz::PointTool::deactivate
void deactivate() override
Definition:
point_tool.cpp:80
rviz::PointTool::std_cursor_
QCursor std_cursor_
Definition:
point_tool.h:70
rviz::PointTool::updateAutoDeactivate
void updateAutoDeactivate()
Definition:
point_tool.cpp:96
point_tool.h
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
rviz::PointTool
Definition:
point_tool.h:50
rviz::ViewportMouseEvent::leftUp
bool leftUp()
Definition:
viewport_mouse_event.h:118
rviz::PointTool::hit_cursor_
QCursor hit_cursor_
Definition:
point_tool.h:71
ros::NodeHandle::advertise
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
rviz::PointTool::pub_
ros::Publisher pub_
Definition:
point_tool.h:74
string_property.h
rviz::PointTool::PointTool
PointTool()
Definition:
point_tool.cpp:51
rviz::StringProperty
Property specialized for string values.
Definition:
string_property.h:39
render_panel.h
rviz::Tool::cursor_
QCursor cursor_
Definition:
tool.h:214
rviz::DisplayContext::getFixedFrame
virtual QString getFixedFrame() const =0
Return the fixed frame name.
rviz::Tool::context_
DisplayContext * context_
Definition:
tool.h:207
rviz::Tool::setStatus
void setStatus(const QString &message)
Definition:
tool.cpp:101
rviz::PointTool::activate
void activate() override
Definition:
point_tool.cpp:76
rviz::PointTool::auto_deactivate_property_
BoolProperty * auto_deactivate_property_
Definition:
point_tool.h:77
rviz::BoolProperty
Property specialized to provide getter for booleans.
Definition:
bool_property.h:38
rviz::PointTool::nh_
ros::NodeHandle nh_
Definition:
point_tool.h:73
rviz::ViewportMouseEvent::y
int y
Definition:
viewport_mouse_event.h:148
rviz::PointTool::updateTopic
void updateTopic()
Definition:
point_tool.cpp:84
rviz::Tool::setCursor
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition:
tool.cpp:67
rviz::PointTool::processMouseEvent
int processMouseEvent(ViewportMouseEvent &event) override
Definition:
point_tool.cpp:100
ros::Time::now
static Time now()
ros::Exception
rviz::ViewportMouseEvent
Definition:
viewport_mouse_event.h:45
rviz::SelectionManager::get3DPoint
bool get3DPoint(Ogre::Viewport *viewport, const int x, const int y, Ogre::Vector3 &result_point)
Definition:
selection_manager.cpp:178
rviz::BoolProperty::getBool
virtual bool getBool() const
Definition:
bool_property.cpp:51
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25