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 #include <boost/filesystem.hpp>
35 
36 #include <OgreMaterialManager.h>
37 #include <OgreGpuProgramManager.h>
38 #include <OgreHighLevelGpuProgramManager.h>
39 #include <std_srvs/Empty.h>
40 
41 #ifdef Q_OS_MAC
42 #include <ApplicationServices/ApplicationServices.h>
43 // Apparently OSX #defines 'check' to be an empty string somewhere.
44 // That was fun to figure out.
45 #undef check
46 #endif
47 
48 #include <ros/console.h>
49 #include <ros/ros.h>
50 
52 #include <rviz/env_config.h>
58 
59 #include <rviz/visualizer_app.h>
60 
61 #define CATCH_EXCEPTIONS 0
62 
63 namespace po = boost::program_options;
64 namespace fs = boost::filesystem;
65 
66 namespace rviz
67 {
68 bool reloadShaders(std_srvs::Empty::Request& /*unused*/, std_srvs::Empty::Response& /*unused*/)
69 {
70  ROS_INFO("Reloading materials.");
71  {
72  Ogre::ResourceManager::ResourceMapIterator it =
73  Ogre::MaterialManager::getSingleton().getResourceIterator();
74  while (it.hasMoreElements())
75  {
76  Ogre::ResourcePtr resource = it.getNext();
77  resource->reload();
78  }
79  }
80  ROS_INFO("Reloading high-level gpu shaders.");
81  {
82  Ogre::ResourceManager::ResourceMapIterator it =
83  Ogre::HighLevelGpuProgramManager::getSingleton().getResourceIterator();
84  while (it.hasMoreElements())
85  {
86  Ogre::ResourcePtr resource = it.getNext();
87  resource->reload();
88  }
89  }
90  ROS_INFO("Reloading gpu shaders.");
91  {
92  Ogre::ResourceManager::ResourceMapIterator it =
93  Ogre::GpuProgramManager::getSingleton().getResourceIterator();
94  while (it.hasMoreElements())
95  {
96  Ogre::ResourcePtr resource = it.getNext();
97  resource->reload();
98  }
99  }
100  return true;
101 }
102 
103 VisualizerApp::VisualizerApp() : continue_timer_(nullptr), frame_(nullptr)
104 {
105 }
106 
107 void VisualizerApp::setApp(QApplication* app)
108 {
109  Q_UNUSED(app);
110 }
111 
112 bool VisualizerApp::init(int argc, char** argv)
113 {
114  ROS_INFO("rviz version %s", get_version().c_str());
115  ROS_INFO("compiled against Qt version " QT_VERSION_STR);
116  ROS_INFO("compiled against OGRE version %d.%d.%d%s (%s)", OGRE_VERSION_MAJOR, OGRE_VERSION_MINOR,
117  OGRE_VERSION_PATCH, 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  std::string display_config, fixed_frame, splash_path, help_path;
135  int force_gl_version = 0;
136 
137  po::options_description options;
138  options.add_options() // clang-format off
139  ("help,h", "Produce this help message")
140  ("splash-screen,s", po::value<std::string>(&splash_path),
141  "A custom splash-screen image to display")
142  ("help-file", po::value<std::string>(&help_path),
143  "A custom html file to show as the help screen")
144  ("display-config,d", po::value<std::string>(&display_config),
145  "A display config file (.rviz) to load")
146  ("fullscreen", "Trigger fullscreen display")
147  ("fixed-frame,f", po::value<std::string>(&fixed_frame), "Set the fixed frame")
148  ("ogre-log,l", "Enable the Ogre.log file (output in cwd) and console output.")
149  ("in-mc-wrapper", "Signal that this is running inside a master-chooser wrapper")
150  ("opengl", po::value<int>(&force_gl_version),
151  "Force OpenGL version (use '--opengl 210' for OpenGL 2.1 compatibility mode)")
152  ("disable-anti-aliasing", "Prevent rviz from trying to use anti-aliasing when rendering.")
153  ("no-stereo", "Disable the use of stereo rendering.")("verbose,v", "Enable debug visualizations")
154  ("log-level-debug", "Sets the ROS logger level to debug.");
155  // clang-format on
156  po::variables_map vm;
157  try
158  {
159  po::store(po::parse_command_line(argc, argv, options), vm);
160  po::notify(vm);
161 
162  if (vm.count("help"))
163  {
164  std::cout << "rviz command line options:\n" << options;
165  return false;
166  }
167 
168  if (vm.count("log-level-debug"))
169  {
171  {
173  }
174  }
175  }
176  catch (std::exception& e)
177  {
178  ROS_ERROR("Error parsing command line: %s", e.what());
179  return false;
180  }
181 
182  if (!ros::master::check())
183  {
184  WaitForMasterDialog dialog;
185  if (dialog.exec() != QDialog::Accepted)
186  {
187  return false;
188  }
189  }
190 
191  nh_.reset(new ros::NodeHandle);
192 
193  if (vm.count("ogre-log"))
195 
196  RenderSystem::forceGlVersion(force_gl_version);
197 
198  if (vm.count("disable-anti-aliasing"))
200 
201  if (vm.count("no-stereo"))
203 
204  frame_ = new VisualizationFrame();
205  if (!help_path.empty())
206  {
207  frame_->setHelpPath(QString::fromStdString(help_path));
208  }
209  frame_->setShowChooseNewMaster(vm.count("in-mc-wrapper") > 0);
210  if (vm.count("splash-screen"))
211  frame_->setSplashPath(QString::fromStdString(splash_path));
212 
213  frame_->initialize(QString::fromStdString(display_config));
214 
215  if (!fixed_frame.empty())
216  frame_->getManager()->setFixedFrame(QString::fromStdString(fixed_frame));
217 
218  frame_->getManager()->getSelectionManager()->setDebugMode(vm.count("verbose") > 0);
219 
220  if (vm.count("fullscreen"))
221  frame_->setFullScreen(true);
222  frame_->show();
223 
224  ros::NodeHandle private_nh("~");
225  reload_shaders_service_ = private_nh.advertiseService("reload_shaders", reloadShaders);
226 
228  private_nh.advertiseService("load_config", &VisualizerApp::loadConfigCallback, this);
230  "load_config_discarding_changes", &VisualizerApp::loadConfigDiscardingCallback, this);
232  private_nh.advertiseService("save_config", &VisualizerApp::saveConfigCallback, this);
233 
234 #if CATCH_EXCEPTIONS
235  }
236  catch (std::exception& e)
237  {
238  ROS_ERROR("Caught exception while loading: %s", e.what());
239  return false;
240  }
241 #endif
242  return true;
243 }
244 
246 {
247  delete continue_timer_;
248  delete frame_;
249 }
250 
252 {
253  continue_timer_ = new QTimer(this);
254  connect(continue_timer_, &QTimer::timeout, this, &VisualizerApp::checkContinue);
255  continue_timer_->start(100);
256 }
257 
259 {
260  if (!ros::ok())
261  {
262  if (frame_)
263  {
264  // Make sure the window doesn't ask if we want to save first.
265  frame_->setWindowModified(false);
266  }
267  QApplication::closeAllWindows();
268  }
269 }
270 
271 bool VisualizerApp::loadConfigCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res)
272 {
273  fs::path path = req.path.data;
274  if (fs::is_regular_file(path))
275  res.success = frame_->loadDisplayConfigHelper(path.string());
276  else
277  res.success = false;
278  return true;
279 }
280 
281 bool VisualizerApp::loadConfigDiscardingCallback(rviz::SendFilePathRequest& req,
282  rviz::SendFilePathResponse& res)
283 {
284  fs::path path = req.path.data;
285  if (fs::is_regular_file(path))
286  {
287  bool discard_changes = true;
288  res.success = frame_->loadDisplayConfigHelper(path.string(), discard_changes);
289  }
290  else
291  res.success = false;
292  return true;
293 }
294 
295 bool VisualizerApp::saveConfigCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res)
296 {
297  res.success = frame_->saveDisplayConfig(QString::fromStdString(req.path.data));
298  return true;
299 }
300 
301 
302 } // namespace rviz
ros::init_options::AnonymousName
AnonymousName
ros::master::check
ROSCPP_DECL bool check()
render_system.h
rviz::VisualizerApp::checkContinue
void checkContinue()
Definition: visualizer_app.cpp:258
wait_for_master_dialog.h
env_config.h
rviz::VisualizerApp::setApp
void setApp(QApplication *app)
Definition: visualizer_app.cpp:107
rviz::VisualizerApp::load_config_service_
ros::ServiceServer load_config_service_
Definition: visualizer_app.h:74
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
rviz::VisualizationFrame::setFullScreen
void setFullScreen(bool full_screen)
Set full screen mode.
Definition: visualization_frame.cpp:1368
rviz::VisualizerApp::loadConfigDiscardingCallback
bool loadConfigDiscardingCallback(rviz::SendFilePathRequest &req, rviz::SendFilePathResponse &res)
Definition: visualizer_app.cpp:281
ros.h
rviz::VisualizationManager::getSelectionManager
SelectionManager * getSelectionManager() const override
Return a pointer to the SelectionManager.
Definition: visualization_manager.h:258
rviz::VisualizerApp::nh_
ros::NodeHandlePtr nh_
Definition: visualizer_app.h:72
ros::NodeHandle::advertiseService
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
rviz::RenderSystem::forceGlVersion
static void forceGlVersion(int version)
Definition: render_system.cpp:85
selection_manager.h
rviz::VisualizationFrame::setHelpPath
void setHelpPath(const QString &help_path)
Set the path to the help file. Should contain HTML. Default is a file in the RViz package.
Definition: visualization_frame.cpp:232
ros::console::set_logger_level
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
ogre_logging.h
rviz::VisualizerApp::load_config_discarding_service_
ros::ServiceServer load_config_discarding_service_
Definition: visualizer_app.h:75
ros::ok
ROSCPP_DECL bool ok()
rviz::VisualizationFrame::saveDisplayConfig
bool saveDisplayConfig(const QString &path)
Save display and other settings to the given file.
Definition: visualization_frame.cpp:833
visualizer_app.h
console.h
rviz::VisualizationFrame::setShowChooseNewMaster
void setShowChooseNewMaster(bool show)
Call this before initialize() to have it take effect.
Definition: visualization_frame.cpp:227
ros::console::levels::Debug
Debug
rviz::VisualizationFrame
The main rviz window.
Definition: visualization_frame.h:74
rviz
Definition: add_display_dialog.cpp:54
rviz::VisualizationFrame::loadDisplayConfigHelper
bool loadDisplayConfigHelper(const std::string &full_path, const bool discard_changes=false)
Load display and other settings from the given full file path.
Definition: visualization_frame.cpp:752
rviz::VisualizerApp::~VisualizerApp
~VisualizerApp() override
Definition: visualizer_app.cpp:245
rviz::VisualizationFrame::getManager
VisualizationManager * getManager()
Definition: visualization_frame.h:107
rviz::SelectionManager::setDebugMode
void setDebugMode(bool debug)
Enables or disables publishing of picking and depth rendering images.
Definition: selection_manager.cpp:117
rviz::VisualizerApp::frame_
VisualizationFrame * frame_
Definition: visualizer_app.h:71
app
app
rviz::VisualizerApp::continue_timer_
QTimer * continue_timer_
Definition: visualizer_app.h:70
rviz::VisualizerApp::save_config_service_
ros::ServiceServer save_config_service_
Definition: visualizer_app.h:76
visualization_manager.h
rviz::VisualizationManager::setFixedFrame
void setFixedFrame(const QString &frame)
Set the coordinate frame we should be transforming all fixed data into.
Definition: visualization_manager.cpp:602
ros::console::notifyLoggerLevelsChanged
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
rviz::OgreLogging::useRosLog
static void useRosLog()
Configure Ogre to write output to the ROS logger.
Definition: ogre_logging.cpp:69
rviz::RenderSystem::disableAntiAliasing
static void disableAntiAliasing()
Definition: render_system.cpp:91
ROS_ERROR
#define ROS_ERROR(...)
rviz::VisualizerApp::VisualizerApp
VisualizerApp()
Definition: visualizer_app.cpp:103
visualization_frame.h
rviz::VisualizerApp::saveConfigCallback
bool saveConfigCallback(rviz::SendFilePathRequest &req, rviz::SendFilePathResponse &res)
Definition: visualizer_app.cpp:295
rviz::VisualizationFrame::setSplashPath
void setSplashPath(const QString &splash_path)
Set the path to the "splash" image file. This image is shown during initialization and loading of the...
Definition: visualization_frame.cpp:238
rviz::WaitForMasterDialog
Definition: wait_for_master_dialog.h:36
ROSCONSOLE_DEFAULT_NAME
#define ROSCONSOLE_DEFAULT_NAME
rviz::reloadShaders
bool reloadShaders(std_srvs::Empty::Request &, std_srvs::Empty::Response &)
Definition: visualizer_app.cpp:68
rviz::RenderSystem::forceNoStereo
static void forceNoStereo()
Definition: render_system.cpp:97
ROS_INFO
#define ROS_INFO(...)
rviz::VisualizerApp::reload_shaders_service_
ros::ServiceServer reload_shaders_service_
Definition: visualizer_app.h:73
rviz::VisualizerApp::loadConfigCallback
bool loadConfigCallback(rviz::SendFilePathRequest &req, rviz::SendFilePathResponse &res)
Definition: visualizer_app.cpp:271
rviz::get_version
std::string get_version()
rviz::VisualizerApp::startContinueChecker
void startContinueChecker()
Definition: visualizer_app.cpp:251
ros::NodeHandle
rviz::VisualizationFrame::initialize
void initialize(const QString &display_config_file="")
Initialize the visualizer. Creates the VisualizationManager.
Definition: visualization_frame.cpp:243
rviz::VisualizerApp::init
bool init(int argc, char **argv)
Definition: visualizer_app.cpp:112


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Sat Jun 1 2024 02:31:53