OMK::Vis::OgreVis Class Reference

Specialization of VisBase for the Ogre3D library. More...

#include <OMKOgreVis.h>

Inheritance diagram for OMK::Vis::OgreVis:

Inheritance graph
[legend]
Collaboration diagram for OMK::Vis::OgreVis:

Collaboration graph
[legend]
List of all members.

Public Member Functions

const Ogre::Root & getRoot (void) const
 returns a const reference to the Ogre3D root
Ogre::Root & touchRoot (void) const
 returns a reference to the Ogre3D root

Private Member Functions

 DECLARE_OBJECT_FACTORY (OgreVis)
bool ogreInitialisation (const std::string &pluginsFile, const std::string &configurationFile, const std::string &resourcesFile, const std::string &sceneManagerType, const std::string &windowName)
 initialises Ogre3D, using the parameters found in ogre.cfg or by displaying a configuration window if there is no ogre.cfg available.
void createSceneManager (const std::string &sceneManagerType)
 creates a ST_GENERIC SceneManager named "SceneManager"
void createResourceListener (void)
 not implemented yet
void addResourceLocations (const std::string &resourcesFile)
 add the resources path given in the resources.cfg file
void initResources (void)
 initialises all the resource groups
void loadSceneFile (const std::string &resourceGroupName, const std::string &sceneFileName)
 load the dotScene file of configuration parameters "SceneFile" and resource group "ResourceGroup"
const std::string & initCamera (const std::string &cameraName)
 initialises the ogre camera of name cameraName if no camera was specified by the configuration parameter "Camera" it creates a default camera named "camera0" positioned at (0,0,0), looking at (0,0,-1), with (1,1000) clipping planes return the name of the created camera
void createViewport (const std::string &cameraName)
 creates a default viewport of colour (0.5,0.5,0.5)
Inherited
virtual void computeParameters ()
 Compute the new picture to display.
Loaders
virtual bool loadParameters (const ConfigurationParameterDescriptor *node)
 Configuration parameters loader of OgreVis.

Private Attributes

Ogre::Root * _root
 Ogre3D root, unique point of access to the Ogre3D scene organization.

Detailed Description

Specialization of VisBase for the Ogre3D library.

Author:
Michaël Rouillé, bunraku <michael.rouille@irisa.fr>
This Simulated Object initialises Ogre3D, creates default window/viewport/camera and manages the visual objects and animators creation and updates

User parameters :

See The visualisation of OpenMASK with Ogre.

Definition at line 51 of file OMKOgreVis.h.


Member Function Documentation

OMK::Vis::OgreVis::DECLARE_OBJECT_FACTORY ( OgreVis   )  [private]

const Ogre::Root & OMK::Vis::OgreVis::getRoot ( void   )  const [inline]

returns a const reference to the Ogre3D root

Definition at line 122 of file OMKOgreVis.h.

References _root.

Referenced by OMK::Inp::BoundingBoxExtension::action(), and OMK::Inp::DistributedCameraListener::readConfigurationParameters().

00123                 {
00124                         return *_root ;
00125                 }

Ogre::Root & OMK::Vis::OgreVis::touchRoot ( void   )  const [inline]

returns a reference to the Ogre3D root

Definition at line 131 of file OMKOgreVis.h.

Referenced by OMK::Inp::SceneDetailsExtension::action(), OMK::Inp::InputExtension::createOISInputSystem(), OMK::Inp::DistributedCameraListener::finish(), OMK::Inp::DistributedCameraListener::init(), OMK::Inp::InputExtension::initOIS(), OMK::Vis::OgreObjectScene::loadGeometry(), OMK::Vis::CameraBaseExtension::retreiveCamera(), OMK::Inp::DebugOverlayExtension::updateStats(), and OMK::Vis::OgreObject::~OgreObject().

00132                 {
00133                         return const_cast < Ogre::Root& > ( *_root ) ;
00134                 }

void OgreVis::computeParameters (  )  [private, virtual]

Compute the new picture to display.

This method loops in the list of visual objects to ask to them to update their display.

Reimplemented from OMK::Vis::VisBase.

Definition at line 204 of file OMKOgreVis.cpp.

References _root, and OMK::Vis::VisBase::computeParameters().

00205 {
00206         VisBase::computeParameters() ;
00207 
00208         //Allow platform to pump/create/etc messages/events once per frame 
00209         Ogre::WindowEventUtilities::messagePump( ) ; 
00210         _root->renderOneFrame() ;
00211 }

bool OgreVis::loadParameters ( const ConfigurationParameterDescriptor node  )  [private, virtual]

Configuration parameters loader of OgreVis.

