Main Page   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

Browser Class Reference

Encapsulates a VRML browser. More...

List of all members.


Public Types

typedef void(* SceneCB )(CBReason reason)
 A pointer to a browser callback function.

enum  CBReason {
  DESTROY_WORLD,
  REPLACE_WORLD
}
 Valid reasons for browser callback. More...


Public Methods

 Browser (std::ostream &out, std::ostream &err) throw (std::bad_alloc)
 Constructor.

virtual ~Browser () throw ()
 Destructor.

const MFNodegetRootNodes () const throw ()
 Get the root nodes for the browser.

virtual const char * getName () const throw ()
 Get the browser name.

virtual const char * getVersion () const throw ()
 Get the browser version.

const std::string getWorldURI () const throw (std::bad_alloc)
 Get the URI for the world.

void replaceWorld (const MFNode &nodes)
virtual void loadURI (const MFString &uri, const MFString &parameter) throw (std::bad_alloc)
 Load a resource into the browser.

virtual void setDescription (const std::string &description)
 Send a string to the user interface.

const MFNode createVrmlFromStream (std::istream &in)
 Generate nodes from a stream of VRML syntax.

void createVrmlFromURI (const MFString &uri, const NodePtr &node, const std::string &event)
void addWorldChangedCallback (SceneCB)
 Add a callback function to be called when the world changes.

void sensitiveEvent (Node *object, double timeStamp, bool isOver, bool isActive, double *point)
void queueEvent (double timeStamp, FieldValue *value, const NodePtr &toNode, const std::string &toEventIn)
 Queue an event for a node.

bool eventsPending ()
 Check if any events are waiting to be distributed.

void flushEvents ()
 Discard all pending events.

double getFrameRate () const
 Get the current frame rate.

bool update (double currentTime=-1.0)
 Process events (update the browser).

void render (Viewer &viewer)
 Draw this browser into the specified viewer.

void setModified ()
 Indicate that the browser state has changed; need to rerender.

void clearModified ()
 Clear the "modified" flag for the browser.

bool isModified () const
 Check if the browser has been modified.

void setDelta (double d)
 Set the time until the next update is needed.

double getDelta () const
 Get the time interval between browser updates.

void addNavigationInfo (Vrml97Node::NavigationInfo &)
 Add a NavigationInfo node to the list of NavigationInfo nodes for the browser.

void removeNavigationInfo (Vrml97Node::NavigationInfo &)
 Remove a NavigationInfo node from the list of NavigationInfo nodes for the browser.

Vrml97Node::NavigationInfobindableNavigationInfoTop ()
 Get the active node on the bound NavigationInfo stack.

void bindablePush (Vrml97Node::NavigationInfo *)
 Push a NavigationInfo node onto the bound NavigationInfo node stack.

void bindableRemove (Vrml97Node::NavigationInfo *)
 Remove a NavigationInfo node from the bound NavigationInfo node stack.

void addViewpoint (Vrml97Node::Viewpoint &)
 Add a Viewpoint node to the list of Viewpoint nodes for the browser.

void removeViewpoint (Vrml97Node::Viewpoint &)
 Remove a Viewpoint node from the list of Viewpoint nodes for the browser.

Vrml97Node::ViewpointbindableViewpointTop ()
 Get the active node on the bound Viewpoint stack.

void bindablePush (Vrml97Node::Viewpoint *)
 Push a Viewpoint node onto the bound Viewpoint node stack.

void bindableRemove (Vrml97Node::Viewpoint *)
 Remove a Viewpoint node from the bound Viewpoint node stack.

void nextViewpoint ()
 Bind to the next Viewpoint in the list.

void prevViewpoint ()
 Bind to the previous Viewpoint in the list.

size_t nViewpoints ()
 Get the number of Viewpoint nodes in the browser.

void getViewpoint (size_t index, std::string &name, std::string &description)
 Get the name and description of a Viewpoint.

void setViewpoint (const std::string &name)
 Bind to a specific Viewpoint.

void setViewpoint (size_t index)
 Bind to a Viewpoint with a particular index.

void addScopedLight (Vrml97Node::AbstractLight &)
 Add a scoped light node to the browser.

void removeScopedLight (Vrml97Node::AbstractLight &)
 Remove a scoped light node from the browser.

