Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglSwitch Class Reference

#include <sglSwitch.hpp>

Inheritance diagram for sglSwitch::

sglGroup sglNode sglObject List of all members.

Public Types

enum  {
  eOFF = -2,
  eON = -1
}

Public Methods

 sglSwitch ()
virtual ~sglSwitch ()
void setVal (int val)
int getVal () const
virtual sglBound::IntersectResultEnum intersect (sglIntersectf &isector) const
virtual sglBound::IntersectResultEnum intersect (sglIntersectd &isector) const
virtual void pick (sglPickf &pick_state, unsigned int cull_flags) const
virtual void pick (sglPickd &pick_state, unsigned int cull_flags) const
virtual sglNodeclone (unsigned int mode) const
virtual void printInfo (ostream &ostrm, const char *indent_string) const

Protected Methods

virtual void cull (sglCull< float > &trav_state, unsigned int cull_flags) const
virtual void cull (sglCull< double > &trav_state, unsigned int cull_flags) const
void cull (sglCull< float > &trav_state, unsigned int cull_flags, int switch_val) const
void cull (sglCull< double > &trav_state, unsigned int cull_flags, int switch_val) const
void copyTo (sglSwitch *dst, unsigned int mode) const

Protected Attributes

int m_switch_val

Detailed Description

This node will select (or not) the child or children to be traversed. For this subclass of sglGroup, the order that the children are added to the sglGroup is significant. The value of the switch determines which (if any) children get traversed according to the following table:

   Switch Value       Traversal Behaviour
   ---------------    ----------------------------------------------
   sglSwitch::eOFF    do not traversal any children.
   sglSwitch::eON     traversal all the children (as if an sglGroup)
   0 .. MAX_INT       traverse only one child whose index equals the
                          switch value

The switch value is a signed integer (because the eOFF and eON tokens are negative values). That means it can be used to select one of up to MAX_INT children. If the switch value is out of range of the number of children currently referenced by this node, then the traversal stops at this point in the branch, a warning message is printed, and the traversal function returns.

Special behaviour for cull traversals

The protected cull functions have been rewritten as thin wrappers around reentrant cull functions that take the switch value as parameter. The default implementation in this class is to pass the switch value directly to these reentrant functions. This node can be subclassed, however, and the cull functions can pass different values in as the switch value parameter to create more complex behaviours.

Special behaviour for intersect and pick traversals

In addition to this behaviour, the intersect and pick traversal behaviour for this node can be changed by adding sglProbe::eSWITCH_ALL or sglProbe::eSWITCH_NONE to its mode. The former behaves as if sglSwitch::eON has been set on this node (all nodes are traversed), and the latter corresponds to sglSwitch::eOFF (no nodes traversed).

Example

   sglGeode  *geode1 = new sglGeode;
   sglGeode  *geode2 = new sglGeode;
   sglSwitch *switch_node = new sglSwitch;
   switch_node->addChild(geode1);
   switch_node->addChild(geode2);

   switch_node->setVal(sglSwitch::eOFF);  // select neither
   switch_node->setVal(sglSwitch::eON);   // select both  (the default)
   switch_node->setVal(0);                // select geode1
   switch_node->setVal(1);                // select geode2
   switch_node->setVal(2);                // ERROR: will select neither

Todo:
Should the pick and intersect functions be implemented as wrappers to reentrant functions like cull?

Definition at line 96 of file sglSwitch.hpp.


Member Enumeration Documentation

anonymous enum
 

Some useful switch value constants scoped to this class.

Enumeration values:
eOFF   Select no children.
eON   Select all children.

Definition at line 100 of file sglSwitch.hpp.


Constructor & Destructor Documentation

sglSwitch::sglSwitch ( )
 

default constructor.

sglSwitch::~sglSwitch ( ) [virtual]
 

virtual destructor.


Member Function Documentation

void sglSwitch::setVal ( int val ) [inline]
 

