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

Node Class Reference

A node in the scene graph. More...

Inheritance diagram for Node:

AppearanceNode ChildNode ColorNode CoordinateNode FontStyleNode GeometryNode MaterialNode NormalNode SoundSourceNode TextureCoordinateNode TextureNode TextureTransformNode AbstractBase List of all members.

Public Types

typedef std::list< RouteRouteList
typedef std::list< Node * > NodePath

Public Methods

virtual ~Node ()=0 throw ()
 Destructor.

const std::string getId () const
 Retrieve the nodeId of this node.

void setId (const std::string &nodeId)
 Set the nodeId of the node.

const ScopePtrgetScope () const throw ()
ScenegetScene () const throw ()
std::ostream & print (std::ostream &out, size_t indent) const
bool accept (NodeVisitor &visitor)
 Accept a visitor.

void resetVisitedFlag () throw ()
 Recursively set the visited flag to false for this node and its children.

void addEventOutIS (const std::string &eventOut, PolledEventOutValue &eventOutValue) throw (UnsupportedInterface, std::bad_alloc)
 Add a polled eventOut value.

void initialize (Scene &scene, double timestamp) throw (std::bad_alloc)
 Initialize the Node.

void setField (const std::string &id, const FieldValue &value) throw (UnsupportedInterface, std::bad_cast, std::bad_alloc)
 Generalized field mutator.

const FieldValuegetField (const std::string &id) const throw (UnsupportedInterface)
 Generalized field accessor.

void processEvent (const std::string &id, const FieldValue &value, double timestamp) throw (UnsupportedInterface, std::bad_cast, std::bad_alloc)
 Process an event.

const FieldValuegetEventOut (const std::string &id) const throw (UnsupportedInterface)
 Generalized eventOut accessor.

virtual const ScriptNodetoScript () const throw ()
 Cast to a const ScriptNode.

virtual ScriptNodetoScript () throw ()
 Cast to a ScriptNode.

virtual const AppearanceNodetoAppearance () const throw ()
 Cast to a const AppearanceNode.

virtual AppearanceNodetoAppearance () throw ()
 Cast to an AppearanceNode.

virtual const ChildNodetoChild () const throw ()
 Cast to a const ChildNode.

virtual ChildNodetoChild () throw ()
 Cast to a ChildNode.

virtual const ColorNodetoColor () const throw ()
 Cast to a const ColorNode.

virtual ColorNodetoColor () throw ()
 Cast to a ColorNode.

virtual const CoordinateNodetoCoordinate () const throw ()
 Cast to a const CoordinateNode.

virtual CoordinateNodetoCoordinate () throw ()
 Cast to a CoordinateNode.

virtual const FontStyleNodetoFontStyle () const throw ()
 Cast to a const FontStyleNode.

virtual FontStyleNodetoFontStyle () throw ()
 Cast to a FontStyleNode.

virtual const GeometryNodetoGeometry () const throw ()
 Cast to a const GeometryNode.

virtual GeometryNodetoGeometry () throw ()
 Cast to a GeometryNode.

virtual const MaterialNodetoMaterial () const throw ()
 Cast to a const MaterialNode.

virtual MaterialNodetoMaterial () throw ()
 Cast to a MaterialNode.

virtual const NormalNodetoNormal () const throw ()
 Cast to a const NormalNode.

virtual NormalNodetoNormal () throw ()
 Cast to a NormalNode.

virtual const SoundSourceNodetoSoundSource () const throw ()
 Cast to a const SoundSourceNode.

virtual SoundSourceNodetoSoundSource () throw ()
 Cast to a SoundSourceNode.

virtual const TextureNodetoTexture () const throw ()
 Cast to a const TextureNode.

virtual TextureNodetoTexture () throw ()
 Cast to a TextureNode.

virtual const TextureCoordinateNodetoTextureCoordinate () const throw ()
 Cast to a const TextureCoordinateNode.

virtual TextureCoordinateNodetoTextureCoordinate () throw ()
 Cast to a TextureCoordinateNode.

virtual const TextureTransformNodetoTextureTransform () const throw ()
 Cast to a const TextureTransformNode.

virtual TextureTransformNodetoTextureTransform () throw ()
 Cast to a TextureTransformNode.

