openvrml::scene Class Reference

A scene in the VRML world. More...

#include <openvrml/scene.h>

Public Member Functions

 scene (openvrml::browser &browser, scene *parent=0) throw ()
 Construct.
virtual ~scene () throw ()
 Destroy.
openvrml::browserbrowser () const throw ()
 Get the associated browser.
sceneparent () const throw ()
 Get the parent scene.
void load (resource_istream &in)
 Load the scene from a stream.
void initialize (double timestamp) throw ( std::bad_alloc )
 Initialize the scene.
const std::string meta (const std::string &key) const throw ( std::invalid_argument , std::bad_alloc )
 Get metadata.
void meta (const std::string &key, const std::string &value) throw ( std::bad_alloc )
 Set metadata.
const std::vector< std::string > meta_keys () const throw ( std::bad_alloc )
 Get the metadata keys.
const std::vector
< boost::intrusive_ptr< node > > 
nodes () const throw ( std::bad_alloc )
 Root nodes for the scene.
void nodes (const std::vector< boost::intrusive_ptr< node > > &n) throw ( std::invalid_argument , std::bad_alloc )
 Set the root nodes for the scene.
const scoperoot_scope () const throw ()
 Get the root scope.
const std::string url () const throw ( std::bad_alloc )
 Get the absolute URI for the scene.
void render (openvrml::viewer &viewer, rendering_context context)
 Render the scene.
void load_url (const std::vector< std::string > &url, const std::vector< std::string > &parameter) throw ( std::bad_alloc )
 Load a resource into browser.
std::auto_ptr< resource_istreamget_resource (const std::vector< std::string > &url) const throw ( no_alternative_url , std::bad_alloc )
 Get a resource using a list of alternative URIs.
void read_stream (std::auto_ptr< resource_istream > in, std::auto_ptr< stream_listener > listener)
 Read a stream in a new thread.
void create_vrml_from_url (const std::vector< std::string > &url, const boost::intrusive_ptr< node > &node, const std::string &event) throw ( unsupported_interface , std::bad_cast , boost::thread_resource_error )
 Create nodes from a URI.
void shutdown (double timestamp) throw ()
 Shut down the nodes in the scene.

Private Member Functions

virtual void scene_loaded ()
 Function called once the scene has been loaded.

Detailed Description

A scene in the VRML world.

Constructor & Destructor Documentation

openvrml::scene::scene ( openvrml::browser browser,
scene parent = 0 
) throw ()
explicit

Construct.

Parameters
[in]browserthe browser associated with the scene.
[in]parentthe parent scene.
openvrml::scene::~scene ( ) throw ()
virtual

Destroy.

Member Function Documentation

openvrml::browser & openvrml::scene::browser ( ) const throw ()

Get the associated browser.

Returns
the associated browser.
openvrml::scene * openvrml::scene::parent ( ) const throw ()

Get the parent scene.

Returns
the parent scene, or 0 if this is the root scene.
void openvrml::scene::load ( resource_istream in)

Load the scene from a stream.

This function calls scene_loaded once parsing the scene from in has completed.

Parameters
[in,out]inan input stream.
Exceptions
bad_media_typeif in.type() is not “model/vrml”, “x-world/x-vrml”, or “model/x3d-vrml”.
invalid_vrmlif in has invalid syntax.
void openvrml::scene::initialize ( double  timestamp) throw ( std::bad_alloc )

Initialize the scene.

Parameters
[in]timestampthe current time.
Exceptions
std::bad_allocif memory allocation fails.
const std::string openvrml::scene::meta ( const std::string &  key) const throw ( std::invalid_argument , std::bad_alloc )

Get metadata.

Parameters
[in]keymetadata key.
Returns
the metadata value associated with key.
Exceptions
std::invalid_argumentif there is no value associated with key.
std::bad_allocif memory allocation fails.
void openvrml::scene::meta ( const std::string &  key,
const std::string &  value 
) throw ( std::bad_alloc )

Set metadata.

Parameters
[in]keymetadata key.
[in]valuemetadata value.
Exceptions
std::bad_allocif memory allocation fails.
const std::vector< std::string > openvrml::scene::meta_keys ( ) const throw ( std::bad_alloc )

