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>
32 
34 #include <rviz/load_resource.h>
35 #include <rviz/render_panel.h>
36 #include <rviz/display_context.h>
38 #include <rviz/view_controller.h>
39 
41 
44 
45 #include <geometry_msgs/PointStamped.h>
46 
47 #include <sstream>
48 
49 namespace rviz
50 {
52 {
53  shortcut_key_ = 'c';
54 
56  new StringProperty("Topic", "/clicked_point", "The topic on which to publish points.",
58 
60  new BoolProperty("Single click", true, "Switch away from this tool after one click.",
62 
63  updateTopic();
64 }
65 
67 {
68 }
69 
71 {
74 }
75 
77 {
78 }
79 
81 {
82 }
83 
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 
97 {
98 }
99 
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 
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 
rviz::BoolProperty::getBool
virtual bool getBool() const
Definition: bool_property.cpp:48
rviz::getDefaultCursor
QCursor getDefaultCursor(bool)
Definition: load_resource.cpp:96
rviz::PointTool
Definition: point_tool.h:50
rviz::Tool
Definition: tool.h:56
rviz::Tool::cursor_
QCursor cursor_
Definition: tool.h:214
s
XmlRpcServer s
rviz::BoolProperty
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
rviz::ViewportMouseEvent
Definition: viewport_mouse_event.h:45
rviz::ViewportMouseEvent::x
int x
Definition: viewport_mouse_event.h:157
rviz::Tool::context_
DisplayContext * context_
Definition: tool.h:207
rviz::Tool::setCursor
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:67
viewport_mouse_event.h
ros::Exception
selection_manager.h
bool_property.h
rviz::Tool::setStatus
void setStatus(const QString &message)
Definition: tool.cpp:101
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
rviz::PointTool::deactivate
void deactivate() override
Definition: point_tool.cpp:80
rviz::SelectionManager::get3DPoint
bool get3DPoint(Ogre::Viewport *viewport, const int x, const int y, Ogre::Vector3 &result_point)
Definition: selection_manager.cpp:179
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition: viewport_mouse_event.h:155
rviz::PointTool::updateAutoDeactivate
void updateAutoDeactivate()
Definition: point_tool.cpp:96
rviz::PointTool::~PointTool
~PointTool() override
Definition: point_tool.cpp:66
point_tool.h
rviz::PointTool::topic_property_
StringProperty * topic_property_
Definition: point_tool.h:76
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::Tool::shortcut_key_
char shortcut_key_
Definition: tool.h:209
rviz
Definition: add_display_dialog.cpp:54
rviz::PointTool::onInitialize
void onInitialize() override
Definition: point_tool.cpp:70
ROS_ERROR_STREAM_NAMED
#define ROS_ERROR_STREAM_NAMED(name, args)
rviz::StringProperty
Property specialized for string values.
Definition: string_property.h:39
rviz::StringProperty::getStdString
std::string getStdString()
Definition: string_property.h:71
rviz::ViewportMouseEvent::y
int y
Definition: viewport_mouse_event.h:158
ogre_vector.h
rviz::DisplayContext::getFixedFrame
virtual QString getFixedFrame() const =0
Return the fixed frame name.
rviz::PointTool::pub_
ros::Publisher pub_
Definition: point_tool.h:74
rviz::PointTool::std_cursor_
QCursor std_cursor_
Definition: point_tool.h:70
rviz::PointTool::auto_deactivate_property_
BoolProperty * auto_deactivate_property_
Definition: point_tool.h:77
rviz::Tool::getPropertyContainer
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition: tool.h:76
string_property.h
rviz::PointTool::updateTopic
void updateTopic()
Definition: point_tool.cpp:84
rviz::PointTool::processMouseEvent
int processMouseEvent(ViewportMouseEvent &event) override
Definition: point_tool.cpp:100
render_panel.h
rviz::ViewportMouseEvent::leftUp
bool leftUp()
Definition: viewport_mouse_event.h:128
rviz::PointTool::hit_cursor_
QCursor hit_cursor_
Definition: point_tool.h:71
class_list_macros.hpp
rviz::PointTool::activate
void activate() override
Definition: point_tool.cpp:76
rviz::PointTool::nh_
ros::NodeHandle nh_
Definition: point_tool.h:73
load_resource.h
view_controller.h
rviz::PointTool::PointTool
PointTool()
Definition: point_tool.cpp:51
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
display_context.h
rviz::Tool::Finished
@ Finished
Definition: tool.h:103
ros::Time::now
static Time now()


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Sat Jun 1 2024 02:31:53