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 
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;
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 
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_ */
rviz::InteractiveMarker::M_ControlPtr
std::map< std::string, InteractiveMarkerControlPtr > M_ControlPtr
Definition: interactive_marker.h:223
rviz::InteractiveMarker::InteractiveMarkerControlPtr
boost::shared_ptr< InteractiveMarkerControl > InteractiveMarkerControlPtr
Definition: interactive_marker.h:222
axes.h
rviz::InteractiveMarker::heart_beat_t_
double heart_beat_t_
Definition: interactive_marker.h:257
Ogre
Definition: axes_display.h:35
rviz::InteractiveMarker::MenuNode::entry
visualization_msgs::MenuEntry entry
Definition: interactive_marker.h:244
rviz::InteractiveMarker::name_
std::string name_
Definition: interactive_marker.h:226
rviz::InteractiveMarker::client_id_
std::string client_id_
Definition: interactive_marker.h:266
rviz::InteractiveMarker::context_
DisplayContext * context_
Definition: interactive_marker.h:204
boost::shared_ptr< QMenu >
forwards.h
rviz::InteractiveMarker::reference_frame_
std::string reference_frame_
Definition: interactive_marker.h:207
rviz::InteractiveMarker::getName
const std::string & getName()
Definition: interactive_marker.h:117
rviz::InteractiveMarker::menu_entries_
std::map< uint32_t, MenuNode > menu_entries_
Definition: interactive_marker.h:249
rviz::StatusProperty::Level
Level
Definition: status_property.h:42
rviz::ViewportMouseEvent
Definition: viewport_mouse_event.h:45
rviz::InteractiveMarker::axes_
Axes * axes_
Definition: interactive_marker.h:261
rviz::InteractiveMarker::sys_thread_
boost::shared_ptr< boost::thread > sys_thread_
Definition: interactive_marker.h:270
rviz::InteractiveMarker::show_visual_aids_
bool show_visual_aids_
Definition: interactive_marker.h:275
rviz::InteractiveMarker::requested_orientation_
Ogre::Quaternion requested_orientation_
Definition: interactive_marker.h:234
rviz::InteractiveMarker::reference_time_
ros::Time reference_time_
Definition: interactive_marker.h:208
rviz::InteractiveMarker::position_
Ogre::Vector3 position_
Definition: interactive_marker.h:215
rviz::InteractiveMarker::description_control_
InteractiveMarkerControlPtr description_control_
Definition: interactive_marker.h:263
rviz::InteractiveMarker::reference_node_
Ogre::SceneNode * reference_node_
Definition: interactive_marker.h:212
status_property.h
rviz::InteractiveMarker::topic_ns_
std::string topic_ns_
Definition: interactive_marker.h:265
rviz::InteractiveMarker::orientation_
Ogre::Quaternion orientation_
Definition: interactive_marker.h:216
publisher.h
rviz::InteractiveMarker::got_3d_point_for_menu_
bool got_3d_point_for_menu_
Definition: interactive_marker.h:272
rviz::InteractiveMarker::MenuNode::child_ids
std::vector< uint32_t > child_ids
Definition: interactive_marker.h:245
rviz::InteractiveMarker::description_
std::string description_
Definition: interactive_marker.h:227
rviz::InteractiveMarker::frame_locked_
bool frame_locked_
Definition: interactive_marker.h:209
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
rviz
Definition: add_display_dialog.cpp:54
rviz::InteractiveMarker::scale_
float scale_
Definition: interactive_marker.h:236
rviz::InteractiveMarker::hasMenu
bool hasMenu()
Definition: interactive_marker.h:170
rviz::InteractiveMarker::time_since_last_feedback_
double time_since_last_feedback_
Definition: interactive_marker.h:220
rviz::InteractiveMarker::has_menu_
bool has_menu_
Definition: interactive_marker.h:239
rviz::InteractiveMarker::mutex_
boost::recursive_mutex mutex_
Definition: interactive_marker.h:268
ogre_vector.h
rviz::InteractiveMarker::three_d_point_for_menu_
Ogre::Vector3 three_d_point_for_menu_
Definition: interactive_marker.h:273
rviz::InteractiveMarker::last_control_name_
std::string last_control_name_
Definition: interactive_marker.h:255
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
rviz::InteractiveMarker::pose_changed_
bool pose_changed_
Definition: interactive_marker.h:219
rviz::Axes
An object that displays a set of X/Y/Z axes, with X=Red, Y=Green, Z=Blue.
Definition: axes.h:57
rviz::InteractiveMarker::MenuNode
Definition: interactive_marker.h:242
rviz::InteractiveMarker::getSize
float getSize()
Definition: interactive_marker.h:109
rviz::InteractiveMarker::controls_
M_ControlPtr controls_
Definition: interactive_marker.h:224
rviz::InteractiveMarker::menu_
boost::shared_ptr< QMenu > menu_
Definition: interactive_marker.h:238
ros::Time
rviz::InteractiveMarker::getOrientation
const Ogre::Quaternion & getOrientation()
Definition: interactive_marker.h:104
rviz::InteractiveMarker::top_level_menu_ids_
std::vector< uint32_t > top_level_menu_ids_
Definition: interactive_marker.h:252
rviz::InteractiveMarker
Definition: interactive_marker.h:69
rviz::InteractiveMarker::getMenu
boost::shared_ptr< QMenu > getMenu()
Definition: interactive_marker.h:176
rviz::InteractiveMarker::getReferenceFrame
const std::string & getReferenceFrame()
Definition: interactive_marker.h:113
rviz::InteractiveMarker::requested_position_
Ogre::Vector3 requested_position_
Definition: interactive_marker.h:233
rviz::InteractiveMarker::getPosition
const Ogre::Vector3 & getPosition()
Definition: interactive_marker.h:100
rviz::InteractiveMarker::dragging_
bool dragging_
Definition: interactive_marker.h:229
rviz::InteractiveMarker::pose_update_requested_
bool pose_update_requested_
Definition: interactive_marker.h:232
interactive_marker_control.h


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