Parameters:
[in] node the root node of the configuration parameter.
Returns:
true if all needed parameters can be read.
Reads in the configuration node the values to set the attributs. Reads the parameters to create visual objects and animators.

Reimplemented from OMK::ExtensibleSimulatedObject.

Definition at line 85 of file OMKOgreVis.cpp.

References _root, createViewport(), OMK::Vis::debugMsg(), OMK::ParametersAccessor::get(), initCamera(), OMK::ExtensibleSimulatedObject::loadParameters(), loadSceneFile(), ogreInitialisation(), OMERROR, OMK_DEBUG_VIS, and OMTRACEID.

00086 {
00087         bool ok( VisBase::loadParameters( node ) );
00088 
00089         // Retrieve the plugins for Ogre
00090         std::string pluginsFile ;
00091         if( ParametersAccessor::get( node, "OgreHome", pluginsFile ) )
00092         {
00093 #if defined _MSC_VER
00094                 // Windows
00095 #  if defined NDEBUG 
00096                 pluginsFile += "\\bin\\release\\Plugins.cfg" ;
00097 #  else // !defined NDEBUG 
00098                 pluginsFile += "\\bin\\debug\\Plugins.cfg" ;
00099 #  endif
00100 #else
00101     // Linux 
00102     pluginsFile += "/lib/OGRE/Plugins.cfg" ;
00103 #endif
00104         }
00105         else if( !ParametersAccessor::get( node, "PluginsCfg", pluginsFile ) )
00106         {
00107                 OMERROR( "Error for " << debugMsg( this ) << std::endl
00108                         << ">>> :-( Unable to determine which configuration must be used for Ogre." << std::endl
00109                         << "One of these two fields, 'OgreHome' or 'PluginsCfg', must be set." << std::endl
00110                         << "The path to the Ogre folder is defined in 'OgreHome' like this : OgreHome \"${OGRE_HOME}\"" << std::endl
00111                         << "Or the configuration file path is defined in 'OgrePluginsCfg' like this : PluginsCfg \"${OGRE_HOME}/lib/OGRE/plugins.cfg\"" << std::endl
00112                         << "See documentation" ) ;
00113                 ok = false ;
00114         }
00115 
00116         if ( ok )
00117         {
00118                 // Retrieve the configuration file
00119                 std::string configFile( "ogre.cfg" ) ;
00120                 if( !ParametersAccessor::get( node, "ConfigFile", configFile ) )
00121                 {
00122                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00123                                 << ">>> :-| no configuration file provided, will use \"ogre.cfg\" by default" ) ; 
00124                 }
00125 
00126                 // Retrieve the resource configuration
00127                 std::string resourcesFile( "resources.cfg" ) ;
00128                 if( !ParametersAccessor::get( node, "ResourcesFile", resourcesFile ) )
00129                 {
00130                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00131                                 << ">>> :-| no resources file provided, will use \"resources.cfg\" by default" ) ; 
00132                 }
00133 
00134                 // Retrieve the resource group name
00135                 std::string resourceGroupName( "General" ) ; // default value
00136                 if( !ParametersAccessor::get( node, "ResourceGroup", resourceGroupName ) )
00137                 {
00138                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00139                                 << ">>> :-| no resource group name provided, will use \"General\" by default" ) ; 
00140                 }
00141 
00142                 // Retrieve scene file name
00143                 std::string sceneFileName ;
00144                 if( !ParametersAccessor::get( node, "SceneFile", sceneFileName ) )
00145                 {
00146                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00147                                 << ">>> :-| no scene file name provided" ) ; 
00148                 }
00149 
00150                 // Retrieve camera name
00151                 std::string cameraName ;
00152                 if( !ParametersAccessor::get( node, "Camera", cameraName ) )
00153                 {
00154                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00155                                 << ">>> :-| no camera name provided" ) ; 
00156                 }
00157 
00158                 // Retrieve sceneManagerType
00159                 std::string sceneManagerType( "DefaultSceneManager" ) ;
00160                 if( !ParametersAccessor::get( node, "SceneManagerType", sceneManagerType ) )
00161                 {
00162                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00163                                 << ">>> :-| no SceneManagerType provided" ) ; 
00164                 }
00165 
00166                 // Retrieve windowName
00167                 std::string windowName( "Ogre Window" ) ;
00168                 if( !ParametersAccessor::get( node, "WindowName", windowName ) )
00169                 {
00170                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00171                                 << ">>> :-| no WindowName provided" ) ; 
00172                 }
00173 
00174    // createLog 
00175 
00176                 // OGRE initialisation
00177                 ok = ogreInitialisation( pluginsFile, configFile, resourcesFile, sceneManagerType, windowName ) ;
00178                 if ( ok )
00179                 {
00180                         // load the dotScene file of configuration parameters "SceneFile" 
00181                         // and resource group "ResourceGroup"
00182                         loadSceneFile( resourceGroupName, sceneFileName ) ;
00183 
00184                         if ( _root->getAutoCreatedWindow()->getNumViewports() == 0 )
00185                         {
00186                                 // try to initialise the camera named "Camera"
00187                                 // if cameraName was not specified a default camera is created
00188                                 cameraName = initCamera( cameraName ) ;
00189 
00190 
00191                                 // creates a default viewport of colour (0.5,0.5,0.5)
00192                                 createViewport( cameraName ) ;
00193                         }
00194                 }
00195         }
00196 
00197         return ok ;
00198 }