void addTimeSensor (Vrml97Node::TimeSensor &)
 Add a TimeSensor node to the browser.

void removeTimeSensor (Vrml97Node::TimeSensor &)
 Remove a TimeSensor node from the browser.

void addAudioClip (Vrml97Node::AudioClip &)
 Add an AudioClip node to the browser.

void removeAudioClip (Vrml97Node::AudioClip &)
 Remove an AudioClip node from the browser.

void addMovie (Vrml97Node::MovieTexture &)
 Add a MovieTexture node to the browser.

void removeMovie (Vrml97Node::MovieTexture &)
 Remove a MovieTexture node from the browser.

void addProto (ProtoNode &node)
 Add a PROTO instance to the browser.

void removeProto (ProtoNode &node)
 Remove a PROTO instance from the browser.

void addScript (ScriptNode &)
 Add a Script node to the browser.

void removeScript (ScriptNode &)
 Remove a Script node from the browser.

void updateFlags ()
 Propagate the bvolume dirty flag from children to ancestors.


Public Attributes

std::ostream & out
 Output stream, generally for console output.

std::ostream & err
 Error output stream.

bool d_flags_need_updating
 Set by Node::setBVolumeDirty on any node in this browser graph, cleared by updateFlags.


Protected Types

typedef std::list< SceneCBSceneCBList
 List of functions to call when the world is changed.

enum  { MAXEVENTS = 400 }

Protected Methods

bool headlightOn ()
void doCallbacks (CBReason reason)
 Execute browser callback functions.

const NodePtr bindableTop (const BindStack &stack)
 Get the top node of a BindStack.

void bindablePush (BindStack &stack, const NodePtr &node)
 Push a node onto a BindStack.

void bindableRemove (BindStack &stack, const NodePtr &node)
 Remove a node from a BindStack.


Protected Attributes

SceneCBList d_sceneCallbacks
 List of functions to call when the world is changed.

double d_frameRate
 Frame rate.

Event d_eventMem [MAXEVENTS]
 The event queue.

size_t d_firstEvent
size_t d_lastEvent

Private Types

typedef std::map< std::string,
NodeClassPtr
NodeClassMap
 Maps URIs to NodeClasses.

typedef std::list< NodePtrBindStack
 A list of bound nodes.


Private Methods

 Browser (const Browser &)
Browser & operator= (const Browser &)
void initNodeClassMap ()
 Initialize the NodeClass map with the available node implementations.


Private Attributes

NodeClassMap nodeClassMap
 A map of URIs to node implementations.

ScriptNodeClass scriptNodeClass
 NodeClass for Script nodes in the browser.

Scenescene
 Pointer to the root Scene.

BindStack d_navigationInfoStack
 The stack of bound NavigationInfo nodes.

BindStack d_viewpointStack
 The stack of bound Viewpoint nodes.

std::list< Node * > d_navigationInfos
 A list of all the NavigationInfo nodes in the browser.

std::list< Node * > d_viewpoints
 A list of all the Viewpoint nodes in the browser.

std::list< Node * > d_scopedLights
 A list of all the scoped light nodes in the browser.

std::list< ScriptNode * > d_scripts
 A list of all the Script nodes in the browser.

std::list< Node * > d_timers
 A list of all the TimeSensor nodes in the browser.

std::list< Node * > d_audioClips
 A list of all the AudioClip nodes in the browser.

std::list< Node * > d_movies
 A list of all the MovieTexture nodes in the browser.

std::list< ProtoNode * > protoNodeList
 A list of all the prototype nodes in the browser.

bool d_modified
 Flag to indicate whether the browser has been modified.

bool d_newView
 Flag to indicate if the user has changed to a new view.

double d_deltaTime
 Time elapsed since the last update.


Friends

class Vrml97Parser
 VRML97 parser generated by ANTLR.

class ProtoNodeClass
 Class object for ProtoNodes.

class Vrml97RootScope

Detailed Description

Encapsulates a VRML browser.


Member Typedef Documentation

BindStack [private]
 

A list of bound nodes.

NodeClassMap [private]
 

Maps URIs to NodeClasses.

SceneCB
 

A pointer to a browser callback function.

