00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef RVIZ_SELECTION_MANAGER_H
00031 #define RVIZ_SELECTION_MANAGER_H
00032
00033 #include <QObject>
00034
00035 #include "forwards.h"
00036 #include "selection_handler.h"
00037
00038 #include <boost/shared_ptr.hpp>
00039 #include <boost/unordered_map.hpp>
00040 #include <boost/thread/recursive_mutex.hpp>
00041
00042 #include <OGRE/OgreTexture.h>
00043 #include <OGRE/OgreMaterial.h>
00044 #include <OGRE/OgreMaterialManager.h>
00045 #include <OGRE/OgreMovableObject.h>
00046 #include <OGRE/OgreRenderQueueListener.h>
00047
00048 #include <vector>
00049 #include <set>
00050
00051 namespace rviz
00052 {
00053 class Object;
00054 }
00055
00056 namespace Ogre
00057 {
00058 class SceneManager;
00059 class Viewport;
00060 class WireBoundingBox;
00061 class SceneNode;
00062 class Material;
00063 class PixelBox;
00064 class Rectangle2D;
00065 class MovableObject;
00066 }
00067
00068 namespace rviz
00069 {
00070 class PropertyTreeModel;
00071 class ViewportMouseEvent;
00072 class VisualizationManager;
00073
00074 class SelectionManager: public QObject, public Ogre::MaterialManager::Listener, public Ogre::RenderQueueListener
00075 {
00076 Q_OBJECT
00077 public:
00078 enum SelectType
00079 {
00080 Add,
00081 Remove,
00082 Replace
00083 };
00084
00085 SelectionManager(VisualizationManager* manager);
00086 ~SelectionManager();
00087
00088 void initialize( bool debug = false );
00089
00090 void clearHandlers();
00091 void addObject(CollObjectHandle obj, const SelectionHandlerPtr& handler);
00092 void removeObject(CollObjectHandle obj);
00093
00094
00095 void highlight(Ogre::Viewport* viewport, int x1, int y1, int x2, int y2);
00096 void removeHighlight();
00097
00098
00099 void select(Ogre::Viewport* viewport, int x1, int y1, int x2, int y2, SelectType type);
00100
00101
00102
00103 void pick(Ogre::Viewport* viewport, int x1, int y1, int x2, int y2, M_Picked& results, bool single_render_pass=false );
00104
00105
00106 CollObjectHandle createCollisionForObject(Object* obj, const SelectionHandlerPtr& handler, CollObjectHandle coll = 0);
00107 CollObjectHandle createCollisionForEntity(Ogre::Entity* entity, const SelectionHandlerPtr& handler, CollObjectHandle coll = 0);
00108
00109 void update();
00110
00111
00112 void setSelection(const M_Picked& objs);
00113 void addSelection(const M_Picked& objs);
00114 void removeSelection(const M_Picked& objs);
00115 const M_Picked& getSelection() { return selection_; }
00116
00117 SelectionHandlerPtr getHandler(CollObjectHandle obj);
00118
00119
00120 Ogre::Technique *addPickTechnique(CollObjectHandle handle, const Ogre::MaterialPtr& material);
00121
00122
00123 virtual Ogre::Technique* handleSchemeNotFound(unsigned short scheme_index,
00124 const Ogre::String& scheme_name,
00125 Ogre::Material* original_material,
00126 unsigned short lod_index,
00127 const Ogre::Renderable* rend);
00128
00129
00130 CollObjectHandle createHandle();
00131
00132
00133 void enableInteraction( bool enable );
00134 bool getInteractionEnabled() { return interaction_enabled_; }
00135
00136
00137 void focusOnSelection();
00138
00139
00140 void setTextureSize( unsigned size );
00141
00145 bool get3DPoint( Ogre::Viewport* viewport, int x, int y, Ogre::Vector3& result_point );
00146
00147
00148 void renderQueueStarted( uint8_t queueGroupId,
00149 const std::string& invocation,
00150 bool& skipThisInvocation );
00151
00152 PropertyTreeModel* getPropertyModel() { return property_model_; }
00153
00154 private Q_SLOTS:
00157 void updateProperties();
00158
00159 private:
00160 void selectionAdded( const M_Picked& added );
00161 void selectionRemoved( const M_Picked& removed );
00162
00163 std::pair<Picked, bool> addSelectedObject(const Picked& obj);
00164 void removeSelectedObject(const Picked& obj);
00165
00166 void setHighlightRect(Ogre::Viewport* viewport, int x1, int y1, int x2, int y2);
00167
00169 void renderAndUnpack(Ogre::Viewport* viewport, uint32_t pass, int x1, int y1, int x2, int y2, V_Pixel& pixels);
00170
00172 bool render( Ogre::Viewport* viewport, Ogre::TexturePtr tex,
00173 int x1, int y1, int x2, int y2,
00174 Ogre::PixelBox& dst_box, std::string material_scheme,
00175 unsigned texture_size );
00176
00177 void unpackColors(const Ogre::PixelBox& box, V_Pixel& pixels);
00178
00179 void initDepthFinder();
00180
00181
00182 void setDebugVisibility( bool visible );
00183
00184 VisualizationManager* vis_manager_;
00185
00186 boost::recursive_mutex global_mutex_;
00187
00188 typedef boost::unordered_map<CollObjectHandle, SelectionHandlerPtr> M_CollisionObjectToSelectionHandler;
00189 M_CollisionObjectToSelectionHandler objects_;
00190
00191 bool highlight_enabled_;
00192
00193 struct Highlight
00194 {
00195 int x1;
00196 int y1;
00197 int x2;
00198 int y2;
00199 Ogre::Viewport* viewport;
00200 };
00201 Highlight highlight_;
00202
00203 M_Picked selection_;
00204
00205 const static uint32_t s_num_render_textures_ = 2;
00206 Ogre::TexturePtr render_textures_[s_num_render_textures_];
00207 Ogre::PixelBox pixel_boxes_[s_num_render_textures_];
00208
00209
00210 Ogre::TexturePtr depth_render_texture_;
00211 uint32_t depth_texture_size_;
00212 Ogre::SceneNode* debug_depth_node_;
00213 Ogre::MaterialPtr debug_depth_material_;
00214 Ogre::PixelBox depth_pixel_box_;
00215
00216 uint32_t uid_counter_;
00217
00218 Ogre::Rectangle2D* highlight_rectangle_;
00219 Ogre::SceneNode* highlight_node_;
00220 Ogre::Camera *camera_;
00221
00222 V_Pixel pixel_buffer_;
00223
00224 bool interaction_enabled_;
00225
00226 Ogre::SceneNode* debug_nodes_[s_num_render_textures_];
00227 Ogre::MaterialPtr debug_material_[s_num_render_textures_];
00228 bool debug_mode_;
00229
00230 Ogre::MaterialPtr fallback_pick_material_;
00231 Ogre::Technique *fallback_pick_technique_;
00232
00233 uint32_t texture_size_;
00234
00235 PropertyTreeModel* property_model_;
00236 bool setting_;
00237 };
00238
00239 }
00240
00241 #endif // RVIZ_SELECTION_MANAGER_H