Home | Download | Screen shots | Discussion | Documentation |
---|
#include <openvrml/browser.h>
browser
is the foundation of the OpenVRML runtime. Users need to inherit this class and override do_get_resource
and provide an implementation of resource_istream
.
Public Member Functions | |
browser (std::ostream &out, std::ostream &err) throw ( std::bad_alloc ) | |
Constructor. | |
virtual | ~browser () throw () |
Destructor. | |
void | add_node_metatype (const node_metatype_id &id, const boost::shared_ptr< openvrml::node_metatype > &metatype) throw ( std::invalid_argument , std::bad_alloc ) |
Add a node_metatype . | |
const boost::shared_ptr< openvrml::node_metatype > | node_metatype (const node_metatype_id &id) const throw () |
Get the node_metatype corresponding to id . | |
scene * | root_scene () const throw () |
Get the root scene . | |
const node_path | find_node (const node &n) const throw ( std::bad_alloc ) |
Get the path to a node in the scene graph. | |
viewpoint_node & | active_viewpoint () const throw () |
Get the active viewpoint_node . | |
void | active_viewpoint (viewpoint_node &viewpoint) throw () |
Set the active viewpoint_node . | |
void | reset_default_viewpoint () throw () |
Reset the active viewpoint_node to the default. | |
navigation_info_node & | active_navigation_info () const throw () |
Get the active navigation_info_node . | |
void | active_navigation_info (navigation_info_node &nav_info) throw () |
Set the active navigation_info_node . | |
void | reset_default_navigation_info () throw () |
Reset the active navigation_info_node to the default. | |
void | add_viewpoint (viewpoint_node &viewpoint) throw ( std::bad_alloc ) |
Add a viewpoint_node to the list of viewpoint_nodes for the browser . | |
void | remove_viewpoint (viewpoint_node &viewpoint) throw () |
Remove a viewpoint_node from the list of viewpoint_nodes for the browser . | |
const std::list< viewpoint_node * > & | viewpoints () const throw () |
Get the list of viewpoint_nodes for the world. | |
void | viewer (openvrml::viewer *v) throw ( viewer_in_use ) |
Set the current viewer . | |
openvrml::viewer * | viewer () const throw () |
The current viewer . | |
std::auto_ptr< resource_istream > | get_resource (const std::string &uri) |
Fetch a network resource. | |
virtual const char * | name () const throw () |
Get the browser name. | |
virtual const char * | version () const throw () |
Get the browser version. | |
float | current_speed () |
Get the average navigation speed in meters per second. | |
const std::string | world_url () const throw ( std::bad_alloc ) |
Get the URI for the world. | |
void | set_world (resource_istream &in) |
Set the world from a stream. | |
void | replace_world (const std::vector< boost::intrusive_ptr< node > > &nodes) |
Replace the root nodes of the world. | |
void | load_url (const std::vector< std::string > &url, const std::vector< std::string > ¶meter) throw ( std::bad_alloc , boost::thread_resource_error ) |
Load a VRML world into the browser. | |
virtual void | description (const std::string &description) |
Send a string to the user interface. | |
const std::vector< boost::intrusive_ptr< node > > | create_vrml_from_stream (std::istream &in, const std::string &type=vrml_media_type) |
Generate nodes from a stream of VRML syntax. | |
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. | |
bool | add_listener (browser_listener &listener) throw ( std::bad_alloc ) |
Add a listener for browser_events . | |
bool | remove_listener (browser_listener &listener) throw () |
Remove a listener for browser_events . | |
void | sensitive_event (node *object, double timestamp, bool is_over, bool is_active, const double(&point)[3]) |
double | frame_rate () const |
Get the current frame rate. | |
bool | update (double current_time=-1.0) |
Process events (update the browser ). | |
void | render () |
Draw this browser into the specified viewer . | |
void | modified (bool value) |
Indicate whether rendering is necessary. | |
bool | modified () const |
Check if the browser has been modified. | |
void | delta (double d) |
Set the time until the next update is needed. | |
double | delta () const |
Get the time interval between browser updates. | |
void | add_scoped_light (scoped_light_node &) |
Add a scoped light node to the browser . | |
void | remove_scoped_light (scoped_light_node &) |
Remove a scoped light node from the browser . | |
void | add_time_dependent (time_dependent_node &n) |
Add a time-dependent node to the browser. | |
void | remove_time_dependent (time_dependent_node &n) |
Remove a time-dependent node from the browser. | |
void | add_script (script_node &) |
Add a Script node to the browser. | |
void | remove_script (script_node &) |
Remove a Script node from the browser. | |
void | update_flags () |
Propagate the bvolume dirty flag from children to ancestors. | |
void | out (const std::string &str) const |
Print a message to the output stream. | |
void | err (const std::string &str) const |
Print a message to the error stream. | |
Static Public Member Functions | |
static double | current_time () throw () |
Get the current time. | |
Public Attributes | |
bool | flags_need_updating |
Set by node::bounding_volume_dirty on any node in this browser graph, cleared by update_flags . | |
Protected Member Functions | |
bool | headlight_on () |
Indicate whether the headlight is on. | |
Protected Attributes | |
double | frame_rate_ |
Frame rate. | |
Private Member Functions | |
virtual std::auto_ptr< resource_istream > | do_get_resource (const std::string &uri)=0 |
Fetch a network resource. | |
Private Attributes | |
boost::recursive_mutex | mutex_ |
Object mutex. | |
std::auto_ptr< null_node_metatype > | null_node_metatype_ |
“Null” class object for default nodes (e.g., default_viewpoint ). | |
std::auto_ptr< null_node_type > | null_node_type_ |
“Null” type object for default nodes (e.g., default_viewpoint ). | |
boost::scoped_ptr< boost::thread > | load_root_scene_thread_ |
The thread that loads the root scene. | |
boost::thread_group | load_proto_thread_group_ |
The threads that load EXTERNPROTO implementations. | |
node_metatype_map | node_metatype_map_ |
A map of URIs to node implementations. | |
script_node_metatype | script_node_metatype_ |
node_metatype for Script nodes in the browser . | |
boost::scoped_ptr< scene > | scene_ |
Pointer to the root scene . | |
const boost::intrusive_ptr< node > | default_viewpoint_ |
The “default” viewpoint_node used when no viewpoint_node in the scene is bound. | |
viewpoint_node * | active_viewpoint_ |
The currently “active” viewpoint_node . | |
const boost::intrusive_ptr< node > | default_navigation_info_ |
The “default” navigation_info_node used when no navigation_info_node in the scene is bound. | |
navigation_info_node * | active_navigation_info_ |
The currently “active” navigation_info_node . | |
std::list< viewpoint_node * > | viewpoint_list |
A list of all the Viewpoint nodes in the browser . | |
std::list< scoped_light_node * > | scoped_lights |
A list of all the scoped light nodes in the browser . | |
std::list< script_node * > | scripts |
A list of all the Script nodes in the browser . | |
std::list< time_dependent_node * > | timers |
A list of all the TimeSensor nodes in the browser . | |
std::set< browser_listener * > | listeners_ |
The set of browser_listeners that will receive browser_events . | |
bool | new_view |
Flag to indicate if the user has changed to a new view. | |
double | delta_time |
Time elapsed since the last update. | |
openvrml::viewer * | viewer_ |
The current viewer . | |
bool | modified_ |
Flag to indicate whether the browser has been modified. | |
boost::mutex | modified_mutex_ |
Mutex protecting modified_ . | |
boost::mutex | out_mutex_ |
Mutex guarding out_ . | |
std::ostream *const | out_ |
Output stream, generally for console output. | |
boost::mutex | err_mutex_ |
Mutex guarding err_ . | |
std::ostream *const | err_ |
Error output stream. | |
Friends | |
class | Vrml97Parser |
VRML97 parser generated by ANTLR. | |
class | X3DVrmlParser |
X3D VRML parser generated by ANTLR. | |
bool | operator== (const node_type &, const node_type &) throw () |
Compare for equality. | |
Classes | |
class | node_metatype_map |
The map of node_metatypes . More... |
openvrml::browser::browser | ( | std::ostream & | out, | |
std::ostream & | err | |||
) | throw ( std::bad_alloc ) |
Constructor.
[in] | out | output stream for console output. |
[in] | err | output stream for error console output. |
std::bad_alloc | if memory allocation fails. |
openvrml::browser::~browser | ( | ) | throw () [virtual] |
Destructor.
double openvrml::browser::current_time | ( | ) | throw () [static] |
Get the current time.
void openvrml::browser::add_node_metatype | ( | const node_metatype_id & | id, | |
const boost::shared_ptr< openvrml::node_metatype > & | nc | |||
) | throw ( std::invalid_argument , std::bad_alloc ) |
Add a node_metatype
.
If a node_metatype
identified by id
has already been added to the browser, it will be replaced.
std::bad_alloc
is thrown here, the browser
's node_metatype
map is left in an unknown state. In all likelihood any preexisting entry in the map with the same implementation identifier as id
will have been removed.[in] | id | a node_metatype identifier. |
[in] | nc | a boost::shared_ptr to a node_metatype |
std::invalid_argument | if nc is null. | |
std::bad_alloc | if memory allocation fails. |
const boost::shared_ptr< openvrml::node_metatype > openvrml::browser::node_metatype | ( | const node_metatype_id & | id | ) | const throw () |
Get the node_metatype
corresponding to id
.
[in] | id | a node_metatype identifier. |
node_metatype
corresponding to id
; or a null pointer if no such node_metatype
exists. openvrml::scene * openvrml::browser::root_scene | ( | ) | const throw () |
const openvrml::node_path openvrml::browser::find_node | ( | const node & | n | ) | const throw ( std::bad_alloc ) |
openvrml::viewpoint_node & openvrml::browser::active_viewpoint | ( | ) | const throw () |
Get the active viewpoint_node
.
The active viewpoint_node
is the one currently associated with the user view.
viewpoint_node
. void openvrml::browser::active_viewpoint | ( | viewpoint_node & | viewpoint | ) | throw () |
void openvrml::browser::reset_default_viewpoint | ( | ) | throw () |
Reset the active viewpoint_node
to the default.
openvrml::navigation_info_node & openvrml::browser::active_navigation_info | ( | ) | const throw () |
Get the active navigation_info_node
.
The active navigation_info_node
is the one currently associated with the user view.
navigation_info_node
. void openvrml::browser::active_navigation_info | ( | navigation_info_node & | nav_info | ) | throw () |
void openvrml::browser::reset_default_navigation_info | ( | ) | throw () |
Reset the active navigation_info_node
to the default.
void openvrml::browser::add_viewpoint | ( | viewpoint_node & | viewpoint | ) | throw ( std::bad_alloc ) |
Add a viewpoint_node
to the list of viewpoint_nodes
for the browser
.
[in] | viewpoint | a viewpoint_node . |
std::bad_alloc | if memory allocation fails. |
viewpoint
is not in the list of viewpoint_nodes
for the browser
. void openvrml::browser::remove_viewpoint | ( | viewpoint_node & | viewpoint | ) | throw () |
Remove a viewpoint_node
from the list of viewpoint_nodes
for the browser
.
[in] | viewpoint | a viewpoint_node . |
viewpoint
is in the list of viewpoint_nodes
for the browser
. const std::list< openvrml::viewpoint_node * > & openvrml::browser::viewpoints | ( | ) | const throw () |
void openvrml::browser::viewer | ( | openvrml::viewer * | v | ) | throw ( viewer_in_use ) |
Set the current viewer
.
[in] | v | viewer . |
viewer_in_use | if v is already associated with a browser . |
openvrml::viewer * openvrml::browser::viewer | ( | ) | const throw () |
std::auto_ptr< openvrml::resource_istream > openvrml::browser::get_resource | ( | const std::string & | uri | ) |
Fetch a network resource.
[in] | uri | a Uniform Resource Identifier. |
std::invalid_argument | if uri is malformed or in an unsupported format. |
const char * openvrml::browser::name | ( | ) | const throw () [virtual] |
const char * openvrml::browser::version | ( | ) | const throw () [virtual] |
Get the browser
version.
float openvrml::browser::current_speed | ( | ) |
Get the average navigation speed in meters per second.
const std::string openvrml::browser::world_url | ( | ) | const throw ( std::bad_alloc ) |
Get the URI for the world.
void openvrml::browser::set_world | ( | resource_istream & | in | ) |
Set the world from a stream.
[in,out] | in | an input stream. |
bad_media_type | if in.type() is not model/vrml , x-world/x-vrml , or model/x3d+vrml . | |
invalid_vrml | if in has invalid syntax. |
void openvrml::browser::replace_world | ( | const std::vector< boost::intrusive_ptr< node > > & | nodes | ) |
Replace the root nodes of the world.
[in] | nodes | new root nodes for the world. |
void openvrml::browser::load_url | ( | const std::vector< std::string > & | url, | |
const std::vector< std::string > & | parameter | |||
) | throw ( std::bad_alloc , boost::thread_resource_error ) |
Load a VRML world into the browser.
[in] | url | a URI. |
[in] | parameter | parameters for url . |
std::bad_alloc | if memory allocation fails. | |
boost::thread_resource_error | if thread creation fails. |
void openvrml::browser::description | ( | const std::string & | description | ) | [virtual] |
Send a string to the user interface.
The default implementation of this method simply prints description
to out. Subclasses can override this method to direct messages to an application's UI; for instance, a status bar.
[in] | description | a string. |
const std::vector< boost::intrusive_ptr< openvrml::node > > openvrml::browser::create_vrml_from_stream | ( | std::istream & | in, | |
const std::string & | type = vrml_media_type | |||
) |
Generate nodes from a stream of VRML syntax.
In addition to the exceptions listed, this method may throw any exception that may result from reading the input stream.
[in,out] | in | an input stream. |
[in] | type | MIME content type of in . |
in
.invalid_vrml | if in has invalid VRML syntax. | |
std::invalid_argument | if type refers to an unsupported content type. | |
std::bad_alloc | if memory allocation fails. |
void openvrml::browser::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
.
[in] | url | an alternative URI list. |
[in] | node | the node to which the nodes loaded from url should be sent as an event. |
[in] | event | the event of node to which the new nodes will be sent. |
unsupported_interface | if node has no eventIn event . | |
std::bad_cast | if the event eventIn of node is not an MFNode. | |
boost::thread_resource_error | if thread creation fails. |
bool openvrml::browser::add_listener | ( | browser_listener & | listener | ) | throw ( std::bad_alloc ) |
Add a listener for browser_events
.
[in] | listener | a browser_listener . |
true
if listener
is added successfully; false
otherwise (if listener
is already listening for events from the browser
).std::bad_alloc | if memory allocation fails. |
bool openvrml::browser::remove_listener | ( | browser_listener & | listener | ) | throw () |
Remove a listener for browser_events
.
[in] | listener | a browser_listener . |
true
if listener
is removed successfully; false
otherwise (if listener
is not listening for events from the browser
). void openvrml::browser::sensitive_event | ( | node * | object, | |
double | timestamp, | |||
bool | is_over, | |||
bool | is_active, | |||
const double & | point[3] | |||
) |
double openvrml::browser::frame_rate | ( | ) | const |
Get the current frame rate.
bool openvrml::browser::update | ( | double | current_time = -1.0 |
) |
void openvrml::browser::modified | ( | bool | value | ) |
Indicate whether rendering is necessary.
[in] | value | true to indicate that the browser state has changed and rerendering is necessary; false once rendering has occurred. |
bool openvrml::browser::modified | ( | ) | const |
void openvrml::browser::delta | ( | double | d | ) |
Set the time until the next update is needed.
[in] | d | a time interval. |
double openvrml::browser::delta | ( | ) | const |
void openvrml::browser::add_scoped_light | ( | scoped_light_node & | light | ) |
void openvrml::browser::remove_scoped_light | ( | scoped_light_node & | light | ) |
void openvrml::browser::add_time_dependent | ( | time_dependent_node & | n | ) |
Add a time-dependent node to the browser.
[in] | n | a time_dependent_node . |
n
is not in the list of time_dependent_nodes
for the browser
. void openvrml::browser::remove_time_dependent | ( | time_dependent_node & | n | ) |
Remove a time-dependent node from the browser.
[in] | n | the time_dependent_node to remove. |
n
is in the list of time_dependent_nodes
for the browser
. void openvrml::browser::add_script | ( | script_node & | script | ) |
void openvrml::browser::remove_script | ( | script_node & | script | ) |
void openvrml::browser::update_flags | ( | ) |
Propagate the bvolume dirty flag from children to ancestors.
The invariant is that if a node
's bounding volume is out of date, then the bounding volumes of all that node
's ancestors must be out of date. However, node
does not maintain a parent pointer. So we must do a traversal of the entire browser graph to do the propagation.
node::isBVolumeDirty
void openvrml::browser::out | ( | const std::string & | str | ) | const |
Print a message to the output stream.
[in] | str | a string. |
void openvrml::browser::err | ( | const std::string & | str | ) | const |
Print a message to the error stream.
[in] | str | a string. |
bool openvrml::browser::headlight_on | ( | ) | [protected] |
Indicate whether the headlight is on.
true
if the headlight is on; false
otherwise. std::auto_ptr< openvrml::resource_istream > openvrml::browser::do_get_resource | ( | const std::string & | uri | ) | [private, pure virtual] |
Fetch a network resource.
Called by get_resource
, clients of OpenVRML are required to provide an implementation for this function. OpenVRML depends on the implementation of this function for all of its input needs. As such, what kind of resources OpenVRML is capable of resolving is entirely dependent on code provided by the application.
Implementations should throw std::invalid_argument
if uri
is malformed or in an format that is not supported by the implementation.
A trivial implementation designed to handle only file
resources can use std::filebuf:
std::auto_ptr<openvrml::resource_istream> my_browser::do_get_resource(const std::string & uri) { using std::auto_ptr; using std::invalid_argument; using std::string; using openvrml::resource_istream; class file_resource_istream : public resource_istream { std::string url_; std::filebuf buf_; public: explicit file_resource_istream(const std::string & path): resource_istream(&this->buf_) { // // Note that the failbit is set in the constructor if no data // can be read from the stream. This is important. If the // failbit is not set on such a stream, OpenVRML will attempt // to read data from a stream that cannot provide it. // if (!this->buf_.open(path.c_str(), ios_base::in | ios_base::binary)) { this->setstate(ios_base::badbit); } } void url(const std::string & str) { this->url_ = str; } private: virtual const std::string url() const { return this->url_; } virtual const std::string type() const { // // A real application should use OS facilities for this; // however, that is beyond the scope of this example (which // is intended to be portable and stupid). // using std::find; using std::string; using boost::algorithm::iequals; using boost::next; string media_type = "application/octet-stream"; const string::const_reverse_iterator dot_pos = find(this->url_.rbegin(), this->url_.rend(), '.'); if (dot_pos == this->url_.rend() || next(dot_pos.base()) == this->url_.end()) { return media_type; } const string::const_iterator hash_pos = find(next(dot_pos.base()), this->url_.end(), '#'); const string ext(dot_pos.base(), hash_pos); if (iequals(ext, "wrl")) { media_type = "model/vrml"; } else if (iequals(ext, "png")) { media_type = "image/png"; } else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) { media_type = "image/jpeg"; } return media_type; } virtual bool data_available() const { return !!(*this); } }; const string scheme = uri.substr(0, uri.find_first_of(':')); if (scheme != "file") { throw invalid_argument('\"' + scheme + "\" URI scheme not " "supported"); } // // file:// // ^ // 01234567 // string path = uri.substr(uri.find_first_of('/', 7)); auto_ptr<resource_istream> in(new file_resource_istream(path)); static_cast<file_resource_istream *>(in.get())->url(uri); return in; }
The uri
parameter is provided by OpenVRML and can be assumed to be an absolute URI. As such, it will always have a scheme through which the client code can choose a resolution mechanism. For more information on URI syntax, see Internet STD 66.
[in] | uri | an absolute Uniform Resource Identifier. |
std::invalid_argument | if uri is malformed or in an unsupported format. |
openvrml::browser::Vrml97Parser [friend] |
VRML97 parser generated by ANTLR.
openvrml::browser::X3DVrmlParser [friend] |
X3D VRML parser generated by ANTLR.
Compare for equality.
Two node_types
t
and u
are considered equal if all of the following are true:
t.id() == u.id()
t.interfaces() == u.interfaces()
t.metatype().id()
is in the set of identifiers associated with u
in the browser
's node_metatype
map.Note that the latter requirement makes this comparison a rather expensive operation.
[in] | lhs | |
[in] | rhs |
true
if lhs
and rhs
are equal; false
otherwise.
boost::recursive_mutex openvrml::browser::mutex_ [mutable, private] |
Object mutex.
For internal use only.
std::auto_ptr< openvrml::null_node_metatype > openvrml::browser::null_node_metatype_ [private] |
“Null” class object for default nodes (e.g., default_viewpoint
).
For internal use only.
std::auto_ptr< openvrml::null_node_type > openvrml::browser::null_node_type_ [private] |
“Null” type object for default nodes (e.g., default_viewpoint
).
For internal use only.
boost::scoped_ptr< boost::thread > openvrml::browser::load_root_scene_thread_ [private] |
boost::thread_group openvrml::browser::load_proto_thread_group_ [private] |
The threads that load EXTERNPROTO
implementations.
For internal use only.
These threads must be joined by the browser
before it is destroyed.
openvrml::scene * openvrml::browser::scene_ [private] |
boost::intrusive_ptr< openvrml::node > openvrml::browser::default_viewpoint_ [private] |
The “default” viewpoint_node
used when no viewpoint_node
in the scene is bound.
For internal use only.
boost::intrusive_ptr< openvrml::node > openvrml::browser::default_navigation_info_ [private] |
The “default” navigation_info_node
used when no navigation_info_node
in the scene is bound.
For internal use only.
std::list< openvrml::viewpoint_node * > openvrml::browser::viewpoint_list [private] |
std::list< openvrml::node * > openvrml::browser::scoped_lights [private] |
std::list< openvrml::script_node * > openvrml::browser::scripts [private] |
std::list< openvrml::time_dependent_node * > openvrml::browser::timers [private] |
std::set< openvrml::browser_listener * > openvrml::browser::listeners_ [private] |
bool openvrml::browser::new_view [private] |
Flag to indicate if the user has changed to a new view.
double openvrml::browser::delta_time [private] |
Time elapsed since the last update.
openvrml::openvrml::viewer * openvrml::browser::viewer_ [private] |
The current viewer
.
bool openvrml::browser::modified_ [private] |
Flag to indicate whether the browser
has been modified.
boost::mutex openvrml::browser::modified_mutex_ [mutable, private] |
Mutex protecting modified_
.
boost::mutex openvrml::browser::out_mutex_ [mutable, private] |
Mutex guarding out_
.
std::ostream & openvrml::browser::out_ [private] |
Output stream, generally for console output.
boost::mutex openvrml::browser::err_mutex_ [mutable, private] |
Mutex guarding err_
.
std::ostream & openvrml::browser::err_ [private] |
Error output stream.
double openvrml::browser::frame_rate_ [protected] |
Frame rate.