visualizer_app.cpp
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 #include <QApplication>
31 #include <QTimer>
32 
33 #include <boost/program_options.hpp>
34 
35 #include <OgreMaterialManager.h>
36 #include <OgreGpuProgramManager.h>
37 #include <OgreHighLevelGpuProgramManager.h>
38 #include <std_srvs/Empty.h>
39 
40 #ifdef Q_OS_MAC
41 #include <ApplicationServices/ApplicationServices.h>
42 // Apparently OSX #defines 'check' to be an empty string somewhere.
43 // That was fun to figure out.
44 #undef check
45 #endif
46 
47 #include <ros/console.h>
48 #include <ros/ros.h>
49 
51 #include "rviz/env_config.h"
57 
58 #include "rviz/visualizer_app.h"
59 
60 #define CATCH_EXCEPTIONS 0
61 
62 namespace po = boost::program_options;
63 
64 namespace rviz
65 {
66 
67 bool reloadShaders(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
68 {
69  ROS_INFO("Reloading materials.");
70  {
71  Ogre::ResourceManager::ResourceMapIterator it = Ogre::MaterialManager::getSingleton().getResourceIterator();
72  while (it.hasMoreElements())
73  {
74  Ogre::ResourcePtr resource = it.getNext();
75  resource->reload();
76  }
77  }
78  ROS_INFO("Reloading high-level gpu shaders.");
79  {
80  Ogre::ResourceManager::ResourceMapIterator it = Ogre::HighLevelGpuProgramManager::getSingleton().getResourceIterator();
81  while (it.hasMoreElements())
82  {
83  Ogre::ResourcePtr resource = it.getNext();
84  resource->reload();
85  }
86  }
87  ROS_INFO("Reloading gpu shaders.");
88  {
89  Ogre::ResourceManager::ResourceMapIterator it = Ogre::GpuProgramManager::getSingleton().getResourceIterator();
90  while (it.hasMoreElements())
91  {
92  Ogre::ResourcePtr resource = it.getNext();
93  resource->reload();
94  }
95  }
96  return true;
97 }
98 
100  : app_( 0 )
101  , continue_timer_( 0 )
102  , frame_( 0 )
103 {
104 }
105 
106 void VisualizerApp::setApp( QApplication * app )
107 {
108  app_ = app;
109 }
110 
111 bool VisualizerApp::init( int argc, char** argv )
112 {
113  ROS_INFO( "rviz version %s", get_version().c_str() );
114  ROS_INFO( "compiled against Qt version " QT_VERSION_STR );
115  ROS_INFO( "compiled against OGRE version %d.%d.%d%s (%s)",
116  OGRE_VERSION_MAJOR, OGRE_VERSION_MINOR, OGRE_VERSION_PATCH,
117  OGRE_VERSION_SUFFIX, OGRE_VERSION_NAME );
118 
119 #ifdef Q_OS_MAC
120  ProcessSerialNumber PSN;
121  GetCurrentProcess(&PSN);
122  TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
123  SetFrontProcess(&PSN);
124 #endif
125 
126 #if CATCH_EXCEPTIONS
127  try
128  {
129 #endif
130  ros::init( argc, argv, "rviz", ros::init_options::AnonymousName );
131 
133 
134  po::options_description options;
135  options.add_options()
136  ("help,h", "Produce this help message")
137  ("splash-screen,s", po::value<std::string>(), "A custom splash-screen image to display")
138  ("help-file", po::value<std::string>(), "A custom html file to show as the help screen")
139  ("display-config,d", po::value<std::string>(), "A display config file (.rviz) to load")
140  ("fixed-frame,f", po::value<std::string>(), "Set the fixed frame")
141  ("ogre-log,l", "Enable the Ogre.log file (output in cwd) and console output.")
142  ("in-mc-wrapper", "Signal that this is running inside a master-chooser wrapper")
143  ("opengl", po::value<int>(), "Force OpenGL version (use '--opengl 210' for OpenGL 2.1 compatibility mode)")
144  ("disable-anti-aliasing", "Prevent rviz from trying to use anti-aliasing when rendering.")
145  ("no-stereo", "Disable the use of stereo rendering.")
146  ("verbose,v", "Enable debug visualizations")
147  ("log-level-debug", "Sets the ROS logger level to debug.");
148  po::variables_map vm;
149  std::string display_config, fixed_frame, splash_path, help_path;
150  bool enable_ogre_log = false;
151  bool in_mc_wrapper = false;
152  bool verbose = false;
153  int force_gl_version = 0;
154  bool disable_anti_aliasing = false;
155  bool disable_stereo = false;
156  try
157  {
158  po::store( po::parse_command_line( argc, argv, options ), vm );
159  po::notify( vm );
160 
161  if( vm.count( "help" ))
162  {
163  std::cout << "rviz command line options:\n" << options;
164  return false;
165  }
166 
167  if( vm.count( "in-mc-wrapper" ))
168  {
169  in_mc_wrapper = true;
170  }
171 
172  if (vm.count("display-config"))
173  {
174  display_config = vm["display-config"].as<std::string>();
175  if (display_config.size() >= 4 && display_config.substr( display_config.size() - 4, 4 ) == ".vcg")
176  {
177  std::cerr << "ERROR: the config file '" << display_config << "' is a .vcg file, which is the old rviz config format." << std::endl;
178  std::cerr << " New config files have a .rviz extension and use YAML formatting. The format changed" << std::endl;
179  std::cerr << " between Fuerte and Groovy. There is not (yet) an automated conversion program." << std::endl;
180  return false;
181  }
182  }
183 
184  if (vm.count("splash-screen"))
185  {
186  splash_path = vm["splash-screen"].as<std::string>();
187  }
188 
189  if (vm.count("help-file"))
190  {
191  help_path = vm["help-file"].as<std::string>();
192  }
193 
194  if (vm.count("fixed-frame"))
195  {
196  fixed_frame = vm["fixed-frame"].as<std::string>();
197  }
198 
199  if (vm.count("ogre-log"))
200  {
201  enable_ogre_log = true;
202  }
203 
204  if (vm.count("no-stereo"))
205  {
206  disable_stereo = true;
207  }
208 
209  if (vm.count("opengl"))
210  {
211  //std::cout << vm["opengl"].as<std::string>() << std::endl;
212  force_gl_version = vm["opengl"].as<int>();
213  }
214 
215  if (vm.count("disable-anti-aliasing"))
216  {
217  disable_anti_aliasing = true;
218  }
219 
220  if (vm.count("verbose"))
221  {
222  verbose = true;
223  }
224 
225  if (vm.count("log-level-debug"))
226  {
228  {
230  }
231  }
232  }
233  catch (std::exception& e)
234  {
235  ROS_ERROR("Error parsing command line: %s", e.what());
236  return false;
237  }
238 
239  if( !ros::master::check() )
240  {
242  if( dialog->exec() != QDialog::Accepted )
243  {
244  return false;
245  }
246  }
247 
248  nh_.reset( new ros::NodeHandle );
249 
250  if( enable_ogre_log )
251  {
253  }
254 
255  if ( force_gl_version )
256  {
257  RenderSystem::forceGlVersion( force_gl_version );
258  }
259 
260  if (disable_anti_aliasing)
261  {
263  }
264 
265  if ( disable_stereo )
266  {
268  }
269 
270  frame_ = new VisualizationFrame();
271  frame_->setApp( this->app_ );
272  if( help_path != "" )
273  {
274  frame_->setHelpPath( QString::fromStdString( help_path ));
275  }
276  frame_->setShowChooseNewMaster( in_mc_wrapper );
277  if( vm.count("splash-screen") )
278  {
279  frame_->setSplashPath( QString::fromStdString( splash_path ));
280  }
281  frame_->initialize( QString::fromStdString( display_config ));
282  if( !fixed_frame.empty() )
283  {
284  frame_->getManager()->setFixedFrame( QString::fromStdString( fixed_frame ));
285  }
286 
288 
289  frame_->show();
290 
291  ros::NodeHandle private_nh("~");
292  reload_shaders_service_ = private_nh.advertiseService("reload_shaders", reloadShaders);
293 
294 #if CATCH_EXCEPTIONS
295  }
296  catch (std::exception& e)
297  {
298  ROS_ERROR("Caught exception while loading: %s", e.what());
299  return false;
300  }
301 #endif
302  return true;
303 }
304 
306 {
307  delete continue_timer_;
308  delete frame_;
309 }
310 
312 {
313  continue_timer_ = new QTimer( this );
314  connect( continue_timer_, SIGNAL( timeout() ), this, SLOT( checkContinue() ));
315  continue_timer_->start( 100 );
316 }
317 
319 {
320  if( !ros::ok() )
321  {
322  if( frame_ )
323  {
324  // Make sure the window doesn't ask if we want to save first.
325  frame_->setWindowModified( false );
326  }
327  QApplication::closeAllWindows();
328  }
329 }
330 
331 } // namespace rviz
void setApp(QApplication *app)
VisualizationManager * getManager()
ROSCPP_DECL bool check()
QApplication * app_
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
bool reloadShaders(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
void setSplashPath(const QString &splash_path)
Set the path to the "splash" image file. This image is shown during initialization and loading of the...
static void forceGlVersion(int version)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setFixedFrame(const QString &frame)
Set the coordinate frame we should be transforming all fixed data into.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceServer reload_shaders_service_
static void disableAntiAliasing()
void initialize(const QString &display_config_file="")
Initialize the visualizer. Creates the VisualizationManager.
void setDebugMode(bool debug)
Enables or disables publishing of picking and depth rendering images.
ros::NodeHandlePtr nh_
#define ROS_INFO(...)
options
ROSCPP_DECL bool ok()
std::string get_version()
void setHelpPath(const QString &help_path)
Set the path to the help file. Should contain HTML. Default is a file in the RViz package...
bool init(int argc, char **argv)
SelectionManager * getSelectionManager() const
Return a pointer to the SelectionManager.
VisualizationFrame * frame_
static void forceNoStereo()
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
void setApp(QApplication *app)
The main rviz window.
#define ROS_ERROR(...)
void setShowChooseNewMaster(bool show)
Call this before initialize() to have it take effect.
#define ROSCONSOLE_DEFAULT_NAME
static void useRosLog()
Configure Ogre to write output to the ROS logger.


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:52