The callback function provoides a way to let the app know when a world is loaded, changed, etc.

SceneCBList [protected]
 

List of functions to call when the world is changed.


Member Enumeration Documentation

anonymous enum [protected]
 

Enumeration values:
MAXEVENTS  The maximum number of events which may be queued.

Each browser can have a limited number of pending events. Repeatedly allocating/freeing events is slow (it would be nice to get rid of the field cloning, too), and if there are so many events pending, we are probably running too slow to handle them effectively anyway.

enum CBReason
 

Valid reasons for browser callback.

Enumeration values:
DESTROY_WORLD  Destroy the world.

REPLACE_WORLD  Replace the world.


Constructor & Destructor Documentation

Browser std::ostream &    out,
std::ostream &    err
throw (std::bad_alloc)
 

Constructor.

Parameters:
out output stream for console output.
err output stream for error console output.
Exceptions:
std::bad_alloc if memory allocation fails.

~Browser   throw () [virtual]
 

Destructor.


Member Function Documentation

void addAudioClip Vrml97Node::AudioClip   audio_clip
 

Add an AudioClip node to the browser.

Parameters:
audio_clip an AudioClip node.
Precondition:
audio_clip is not in the list of AudioClip nodes for the browser.

void addMovie Vrml97Node::MovieTexture   movie
 

Add a MovieTexture node to the browser.

Parameters:
movie a MovieTexture node.
Precondition:
movie is not in the list of MovieTexture nodes for the browser.

void addNavigationInfo Vrml97Node::NavigationInfo   node
 

Add a NavigationInfo node to the list of NavigationInfo nodes for the browser.

Parameters:
node a NavigationInfo node.
Precondition:
node is not in the list of NavigationInfo nodes for the browser.

void addProto ProtoNode &    node
 

Add a PROTO instance to the browser.

Parameters:
node a PROTO instance.
Precondition:
node is not in the list of prototype instances for the browser.

void addScopedLight Vrml97Node::AbstractLight   light
 

Add a scoped light node to the browser.

Parameters:
light a light node.
Precondition:
light is not in the list of light nodes for the browser.

void addScript ScriptNode   script
 

Add a Script node to the browser.

Parameters:
script a Script node.
Precondition:
script is not in the list of Script nodes for the browser.

void addTimeSensor Vrml97Node::TimeSensor   timer
 

Add a TimeSensor node to the browser.

Parameters:
timer a TimeSensor node.
Precondition:
timer is not in the list of TimeSensor nodes for the browser.

void addViewpoint Vrml97Node::Viewpoint   node
 

Add a Viewpoint node to the list of Viewpoint nodes for the browser.

Parameters:
node a Viewpoint node.
Precondition:
node is not in the list of Viewpoint nodes for the browser.

void addWorldChangedCallback SceneCB    cb
 

Add a callback function to be called when the world changes.

Parameters:
cb a browser callback function.

Vrml97Node::NavigationInfo * bindableNavigationInfoTop  
 

Get the active node on the bound NavigationInfo stack.

Returns:
the active node on the bound NavigationInfo stack.

void bindablePush BindStack   stack,
const NodePtr   node
[protected]
 

Push a node onto a BindStack.

Parameters:
stack the BindStack onto which to push node.
node the Node to push onto stack.

void bindablePush Vrml97Node::Viewpoint   n
 

Push a Viewpoint node onto the bound Viewpoint node stack.

Parameters:
n a Viewpoint node.

void bindablePush Vrml97Node::NavigationInfo   n
 

Push a NavigationInfo node onto the bound NavigationInfo node stack.

Parameters:
n a NavigationInfo node.

void bindableRemove BindStack   stack,
const NodePtr   node
[protected]
 

Remove a node from a BindStack.

Parameters:
stack the BindStack from which to remove node.
node the Node to remove from stack.

void bindableRemove Vrml97Node::Viewpoint   n
 

Remove a Viewpoint node from the bound Viewpoint node stack.

Parameters:
n a Viewpoint node.

void bindableRemove Vrml97Node::NavigationInfo   n
 

Remove a NavigationInfo node from the bound NavigationInfo node stack.

Parameters:
n a NavigationInfo node.

const NodePtr bindableTop const BindStack   stack [protected]
 

Get the top node of a BindStack.

