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 
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.",
57  getPropertyContainer(), SLOT(updateTopic()), this);
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 
#define ROS_ERROR_STREAM_NAMED(name, args)
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition: tool.h:76
XmlRpcServer s
QCursor getDefaultCursor(bool)
char shortcut_key_
Definition: tool.h:209
void onInitialize() override
Definition: point_tool.cpp:70
~PointTool() override
Definition: point_tool.cpp:66
StringProperty * topic_property_
Definition: point_tool.h:76
std::string getStdString()
void publish(const boost::shared_ptr< M > &message) const
void deactivate() override
Definition: point_tool.cpp:80
QCursor std_cursor_
Definition: point_tool.h:70
void updateAutoDeactivate()
Definition: point_tool.cpp:96
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
QCursor hit_cursor_
Definition: point_tool.h:71
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Publisher pub_
Definition: point_tool.h:74
Property specialized for string values.
QCursor cursor_
Definition: tool.h:214
virtual QString getFixedFrame() const =0
Return the fixed frame name.
DisplayContext * context_
Definition: tool.h:207
void setStatus(const QString &message)
Definition: tool.cpp:101
void activate() override
Definition: point_tool.cpp:76
BoolProperty * auto_deactivate_property_
Definition: point_tool.h:77
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
ros::NodeHandle nh_
Definition: point_tool.h:73
void updateTopic()
Definition: point_tool.cpp:84
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:67
int processMouseEvent(ViewportMouseEvent &event) override
Definition: point_tool.cpp:100
static Time now()
bool get3DPoint(Ogre::Viewport *viewport, const int x, const int y, Ogre::Vector3 &result_point)
virtual bool getBool() const
#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