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 <QApplication>
00031 #include <QTimer>
00032
00033 #include <boost/program_options.hpp>
00034
00035 #include <OgreMaterialManager.h>
00036 #include <OgreGpuProgramManager.h>
00037 #include <OgreHighLevelGpuProgramManager.h>
00038 #include <std_srvs/Empty.h>
00039
00040 #ifdef Q_OS_MAC
00041 #include <ApplicationServices/ApplicationServices.h>
00042
00043
00044 #undef check
00045 #endif
00046
00047 #include <ros/ros.h>
00048
00049 #include "rviz/selection/selection_manager.h"
00050 #include "rviz/env_config.h"
00051 #include "rviz/ogre_helpers/ogre_logging.h"
00052 #include "rviz/visualization_frame.h"
00053 #include "rviz/visualization_manager.h"
00054 #include "rviz/wait_for_master_dialog.h"
00055 #include "rviz/ogre_helpers/render_system.h"
00056
00057 #include "rviz/visualizer_app.h"
00058
00059 #define CATCH_EXCEPTIONS 0
00060
00061 namespace po = boost::program_options;
00062
00063 namespace rviz
00064 {
00065
00066 bool reloadShaders(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
00067 {
00068 ROS_INFO("Reloading materials.");
00069 {
00070 Ogre::ResourceManager::ResourceMapIterator it = Ogre::MaterialManager::getSingleton().getResourceIterator();
00071 while (it.hasMoreElements())
00072 {
00073 Ogre::ResourcePtr resource = it.getNext();
00074 resource->reload();
00075 }
00076 }
00077 ROS_INFO("Reloading high-level gpu shaders.");
00078 {
00079 Ogre::ResourceManager::ResourceMapIterator it = Ogre::HighLevelGpuProgramManager::getSingleton().getResourceIterator();
00080 while (it.hasMoreElements())
00081 {
00082 Ogre::ResourcePtr resource = it.getNext();
00083 resource->reload();
00084 }
00085 }
00086 ROS_INFO("Reloading gpu shaders.");
00087 {
00088 Ogre::ResourceManager::ResourceMapIterator it = Ogre::GpuProgramManager::getSingleton().getResourceIterator();
00089 while (it.hasMoreElements())
00090 {
00091 Ogre::ResourcePtr resource = it.getNext();
00092 resource->reload();
00093 }
00094 }
00095 return true;
00096 }
00097
00098 VisualizerApp::VisualizerApp()
00099 : continue_timer_( 0 )
00100 , frame_( 0 )
00101 {
00102 }
00103
00104 bool VisualizerApp::init( int argc, char** argv )
00105 {
00106 ROS_INFO( "rviz version %s", get_version().c_str() );
00107 ROS_INFO( "compiled against OGRE version %d.%d.%d%s (%s)",
00108 OGRE_VERSION_MAJOR, OGRE_VERSION_MINOR, OGRE_VERSION_PATCH,
00109 OGRE_VERSION_SUFFIX, OGRE_VERSION_NAME );
00110
00111 #ifdef Q_OS_MAC
00112 ProcessSerialNumber PSN;
00113 GetCurrentProcess(&PSN);
00114 TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
00115 SetFrontProcess(&PSN);
00116 #endif
00117
00118 #if CATCH_EXCEPTIONS
00119 try
00120 {
00121 #endif
00122 ros::init( argc, argv, "rviz", ros::init_options::AnonymousName );
00123
00124 startContinueChecker();
00125
00126 po::options_description options;
00127 options.add_options()
00128 ("help,h", "Produce this help message")
00129 ("splash-screen,s", po::value<std::string>(), "A custom splash-screen image to display")
00130 ("help-file", po::value<std::string>(), "A custom html file to show as the help screen")
00131 ("display-config,d", po::value<std::string>(), "A display config file (.rviz) to load")
00132 ("fixed-frame,f", po::value<std::string>(), "Set the fixed frame")
00133 ("ogre-log,l", "Enable the Ogre.log file (output in cwd) and console output.")
00134 ("in-mc-wrapper", "Signal that this is running inside a master-chooser wrapper")
00135 ("opengl", po::value<int>(), "Force OpenGL version (use '--opengl 210' for OpenGL 2.1 compatibility mode)")
00136 ("no-stereo", "Disable the use of stereo rendering.")
00137 ("verbose,v", "Enable debug visualizations");
00138 po::variables_map vm;
00139 std::string display_config, fixed_frame, splash_path, help_path;
00140 bool enable_ogre_log = false;
00141 bool in_mc_wrapper = false;
00142 bool verbose = false;
00143 int force_gl_version = 0;
00144 bool disable_stereo = false;
00145 try
00146 {
00147 po::store( po::parse_command_line( argc, argv, options ), vm );
00148 po::notify( vm );
00149
00150 if( vm.count( "help" ))
00151 {
00152 std::cout << "rviz command line options:\n" << options;
00153 return false;
00154 }
00155
00156 if( vm.count( "in-mc-wrapper" ))
00157 {
00158 in_mc_wrapper = true;
00159 }
00160
00161 if (vm.count("display-config"))
00162 {
00163 display_config = vm["display-config"].as<std::string>();
00164 if( display_config.substr( display_config.size() - 4, 4 ) == ".vcg" )
00165 {
00166 std::cerr << "ERROR: the config file '" << display_config << "' is a .vcg file, which is the old rviz config format." << std::endl;
00167 std::cerr << " New config files have a .rviz extension and use YAML formatting. The format changed" << std::endl;
00168 std::cerr << " between Fuerte and Groovy. There is not (yet) an automated conversion program." << std::endl;
00169 return false;
00170 }
00171 }
00172
00173 if (vm.count("splash-screen"))
00174 {
00175 splash_path = vm["splash-screen"].as<std::string>();
00176 }
00177
00178 if (vm.count("help-file"))
00179 {
00180 help_path = vm["help-file"].as<std::string>();
00181 }
00182
00183 if (vm.count("fixed-frame"))
00184 {
00185 fixed_frame = vm["fixed-frame"].as<std::string>();
00186 }
00187
00188 if (vm.count("ogre-log"))
00189 {
00190 enable_ogre_log = true;
00191 }
00192
00193 if (vm.count("no-stereo"))
00194 {
00195 disable_stereo = true;
00196 }
00197
00198 if (vm.count("opengl"))
00199 {
00200
00201 force_gl_version = vm["opengl"].as<int>();
00202 }
00203
00204 if (vm.count("verbose"))
00205 {
00206 verbose = true;
00207 }
00208 }
00209 catch (std::exception& e)
00210 {
00211 ROS_ERROR("Error parsing command line: %s", e.what());
00212 return false;
00213 }
00214
00215 if( !ros::master::check() )
00216 {
00217 WaitForMasterDialog* dialog = new WaitForMasterDialog;
00218 if( dialog->exec() != QDialog::Accepted )
00219 {
00220 return false;
00221 }
00222 }
00223
00224 nh_.reset( new ros::NodeHandle );
00225
00226 if( enable_ogre_log )
00227 {
00228 OgreLogging::useRosLog();
00229 }
00230
00231 if ( force_gl_version )
00232 {
00233 RenderSystem::forceGlVersion( force_gl_version );
00234 }
00235
00236 if ( disable_stereo )
00237 {
00238 RenderSystem::forceNoStereo();
00239 }
00240
00241 frame_ = new VisualizationFrame;
00242 if( help_path != "" )
00243 {
00244 frame_->setHelpPath( QString::fromStdString( help_path ));
00245 }
00246 frame_->setShowChooseNewMaster( in_mc_wrapper );
00247 if( splash_path != "" )
00248 {
00249 frame_->setSplashPath( QString::fromStdString( splash_path ));
00250 }
00251 frame_->initialize( QString::fromStdString( display_config ));
00252 if( !fixed_frame.empty() )
00253 {
00254 frame_->getManager()->setFixedFrame( QString::fromStdString( fixed_frame ));
00255 }
00256
00257 frame_->getManager()->getSelectionManager()->setDebugMode( verbose );
00258
00259 frame_->show();
00260
00261 ros::NodeHandle private_nh("~");
00262 reload_shaders_service_ = private_nh.advertiseService("reload_shaders", reloadShaders);
00263
00264 #if CATCH_EXCEPTIONS
00265 }
00266 catch (std::exception& e)
00267 {
00268 ROS_ERROR("Caught exception while loading: %s", e.what());
00269 return false;
00270 }
00271 #endif
00272 return true;
00273 }
00274
00275 VisualizerApp::~VisualizerApp()
00276 {
00277 delete continue_timer_;
00278 delete frame_;
00279 }
00280
00281 void VisualizerApp::startContinueChecker()
00282 {
00283 continue_timer_ = new QTimer( this );
00284 connect( continue_timer_, SIGNAL( timeout() ), this, SLOT( checkContinue() ));
00285 continue_timer_->start( 100 );
00286 }
00287
00288 void VisualizerApp::checkContinue()
00289 {
00290 if( !ros::ok() )
00291 {
00292 if( frame_ )
00293 {
00294
00295 frame_->setWindowModified( false );
00296 }
00297 QApplication::closeAllWindows();
00298 }
00299 }
00300
00301 }