selection_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 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_SELECTION_MANAGER_H
31 #define RVIZ_SELECTION_MANAGER_H
32 
33 #include <map>
34 
35 #include <QObject>
36 
37 #include "forwards.h"
38 #include "selection_handler.h"
39 #include <rviz/rviz_export.h>
40 
41 #ifndef Q_MOC_RUN
42 #include <boost/shared_ptr.hpp>
43 #include <boost/unordered_map.hpp>
44 #include <boost/thread/recursive_mutex.hpp>
45 
46 #include <OgreTexture.h>
47 #include <OgreMaterial.h>
48 #include <OgreMaterialManager.h>
49 #include <OgreMovableObject.h>
50 #include <OgreRenderQueueListener.h>
51 #include <OgreSharedPtr.h>
52 #endif
53 
54 #include <vector>
55 #include <set>
56 
57 namespace ros
58 {
59 class Publisher;
60 }
61 
62 namespace Ogre
63 {
64 class SceneManager;
65 class Viewport;
66 class WireBoundingBox;
67 class SceneNode;
68 class Material;
69 class PixelBox;
70 class Rectangle2D;
71 class MovableObject;
72 } // namespace Ogre
73 
74 namespace rviz
75 {
76 class Object;
77 class PropertyTreeModel;
78 class ViewportMouseEvent;
79 class VisualizationManager;
80 
81 class RVIZ_EXPORT SelectionManager : public QObject,
82  public Ogre::MaterialManager::Listener,
83  public Ogre::RenderQueueListener
84 {
85  Q_OBJECT
86 public:
88  {
89  Add,
91  Replace
92  };
93 
95  ~SelectionManager() override;
96 
97  void initialize();
98 
100  void setDebugMode(bool debug);
101 
102  void clearHandlers();
103  void addObject(CollObjectHandle obj, SelectionHandler* handler);
104  void removeObject(CollObjectHandle obj);
105 
106  // control the highlight box being displayed while selecting
107  void highlight(Ogre::Viewport* viewport, int x1, int y1, int x2, int y2);
108  void removeHighlight();
109 
110  // select all objects in bounding box
111  void select(Ogre::Viewport* viewport, int x1, int y1, int x2, int y2, SelectType type);
112 
113  // @return handles of all objects in the given bounding box
114  // @param single_render_pass only perform one rendering pass (point cloud selecting won't work)
115  void pick(Ogre::Viewport* viewport,
116  int x1,
117  int y1,
118  int x2,
119  int y2,
120  M_Picked& results,
121  bool single_render_pass = false);
122 
123  void update();
124 
125  // modify the list of currently selected objects
126  void setSelection(const M_Picked& objs);
127  void addSelection(const M_Picked& objs);
128  void removeSelection(const M_Picked& objs);
130  {
131  return selection_;
132  }
133 
134  SelectionHandler* getHandler(CollObjectHandle obj);
135 
136  static Ogre::ColourValue handleToColor(CollObjectHandle handle);
137  // static CollObjectHandle colourToHandle( const Ogre::ColourValue & color );
138  static void setPickColor(const Ogre::ColourValue& color, Ogre::SceneNode* node)
139  {
140  setPickData(colorToHandle(color), color, node);
141  }
142  static void setPickColor(const Ogre::ColourValue& color, Ogre::MovableObject* object)
143  {
144  setPickData(colorToHandle(color), color, object);
145  }
146  static void setPickHandle(CollObjectHandle handle, Ogre::SceneNode* node)
147  {
148  setPickData(handle, handleToColor(handle), node);
149  }
150  static void setPickHandle(CollObjectHandle handle, Ogre::MovableObject* object)
151  {
152  setPickData(handle, handleToColor(handle), object);
153  }
154  static void setPickData(CollObjectHandle handle, const Ogre::ColourValue& color, Ogre::SceneNode* node);
155  static void
156  setPickData(CollObjectHandle handle, const Ogre::ColourValue& color, Ogre::MovableObject* object);
157 
158  // if a material does not support the picking scheme, paint it black
159  Ogre::Technique* handleSchemeNotFound(unsigned short scheme_index,
160  const Ogre::String& scheme_name,
161  Ogre::Material* original_material,
162  unsigned short lod_index,
163  const Ogre::Renderable* rend) override;
164 
165  // create a new unique handle
166  CollObjectHandle createHandle();
167 
168  // tell all handlers that interactive mode is active/inactive
169  void enableInteraction(bool enable);
171  {
172  return interaction_enabled_;
173  }
174 
175  // tell the view controller to look at the selection
176  void focusOnSelection();
177 
178  // change the size of the off-screen selection buffer texture
179  void setTextureSize(unsigned size);
180 
184  bool get3DPoint(Ogre::Viewport* viewport, const int x, const int y, Ogre::Vector3& result_point);
185 
202  bool get3DPatch(Ogre::Viewport* viewport,
203  const int x,
204  const int y,
205  const unsigned width,
206  const unsigned height,
207  const bool skip_missing,
208  std::vector<Ogre::Vector3>& result_points);
209 
210 
226  bool getPatchDepthImage(Ogre::Viewport* viewport,
227  const int x,
228  const int y,
229  const unsigned width,
230  const unsigned height,
231  std::vector<float>& depth_vector);
232 
233  // Implementation for Ogre::RenderQueueListener.
234  void renderQueueStarted(uint8_t queueGroupId,
235  const std::string& invocation,
236  bool& skipThisInvocation) override;
237 
239  {
240  return property_model_;
241  }
242 
243 private Q_SLOTS:
246  void updateProperties();
247 
248 private:
249  void selectionAdded(const M_Picked& added);
250  void selectionRemoved(const M_Picked& removed);
251 
252  std::pair<Picked, bool> addSelectedObject(const Picked& obj);
253  void removeSelectedObject(const Picked& obj);
254 
255  void setHighlightRect(Ogre::Viewport* viewport, int x1, int y1, int x2, int y2);
256 
258  void renderAndUnpack(Ogre::Viewport* viewport,
259  uint32_t pass,
260  int x1,
261  int y1,
262  int x2,
263  int y2,
264  V_CollObject& pixels);
265 
267  bool render(Ogre::Viewport* viewport,
268  const Ogre::TexturePtr& tex,
269  int x1,
270  int y1,
271  int x2,
272  int y2,
273  Ogre::PixelBox& dst_box,
274  const std::string& material_scheme,
275  unsigned texture_width,
276  unsigned textured_height);
277 
278  void unpackColors(Ogre::PixelBox& box, V_CollObject& pixels);
279 
280  void setDepthTextureSize(unsigned width, unsigned height);
281 
282  void publishDebugImage(const Ogre::PixelBox& pixel_box, const std::string& label);
283 
285 
286  boost::recursive_mutex global_mutex_;
287 
288  typedef boost::unordered_map<CollObjectHandle, SelectionHandler*> M_CollisionObjectToSelectionHandler;
290 
292 
293  struct Highlight
294  {
295  int x1;
296  int y1;
297  int x2;
298  int y2;
299  Ogre::Viewport* viewport;
300  };
302 
304 
305  const static uint32_t s_num_render_textures_ = 2; // If you want to change this number to something > 3
306  // you must provide more width for extra handles in
307  // the Picked structure (currently a u64)
308  Ogre::TexturePtr render_textures_[s_num_render_textures_];
309  Ogre::PixelBox pixel_boxes_[s_num_render_textures_];
310 
311  // Graphics card -based depth finding of clicked points.
312  Ogre::TexturePtr depth_render_texture_;
313  uint32_t depth_texture_width_, depth_texture_height_;
314  Ogre::PixelBox depth_pixel_box_;
315 
316  uint32_t uid_counter_;
317 
318  Ogre::Rectangle2D* highlight_rectangle_;
319  Ogre::SceneNode* highlight_node_;
320  Ogre::Camera* camera_;
321 
323 
325 
327 
328  Ogre::MaterialPtr fallback_pick_material_;
329  Ogre::Technique* fallback_pick_technique_;
330  Ogre::Technique* fallback_black_technique_;
331  Ogre::Technique* fallback_depth_technique_;
335 
336  uint32_t texture_size_;
337 
339 
340  typedef std::map<std::string, ros::Publisher> PublisherMap;
342 };
343 
344 } // namespace rviz
345 
346 #endif // RVIZ_SELECTION_MANAGER_H
rviz::SelectionManager::highlight_enabled_
bool highlight_enabled_
Definition: selection_manager.h:291
rviz::SelectionManager::vis_manager_
VisualizationManager * vis_manager_
Definition: selection_manager.h:284
rviz::SelectionManager::depth_pixel_box_
Ogre::PixelBox depth_pixel_box_
Definition: selection_manager.h:314
Ogre
Definition: axes_display.h:35
rviz::SelectionManager::global_mutex_
boost::recursive_mutex global_mutex_
Definition: selection_manager.h:286
rviz::SelectionManager::setPickHandle
static void setPickHandle(CollObjectHandle handle, Ogre::MovableObject *object)
Definition: selection_manager.h:150
rviz::SelectionManager::uid_counter_
uint32_t uid_counter_
Definition: selection_manager.h:316
rviz::SelectionManager::texture_size_
uint32_t texture_size_
Definition: selection_manager.h:336
forwards.h
rviz::VisualizationManager
The VisualizationManager class is the central manager class of rviz, holding all the Displays,...
Definition: visualization_manager.h:96
rviz::PropertyTreeModel
Definition: property_tree_model.h:38
rviz::SelectionManager::Highlight::viewport
Ogre::Viewport * viewport
Definition: selection_manager.h:299
ros
rviz::SelectionManager::setPickHandle
static void setPickHandle(CollObjectHandle handle, Ogre::SceneNode *node)
Definition: selection_manager.h:146
rviz::SelectionManager::Highlight::x1
int x1
Definition: selection_manager.h:295
rviz::SelectionManager::PublisherMap
std::map< std::string, ros::Publisher > PublisherMap
Definition: selection_manager.h:340
rviz::SelectionManager::fallback_black_cull_technique_
Ogre::Technique * fallback_black_cull_technique_
Definition: selection_manager.h:333
rviz::V_CollObject
std::vector< CollObjectHandle > V_CollObject
Definition: forwards.h:46
rviz::SelectionManager::SelectType
SelectType
Definition: selection_manager.h:87
rviz::SelectionManager::setPickColor
static void setPickColor(const Ogre::ColourValue &color, Ogre::SceneNode *node)
Definition: selection_manager.h:138
rviz::SelectionManager::Highlight::x2
int x2
Definition: selection_manager.h:297
rviz::SelectionManager::depth_texture_width_
uint32_t depth_texture_width_
Definition: selection_manager.h:313
rviz::CollObjectHandle
uint32_t CollObjectHandle
Definition: forwards.h:45
rviz::SelectionManager::fallback_black_technique_
Ogre::Technique * fallback_black_technique_
Definition: selection_manager.h:330
rviz::SelectionManager::fallback_pick_material_
Ogre::MaterialPtr fallback_pick_material_
Definition: selection_manager.h:328
rviz::Picked
Definition: forwards.h:53
selection_handler.h
rviz::SelectionManager::objects_
M_CollisionObjectToSelectionHandler objects_
Definition: selection_manager.h:289
rviz::SelectionManager::Highlight::y2
int y2
Definition: selection_manager.h:298
rviz::SelectionManager::highlight_rectangle_
Ogre::Rectangle2D * highlight_rectangle_
Definition: selection_manager.h:318
rviz::SelectionManager::Highlight
Definition: selection_manager.h:293
rviz::SelectionManager::pixel_buffer_
V_CollObject pixel_buffer_
Definition: selection_manager.h:322
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
rviz::SelectionManager::interaction_enabled_
bool interaction_enabled_
Definition: selection_manager.h:324
rviz::SelectionManager::M_CollisionObjectToSelectionHandler
boost::unordered_map< CollObjectHandle, SelectionHandler * > M_CollisionObjectToSelectionHandler
Definition: selection_manager.h:288
rviz::SelectionManager::setPickColor
static void setPickColor(const Ogre::ColourValue &color, Ogre::MovableObject *object)
Definition: selection_manager.h:142
rviz
Definition: add_display_dialog.cpp:54
rviz::SelectionManager::debug_publishers_
PublisherMap debug_publishers_
Definition: selection_manager.h:341
rviz::SelectionManager::getInteractionEnabled
bool getInteractionEnabled()
Definition: selection_manager.h:170
rviz::SelectionManager::fallback_depth_cull_technique_
Ogre::Technique * fallback_depth_cull_technique_
Definition: selection_manager.h:334
rviz::SelectionManager::getPropertyModel
PropertyTreeModel * getPropertyModel()
Definition: selection_manager.h:238
rviz::SelectionManager::Highlight::y1
int y1
Definition: selection_manager.h:296
rviz::SelectionManager::fallback_pick_technique_
Ogre::Technique * fallback_pick_technique_
Definition: selection_manager.h:329
rviz::SelectionManager
Definition: selection_manager.h:81
rviz::SelectionHandler
Definition: selection_handler.h:64
rviz::SelectionManager::Remove
@ Remove
Definition: selection_manager.h:90
rviz::SelectionManager::debug_mode_
bool debug_mode_
Definition: selection_manager.h:326
initialize
ROSCONSOLE_DECL void initialize()
rviz::SelectionManager::selection_
M_Picked selection_
Definition: selection_manager.h:303
rviz::SelectionManager::Add
@ Add
Definition: selection_manager.h:89
rviz::SelectionManager::fallback_pick_cull_technique_
Ogre::Technique * fallback_pick_cull_technique_
Definition: selection_manager.h:332
rviz::SelectionManager::getSelection
const M_Picked & getSelection()
Definition: selection_manager.h:129
rviz::SelectionManager::highlight_node_
Ogre::SceneNode * highlight_node_
Definition: selection_manager.h:319
rviz::SelectionManager::depth_render_texture_
Ogre::TexturePtr depth_render_texture_
Definition: selection_manager.h:312
rviz::SelectionManager::highlight_
Highlight highlight_
Definition: selection_manager.h:301
rviz::M_Picked
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition: forwards.h:63
rviz::SelectionManager::fallback_depth_technique_
Ogre::Technique * fallback_depth_technique_
Definition: selection_manager.h:331
rviz::colorToHandle
uint32_t colorToHandle(Ogre::PixelFormat fmt, uint32_t col)
Definition: forwards.h:66
rviz::SelectionManager::property_model_
PropertyTreeModel * property_model_
Definition: selection_manager.h:338
rviz::SelectionManager::camera_
Ogre::Camera * camera_
Definition: selection_manager.h:320


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02