bool OgreVis::ogreInitialisation ( const std::string &  pluginsFile,
const std::string &  configurationFile,
const std::string &  resourcesFile,
const std::string &  sceneManagerType,
const std::string &  windowName 
) [private]

initialises Ogre3D, using the parameters found in ogre.cfg or by displaying a configuration window if there is no ogre.cfg available.

Definition at line 217 of file OMKOgreVis.cpp.

References _root, addResourceLocations(), createResourceListener(), createSceneManager(), and initResources().

Referenced by loadParameters().

00222 {
00223         bool initialised( false ) ;
00224 
00225         // creation of Ogre Root
00226         _root = new Ogre::Root( pluginsFile, configurationFile, "" ) ;
00227 
00228         // add resource locations
00229         addResourceLocations( resourcesFile );
00230 
00231         // Show the configuration dialog and initialise the system
00232         // You can skip this and use root.restoreConfig() to load configuration
00233         // settings if you were sure there are valid ones saved in ogre.cfg
00234         if( ( _root->restoreConfig() == true ) || ( _root->showConfigDialog() == true ) )
00235         {
00236                 // If returned true, user clicked OK so initialise
00237                 // Here we choose to let the system create a default rendering window by passing 'true'
00238                 _root->initialise( true, windowName ) ;
00239 
00240                 // creates a sceneManager named "sceneManager" of type ST_GENERIC
00241                 createSceneManager( sceneManagerType ) ;
00242 
00243                 // Set default mipmap level (NB some APIs ignore this)
00244                 TextureManager::getSingleton().setDefaultNumMipmaps( 5 ) ;
00245 
00246                 // Create any resource listeners (for loading screens)
00247                 createResourceListener() ;
00248 
00249                 // Initialise resources
00250                 initResources();
00251 
00252 #if !defined NDEBUG 
00253                 // Initialise the trace output to the console
00254                 OBT::Singleton<OBT::Tracer>::getInstance().setOutput( new LogOutput, true ) ;
00255 #endif
00256 
00257                 initialised = true ;
00258         }
00259 
00260         return initialised ;
00261 }

void OgreVis::createSceneManager ( const std::string &  sceneManagerType  )  [private]

creates a ST_GENERIC SceneManager named "SceneManager"

Definition at line 267 of file OMKOgreVis.cpp.

References _root, and OMFATALERROR.

Referenced by ogreInitialisation().

00268 {
00269         try
00270         {
00271                 // Create the SceneManager
00272                 _root->createSceneManager( sceneManagerType, "sceneManager" ) ;
00273         }
00274         catch ( Ogre::ItemIdentityException& e )
00275         {
00276                 OMFATALERROR( "Scene manager type : " << sceneManagerType << " does not exist" << std::endl 
00277                         << e.getFullDescription() ) ;
00278         }
00279 }

void OgreVis::createResourceListener ( void   )  [private]

not implemented yet

Definition at line 285 of file OMKOgreVis.cpp.

Referenced by ogreInitialisation().

00286 {
00287 }

void OgreVis::addResourceLocations ( const std::string &  resourcesFile  )  [private]

add the resources path given in the resources.cfg file

Definition at line 293 of file OMKOgreVis.cpp.

Referenced by ogreInitialisation().

00294 {
00295         // Load resource paths from config file
00296         ConfigFile configFile ;
00297         configFile.load( resourcesFile ) ;
00298 
00299         // Go through all sections & settings in the file
00300         ConfigFile::SectionIterator sectionIterator( configFile.getSectionIterator() ) ;
00301 
00302         String sectionName ;
00303         String typeName ;
00304         String archName ;
00305         while ( sectionIterator.hasMoreElements() == true )
00306         {
00307                 sectionName = sectionIterator.peekNextKey();
00308                 ConfigFile::SettingsMultiMap* settings( sectionIterator.getNext() ) ;
00309                 for ( ConfigFile::SettingsMultiMap::iterator i( settings->begin() ) ; i != settings->end(); ++i )
00310                 {
00311                         typeName = i->first ;
00312                         archName = i->second ;
00313                         ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, sectionName ) ;
00314                 }
00315         }
00316 }

