visualization_panel.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <OGRE/OgreLogManager.h>
00031 
00032 #include <ros/package.h>
00033 #include <ros/console.h>
00034 
00035 #include <ogre_helpers/initialization.h>
00036 
00037 #include "view_controller.h"
00038 #include "render_panel.h"
00039 #include "displays_panel.h"
00040 #include "visualization_manager.h"
00041 #include "config.h"
00042 
00043 #include "visualization_panel.h"
00044 
00045 namespace rviz
00046 {
00047 
00048 VisualizationPanel::VisualizationPanel(QWidget* parent)
00049   : QSplitter( parent )
00050 {
00051   Ogre::LogManager* log_manager = new Ogre::LogManager();
00052   log_manager->createLog( "Ogre.log", false, false, true );
00053 
00054   if( !ros::isInitialized() )
00055   {
00056     int argc = 0;
00057     ros::init(argc, 0, "rviz", ros::init_options::NoSigintHandler | ros::init_options::AnonymousName);
00058   }
00059 
00060   displays_panel_ = new DisplaysPanel( this );
00061   render_panel_ = new RenderPanel( this );
00062 
00063   QList<int> sizes;
00064   sizes.push_back( 300 );
00065   sizes.push_back( 500 );
00066   setSizes( sizes );
00067 
00068   std::string package_path = ros::package::getPath("rviz");
00069   V_string paths;
00070   paths.push_back(package_path + "/ogre_media/textures");
00071   initializeResources( paths );
00072 
00073   manager_ = new VisualizationManager( render_panel_ );
00074   render_panel_->initialize( manager_->getSceneManager(), manager_ );
00075   displays_panel_->initialize( manager_ );
00076 
00077   manager_->initialize();
00078   manager_->startUpdate();
00079 }
00080 
00081 VisualizationPanel::~VisualizationPanel()
00082 {
00083   // TODO: make Properties, PropertyWidgetItems, and things that hold
00084   // Ogre Node pointers less tightly connected so they can be moved
00085   // around easier.  The tricky dependencies are a big source of bugs.
00086 
00087   // Have to remove displays before destroying DisplaysPanel, because
00088   // Displays own Properties, and Properties own children of
00089   // DisplaysPanel (PropertyWidgetItems).  DisplaysPanel notices when
00090   // PropertyWidgetItems are destroyed, but Properties don't notice
00091   // when PropertyWidgetItems are destroyed, so must destroy in the
00092   // right order.
00093   if( manager_ )
00094   {
00095     manager_->removeAllDisplays();
00096   }
00097 
00098   delete render_panel_;
00099   // Have to delete render_panel_ before manager_ because
00100   // ~VisualizationManager destroys ogre SceneManager which destroys
00101   // all attached nodes.  RenderPanel indirectly holds pointers to
00102   // nodes which it destroys.
00103   delete manager_;
00104 }
00105 
00106 void VisualizationPanel::loadDisplayConfig(const std::string& filepath)
00107 {
00108   manager_->removeAllDisplays();
00109 
00110   boost::shared_ptr<Config> config( new Config() );
00111   config->readFromFile( filepath );
00112   manager_->loadDisplayConfig( config );
00113 }
00114 
00115 void VisualizationPanel::setViewControllerType( const std::string& view_type_name )
00116 {
00117   manager_->setCurrentViewControllerType( view_type_name );
00118 }
00119 
00120 void VisualizationPanel::setViewString( const std::string& view_string )
00121 {
00122   manager_->getCurrentViewController()->fromString( view_string );
00123 }
00124 
00125 void VisualizationPanel::setTargetFrame( const std::string& target_frame )
00126 {
00127   manager_->getCurrentViewController()->setTargetFrame( target_frame );
00128 }
00129 
00130 }


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:33