virtual Vrml97Node::AnchortoAnchor () const
virtual Vrml97Node::AudioCliptoAudioClip () const
virtual Vrml97Node::CylinderSensortoCylinderSensor () const
virtual Vrml97Node::GrouptoGroup () const
virtual Vrml97Node::AbstractLighttoLight () const
virtual Vrml97Node::MovieTexturetoMovieTexture () const
virtual Vrml97Node::NavigationInfotoNavigationInfo () const
virtual Vrml97Node::PlaneSensortoPlaneSensor () const
virtual Vrml97Node::PointLighttoPointLight () const
virtual Vrml97Node::SphereSensortoSphereSensor () const
virtual Vrml97Node::SpotLighttoSpotLight () const
virtual Vrml97Node::TimeSensortoTimeSensor () const
virtual Vrml97Node::TouchSensortoTouchSensor () const
virtual Vrml97Node::ViewpointtoViewpoint () const
void setModified ()
void clearModified ()
virtual bool isModified () const
 Determine whether the node has been modified.

virtual void updateModified (NodePath &path, int flags=0x003)
 Propagate the bvolume dirty flag from children to parents.

void updateModified (int flags=0x003)
virtual const BVolumegetBVolume () const
 Get this node's bounding volume.

virtual void setBVolume (const BVolume &v)
virtual void setBVolumeDirty (bool f)
virtual bool isBVolumeDirty () const
void addRoute (const std::string &fromEventOut, const NodePtr &toNode, const std::string &toEventIn) throw (UnsupportedInterface, FieldValueTypeMismatch)
 Add a route from an eventOut of this node to an eventIn of another node.

void deleteRoute (const std::string &fromEventOut, const NodePtr &toNode, const std::string &toEventIn) throw ()
 Remove a route from an eventOut of this node to an eventIn of another node.

const RouteList & getRoutes () const
 Get the routes from this node.

virtual void render (Viewer &viewer, VrmlRenderContext context)
 Render this node.

virtual void accumulateTransform (Node *)
 Accumulate transformations for proper rendering of bindable nodes.

virtual Node * getParentTransform ()
 Get the nearest ancestor node that affects the modelview transform.

virtual void inverseTransform (VrmlMatrix &)

Static Public Methods

void markPathModified (NodePath &path, bool mod, int flags=0x003)
 Mark all the nodes in the path as (not) modified.


Public Attributes

const NodeTypenodeType
 The type information object for the node.


Protected Methods

 Node (const NodeType &nodeType, const ScopePtr &scope)
 Constructor.

void emitEvent (const std::string &id, const FieldValue &fieldValue, double timestamp) throw (std::bad_cast, std::bad_alloc)
 Send an event from this node.


Protected Attributes

bool d_modified
bool d_bvol_dirty
bool visited

Private Types

typedef std::map< std::string,
PolledEventOutValue * > 
EventOutISMap

Private Methods

 Node (const Node &)
Node & operator= (const Node &)
virtual void initializeImpl (double timestamp) throw (std::bad_alloc)
 Node subclass-specific initialization.

virtual void setFieldImpl (const std::string &id, const FieldValue &value)=0 throw (UnsupportedInterface, std::bad_cast, std::bad_alloc)
virtual const FieldValuegetFieldImpl (const std::string &id) const=0 throw (UnsupportedInterface)
virtual void processEventImpl (const std::string &id, const FieldValue &value, double timestamp)=0 throw (UnsupportedInterface, std::bad_cast, std::bad_alloc)
virtual const FieldValuegetEventOutImpl (const std::string &id) const=0 throw (UnsupportedInterface)

Private Attributes

ScopePtr scope
Scenescene
RouteList routes
EventOutISMap eventOutISMap

Friends

std::ostream & operator<< (std::ostream &out, const Node &node)
 Stream output.


Detailed Description

A node in the scene graph.


Constructor & Destructor Documentation

~Node   throw () [pure virtual]
 

Destructor.

Remove node name (if any) from the scope.

Node const NodeType   type,
const ScopePtr   scope
[protected]
 

Constructor.

Parameters:
type the NodeType associated with the instance.
scope the Scope associated with the instance.

Member Function Documentation

bool accept NodeVisitor   visitor
 

Accept a visitor.

If the node has not been visited, set the visited flag to true and call NodeVisitor::visit for this object. Otherwise (if the visited flag is already true), this method has no effect.