void OgreVis::initResources ( void   )  [private]

initialises all the resource groups

Definition at line 322 of file OMKOgreVis.cpp.

Referenced by ogreInitialisation().

00323 {
00324         ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
00325 }

void OgreVis::loadSceneFile ( const std::string &  resourceGroupName,
const std::string &  sceneFileName 
) [private]

load the dotScene file of configuration parameters "SceneFile" and resource group "ResourceGroup"

Definition at line 331 of file OMKOgreVis.cpp.

References _root, OMK::Vis::debugMsg(), OMK_DEBUG_VIS, and OMTRACEID.

Referenced by loadParameters().

00332 {
00333         if ( sceneFileName.empty() == false )
00334         {
00335                 // load the scene associated to the simulated object OgreVis
00336                 OBT::Singleton<dsi::dotSceneLoader>::getInstance().load
00337                         (       sceneFileName, 
00338                                 resourceGroupName, 
00339                                 _root->getSceneManager( "sceneManager" ), 
00340                                 _root->getAutoCreatedWindow(), 
00341                                 NULL, 
00342                                 false, 
00343                                 false, 
00344                                 true ) ;
00345 
00346                 // check for load errors
00347                 dsi::dotSceneInfo::itLoadLog it( dsi::dotSceneInfo::getSceneLoadingLog() ) ;
00348                 String errs ;
00349                 while ( it.hasMoreElements() )
00350                 {
00351                         errs += it.getNext() + "\n";
00352                 }
00353                 if ( errs != StringUtil::BLANK )
00354                 {
00355                         OMTRACEID( OMK_DEBUG_VIS, "Warning for " << debugMsg( this ) << std::endl
00356                                 << ">>> :-| errors occured during scene loading\n" << errs ) ;
00357                 }
00358         }
00359 }

const std::string & OgreVis::initCamera ( const std::string &  cameraName  )  [private]

initialises the ogre camera of name cameraName if no camera was specified by the configuration parameter "Camera" it creates a default camera named "camera0" positioned at (0,0,0), looking at (0,0,-1), with (1,1000) clipping planes return the name of the created camera

Definition at line 365 of file OMKOgreVis.cpp.

References _root.

Referenced by loadParameters().

00366 {
00367         Ogre::SceneManager* sceneManager( _root->getSceneManager( "sceneManager" ) ) ;
00368         // creates a default camera if cameraName does not exist        
00369         if ( sceneManager->hasCamera( cameraName ) == false )
00370         {
00371 
00372                 // Create the camera
00373                 Camera* camera( sceneManager->createCamera( "camera0" ) ) ;
00374                 // Position it at 0, 0, 0
00375                 camera->setPosition( Vector3( 0, 0, 0 ) ) ;
00376                 // Look back along -Z
00377                 camera->lookAt( Vector3( 0, 0, -1 ) ) ;
00378                 camera->setNearClipDistance( 1 ) ;
00379                 camera->setFarClipDistance( 5000 ) ;
00380                 
00381                 //Put Camera on Node, useful for SoundListener 
00382                 SceneNode* cameraNode( sceneManager->getRootSceneNode()->createChildSceneNode( "CameraNode" ) ) ;
00383                 cameraNode->attachObject( camera );
00384                 return camera->getName() ;
00385         }
00386         return cameraName ;
00387 }

void OgreVis::createViewport ( const std::string &  cameraName  )  [private]

creates a default viewport of colour (0.5,0.5,0.5)

Definition at line 393 of file OMKOgreVis.cpp.

References _root.

Referenced by loadParameters().

00394 {
00395         Ogre::Camera* camera( _root->getSceneManager( "sceneManager" )->getCamera( cameraName ) ) ;
00396 
00397         // Create one viewport, entire window
00398         Viewport* viewport( _root->getAutoCreatedWindow()->addViewport( camera ) ) ;
00399         viewport->setBackgroundColour( ColourValue( 0.5, 0.5, 0.5 ) ) ;
00400 
00401         // Alter the camera aspect ratio to match the viewport
00402         camera->setAspectRatio( Real( viewport->getActualWidth() ) / Real( viewport->getActualHeight() ) ) ;
00403 }


Member Data Documentation

Ogre::Root* OMK::Vis::OgreVis::_root [private]

Ogre3D root, unique point of access to the Ogre3D scene organization.

Definition at line 115 of file OMKOgreVis.h.

Referenced by computeParameters(), createSceneManager(), createViewport(), getRoot(), initCamera(), loadParameters(), loadSceneFile(), and ogreInitialisation().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:05 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007