Set the switch value (defaults to eON).

Parameters:
val   The switch value which can be one of eOff, eOn, 0..MAX_INT.

Definition at line 118 of file sglSwitch.hpp.

int sglSwitch::getVal ( ) const [inline]
 

Get the current switch value.

Returns:
current switch value

Definition at line 123 of file sglSwitch.hpp.

virtual sglBound::IntersectResultEnum sglSwitch::intersect ( sglIntersectf & isector ) const [virtual]
 

The single precision intersection traversal function which returns the closest object (bounding volume and/or triangle) that intersects with the given intersect segment.

Parameters:
isector   A reference to a single precision intersection state

Reimplemented from sglGroup.

virtual sglBound::IntersectResultEnum sglSwitch::intersect ( sglIntersectd & isector ) const [virtual]
 

The double precision intersection traversal function which returns the closest object (bounding volume and/or triangle) that intersects with the given intersect segment.

Parameters:
isector   A reference to a double precision intersection state

Reimplemented from sglGroup.

virtual void sglSwitch::pick ( sglPickf & pick_state,
unsigned int cull_flags ) const [virtual]
 

The single precision pick traversal function which returns all objects that fall within the pick frustum.

Parameters:
pick_state   A reference to a single precision pick state.
cull_flags   Bit flags that indicate which planes of the pick frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free picking can be accomplished by setting this to 0.

Reimplemented from sglGroup.

virtual void sglSwitch::pick ( sglPickd & pick_state,
unsigned int cull_flags ) const [virtual]
 

The double precision pick traversal function which returns all objects that fall within the pick frustum.

Parameters:
pick_state   A reference to a double precision pick state.
cull_flags   Bit flags that indicate which planes of the pick frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free picking can be accomplished by setting this to 0.

Reimplemented from sglGroup.

virtual sglNode* sglSwitch::clone ( unsigned int mode ) const [virtual]
 

Make a copy of the scenegraph rooted at this node.

Parameters:
mode   Bit masks to control the behaviour of the clone. These are OR-ed together from the mode values in sglObject::CloneModeEnum.
Returns:
Pointer to root of cloned scene graph.

Reimplemented from sglGroup.

virtual void sglSwitch::printInfo ( ostream & ostrm,
const char * indent_string ) const [virtual]
 

Output the state of this node to the specified ostream.

Parameters:
ostrm   the ostream to which the output is sent
indent_string   the string (usually spaces) that is output at the beginning of every line of output

Reimplemented from sglGroup.

void sglSwitch::cull ( sglCull< float > & trav_state,
unsigned int cull_flags ) const [inline, protected, virtual]
 

The single precision cull traversal function that culls out subgraphs that do not lie in the view frustum (stored in the sglCull parameter). Subclasses must implement this function. The entry point for user-friendly culling is in the sglScene class.

Parameters:
trav_state   The single precision traversal state that collects all the state and geometry information that passes the cull.
cull_flags   Bit flags that indicate which planes of the view frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free drawing can be accomplished with cull_flags = 0.

Reimplemented from sglGroup.

Definition at line 147 of file sglSwitch.hpp.

void sglSwitch::cull ( sglCull< double > & trav_state,
unsigned int cull_flags ) const [inline, protected, virtual]
 

The double precision cull traversal function that culls out subgraphs that do not lie in the view frustum (stored in the sglCull parameter). Subclasses must implement this function. The entry point for user-friendly culling is in the sglScene class.

Parameters:
trav_state   The single precision traversal state that collects all the state and geometry information that passes the cull.
cull_flags   Bit flags that indicate which planes of the view frustum (polytope) still need to be tested to determine if bounding spheres and boxes lie within the frustum. Cull-free drawing can be accomplished with cull_flags = 0.

Reimplemented from sglGroup.

Definition at line 154 of file sglSwitch.hpp.


The documentation for this class was generated from the following file:
Generated at Mon Jul 1 18:00:10 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001