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
00031 #ifndef RVIZ_VISUALIZATION_MANAGER_H_
00032 #define RVIZ_VISUALIZATION_MANAGER_H_
00033
00034 #include "helpers/color.h"
00035 #include "properties/forwards.h"
00036
00037 #include <wx/event.h>
00038 #include <wx/stopwatch.h>
00039
00040 #include <boost/signal.hpp>
00041 #include <boost/thread.hpp>
00042
00043 #include <vector>
00044 #include <map>
00045 #include <set>
00046
00047 #include <ros/ros.h>
00048 #include <ros/callback_queue.h>
00049 #include <ros/time.h>
00050
00051 namespace Ogre
00052 {
00053 class Root;
00054 class SceneManager;
00055 class SceneNode;
00056 class Camera;
00057 class RaySceneQuery;
00058 }
00059
00060 namespace tf
00061 {
00062 class TransformListener;
00063 }
00064
00065 class wxTimerEvent;
00066 class wxTimer;
00067 class wxPropertyGrid;
00068 class wxPropertyGridEvent;
00069 class wxConfigBase;
00070 class wxKeyEvent;
00071 class wxIdleEvent;
00072
00073 namespace rviz
00074 {
00075
00076 class PropertyManager;
00077 class SelectionManager;
00078 class RenderPanel;
00079 class Display;
00080 class Tool;
00081 class ViewportMouseEvent;
00082 class WindowManagerInterface;
00083 class PluginManager;
00084 class PluginStatus;
00085 class FrameManager;
00086 class ViewController;
00087 typedef boost::shared_ptr<FrameManager> FrameManagerPtr;
00088
00089 typedef std::vector<std::string> V_string;
00090
00091 class DisplayWrapper;
00092 typedef std::vector<DisplayWrapper*> V_DisplayWrapper;
00093
00094 typedef boost::signal<void (DisplayWrapper*)> DisplayWrapperSignal;
00095 typedef boost::signal<void (const V_DisplayWrapper&)> DisplayWrappersSignal;
00096 typedef boost::signal<void (const V_string&)> FramesChangedSignal;
00097 typedef boost::signal<void (const boost::shared_ptr<wxConfigBase>&)> ConfigSignal;
00098 typedef boost::signal<void (Tool*)> ToolSignal;
00099 typedef boost::signal<void (const std::string&, const std::string&)> ViewControllerTypeAddedSignal;
00100 typedef boost::signal<void (ViewController*)> ViewControllerSignal;
00101 typedef boost::signal<void (void)> TimeSignal;
00102
00103 class DisplayTypeInfo;
00104 typedef boost::shared_ptr<DisplayTypeInfo> DisplayTypeInfoPtr;
00105
00106 class VisualizationManager : public wxEvtHandler
00107 {
00108 public:
00112 VisualizationManager(RenderPanel* render_panel, WindowManagerInterface* wm = 0);
00113 virtual ~VisualizationManager();
00114
00115 void initialize(const StatusCallback& cb = StatusCallback());
00116 void startUpdate();
00117
00125 DisplayWrapper* createDisplay( const std::string& package, const std::string& class_name, const std::string& name, bool enabled );
00126
00131 void removeDisplay( DisplayWrapper* display );
00136 void removeDisplay( const std::string& name );
00140 void removeAllDisplays();
00141
00142 template< class T >
00143 T* createTool( const std::string& name, char shortcut_key )
00144 {
00145 T* tool = new T( name, shortcut_key, this );
00146 addTool( tool );
00147
00148 return tool;
00149 }
00150
00151 void addTool( Tool* tool );
00152 Tool* getCurrentTool() { return current_tool_; }
00153 Tool* getTool( int index );
00154 void setCurrentTool( Tool* tool );
00155 void setDefaultTool( Tool* tool );
00156 Tool* getDefaultTool() { return default_tool_; }
00157
00162 void loadGeneralConfig( const boost::shared_ptr<wxConfigBase>& config, const StatusCallback& cb = StatusCallback() );
00167 void saveGeneralConfig( const boost::shared_ptr<wxConfigBase>& config );
00172 void loadDisplayConfig( const boost::shared_ptr<wxConfigBase>& config, const StatusCallback& cb = StatusCallback() );
00177 void saveDisplayConfig( const boost::shared_ptr<wxConfigBase>& config );
00178
00183 void setTargetFrame( const std::string& frame );
00184 std::string getTargetFrame();
00185
00190 void setFixedFrame( const std::string& frame );
00191 const std::string& getFixedFrame() { return fixed_frame_; }
00192
00197 DisplayWrapper* getDisplayWrapper( const std::string& name );
00198
00203 DisplayWrapper* getDisplayWrapper( Display* display );
00204
00205 PropertyManager* getPropertyManager() { return property_manager_; }
00206 PropertyManager* getToolPropertyManager() { return tool_property_manager_; }
00207
00208 bool isValidDisplay( const DisplayWrapper* display );
00209
00210 tf::TransformListener* getTFClient();
00211 Ogre::SceneManager* getSceneManager() { return scene_manager_; }
00212
00213 RenderPanel* getRenderPanel() { return render_panel_; }
00214
00215 typedef std::set<std::string> S_string;
00216 void getDisplayNames(S_string& displays);
00217 V_DisplayWrapper& getDisplays() { return displays_; }
00218
00219 void resetDisplays();
00220
00221 double getWallClock();
00222 double getROSTime();
00223 double getWallClockElapsed();
00224 double getROSTimeElapsed();
00225
00226 void handleChar( wxKeyEvent& event );
00227 void handleMouseEvent( ViewportMouseEvent& event );
00228
00229 void setBackgroundColor(const Color& c);
00230 const Color& getBackgroundColor();
00231
00232 void resetTime();
00233
00234 ViewController* getCurrentViewController() { return view_controller_; }
00235 std::string getCurrentViewControllerType();
00236 bool setCurrentViewControllerType(const std::string& type);
00237
00238 SelectionManager* getSelectionManager() { return selection_manager_; }
00239
00240 void lockRender() { render_mutex_.lock(); }
00241 void unlockRender() { render_mutex_.unlock(); }
00246 void queueRender();
00247
00248 WindowManagerInterface* getWindowManager() { return window_manager_; }
00249
00250 ros::CallbackQueueInterface* getUpdateQueue() { return ros::getGlobalCallbackQueue(); }
00251 ros::CallbackQueueInterface* getThreadedQueue() { return &threaded_queue_; }
00252
00253 PluginManager* getPluginManager() { return plugin_manager_; }
00254 FrameManager* getFrameManager() { return frame_manager_.get(); }
00255
00256 protected:
00261 bool addDisplay(DisplayWrapper* wrapper, bool enabled);
00262
00263 void addViewController(const std::string& class_name, const std::string& name);
00264
00266 void onUpdate( wxTimerEvent& event );
00267 void onIdle(wxIdleEvent& event);
00268
00269 void updateRelativeNode();
00270
00271 void incomingROSTime();
00272
00273 void updateTime();
00274 void updateFrames();
00275
00276 void onDisplayCreated(DisplayWrapper* wrapper);
00277
00278 void createColorMaterials();
00279
00280 void threadedQueueThreadFunc();
00281
00282 void onPluginUnloading(const PluginStatus& status);
00283
00284 Ogre::Root* ogre_root_;
00285 Ogre::SceneManager* scene_manager_;
00286
00287 wxTimer* update_timer_;
00288 ros::Time last_update_ros_time_;
00289 ros::WallTime last_update_wall_time_;
00290
00291 ros::CallbackQueue threaded_queue_;
00292 boost::thread_group threaded_queue_threads_;
00293 ros::NodeHandle update_nh_;
00294 ros::NodeHandle threaded_nh_;
00295 volatile bool shutting_down_;
00296
00297
00298 V_DisplayWrapper displays_;
00299
00300 typedef std::vector< Tool* > V_Tool;
00301 V_Tool tools_;
00302 Tool* current_tool_;
00303 Tool* default_tool_;
00304
00305 std::string target_frame_;
00306 std::string fixed_frame_;
00307
00308 PropertyManager* property_manager_;
00309 PropertyManager* tool_property_manager_;
00310 TFFramePropertyWPtr target_frame_property_;
00311 EditEnumPropertyWPtr fixed_frame_property_;
00312 StatusPropertyWPtr status_property_;
00313
00314 V_string available_frames_;
00315
00316 RenderPanel* render_panel_;
00317
00318 ros::WallTime wall_clock_begin_;
00319 ros::Time ros_time_begin_;
00320 ros::WallDuration wall_clock_elapsed_;
00321 ros::Duration ros_time_elapsed_;
00322
00323 Color background_color_;
00324 ColorPropertyWPtr background_color_property_;
00325
00326 float time_update_timer_;
00327 float frame_update_timer_;
00328
00329 ViewController* view_controller_;
00330
00331 SelectionManager* selection_manager_;
00332
00333 boost::mutex render_mutex_;
00334 uint32_t render_requested_;
00335 uint64_t frame_count_;
00336 ros::WallTime last_render_;
00337
00338 WindowManagerInterface* window_manager_;
00339
00340 PluginManager* plugin_manager_;
00341 FrameManagerPtr frame_manager_;
00342
00343 bool disable_update_;
00344 bool target_frame_is_fixed_frame_;
00345
00346 public:
00347 FramesChangedSignal& getFramesChangedSignal() { return frames_changed_; }
00348 DisplayWrapperSignal& getDisplayAddingSignal() { return display_adding_; }
00349 DisplayWrapperSignal& getDisplayAddedSignal() { return display_added_; }
00350 DisplayWrapperSignal& getDisplayRemovingSignal() { return display_removing_; }
00351 DisplayWrapperSignal& getDisplayRemovedSignal() { return display_removed_; }
00352 DisplayWrappersSignal& getDisplaysRemovingSignal() { return displays_removing_; }
00353 DisplayWrappersSignal& getDisplaysRemovedSignal() { return displays_removed_; }
00354 ConfigSignal& getDisplaysConfigLoadedSignal() { return displays_config_loaded_; }
00355 ConfigSignal& getDisplaysConfigSavingSignal() { return displays_config_saving_; }
00356 ConfigSignal& getGeneralConfigLoadedSignal() { return general_config_loaded_; }
00357 ConfigSignal& getGeneralConfigSavingSignal() { return general_config_saving_; }
00358 ToolSignal& getToolAddedSignal() { return tool_added_; }
00359 ToolSignal& getToolChangedSignal() { return tool_changed_; }
00360 ViewControllerTypeAddedSignal& getViewControllerTypeAddedSignal() { return view_controller_type_added_; }
00361 ViewControllerSignal& getViewControllerTypeChangedSignal() { return view_controller_type_changed_; }
00362 TimeSignal& getTimeChangedSignal() { return time_changed_; }
00363
00364 private:
00365 FramesChangedSignal frames_changed_;
00366 DisplayWrapperSignal display_adding_;
00367 DisplayWrapperSignal display_added_;
00368 DisplayWrapperSignal display_removing_;
00369 DisplayWrapperSignal display_removed_;
00370 DisplayWrappersSignal displays_removing_;
00371 DisplayWrappersSignal displays_removed_;
00372 ConfigSignal displays_config_loaded_;
00373 ConfigSignal displays_config_saving_;
00374 ConfigSignal general_config_loaded_;
00375 ConfigSignal general_config_saving_;
00376 ToolSignal tool_added_;
00377 ToolSignal tool_changed_;
00378 ViewControllerTypeAddedSignal view_controller_type_added_;
00379 ViewControllerSignal view_controller_type_changed_;
00380 TimeSignal time_changed_;
00381 };
00382
00383 }
00384
00385 #endif