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  Ogre::TexturePtr tex,
269  int x1,
270  int y1,
271  int x2,
272  int y2,
273  Ogre::PixelBox& dst_box,
274  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;
289  M_CollisionObjectToSelectionHandler objects_;
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;
341  PublisherMap debug_publishers_;
342 };
343 
344 } // namespace rviz
345 
346 #endif // RVIZ_SELECTION_MANAGER_H
ROSCONSOLE_DECL void initialize()
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition: forwards.h:63
Ogre::Technique * fallback_black_cull_technique_
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
Ogre::Technique * fallback_pick_cull_technique_
static void setPickHandle(CollObjectHandle handle, Ogre::SceneNode *node)
PropertyTreeModel * property_model_
Ogre::Technique * fallback_pick_technique_
std::map< std::string, ros::Publisher > PublisherMap
const M_Picked & getSelection()
Ogre::Technique * fallback_depth_cull_technique_
The VisualizationManager class is the central manager class of rviz, holding all the Displays...
static void setPickColor(const Ogre::ColourValue &color, Ogre::MovableObject *object)
std::vector< CollObjectHandle > V_CollObject
Definition: forwards.h:46
boost::unordered_map< CollObjectHandle, SelectionHandler * > M_CollisionObjectToSelectionHandler
Ogre::TexturePtr depth_render_texture_
static void setPickHandle(CollObjectHandle handle, Ogre::MovableObject *object)
Ogre::Technique * fallback_depth_technique_
uint32_t colorToHandle(Ogre::PixelFormat fmt, uint32_t col)
Definition: forwards.h:66
Ogre::SceneNode * highlight_node_
VisualizationManager * vis_manager_
static void setPickColor(const Ogre::ColourValue &color, Ogre::SceneNode *node)
Ogre::Rectangle2D * highlight_rectangle_
Ogre::MaterialPtr fallback_pick_material_
Ogre::Technique * fallback_black_technique_
PropertyTreeModel * getPropertyModel()
Ogre::PixelBox depth_pixel_box_
boost::recursive_mutex global_mutex_
M_CollisionObjectToSelectionHandler objects_
uint32_t CollObjectHandle
Definition: forwards.h:45


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25