Get the metadata keys.

Returns
the metadata keys.
const std::vector< boost::intrusive_ptr< openvrml::node > > openvrml::scene::nodes ( ) const throw ( std::bad_alloc )

Root nodes for the scene.

Returns
the root nodes for the scene.
Exceptions
std::bad_allocif memory allocation fails.
void openvrml::scene::nodes ( const std::vector< boost::intrusive_ptr< node > > &  n) throw ( std::invalid_argument , std::bad_alloc )

Set the root nodes for the scene.

This function calls shutdown to shut down the scene's existing nodes.

Parameters
[in]nthe new root nodes for the scene.
Exceptions
std::invalid_argumentif any of the nodes in n has already been initialized.
std::bad_allocif memory allocation fails.
const openvrml::scope * openvrml::scene::root_scope ( ) const throw ()

Get the root scope.

Returns
the root scope.
const std::string openvrml::scene::url ( ) const throw ( std::bad_alloc )

Get the absolute URI for the scene.

Returns
the absolute URI for the scene.
Exceptions
std::bad_allocif memory allocation fails.
void openvrml::scene::render ( openvrml::viewer viewer,
rendering_context  context 
)

Render the scene.

Parameters
[in,out]viewera viewer to render to.
[in]contexta rendering_context.
void openvrml::scene::load_url ( const std::vector< std::string > &  url,
const std::vector< std::string > &  parameter 
) throw ( std::bad_alloc )

Load a resource into browser.

This method simply resolves any relative references in uri and calls browser::load_url.

Note
There are a couple of edge cases here where we are probably doing the wrong thing:
  • If there is a URI in the list of the form “#NodeId” and it is not the first URI in the list, this URI will be loaded as if it were a new world rather than as a Viewpoint that should simply be bound.
  • If the first URI in the list is of the form “#NodeId” and no Viewpoint named “NodeId” exists in the scene, this method will not try any subsequent URIs in the list.
Parameters
[in]urlan array of URIs. Per VRML97 convention, the first resource in the sequence that can be reached will be loaded into the browser.
[in]parameteran array of parameters to be associated with the URIs in uri.
Exceptions
std::bad_allocif memory allocation fails.
std::auto_ptr< openvrml::resource_istream > openvrml::scene::get_resource ( const std::vector< std::string > &  url) const throw ( no_alternative_url , std::bad_alloc )

Get a resource using a list of alternative URIs.

Relative URIs in url are resolved against the absolute URI of the scene.

Parameters
[in]urla list of alternative URIs.
Returns
the resource.
Exceptions
no_alternative_urlif none of the elements of url can be resolved.
std::bad_allocif memory allocation fails.
void openvrml::scene::read_stream ( std::auto_ptr< resource_istream in,
std::auto_ptr< stream_listener listener 
)

Read a stream in a new thread.

read_stream takes ownership of its arguments; the resources are released when reading the stream completes and the thread terminates.

Parameters
[in]inan input stream.
[in]listenera stream listener.
void openvrml::scene::create_vrml_from_url ( const std::vector< std::string > &  url,
const boost::intrusive_ptr< node > &  node,
const std::string &  event 
) throw ( unsupported_interface , std::bad_cast , boost::thread_resource_error )

Create nodes from a URI.

This function executes asynchronously. When the nodes have been completely loaded, they are sent to the event MFNode eventIn of node.

Parameters
[in]urlan alternative URI list.
[in]nodethe node to which the nodes loaded from url should be sent as an event.
[in]eventthe event of node to which the new nodes will be sent.
Exceptions
unsupported_interfaceif node has no eventIn event.
std::bad_castif the event eventIn of node is not an MFNode.
boost::thread_resource_errorif thread creation fails.
void openvrml::scene::shutdown ( double  timestamp) throw ()

Shut down the nodes in the scene.

This function must be called before the scene is destroyed.

Parameters
[in]timestampthe current time.
void openvrml::scene::scene_loaded ( )
privatevirtual

Function called once the scene has been loaded.

load calls this function once the scene has finished loading. The default implementation does nothing.