Returns:
the top node of stack.

Vrml97Node::Viewpoint * bindableViewpointTop  
 

Get the active node on the bound Viewpoint stack.

Returns:
the active node on the bound Viewpoint stack.

void clearModified  
 

Clear the "modified" flag for the browser.

const MFNode createVrmlFromStream std::istream &    in
 

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.

Parameters:
in an input stream.
Returns:
the root nodes generated from in.
Exceptions:
InvalidVrml if in has invalid VRML syntax.
std::bad_alloc if memory allocation fails.

void createVrmlFromURI const MFString   uri,
const NodePtr   node,
const std::string &    event
 

Todo:
Implement me!

void doCallbacks CBReason    reason [protected]
 

Execute browser callback functions.

Parameters:
reason the CBReason to pass to the callback functions.

bool eventsPending  
 

Check if any events are waiting to be distributed.

Returns:
true if there are pending events, false otherwise.

void flushEvents  
 

Discard all pending events.

double getDelta   const
 

Get the time interval between browser updates.

Returns:
the time interval between browser updates.

double getFrameRate   const
 

Get the current frame rate.

Returns:
the current frame rate.

const char * getName   const throw () [virtual]
 

Get the browser name.

Returns:
"%OpenVRML"
Specific browsers may wish to override this method.

const MFNode & getRootNodes   const throw ()
 

Get the root nodes for the browser.

Returns:
the root nodes for the browser.

const char * getVersion   const throw () [virtual]
 

Get the browser version.

Returns:
the version of OpenVRML.
Specific browsers may wish to override this method.

void getViewpoint size_t    index,
std::string &    name,
std::string &    description
 

Get the name and description of a Viewpoint.

Parameters:
index the index of the Viewpoint.
Return values:
name the name of the Viewpoint.
description the description of the Viewpoint.

const std::string getWorldURI   const throw (std::bad_alloc)
 

Get the URI for the world.

Returns:
the URI for the world.

void initNodeClassMap   [private]
 

Initialize the NodeClass map with the available node implementations.

bool isModified   const
 

Check if the browser has been modified.

Returns:
true if the browser has been modified, false otherwise.

void loadURI const MFString   uri,
const MFString   parameter
throw (std::bad_alloc) [virtual]
 

Load a resource into the browser.

The default implementation of this method simply loads a VRML world into the Browser. If the resource at uri is not a VRML world, this method as no effect.

Implementations should override this method to handle non-VRML resources, handing them off to a Web browser or other appropriate handler.

Parameters:
uri a URI.
parameter paramaters for uri.

Todo:
Make this asynchronous.

void nextViewpoint  
 

Bind to the next Viewpoint in the list.

size_t nViewpoints  
 

Get the number of Viewpoint nodes in the browser.

Returns:
the number of Viewpoint nodes in the browser.

void prevViewpoint  
 

Bind to the previous Viewpoint in the list.

void queueEvent double    timeStamp,
FieldValue   value,
const NodePtr   toNode,
const std::string &    toEventIn
 

Queue an event for a node.

Current events are in the array d_eventMem[d_firstEvent,d_lastEvent). If d_firstEvent == d_lastEvent, the queue is empty. There is a fixed maximum number of events. If we are so far behind that the queue is filled, the oldest events get overwritten.

void removeAudioClip Vrml97Node::AudioClip   audio_clip
 

Remove an AudioClip node from the browser.

Parameters:
audio_clip the AudioClip node to remove.
Precondition:
audio_clip is in the list of AudioClip nodes for the browser.

void removeMovie Vrml97Node::MovieTexture   movie
 

Remove a MovieTexture node from the browser.

Parameters:
movie the MovieTexture node to remove.
Precondition:
movie is in the list of MovieTexture nodes for the browser.

void removeNavigationInfo Vrml97Node::NavigationInfo   node
 

Remove a NavigationInfo node from the list of NavigationInfo nodes for the browser.

Parameters:
node a NavigationInfo node.
Precondition:
node is in the list of NavigationInfo nodes for the browser.

void removeProto ProtoNode &    node
 

Remove a PROTO instance from the browser.

Parameters:
node the PROTO instance to remove.
Precondition:
node exists in the browser's list of prototype instances.

