Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
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
52
PointTool::PointTool
()
53
:
Tool
()
54
{
55
shortcut_key_
=
'c'
;
56
57
topic_property_
=
new
StringProperty
(
"Topic"
,
"/clicked_point"
,
58
"The topic on which to publish points."
,
59
getPropertyContainer
(), SLOT(
updateTopic
() ),
this
);
60
61
auto_deactivate_property_
=
new
BoolProperty
(
"Single click"
,
true
,
62
"Switch away from this tool after one click."
,
63
getPropertyContainer
(), SLOT(
updateAutoDeactivate
() ),
this
);
64
65
updateTopic
();
66
}
67
68
PointTool::~PointTool
()
69
{
70
}
71
72
void
PointTool::onInitialize
()
73
{
74
hit_cursor_
=
cursor_
;
75
std_cursor_
=
getDefaultCursor
();
76
}
77
78
void
PointTool::activate
()
79
{
80
}
81
82
void
PointTool::deactivate
()
83
{
84
}
85
86
void
PointTool::updateTopic
()
87
{
88
pub_
=
nh_
.
advertise
<geometry_msgs::PointStamped>(
topic_property_
->
getStdString
(), 1 );
89
}
90
91
void
PointTool::updateAutoDeactivate
()
92
{
93
}
94
95
int
PointTool::processMouseEvent
(
ViewportMouseEvent
& event )
96
{
97
int
flags = 0;
98
99
Ogre::Vector3 pos;
100
bool
success =
context_
->
getSelectionManager
()->
get3DPoint
( event.
viewport
, event.
x
, event.
y
, pos );
101
setCursor
( success ?
hit_cursor_
:
std_cursor_
);
102
103
if
( success )
104
{
105
std::ostringstream
s
;
106
s <<
"<b>Left-Click:</b> Select this point."
;
107
s.precision(3);
108
s <<
" ["
<< pos.x <<
","
<< pos.y <<
","
<< pos.z <<
"]"
;
109
setStatus
( s.str().c_str() );
110
111
if
( event.
leftUp
() )
112
{
113
geometry_msgs::PointStamped ps;
114
ps.point.x = pos.x;
115
ps.point.y = pos.y;
116
ps.point.z = pos.z;
117
ps.header.frame_id =
context_
->
getFixedFrame
().toStdString();
118
ps.header.stamp =
ros::Time::now
();
119
pub_
.
publish
( ps );
120
121
if
(
auto_deactivate_property_
->
getBool
() )
122
{
123
flags |=
Finished
;
124
}
125
}
126
}
127
else
128
{
129
setStatus
(
"Move over an object to select the target point."
);
130
}
131
132
return
flags;
133
}
134
135
}
136
137
#include <
pluginlib/class_list_macros.hpp
>
138
PLUGINLIB_EXPORT_CLASS
(
rviz::PointTool
,
rviz::Tool
)
rviz::PointTool::onInitialize
virtual void onInitialize()
Definition:
point_tool.cpp:72
rviz::Tool::Finished
Definition:
tool.h:92
selection_manager.h
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
rviz::Tool
Definition:
tool.h:55
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition:
viewport_mouse_event.h:108
rviz::PointTool::processMouseEvent
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition:
point_tool.cpp:95
s
XmlRpcServer s
view_controller.h
bool_property.h
rviz::Tool::shortcut_key_
char shortcut_key_
Definition:
tool.h:177
load_resource.h
rviz
Definition:
add_display_dialog.cpp:54
rviz::ViewportMouseEvent::x
int x
Definition:
viewport_mouse_event.h:110
rviz::PointTool::topic_property_
StringProperty * topic_property_
Definition:
point_tool.h:76
rviz::StringProperty::getStdString
std::string getStdString()
Definition:
string_property.h:51
rviz::BoolProperty::getBool
virtual bool getBool() const
Definition:
bool_property.cpp:52
display_context.h
class_list_macros.hpp
viewport_mouse_event.h
rviz::PointTool::deactivate
virtual void deactivate()
Definition:
point_tool.cpp:82
rviz::PointTool::activate
virtual void activate()
Definition:
point_tool.cpp:78
rviz::PointTool::std_cursor_
QCursor std_cursor_
Definition:
point_tool.h:70
rviz::PointTool::updateAutoDeactivate
void updateAutoDeactivate()
Definition:
point_tool.cpp:91
point_tool.h
rviz::getDefaultCursor
QCursor getDefaultCursor(bool fill_cache)
Definition:
load_resource.cpp:97
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:99
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:52
rviz::StringProperty
Property specialized for string values.
Definition:
string_property.h:40
render_panel.h
rviz::Tool::cursor_
QCursor cursor_
Definition:
tool.h:182
rviz::DisplayContext::getFixedFrame
virtual QString getFixedFrame() const =0
Return the fixed frame name.
rviz::Tool::context_
DisplayContext * context_
Definition:
tool.h:175
rviz::Tool::setStatus
void setStatus(const QString &message)
Definition:
tool.cpp:97
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:111
rviz::PointTool::updateTopic
void updateTopic()
Definition:
point_tool.cpp:86
rviz::Tool::setCursor
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition:
tool.cpp:69
ros::Time::now
static Time now()
rviz::Tool::getPropertyContainer
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition:
tool.h:75
rviz::ViewportMouseEvent
Definition:
viewport_mouse_event.h:46
rviz::PointTool::~PointTool
virtual ~PointTool()
Definition:
point_tool.cpp:68
rviz::SelectionManager::get3DPoint
bool get3DPoint(Ogre::Viewport *viewport, const int x, const int y, Ogre::Vector3 &result_point)
Definition:
selection_manager.cpp:176
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42