interactive_marker.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 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 #ifndef RVIZ_INTERACTIVE_MARKER_H_
31 #define RVIZ_INTERACTIVE_MARKER_H_
32 
33 #ifndef Q_MOC_RUN
34 #include <boost/shared_ptr.hpp>
35 #include <boost/thread/mutex.hpp>
36 #include <boost/thread/recursive_mutex.hpp>
37 #include <boost/thread/thread.hpp>
38 
39 #include <OgreVector3.h>
40 #include <OgreQuaternion.h>
41 #endif
42 
43 #include <visualization_msgs/InteractiveMarker.h>
44 #include <visualization_msgs/InteractiveMarkerPose.h>
45 #include <visualization_msgs/InteractiveMarkerFeedback.h>
46 #include <geometry_msgs/Pose.h>
47 
48 #include <ros/publisher.h>
49 
51 #include "rviz/ogre_helpers/axes.h"
52 
53 #include "rviz/default_plugin/rviz_default_plugin_export.h"
56 
57 namespace Ogre
58 {
59 class SceneNode;
60 }
61 
62 class QMenu;
63 
64 namespace rviz
65 {
66 class DisplayContext;
67 class InteractiveMarkerDisplay;
68 
69 class RVIZ_DEFAULT_PLUGIN_EXPORT InteractiveMarker : public QObject
70 {
71  Q_OBJECT
72 public:
73  InteractiveMarker(Ogre::SceneNode* scene_node, DisplayContext* context);
74  ~InteractiveMarker() override;
75 
76  // reset contents to reflect the data from a new message
77  // @return success
78  bool processMessage(const visualization_msgs::InteractiveMarker& message);
79 
80  // reset contents to reflect the data from a new message
81  // @return success
82  void processMessage(const visualization_msgs::InteractiveMarkerPose& message);
83 
84  // called every frame update
85  void update(float wall_dt);
86 
87  // directly set the pose, relative to parent frame
88  // if publish is set to true, publish the change
89  void setPose(Ogre::Vector3 position, Ogre::Quaternion orientation, const std::string& control_name);
90 
91  void translate(Ogre::Vector3 delta_position, const std::string& control_name);
92  void rotate(Ogre::Quaternion delta_orientation, const std::string& control_name);
93 
94  // schedule a pose reset once dragging is finished
95  void requestPoseUpdate(Ogre::Vector3 position, Ogre::Quaternion orientation);
96 
97  void startDragging();
98  void stopDragging();
99 
100  const Ogre::Vector3& getPosition()
101  {
102  return position_;
103  }
104  const Ogre::Quaternion& getOrientation()
105  {
106  return orientation_;
107  }
108 
109  float getSize()
110  {
111  return scale_;
112  }
113  const std::string& getReferenceFrame()
114  {
115  return reference_frame_;
116  }
117  const std::string& getName()
118  {
119  return name_;
120  }
121 
122  // show name above marker
123  void setShowDescription(bool show);
124 
125  // show axes in origin
126  void setShowAxes(bool show);
127 
128  // show visual helpers while dragging
129  void setShowVisualAids(bool show);
130 
131  // @return true if the mouse event was intercepted, false if it was ignored
132  bool handleMouseEvent(ViewportMouseEvent& event, const std::string& control_name);
133 
144  bool handle3DCursorEvent(ViewportMouseEvent& event,
145  const Ogre::Vector3& cursor_pos,
146  const Ogre::Quaternion& cursor_rot,
147  const std::string& control_name);
148 
149 
160  void showMenu(ViewportMouseEvent& event,
161  const std::string& control_name,
162  const Ogre::Vector3& three_d_point,
163  bool valid_point);
164 
165  // fill in current marker pose & name, publish
166  void publishFeedback(visualization_msgs::InteractiveMarkerFeedback& feedback,
167  bool mouse_point_valid = false,
168  const Ogre::Vector3& mouse_point_rel_world = Ogre::Vector3(0, 0, 0));
169 
170  bool hasMenu()
171  {
172  return has_menu_;
173  }
174 
177  {
178  return menu_;
179  }
180 
181 Q_SIGNALS:
182 
183  void userFeedback(visualization_msgs::InteractiveMarkerFeedback& feedback);
184  void statusUpdate(StatusProperty::Level level, const std::string& name, const std::string& text);
185 
186 protected Q_SLOTS:
187  void handleMenuSelect(int menu_item_id);
188 
189 protected:
190  void publishPose();
191 
192  void reset();
193 
194  // set the pose of the parent frame, relative to the fixed frame
195  void updateReferencePose();
196 
197  QString makeMenuString(const std::string& entry);
198 
199  // Recursively append menu and submenu entries to menu, based on a
200  // vector of menu entry id numbers describing the menu entries at the
201  // current level.
202  void populateMenu(QMenu* menu, std::vector<uint32_t>& ids);
203 
205 
206  // pose of parent coordinate frame
207  std::string reference_frame_;
210 
211  // node representing reference frame in tf, like /map, /base_link, /head, etc.
212  Ogre::SceneNode* reference_node_;
213 
214  // pose being controlled, relative to reference frame
215  Ogre::Vector3 position_;
216  Ogre::Quaternion orientation_;
217 
218  // has the pose changed since the last feedback was sent?
221 
223  typedef std::map<std::string, InteractiveMarkerControlPtr> M_ControlPtr;
224  M_ControlPtr controls_;
225 
226  std::string name_;
227  std::string description_;
228 
229  bool dragging_;
230 
231  // pose being controlled
233  Ogre::Vector3 requested_position_;
234  Ogre::Quaternion requested_orientation_;
235 
236  float scale_;
237 
239  bool has_menu_;
240 
241  // Helper to more simply represent the menu tree.
242  struct MenuNode
243  {
244  visualization_msgs::MenuEntry entry;
245  std::vector<uint32_t> child_ids;
246  };
247 
248  // maps menu index to menu entry and item
249  std::map<uint32_t, MenuNode> menu_entries_;
250 
251  // Helper to store the top level of the menu tree.
252  std::vector<uint32_t> top_level_menu_ids_;
253 
254  // which control has popped up the menu
255  std::string last_control_name_;
256 
258 
259  // visual aids
260 
262 
263  InteractiveMarkerControlPtr description_control_;
264 
265  std::string topic_ns_;
266  std::string client_id_;
267 
268  boost::recursive_mutex mutex_;
269 
271 
273  Ogre::Vector3 three_d_point_for_menu_;
274 
276 };
277 
278 
279 } // namespace rviz
280 
281 #endif /* INTERACTIVE_MARKER_H_ */
boost::recursive_mutex mutex_
const Ogre::Quaternion & getOrientation()
Ogre::Vector3 three_d_point_for_menu_
boost::shared_ptr< boost::thread > sys_thread_
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
const Ogre::Vector3 & getPosition()
Pure-virtual base class for objects which give Display subclasses context in which to work...
const std::string & getName()
std::map< std::string, InteractiveMarkerControlPtr > M_ControlPtr
Ogre::Quaternion requested_orientation_
InteractiveMarkerControlPtr description_control_
An object that displays a set of X/Y/Z axes, with X=Red, Y=Green, Z=Blue.
Definition: axes.h:59
visualization_msgs::MenuEntry entry
std::vector< uint32_t > top_level_menu_ids_
boost::shared_ptr< InteractiveMarkerControl > InteractiveMarkerControlPtr
boost::shared_ptr< QMenu > getMenu()
const std::string & getReferenceFrame()
boost::shared_ptr< QMenu > menu_
Ogre::Quaternion orientation_
std::map< uint32_t, MenuNode > menu_entries_
Ogre::SceneNode * reference_node_


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Aug 15 2022 02:05:16