void removeScopedLight Vrml97Node::AbstractLight   light
 

Remove a scoped light node from the browser.

Parameters:
light the light node to remove.
Precondition:
light is in the list of light nodes for the browser.

void removeScript ScriptNode   script
 

Remove a Script node from the browser.

Parameters:
script the Script node to remove.
Precondition:
script is in the list of Script nodes for the browser.

void removeTimeSensor Vrml97Node::TimeSensor   timer
 

Remove a TimeSensor node from the browser.

Parameters:
timer the TimeSensor node to remove.
Precondition:
timer is in the list of TimeSensor nodes for the browser.

void removeViewpoint Vrml97Node::Viewpoint   node
 

Remove a Viewpoint node from the list of Viewpoint nodes for the browser.

Parameters:
node a Viewpoint node.
Precondition:
node is in the list of Viewpoint nodes for the browser.

void render Viewer   viewer
 

Draw this browser into the specified viewer.

void replaceWorld const MFNode   nodes
 

Todo:
Implement me!

void setDelta double    d
 

Set the time until the next update is needed.

Parameters:
d a time interval.

void setDescription 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.

Parameters:
description a string.

void setModified  
 

Indicate that the browser state has changed; need to rerender.

void setViewpoint size_t    index
 

Bind to a Viewpoint with a particular index.

Parameters:
index the index of the Viewpoint to bind to.
If index is not a valid index, this method has no effect.

void setViewpoint const std::string &    name
 

Bind to a specific Viewpoint.

Parameters:
name the nodeId of the Viewpoint to bind to.
This method will bind to a Viewpoint with the nodeId name. If no such Viewpoint is available, this method has no effect.

bool update double    currentTime = -1.0
 

Process events (update the browser).

This method should be called after each frame is rendered.

Returns:
true if the browser needs to be rerendered, false otherwise.

void updateFlags  
 

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 nodes'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.

See also:
Node::setBVolumeDirty

Node::isBVolumeDirty


Friends And Related Function Documentation

ProtoNodeClass [friend]
 

Class object for ProtoNodes.

Vrml97Parser [friend]
 

VRML97 parser generated by ANTLR.


Member Data Documentation

std::list< Node * > d_audioClips [private]
 

A list of all the AudioClip nodes in the browser.

double d_deltaTime [private]
 

Time elapsed since the last update.

Browser::Event d_eventMem [protected]
 

The event queue.

Todo:
The event queue ought to be sorted by timeStamp.

bool d_flags_need_updating
 

Set by Node::setBVolumeDirty on any node in this browser graph, cleared by updateFlags.

true if the bvolume dirty flag has been set on a node in the browser graph, but has not yet been propegated to that node's ancestors.

double d_frameRate [protected]
 

Frame rate.

bool d_modified [private]
 

Flag to indicate whether the browser has been modified.

std::list< Node * > d_movies [private]
 

A list of all the MovieTexture nodes in the browser.

std::list< Node * > d_navigationInfos [private]
 

A list of all the NavigationInfo nodes in the browser.

Browser::BindStack d_navigationInfoStack [private]
 

The stack of bound NavigationInfo nodes.

bool d_newView [private]
 

Flag to indicate if the user has changed to a new view.

Browser::SceneCBList d_sceneCallbacks [protected]
 

List of functions to call when the world is changed.

std::list< Node * > d_scopedLights [private]
 

A list of all the scoped light nodes in the browser.

std::list< ScriptNode * > d_scripts [private]
 

A list of all the Script nodes in the browser.

std::list< Node * > d_timers [private]
 

A list of all the TimeSensor nodes in the browser.

std::list< Node * > d_viewpoints [private]
 

A list of all the Viewpoint nodes in the browser.

Browser::BindStack d_viewpointStack [private]
 

The stack of bound Viewpoint nodes.

std::ostream & err
 

Error output stream.

Browser::NodeClassMap nodeClassMap [private]
 

A map of URIs to node implementations.

std::ostream & out
 

Output stream, generally for console output.

std::list< Node * > protoNodeList [private]
 

A list of all the prototype nodes in the browser.

Scene * scene [private]
 

Pointer to the root Scene.

ScriptNodeClass scriptNodeClass [private]
 

NodeClass for Script nodes in the browser.