The fact that the visited flag is set before the node is actually visited is an important detail. Even though scene graphs should not have cycles, nodes can be self-referencing: a field of a Script node can legally USE the Script node. (This does not pose a problem for rendering since nodes in a Script node's fields are not part of the transformation hierarchy.)

Parameters:
visitor a NodeVisitor.
Returns:
true if the visitor is accepted (the node has not been visited during this traversal), false otherwise (the node has been visited during this traversal).

void accumulateTransform Node *    parent [virtual]
 

Accumulate transformations for proper rendering of bindable nodes.

Cache a pointer to one of the parent transforms. The resulting pointer is used by getParentTransform. Grouping nodes need to redefine this, the default implementation does nothing.

Parameters:
parent the parent node.

Reimplemented in Group, Billboard, Transform, and Viewpoint.

void addEventOutIS const std::string &    eventOutId,
PolledEventOutValue   eventOutValue
throw (UnsupportedInterface, std::bad_alloc)
 

Add a polled eventOut value.

Used internally by the PROTO implementation.

Parameters:
eventOutId eventOut name.
eventOutValue a PolledEventOutValue.
Exceptions:
UnsupportedInterface if the node has no eventOut eventOutId.
std::bad_alloc if memory allocation fails.

void addRoute const std::string &    fromEventOut,
const NodePtr   toNode,
const std::string &    toEventIn
throw (UnsupportedInterface, FieldValueTypeMismatch)
 

Add a route from an eventOut of this node to an eventIn of another node.

If the route being added already exists, this method has no effect.

Parameters:
fromEventOut an eventOut of the node.
toNode a node.
toEventIn an eventIn of toNode.
Exceptions:
UnsupportedInterface if the node has no eventOut fromEventOut; or if toNode has no eventIn toEventIn.
FieldValueTypeMismatch if fromEventOut and toEventIn have different field value types.
Precondition:
toNode is not null.

void deleteRoute const std::string &    fromEventOut,
const NodePtr   toNode,
const std::string &    toEventIn
throw ()
 

Remove a route from an eventOut of this node to an eventIn of another node.

If no such route exists, this method has no effect.

Parameters:
fromEventOut an eventOut of the node.
toNode a node.
toEventIn an eventIn of toNode.

void emitEvent const std::string &    id,
const FieldValue   value,
double    timestamp
throw (std::bad_cast, std::bad_alloc) [protected]
 

Send an event from this node.

const BVolume * getBVolume   const [virtual]
 

Get this node's bounding volume.

Nodes that have no bounding volume, or have a difficult to calculate bvolume (like, say, Extrusion or Billboard) can just return an infinite bsphere. Note that returning an infinite bvolume means that all the node's ancestors will also end up with an infinite bvolume, and will never be culled.

Returns:
this node's bounding volume

Todo:
Should this return a reference?

Reimplemented in Group, Anchor, Box, IndexedFaceSet, LOD, PointSet, Shape, Sphere, Switch, TimeSensor, Transform, and Viewpoint.

const FieldValue & getEventOut const std::string &    id const throw (UnsupportedInterface)
 

Generalized eventOut accessor.

Parameters:
id the name of the eventOut.
Exceptions:
UnsupportedInterface if the node has no eventOut named id.

const FieldValue & getField const std::string &    id const throw (UnsupportedInterface)
 

Generalized field accessor.

Parameters:
id the name of the field.
Exceptions:
UnsupportedInterface if the node has no field named id.

const std::string getId   const
 

Retrieve the nodeId of this node.

Returns:
the nodeId

Node * getParentTransform   [virtual]
 

Get the nearest ancestor node that affects the modelview transform.

Doesn't work for nodes with more than one parent.

Returns:
the nearest ancestor node that affects the modelview transform.

Reimplemented in Viewpoint.

const Node::RouteList & getRoutes   const
 

Get the routes from this node.

Returns:
an std::vector of Routes from this node.

void initialize Scene   scene,
double    timestamp
throw (std::bad_alloc)
 

Initialize the Node.

This method works recursively, initializing any child nodes to the same scene and timestamp. If the node has already been initialized, this method has no effect.

Parameters:
scene the Scene to which the Node will belong.
timestamp the current time.
Exceptions:
std::bad_alloc if memory allocation fails.

void initializeImpl double    timestamp throw (std::bad_alloc) [private, virtual]
 

Node subclass-specific initialization.

This method is called by Node::initialize. Subclasses of Node should override this method for any subclass-specific initialization. Note that this method cannot throw.

The default implementation of this method does nothing.

Parameters:
timestamp the current time.
Exceptions:
std::bad_alloc if memory allocation fails.

Reimplemented in ScriptNode, AudioClip, Background, Fog, MovieTexture, NavigationInfo, PointLight, SpotLight, Text, TimeSensor, and Viewpoint.

void inverseTransform VrmlMatrix   M [virtual]
 

Compute the inverse of the transform stack above a Viewpoint node. This is safe since the behavior of multi-parented Viewpoint nodes is undefined. May be called at any time.

Parameters:
M return the accumulated inverse
See also:
accumulateTransform

getParentTransform

Reimplemented in Transform.

bool isBVolumeDirty   const [virtual]
 

Return true if the node's bounding volume needs to be recalculated.

bool isModified   const [virtual]
 

Determine whether the node has been modified.

The default implementation returns whether this node has been modified. Subclasses that can have child nodes should override this method and return true if any of their children have been modified.

Returns:
true if the node has been modified; false otherwise.

Reimplemented in AbstractIndexedSet, Group, Appearance, Collision, ElevationGrid, IndexedFaceSet, LOD, PointSet, Shape, Switch, and Text.

void markPathModified NodePath &    path,
bool    mod,
int    flags = 0x003
[static]
 

Mark all the nodes in the path as (not) modified.

Convenience function used by updateModified.

Parameters:
path stack of ancestor nodes.
mod set modified flag to this value.
flags 1 indicates normal modified flag, 2 indicates the bvolume dirty flag, 3 indicates both.

void processEvent const std::string &    id,
const FieldValue   value,
double    timestamp
throw (UnsupportedInterface, std::bad_cast, std::bad_alloc)
 

Process an event.

Parameters:
id the name of the eventIn to which the event is being sent.
value the new value.
timestamp the current time.
Exceptions:
UnsupportedInterface if the node has no eventIn named id.
std::bad_cast if value is not the correct type.
std::bad_alloc if memory allocation fails.
Precondition:
value must be the appropriate type for the interface.

void render Viewer   viewer,
VrmlRenderContext    context
[virtual]
 

Render this node.

Actually, most of the rendering work is delegated to the viewer, but this method is responsible for traversal to the node's renderable children, including culling. Each node class needs to implement this routine appropriately. It's not abstract since it doesn't make sense to call render on some nodes. Alternative would be to break render out into a seperate mixins class, but that's probably overkill.

Parameters:
viewer viewer implementation responsible for actually doing the drawing.
context generic context argument; holds things like the accumulated modelview transform.

Reimplemented in AbstractGeometry, Group, Anchor, Appearance, Billboard, CylinderSensor, DirectionalLight, ImageTexture, Inline, LOD, MovieTexture, PixelTexture, PlaneSensor, ProximitySensor, Shape, Sound, SphereSensor, Switch, TextureTransform, Transform, and VisibilitySensor.

void resetVisitedFlag   throw ()
 

Recursively set the visited flag to false for this node and its children.

Typically used by a visitor (a class that implements NodeVisitor) after traversal is complete.

void setBVolume const BVolume   v [virtual]
 

Override a node's calculated bounding volume. Not implemented.

Todo:
Implement me!

void setBVolumeDirty bool    f [virtual]
 

Indicate that a node's bounding volume needs to be recalculated (or not). If a node's bvolume is invalid, then the bvolumes of all that node's ancestors are also invalid. Normally, the node itself will determine when its bvolume needs updating.

void setField const std::string &    id,
const FieldValue   value
throw (UnsupportedInterface, std::bad_cast, std::bad_alloc)
 

Generalized field mutator.

Parameters:
id the name of the field.
value the new value.
Exceptions:
UnsupportedInterface if the node has no field named id.
std::bad_cast if value is not the correct type.
std::bad_alloc if memory allocation fails.
Precondition:
value must be the appropriate type for the interface.

void setId const std::string &    nodeId
 

Set the nodeId of the node.

Parameters:
nodeId the ID for the node.

void setModified  
 

Dirty bit - indicates node needs to be revisited for rendering.

AppearanceNode * toAppearance   throw () [virtual]
 

Cast to an AppearanceNode.

Default implementation returns 0.

Returns:
0

Reimplemented in AppearanceNode.

const AppearanceNode * toAppearance   const throw () [virtual]
 

Cast to a const AppearanceNode.

Default implementation returns 0.

Returns:
0

Reimplemented in AppearanceNode.

ChildNode * toChild   throw () [virtual]
 

Cast to a ChildNode.

Default implementation returns 0.

Returns:
0

Reimplemented in ChildNode.

const ChildNode * toChild   const throw () [virtual]
 

Cast to a const ChildNode.

Default implementation returns 0.

Returns:
0

Reimplemented in ChildNode.

ColorNode * toColor   throw () [virtual]
 

Cast to a ColorNode.

Default implementation returns 0.

Returns:
0

Reimplemented in ColorNode.

const ColorNode * toColor   const throw () [virtual]
 

Cast to a const ColorNode.

Default implementation returns 0.

Returns:
0

Reimplemented in ColorNode.

CoordinateNode * toCoordinate   throw () [virtual]
 

Cast to a CoordinateNode.

Default implementation returns 0.

Returns:
0

Reimplemented in CoordinateNode.

const CoordinateNode * toCoordinate   const throw () [virtual]
 

Cast to a const CoordinateNode.

Default implementation returns 0.

Returns:
0

Reimplemented in CoordinateNode.

FontStyleNode * toFontStyle   throw () [virtual]
 

Cast to a FontStyleNode.

Default implementation returns 0.

Returns:
0

Reimplemented in FontStyleNode.

const FontStyleNode * toFontStyle   const throw () [virtual]
 

Cast to a const FontStyleNode.

Default implementation returns 0.

Returns:
0

Reimplemented in FontStyleNode.

GeometryNode * toGeometry   throw () [virtual]
 

Cast to a GeometryNode.

Default implementation returns 0.

Returns:
0

Reimplemented in GeometryNode.

const GeometryNode * toGeometry   const throw () [virtual]
 

Cast to a const GeometryNode.

Default implementation returns 0.

Returns:
0

Reimplemented in GeometryNode.

MaterialNode * toMaterial   throw () [virtual]
 

Cast to a MaterialNode.

Default implementation returns 0.

Returns:
0

Reimplemented in MaterialNode.

const MaterialNode * toMaterial   const throw () [virtual]
 

Cast to a const MaterialNode.

Default implementation returns 0.

Returns:
0

Reimplemented in MaterialNode.

NormalNode * toNormal   throw () [virtual]
 

Cast to a NormalNode.

Default implementation returns 0.

Returns:
0

Reimplemented in NormalNode.

const NormalNode * toNormal   const throw () [virtual]
 

Cast to a const NormalNode.

Default implementation returns 0.

Returns:
0

Reimplemented in NormalNode.

ScriptNode * toScript   throw () [virtual]
 

Cast to a ScriptNode.

Default implementation returns 0.

Returns:
0

Reimplemented in ScriptNode.

const ScriptNode * toScript   const throw () [virtual]
 

Cast to a const ScriptNode.

Default implementation returns 0.

Returns:
0

Reimplemented in ScriptNode.

SoundSourceNode * toSoundSource   throw () [virtual]
 

Cast to a SoundSourceNode.

Default implementation returns 0.

Returns:
0

Reimplemented in SoundSourceNode.

const SoundSourceNode * toSoundSource   const throw () [virtual]
 

Cast to a const SoundSourceNode.

Default implementation returns 0.

Returns:
0

Reimplemented in SoundSourceNode.

TextureNode * toTexture   throw () [virtual]
 

Cast to a TextureNode.

Default implementation returns 0.

Returns:
0

Reimplemented in TextureNode.

const TextureNode * toTexture   const throw () [virtual]
 

Cast to a const TextureNode.

Default implementation returns 0.

Returns:
0

Reimplemented in TextureNode.

TextureCoordinateNode * toTextureCoordinate   throw () [virtual]
 

Cast to a TextureCoordinateNode.

Default implementation returns 0.

Returns:
0

Reimplemented in TextureCoordinateNode.

const TextureCoordinateNode * toTextureCoordinate   const throw () [virtual]
 

Cast to a const TextureCoordinateNode.

Default implementation returns 0.

Returns:
0

Reimplemented in TextureCoordinateNode.

TextureTransformNode * toTextureTransform   throw () [virtual]
 

Cast to a TextureTransformNode.

Default implementation returns 0.

Returns:
0

Reimplemented in TextureTransformNode.

const TextureTransformNode * toTextureTransform   const throw () [virtual]
 

Cast to a const TextureTransformNode.

Default implementation returns 0.

Returns:
0

Reimplemented in TextureTransformNode.

void updateModified NodePath &    path,
int    flags = 0x003
[virtual]
 

Propagate the bvolume dirty flag from children to parents.

I don't like this at all, but it's not worth making it pretty because the need for it will go away when parent pointers are implemented.

Parameters:
path stack of ancestor nodes.
flags 1 indicates normal modified flag, 2 indicates the bvolume dirty flag, 3 indicates both.

Reimplemented in AbstractIndexedSet, Group, Appearance, ElevationGrid, IndexedFaceSet, LOD, PointSet, Shape, Sound, Switch, and Text.


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &    out,
const Node &    node
[friend]
 

Stream output.

Parameters:
out output stream.
node a Node.
Returns:
out.

Member Data Documentation

nodeType
 

The type information object for the node.