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 #include "visualization_manager.h"
00031 #include "selection/selection_manager.h"
00032 #include "plugin/plugin_manager.h"
00033 #include "plugin/display_type_info.h"
00034 #include "render_panel.h"
00035 #include "displays_panel.h"
00036 #include "viewport_mouse_event.h"
00037 #include "frame_manager.h"
00038 #include "view_controller.h"
00039 #include "view_controllers/orbit_view_controller.h"
00040 #include "view_controllers/fps_view_controller.h"
00041 #include "view_controllers/fixed_orientation_ortho_view_controller.h"
00042
00043 #include "display.h"
00044 #include "display_wrapper.h"
00045 #include "properties/property_manager.h"
00046 #include "properties/property.h"
00047 #include "common.h"
00048 #include "new_display_dialog.h"
00049
00050 #include "tools/tool.h"
00051 #include "tools/move_tool.h"
00052 #include "tools/goal_tool.h"
00053 #include "tools/initial_pose_tool.h"
00054 #include "tools/selection_tool.h"
00055
00056 #include <ogre_tools/wx_ogre_render_window.h>
00057
00058 #include <tf/transform_listener.h>
00059
00060 #include <ros/package.h>
00061
00062 #include <wx/timer.h>
00063 #include <wx/propgrid/propgrid.h>
00064 #include <wx/confbase.h>
00065
00066 #include <boost/bind.hpp>
00067
00068 #include <OGRE/OgreRoot.h>
00069 #include <OGRE/OgreSceneManager.h>
00070 #include <OGRE/OgreSceneNode.h>
00071 #include <OGRE/OgreLight.h>
00072 #include <OGRE/OgreViewport.h>
00073 #include <OGRE/OgreMaterialManager.h>
00074 #include <OGRE/OgreMaterial.h>
00075 #include <OGRE/OgreRenderWindow.h>
00076
00077 #include <algorithm>
00078
00079 namespace rviz
00080 {
00081
00082 VisualizationManager::VisualizationManager( RenderPanel* render_panel, WindowManagerInterface* wm )
00083 : ogre_root_( Ogre::Root::getSingletonPtr() )
00084 , update_timer_(0)
00085 , shutting_down_(false)
00086 , current_tool_( NULL )
00087 , render_panel_( render_panel )
00088 , time_update_timer_(0.0f)
00089 , frame_update_timer_(0.0f)
00090 , view_controller_(0)
00091 , render_requested_(1)
00092 , frame_count_(0)
00093 , window_manager_(wm)
00094 , disable_update_(false)
00095 , target_frame_is_fixed_frame_(false)
00096 {
00097 initializeCommon();
00098
00099 frame_manager_ = FrameManager::instance();
00100
00101 render_panel->setAutoRender(false);
00102
00103 threaded_nh_.setCallbackQueue(&threaded_queue_);
00104
00105 scene_manager_ = ogre_root_->createSceneManager( Ogre::ST_GENERIC );
00106
00107 Ogre::Light* directional_light = scene_manager_->createLight( "MainDirectional" );
00108 directional_light->setType( Ogre::Light::LT_DIRECTIONAL );
00109 directional_light->setDirection( Ogre::Vector3( 0, -1, 1 ) );
00110 directional_light->setDiffuseColour( Ogre::ColourValue( 1.0f, 1.0f, 1.0f ) );
00111
00112 property_manager_ = new PropertyManager();
00113 tool_property_manager_ = new PropertyManager();
00114
00115 CategoryPropertyWPtr options_category = property_manager_->createCategory( ".Global Options", "", CategoryPropertyWPtr(), this );
00116 target_frame_property_ = property_manager_->createProperty<TFFrameProperty>( "Target Frame", "", boost::bind( &VisualizationManager::getTargetFrame, this ),
00117 boost::bind( &VisualizationManager::setTargetFrame, this, _1 ), options_category, this );
00118 setPropertyHelpText(target_frame_property_, "Reference frame for the 3D camera view.");
00119 fixed_frame_property_ = property_manager_->createProperty<EditEnumProperty>( "Fixed Frame", "", boost::bind( &VisualizationManager::getFixedFrame, this ),
00120 boost::bind( &VisualizationManager::setFixedFrame, this, _1 ), options_category, this );
00121 setPropertyHelpText(fixed_frame_property_, "Frame into which all data is transformed before being displayed.");
00122 background_color_property_ = property_manager_->createProperty<ColorProperty>( "Background Color", "", boost::bind( &VisualizationManager::getBackgroundColor, this ),
00123 boost::bind( &VisualizationManager::setBackgroundColor, this, _1 ), options_category, this );
00124 setPropertyHelpText(background_color_property_, "Background color for the 3D view.");
00125 status_property_ = property_manager_->createStatus(".Global Status", "", CategoryPropertyWPtr(), this);
00126
00127 CategoryPropertyPtr cat_prop = options_category.lock();
00128 cat_prop->collapse();
00129
00130 setBackgroundColor(Color(0.0f, 0.0f, 0.0f));
00131
00132 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(ROS_PACKAGE_NAME );
00133
00134 createColorMaterials();
00135
00136 selection_manager_ = new SelectionManager(this);
00137
00138 threaded_queue_threads_.create_thread(boost::bind(&VisualizationManager::threadedQueueThreadFunc, this));
00139
00140 plugin_manager_ = new PluginManager;
00141 std::string rviz_path = ros::package::getPath("rviz");
00142 plugin_manager_->loadDescription(rviz_path + "/lib/default_plugin.yaml");
00143 plugin_manager_->loadDescriptions();
00144
00145 {
00146 const L_Plugin& plugins = plugin_manager_->getPlugins();
00147 L_Plugin::const_iterator it = plugins.begin();
00148 L_Plugin::const_iterator end = plugins.end();
00149 for (; it != end; ++it)
00150 {
00151 const PluginPtr& plugin = *it;
00152 plugin->getUnloadingSignal().connect(boost::bind(&VisualizationManager::onPluginUnloading, this, _1));
00153 }
00154 }
00155 }
00156
00157 VisualizationManager::~VisualizationManager()
00158 {
00159 if (update_timer_)
00160 {
00161 Disconnect( wxEVT_TIMER, update_timer_->GetId(), wxTimerEventHandler( VisualizationManager::onUpdate ), NULL, this );
00162 update_timer_->Stop();
00163 delete update_timer_;
00164 }
00165
00166 shutting_down_ = true;
00167 threaded_queue_threads_.join_all();
00168
00169 if (selection_manager_)
00170 {
00171 selection_manager_->setSelection(M_Picked());
00172 }
00173
00174 V_DisplayWrapper::iterator it = displays_.begin();
00175 V_DisplayWrapper::iterator end = displays_.end();
00176 for (; it != end; ++it)
00177 {
00178 delete *it;
00179 }
00180 displays_.clear();
00181
00182 V_Tool::iterator tool_it = tools_.begin();
00183 V_Tool::iterator tool_end = tools_.end();
00184 for ( ; tool_it != tool_end; ++tool_it )
00185 {
00186 delete *tool_it;
00187 }
00188 tools_.clear();
00189
00190 delete plugin_manager_;
00191 delete property_manager_;
00192 delete tool_property_manager_;
00193
00194 delete selection_manager_;
00195
00196 if (ogre_root_)
00197 {
00198 ogre_root_->destroySceneManager( scene_manager_ );
00199 }
00200 }
00201
00202 void VisualizationManager::initialize(const StatusCallback& cb)
00203 {
00204 if (cb)
00205 {
00206 cb("Initializing TF");
00207 }
00208
00209 setFixedFrame("/map");
00210 setTargetFrame(FIXED_FRAME_STRING);
00211
00212 render_panel_->getCamera()->setPosition(0, 10, 15);
00213 render_panel_->getCamera()->setNearClipDistance(0.01f);
00214 render_panel_->getCamera()->lookAt(0, 0, 0);
00215
00216 addViewController(OrbitViewController::getClassNameStatic(), "Orbit");
00217 addViewController(FPSViewController::getClassNameStatic(), "FPS");
00218 addViewController(FixedOrientationOrthoViewController::getClassNameStatic(), "TopDownOrtho");
00219 setCurrentViewControllerType(OrbitViewController::getClassNameStatic());
00220
00221 MoveTool* move_tool = createTool< MoveTool >( "Move Camera", 'm' );
00222 setCurrentTool( move_tool );
00223 setDefaultTool( move_tool );
00224
00225 createTool< SelectionTool >( "Select", 's' );
00226 createTool< GoalTool >( "2D Nav Goal", 'g' );
00227 createTool< InitialPoseTool >( "2D Pose Estimate", 'p' );
00228
00229 selection_manager_->initialize();
00230
00231 last_update_ros_time_ = ros::Time::now();
00232 last_update_wall_time_ = ros::WallTime::now();
00233 }
00234
00235 void VisualizationManager::startUpdate()
00236 {
00237 update_timer_ = new wxTimer( this );
00238 update_timer_->Start( 33 );
00239 Connect( update_timer_->GetId(), wxEVT_TIMER, wxTimerEventHandler( VisualizationManager::onUpdate ), NULL, this );
00240
00241 wxTheApp->Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(VisualizationManager::onIdle), NULL, this);
00242 }
00243
00244 void createColorMaterial(const std::string& name, const Ogre::ColourValue& color)
00245 {
00246 Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create( name, ROS_PACKAGE_NAME );
00247 mat->setAmbient(color * 0.5f);
00248 mat->setDiffuse(color);
00249 mat->setSelfIllumination(color);
00250 mat->setLightingEnabled(true);
00251 mat->setReceiveShadows(false);
00252 }
00253
00254 void VisualizationManager::createColorMaterials()
00255 {
00256 createColorMaterial("RVIZ/Red", Ogre::ColourValue(1.0f, 0.0f, 0.0f, 1.0f));
00257 createColorMaterial("RVIZ/Green", Ogre::ColourValue(0.0f, 1.0f, 0.0f, 1.0f));
00258 createColorMaterial("RVIZ/Blue", Ogre::ColourValue(0.0f, 0.0f, 1.0f, 1.0f));
00259 createColorMaterial("RVIZ/Cyan", Ogre::ColourValue(0.0f, 1.0f, 1.0f, 1.0f));
00260 }
00261
00262 void VisualizationManager::getDisplayNames(S_string& displays)
00263 {
00264 V_DisplayWrapper::iterator vis_it = displays_.begin();
00265 V_DisplayWrapper::iterator vis_end = displays_.end();
00266 for ( ; vis_it != vis_end; ++vis_it )
00267 {
00268 displays.insert((*vis_it)->getName());
00269 }
00270 }
00271
00272 std::string VisualizationManager::getTargetFrame()
00273 {
00274 if (target_frame_is_fixed_frame_)
00275 {
00276 return FIXED_FRAME_STRING;
00277 }
00278
00279 return target_frame_;
00280 }
00281
00282 void VisualizationManager::queueRender()
00283 {
00284 if (!render_requested_)
00285 {
00286 wxWakeUpIdle();
00287 }
00288
00289 render_requested_ = 1;
00290 }
00291
00292 void VisualizationManager::onUpdate( wxTimerEvent& event )
00293 {
00294 if (disable_update_)
00295 {
00296 return;
00297 }
00298
00299 disable_update_ = true;
00300
00301 ros::WallTime update_start = ros::WallTime::now();
00302
00303 ros::WallDuration wall_diff = ros::WallTime::now() - last_update_wall_time_;
00304 ros::Duration ros_diff = ros::Time::now() - last_update_ros_time_;
00305 float wall_dt = wall_diff.toSec();
00306 float ros_dt = ros_diff.toSec();
00307
00308 if (ros_dt < 0.0)
00309 {
00310 resetTime();
00311 }
00312
00313 frame_manager_->update();
00314
00315 ros::spinOnce();
00316
00317 last_update_ros_time_ = ros::Time::now();
00318 last_update_wall_time_ = ros::WallTime::now();
00319
00320 V_DisplayWrapper::iterator vis_it = displays_.begin();
00321 V_DisplayWrapper::iterator vis_end = displays_.end();
00322 for ( ; vis_it != vis_end; ++vis_it )
00323 {
00324 Display* display = (*vis_it)->getDisplay();
00325
00326 if ( display && display->isEnabled() )
00327 {
00328 display->update( wall_dt, ros_dt );
00329 }
00330 }
00331
00332 view_controller_->update(wall_dt, ros_dt);
00333
00334 time_update_timer_ += wall_dt;
00335
00336 if ( time_update_timer_ > 0.1f )
00337 {
00338 time_update_timer_ = 0.0f;
00339
00340 updateTime();
00341 }
00342
00343 frame_update_timer_ += wall_dt;
00344
00345 if (frame_update_timer_ > 1.0f)
00346 {
00347 frame_update_timer_ = 0.0f;
00348
00349 updateFrames();
00350 }
00351
00352 selection_manager_->update();
00353
00354 if (frame_count_ % 6 == 0)
00355 {
00356 property_manager_->update();
00357 tool_property_manager_->update();
00358 }
00359
00360 current_tool_->update(wall_dt, ros_dt);
00361
00362 disable_update_ = false;
00363
00364 ++frame_count_;
00365
00366 wxWakeUpIdle();
00367 }
00368
00369 void VisualizationManager::onIdle(wxIdleEvent& evt)
00370 {
00371 ros::WallTime cur = ros::WallTime::now();
00372 double dt = (cur - last_render_).toSec();
00373
00374 if (dt > 0.1f)
00375 {
00376 render_requested_ = 1;
00377 }
00378
00379
00380 if (render_requested_ && dt > 0.016f)
00381 {
00382 render_requested_ = 0;
00383 last_render_ = cur;
00384
00385 boost::mutex::scoped_lock lock(render_mutex_);
00386
00387
00388 ogre_root_->renderOneFrame();
00389
00390
00391
00392 }
00393
00394 evt.Skip();
00395 }
00396
00397 void VisualizationManager::updateTime()
00398 {
00399 if ( ros_time_begin_.isZero() )
00400 {
00401 ros_time_begin_ = ros::Time::now();
00402 }
00403
00404 ros_time_elapsed_ = ros::Time::now() - ros_time_begin_;
00405
00406 if ( wall_clock_begin_.isZero() )
00407 {
00408 wall_clock_begin_ = ros::WallTime::now();
00409 }
00410
00411 wall_clock_elapsed_ = ros::WallTime::now() - wall_clock_begin_;
00412
00413 time_changed_();
00414 }
00415
00416 void VisualizationManager::updateFrames()
00417 {
00418 typedef std::vector<std::string> V_string;
00419 V_string frames;
00420 frame_manager_->getTFClient()->getFrameStrings( frames );
00421 std::sort(frames.begin(), frames.end());
00422
00423 EditEnumPropertyPtr target_prop = target_frame_property_.lock();
00424 EditEnumPropertyPtr fixed_prop = fixed_frame_property_.lock();
00425 StatusPropertyPtr status_prop = status_property_.lock();
00426 ROS_ASSERT(target_prop);
00427 ROS_ASSERT(fixed_prop);
00428 ROS_ASSERT(status_prop);
00429
00430 if (frames != available_frames_)
00431 {
00432 fixed_prop->clear();
00433
00434 V_string::iterator it = frames.begin();
00435 V_string::iterator end = frames.end();
00436 for (; it != end; ++it)
00437 {
00438 const std::string& frame = *it;
00439
00440 if (frame.empty())
00441 {
00442 continue;
00443 }
00444
00445 fixed_prop->addOption(frame);
00446 }
00447
00448 available_frames_ = frames;
00449
00450 frames_changed_(frames);
00451 }
00452
00453
00454 std::string error;
00455 if (frame_manager_->frameHasProblems(fixed_frame_, ros::Time(), error))
00456 {
00457 if (frames.empty())
00458 {
00459 fixed_prop->setToWarn();
00460 std::stringstream ss;
00461 ss << "No tf data. Actual error: " << error;
00462 status_prop->setStatus(status_levels::Warn, "Fixed Frame", ss.str());
00463 }
00464 else
00465 {
00466 fixed_prop->setToError();
00467 status_prop->setStatus(status_levels::Error, "Fixed Frame", error);
00468 }
00469 }
00470 else
00471 {
00472 fixed_prop->setToOK();
00473 status_prop->setStatus(status_levels::Ok, "Fixed Frame", "OK");
00474 }
00475
00476 if (frame_manager_->transformHasProblems(target_frame_, ros::Time(), error))
00477 {
00478 target_prop->setToError();
00479 status_prop->setStatus(status_levels::Error, "Target Frame", error);
00480 }
00481 else
00482 {
00483 target_prop->setToOK();
00484 status_prop->setStatus(status_levels::Ok, "Target Frame", "OK");
00485 }
00486 }
00487
00488 tf::TransformListener* VisualizationManager::getTFClient()
00489 {
00490 return frame_manager_->getTFClient();
00491 }
00492
00493 void VisualizationManager::resetTime()
00494 {
00495 resetDisplays();
00496 frame_manager_->getTFClient()->clear();
00497
00498 ros_time_begin_ = ros::Time();
00499 wall_clock_begin_ = ros::WallTime();
00500
00501 queueRender();
00502 }
00503
00504 void VisualizationManager::onDisplayCreated(DisplayWrapper* wrapper)
00505 {
00506 Display* display = wrapper->getDisplay();
00507 display->setRenderCallback( boost::bind( &VisualizationManager::queueRender, this ) );
00508 display->setLockRenderCallback( boost::bind( &VisualizationManager::lockRender, this ) );
00509 display->setUnlockRenderCallback( boost::bind( &VisualizationManager::unlockRender, this ) );
00510
00511 display->setTargetFrame( target_frame_ );
00512 display->setFixedFrame( fixed_frame_ );
00513 }
00514
00515 bool VisualizationManager::addDisplay(DisplayWrapper* wrapper, bool enabled)
00516 {
00517 if (getDisplayWrapper(wrapper->getName()))
00518 {
00519 ROS_ERROR("Display of name [%s] already exists", wrapper->getName().c_str());
00520 return false;
00521 }
00522
00523 display_adding_(wrapper);
00524 displays_.push_back(wrapper);
00525
00526 wrapper->getDisplayCreatedSignal().connect(boost::bind(&VisualizationManager::onDisplayCreated, this, _1));
00527 wrapper->setPropertyManager( property_manager_, CategoryPropertyWPtr() );
00528 wrapper->createDisplay();
00529
00530 display_added_(wrapper);
00531
00532 wrapper->setEnabled(enabled);
00533
00534 return true;
00535 }
00536
00537 void VisualizationManager::removeDisplay( DisplayWrapper* display )
00538 {
00539 V_DisplayWrapper::iterator it = std::find(displays_.begin(), displays_.end(), display);
00540 ROS_ASSERT( it != displays_.end() );
00541
00542 display_removing_(display);
00543
00544 displays_.erase( it );
00545
00546 display_removed_(display);
00547
00548 delete display;
00549
00550 queueRender();
00551 }
00552
00553 void VisualizationManager::removeAllDisplays()
00554 {
00555 displays_removing_(displays_);
00556
00557 while (!displays_.empty())
00558 {
00559 removeDisplay(displays_.back());
00560 }
00561
00562 displays_removed_(V_DisplayWrapper());
00563 }
00564
00565 void VisualizationManager::removeDisplay( const std::string& name )
00566 {
00567 DisplayWrapper* display = getDisplayWrapper( name );
00568
00569 if ( !display )
00570 {
00571 return;
00572 }
00573
00574 removeDisplay( display );
00575 }
00576
00577 void VisualizationManager::resetDisplays()
00578 {
00579 V_DisplayWrapper::iterator vis_it = displays_.begin();
00580 V_DisplayWrapper::iterator vis_end = displays_.end();
00581 for ( ; vis_it != vis_end; ++vis_it )
00582 {
00583 Display* display = (*vis_it)->getDisplay();
00584
00585 if (display)
00586 {
00587 display->reset();
00588 }
00589 }
00590 }
00591
00592 void VisualizationManager::addTool( Tool* tool )
00593 {
00594 tools_.push_back( tool );
00595
00596 tool_added_(tool);
00597 }
00598
00599 void VisualizationManager::setCurrentTool( Tool* tool )
00600 {
00601 if ( current_tool_ )
00602 {
00603 current_tool_->deactivate();
00604 }
00605
00606 current_tool_ = tool;
00607 current_tool_->activate();
00608
00609 tool_changed_(tool);
00610 }
00611
00612 void VisualizationManager::setDefaultTool( Tool* tool )
00613 {
00614 default_tool_ = tool;
00615 }
00616
00617 Tool* VisualizationManager::getTool( int index )
00618 {
00619 ROS_ASSERT( index >= 0 );
00620 ROS_ASSERT( index < (int)tools_.size() );
00621
00622 return tools_[ index ];
00623 }
00624
00625 DisplayWrapper* VisualizationManager::getDisplayWrapper( const std::string& name )
00626 {
00627 V_DisplayWrapper::iterator vis_it = displays_.begin();
00628 V_DisplayWrapper::iterator vis_end = displays_.end();
00629 for ( ; vis_it != vis_end; ++vis_it )
00630 {
00631 DisplayWrapper* wrapper = *vis_it;
00632 if ( wrapper->getName() == name )
00633 {
00634 return wrapper;
00635 }
00636 }
00637
00638 return 0;
00639 }
00640
00641 DisplayWrapper* VisualizationManager::getDisplayWrapper( Display* display )
00642 {
00643 V_DisplayWrapper::iterator vis_it = displays_.begin();
00644 V_DisplayWrapper::iterator vis_end = displays_.end();
00645 for ( ; vis_it != vis_end; ++vis_it )
00646 {
00647 DisplayWrapper* wrapper = *vis_it;
00648 if ( wrapper->getDisplay() == display )
00649 {
00650 return wrapper;
00651 }
00652 }
00653
00654 return 0;
00655 }
00656
00657 #define CAMERA_TYPE wxT("Camera Type")
00658 #define CAMERA_CONFIG wxT("Camera Config")
00659
00660 void VisualizationManager::loadGeneralConfig( const boost::shared_ptr<wxConfigBase>& config, const StatusCallback& cb )
00661 {
00662
00664 wxString camera_type;
00665 if (config->Read(CAMERA_TYPE, &camera_type))
00666 {
00667 if (setCurrentViewControllerType((const char*)camera_type.char_str()))
00668 {
00669 wxString camera_config;
00670 if (config->Read(CAMERA_CONFIG, &camera_config))
00671 {
00672 view_controller_->fromString((const char*)camera_config.char_str());
00673 }
00674 }
00675 }
00676
00677 if (cb)
00678 {
00679 cb("Loading plugins");
00680 }
00681
00682 plugin_manager_->loadConfig(config);
00683
00684 general_config_loaded_(config);
00685 }
00686
00687 void VisualizationManager::saveGeneralConfig( const boost::shared_ptr<wxConfigBase>& config )
00688 {
00689 plugin_manager_->saveConfig(config);
00690 general_config_saving_(config);
00691 }
00692
00693 void VisualizationManager::loadDisplayConfig( const boost::shared_ptr<wxConfigBase>& config, const StatusCallback& cb )
00694 {
00695 disable_update_ = true;
00696
00697 if (cb)
00698 {
00699 cb("Creating displays");
00700 }
00701
00702 int i = 0;
00703 while (1)
00704 {
00705 wxString name, package, class_name, type;
00706 name.Printf( wxT("Display%d/Name"), i );
00707 package.Printf( wxT("Display%d/Package"), i );
00708 class_name.Printf( wxT("Display%d/ClassName"), i );
00709 type.Printf(wxT("Display%d/Type"), i);
00710
00711 wxString vis_name, vis_package, vis_class, vis_type;
00712 if (!config->Read(name, &vis_name))
00713 {
00714 break;
00715 }
00716
00717 if (!config->Read(type, &vis_type))
00718 {
00719 if (!config->Read(package, &vis_package))
00720 {
00721 break;
00722 }
00723
00724 if (!config->Read(class_name, &vis_class))
00725 {
00726 break;
00727 }
00728 }
00729
00730
00731 if (!vis_type.IsEmpty())
00732 {
00733 std::string type = (const char*)vis_type.char_str();
00734 PluginPtr plugin = plugin_manager_->getPluginByDisplayName(type);
00735 if (plugin)
00736 {
00737 const DisplayTypeInfoPtr& info = plugin->getDisplayTypeInfoByDisplayName(type);
00738 createDisplay(plugin->getPackageName(), info->class_name, (const char*)vis_name.char_str(), false);
00739 }
00740 else
00741 {
00742 ROS_WARN("Display type [%s] no longer exists for display [%s]", type.c_str(), (const char*)vis_name.char_str());
00743 }
00744 }
00745 else
00746 {
00747 createDisplay((const char*)vis_package.char_str(), (const char*)vis_class.char_str(), (const char*)vis_name.char_str(), false);
00748 }
00749
00750 ++i;
00751 }
00752
00753 property_manager_->load( config, cb );
00754 tool_property_manager_->load( config, cb );
00755
00756 wxString camera_type;
00757 if (config->Read(CAMERA_TYPE, &camera_type))
00758 {
00759 if (setCurrentViewControllerType((const char*)camera_type.char_str()))
00760 {
00761 wxString camera_config;
00762 if (config->Read(CAMERA_CONFIG, &camera_config))
00763 {
00764 view_controller_->fromString((const char*)camera_config.char_str());
00765 }
00766 }
00767 }
00768
00769 displays_config_loaded_(config);
00770
00771 disable_update_ = false;
00772 }
00773
00774 void VisualizationManager::saveDisplayConfig( const boost::shared_ptr<wxConfigBase>& config )
00775 {
00776 int i = 0;
00777 V_DisplayWrapper::iterator vis_it = displays_.begin();
00778 V_DisplayWrapper::iterator vis_end = displays_.end();
00779 for ( ; vis_it != vis_end; ++vis_it, ++i )
00780 {
00781 DisplayWrapper* wrapper = *vis_it;
00782
00783 wxString name, package, class_name;
00784 name.Printf( wxT("Display%d/Name"), i );
00785 package.Printf( wxT("Display%d/Package"), i );
00786 class_name.Printf( wxT("Display%d/ClassName"), i );
00787 config->Write( name, wxString::FromAscii( wrapper->getName().c_str() ) );
00788 config->Write( package, wxString::FromAscii( wrapper->getPackage().c_str() ) );
00789 config->Write( class_name, wxString::FromAscii( wrapper->getClassName().c_str() ) );
00790 }
00791
00792 property_manager_->save( config );
00793 tool_property_manager_->save( config );
00794
00795 if (view_controller_)
00796 {
00797 config->Write(CAMERA_TYPE, wxString::FromAscii(view_controller_->getClassName().c_str()));
00798 config->Write(CAMERA_CONFIG, wxString::FromAscii(view_controller_->toString().c_str()));
00799 }
00800
00801 displays_config_saving_(config);
00802 }
00803
00804 DisplayWrapper* VisualizationManager::createDisplay( const std::string& package, const std::string& class_name, const std::string& name, bool enabled )
00805 {
00806 PluginPtr plugin = plugin_manager_->getPluginByPackage(package);
00807 if (!plugin)
00808 {
00809 ROS_ERROR("Package [%s] does not have any plugins loaded available, for display of type [%s], and name [%s]", package.c_str(), class_name.c_str(), name.c_str());
00810 }
00811
00812 DisplayWrapper* wrapper = new DisplayWrapper(package, class_name, plugin, name, this);
00813 if (addDisplay(wrapper, enabled))
00814 {
00815 return wrapper;
00816 }
00817 else
00818 {
00819 delete wrapper;
00820 return 0;
00821 }
00822 }
00823
00824 void VisualizationManager::setTargetFrame( const std::string& _frame )
00825 {
00826 target_frame_is_fixed_frame_ = false;
00827 std::string frame = _frame;
00828 if (frame == FIXED_FRAME_STRING)
00829 {
00830 frame = fixed_frame_;
00831 target_frame_is_fixed_frame_ = true;
00832 }
00833
00834 std::string remapped_name = frame_manager_->getTFClient()->resolve(frame);
00835
00836 if (target_frame_ == remapped_name)
00837 {
00838 return;
00839 }
00840
00841 target_frame_ = remapped_name;
00842
00843 V_DisplayWrapper::iterator it = displays_.begin();
00844 V_DisplayWrapper::iterator end = displays_.end();
00845 for ( ; it != end; ++it )
00846 {
00847 Display* display = (*it)->getDisplay();
00848
00849 if (display)
00850 {
00851 display->setTargetFrame(target_frame_);
00852 }
00853 }
00854
00855 propertyChanged(target_frame_property_);
00856
00857 if (view_controller_)
00858 {
00859 view_controller_->setReferenceFrame(target_frame_);
00860 }
00861 }
00862
00863 void VisualizationManager::setFixedFrame( const std::string& frame )
00864 {
00865 std::string remapped_name = frame_manager_->getTFClient()->resolve(frame);
00866
00867 if (fixed_frame_ == remapped_name)
00868 {
00869 return;
00870 }
00871
00872 fixed_frame_ = remapped_name;
00873
00874 frame_manager_->setFixedFrame(fixed_frame_);
00875
00876 V_DisplayWrapper::iterator it = displays_.begin();
00877 V_DisplayWrapper::iterator end = displays_.end();
00878 for ( ; it != end; ++it )
00879 {
00880 Display* display = (*it)->getDisplay();
00881
00882 if (display)
00883 {
00884 display->setFixedFrame(fixed_frame_);
00885 }
00886 }
00887
00888 propertyChanged(fixed_frame_property_);
00889
00890 if (target_frame_is_fixed_frame_)
00891 {
00892 setTargetFrame(FIXED_FRAME_STRING);
00893 }
00894 }
00895
00896 bool VisualizationManager::isValidDisplay(const DisplayWrapper* display)
00897 {
00898 V_DisplayWrapper::iterator it = displays_.begin();
00899 V_DisplayWrapper::iterator end = displays_.end();
00900 for ( ; it != end; ++it )
00901 {
00902 if (display == (*it))
00903 {
00904 return true;
00905 }
00906 }
00907
00908 return false;
00909 }
00910
00911 double VisualizationManager::getWallClock()
00912 {
00913 return ros::WallTime::now().toSec();
00914 }
00915
00916 double VisualizationManager::getROSTime()
00917 {
00918 return (ros_time_begin_ + ros_time_elapsed_).toSec();
00919 }
00920
00921 double VisualizationManager::getWallClockElapsed()
00922 {
00923 return wall_clock_elapsed_.toSec();
00924 }
00925
00926 double VisualizationManager::getROSTimeElapsed()
00927 {
00928 return ros_time_elapsed_.toSec();
00929 }
00930
00931 void VisualizationManager::setBackgroundColor(const Color& c)
00932 {
00933 background_color_ = c;
00934
00935 render_panel_->getViewport()->setBackgroundColour(Ogre::ColourValue(c.r_, c.g_, c.b_, 1.0f));
00936
00937 propertyChanged(background_color_property_);
00938
00939 queueRender();
00940 }
00941
00942 const Color& VisualizationManager::getBackgroundColor()
00943 {
00944 return background_color_;
00945 }
00946
00947 void VisualizationManager::handleChar( wxKeyEvent& event )
00948 {
00949 if ( event.GetKeyCode() == WXK_ESCAPE )
00950 {
00951 setCurrentTool( getDefaultTool() );
00952
00953 return;
00954 }
00955
00956 char key = event.GetKeyCode();
00957 V_Tool::iterator it = tools_.begin();
00958 V_Tool::iterator end = tools_.end();
00959 for ( ; it != end; ++it )
00960 {
00961 Tool* tool = *it;
00962 if ( tool->getShortcutKey() == key && tool != getCurrentTool() )
00963 {
00964 setCurrentTool( tool );
00965 return;
00966 }
00967 }
00968
00969 getCurrentTool()->processKeyEvent(event);
00970 }
00971
00972 void VisualizationManager::addViewController(const std::string& class_name, const std::string& name)
00973 {
00974 view_controller_type_added_(class_name, name);
00975 }
00976
00977 bool VisualizationManager::setCurrentViewControllerType(const std::string& type)
00978 {
00979 if (view_controller_ && (view_controller_->getClassName() == type || view_controller_->getName() == type))
00980 {
00981 return true;
00982 }
00983
00984 bool found = true;
00985
00986 if (type == "rviz::OrbitViewController" || type == "Orbit")
00987 {
00988 view_controller_ = new OrbitViewController(this, "Orbit");
00989 }
00990 else if (type == "rviz::FPSViewController" || type == "FPS")
00991 {
00992 view_controller_ = new FPSViewController(this, "FPS");
00993 }
00994 else if (type == "rviz::FixedOrientationOrthoViewController" || type == "TopDownOrtho" || type == "Top-down Orthographic")
00995 {
00996 FixedOrientationOrthoViewController* controller = new FixedOrientationOrthoViewController(this, "TopDownOrtho");
00997 Ogre::Quaternion orient;
00998 orient.FromAngleAxis(Ogre::Degree(-90), Ogre::Vector3::UNIT_X);
00999 controller->setOrientation(orient);
01000 view_controller_ = controller;
01001 }
01002 else if (!view_controller_)
01003 {
01004 view_controller_ = new OrbitViewController(this, "Orbit");
01005 }
01006 else
01007 {
01008 found = false;
01009 }
01010
01011 if (found)
01012 {
01013 render_panel_->setViewController(view_controller_);
01014 view_controller_type_changed_(view_controller_);
01015 }
01016
01017 return found;
01018 }
01019
01020 std::string VisualizationManager::getCurrentViewControllerType()
01021 {
01022 return view_controller_->getClassName();
01023 }
01024
01025 void VisualizationManager::handleMouseEvent(ViewportMouseEvent& vme)
01026 {
01027 int flags = getCurrentTool()->processMouseEvent(vme);
01028
01029 if ( flags & Tool::Render )
01030 {
01031 queueRender();
01032 }
01033
01034 if ( flags & Tool::Finished )
01035 {
01036 setCurrentTool( getDefaultTool() );
01037 }
01038 }
01039
01040 void VisualizationManager::threadedQueueThreadFunc()
01041 {
01042 while (!shutting_down_)
01043 {
01044 threaded_queue_.callOne(ros::WallDuration(0.1));
01045 }
01046 }
01047
01048 void VisualizationManager::onPluginUnloading(const PluginStatus& status)
01049 {
01050
01051
01052
01053 property_manager_->update();
01054 }
01055
01056 }