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 {
51 
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 
69 {
70 }
71 
73 {
76 }
77 
79 {
80 }
81 
83 {
84 }
85 
87 {
88  pub_ = nh_.advertise<geometry_msgs::PointStamped>( topic_property_->getStdString(), 1 );
89 }
90 
92 {
93 }
94 
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 
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 
virtual void onInitialize()
Definition: point_tool.cpp:72
void publish(const boost::shared_ptr< M > &message) const
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition: point_tool.cpp:95
XmlRpcServer s
char shortcut_key_
Definition: tool.h:177
StringProperty * topic_property_
Definition: point_tool.h:76
std::string getStdString()
virtual bool getBool() const
virtual void deactivate()
Definition: point_tool.cpp:82
virtual void activate()
Definition: point_tool.cpp:78
QCursor std_cursor_
Definition: point_tool.h:70
void updateAutoDeactivate()
Definition: point_tool.cpp:91
QCursor getDefaultCursor(bool fill_cache)
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:182
virtual QString getFixedFrame() const =0
Return the fixed frame name.
DisplayContext * context_
Definition: tool.h:175
void setStatus(const QString &message)
Definition: tool.cpp:97
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:86
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:69
static Time now()
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition: tool.h:75
virtual ~PointTool()
Definition: point_tool.cpp:68
bool get3DPoint(Ogre::Viewport *viewport, const int x, const int y, Ogre::Vector3 &result_point)
#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