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

SceneGraphReducer Class Reference

An interface for simplifying ("flattening") scene graphs by eliminating unneeded nodes and collapsing out unneeded state changes and transforms. More...

#include <sceneGraphReducer.h>

List of all members.

Public Types

enum  AttribTypes {
  TT_transform = 0x001, TT_color = 0x002, TT_color_scale = 0x004, TT_tex_matrix = 0x008,
  TT_other = 0x010
}

Public Member Functions

 SceneGraphReducer ()
 ~SceneGraphReducer ()
void apply_attribs (PandaNode *node, int attrib_types=~0)
 Walks the scene graph, accumulating attribs of the indicated types, applying them to the vertices, and removing them from the scene graph.

void apply_attribs (PandaNode *node, const AccumulatedAttribs &attribs, int attrib_types, GeomTransformer &transformer)
 This flavor of apply_attribs() can be called recursively from within another flatten process (e.g.

int flatten (PandaNode *root, bool combine_siblings)
 Simplifies the graph by removing unnecessary nodes and nodes.


Protected Member Functions

void r_apply_attribs (PandaNode *node, const AccumulatedAttribs &attribs, int attrib_types, GeomTransformer &transformer)
 The recursive implementation of apply_attribs().

int r_flatten (PandaNode *grandparent_node, PandaNode *parent_node, bool combine_siblings)
 The recursive implementation of flatten().

int flatten_siblings (PandaNode *parent_node)
 Attempts to collapse together any pairs of siblings of the indicated node that share the same properties.

bool consider_child (PandaNode *grandparent_node, PandaNode *parent_node, PandaNode *child_node)
 Decides whether or not the indicated child node is a suitable candidate for removal.

bool consider_siblings (PandaNode *parent_node, PandaNode *child1, PandaNode *child2)
 Decides whether or not the indicated sibling nodes should be collapsed into a single node or not.

bool do_flatten_child (PandaNode *grandparent_node, PandaNode *parent_node, PandaNode *child_node)
 Collapses together the indicated parent node and child node and leaves the result attached to the grandparent.

PandaNodedo_flatten_siblings (PandaNode *parent_node, PandaNode *child1, PandaNode *child2)
 Performs the work of collapsing two sibling nodes together into a single node, leaving the resulting node attached to the parent.

PointerTo< PandaNodecollapse_nodes (PandaNode *node1, PandaNode *node2, bool siblings)
 Collapses the two nodes into a single node, if possible.

void choose_name (PandaNode *preserve, PandaNode *source1, PandaNode *source2)
 Chooses a suitable name for the collapsed node, based on the names of the two sources nodes.


Private Attributes

GeomTransformer _transformer


Detailed Description

An interface for simplifying ("flattening") scene graphs by eliminating unneeded nodes and collapsing out unneeded state changes and transforms.

This class is designed so that it may be inherited from and specialized, if needed, to fine-tune the flattening behavior, but normally the default behavior is sufficient.

Definition at line 58 of file sceneGraphReducer.h.


Member Enumeration Documentation

enum SceneGraphReducer::AttribTypes
 

Enumeration values:
TT_transform 
TT_color 
TT_color_scale 
TT_tex_matrix 
TT_other 

Definition at line 63 of file sceneGraphReducer.h.


Constructor & Destructor Documentation

SceneGraphReducer::SceneGraphReducer  )  [inline]
 

Definition at line 31 of file sceneGraphReducer.I.

References INLINE.

SceneGraphReducer::~SceneGraphReducer  )  [inline]
 

Definition at line 42 of file sceneGraphReducer.I.

References _transformer, INLINE, and r_apply_attribs().


Member Function Documentation

void SceneGraphReducer::apply_attribs PandaNode node,
const AccumulatedAttribs attribs,
int  attrib_types,
GeomTransformer transformer
[inline]
 

This flavor of apply_attribs() can be called recursively from within another flatten process (e.g.

from PandaNode::apply_attribs_to_vertices()). The parameters were presumably received from a parent SceneGraphReducer object.

Definition at line 101 of file sceneGraphReducer.I.

void SceneGraphReducer::apply_attribs PandaNode node,
int  attrib_types = ~0
[inline]
 

Walks the scene graph, accumulating attribs of the indicated types, applying them to the vertices, and removing them from the scene graph.

This has a performance optimization benefit in itself, but is especially useful to pave the way for a call to flatten() and greatly improve the effectiveness of the flattening operation.

Multiply instanced geometry is duplicated before the attribs are applied.

Of course, this operation does make certain dynamic operations impossible.

Definition at line 79 of file sceneGraphReducer.I.

Referenced by NodePath::clear_depth_write(), NodePath::get_depth_test(), and NodePath::set_depth_write().

void SceneGraphReducer::choose_name PandaNode preserve,
PandaNode source1,
PandaNode source2
[protected]
 

Chooses a suitable name for the collapsed node, based on the names of the two sources nodes.

Definition at line 594 of file sceneGraphReducer.cxx.

PointerTo< PandaNode > SceneGraphReducer::collapse_nodes PandaNode node1,
PandaNode node2,
bool  siblings
[protected]
 

Collapses the two nodes into a single node, if possible.

The 'siblings' flag is true if the two nodes are siblings nodes; otherwise, node1 is a parent of node2. The return value is the resulting node, which may be either one of the source nodes, or a new node altogether, or it may be NULL to indicate that the collapse operation could not take place.

Definition at line 578 of file sceneGraphReducer.cxx.

bool SceneGraphReducer::consider_child PandaNode grandparent_node,
PandaNode parent_node,
PandaNode child_node
[protected]
 

Decides whether or not the indicated child node is a suitable candidate for removal.

Returns true if the node may be removed, false if it should be kept.

Definition at line 406 of file sceneGraphReducer.cxx.

bool SceneGraphReducer::consider_siblings PandaNode parent_node,
PandaNode child1,
PandaNode child2
[protected]
 

Decides whether or not the indicated sibling nodes should be collapsed into a single node or not.

Returns true if the nodes may be collapsed, false if they should be kept distinct.

Definition at line 445 of file sceneGraphReducer.cxx.

References PandaNode::replace_child().

bool SceneGraphReducer::do_flatten_child PandaNode grandparent_node,
PandaNode parent_node,
PandaNode child_node
[protected]
 

Collapses together the indicated parent node and child node and leaves the result attached to the grandparent.

The return value is true if the node is successfully collapsed, false if we chickened out.

Definition at line 468 of file sceneGraphReducer.cxx.

PandaNode * SceneGraphReducer::do_flatten_siblings PandaNode parent_node,
PandaNode child1,
PandaNode child2
[protected]
 

Performs the work of collapsing two sibling nodes together into a single node, leaving the resulting node attached to the parent.

Returns a pointer to a PandaNode the reflects the combined node (which may be either of the source nodes, or a new node altogether) if the siblings are successfully collapsed, or NULL if we chickened out.

Definition at line 521 of file sceneGraphReducer.cxx.

References Namable::get_name(), PandaNode::preserve_name(), and Namable::set_name().

int SceneGraphReducer::flatten PandaNode root,
bool  combine_siblings
 

Simplifies the graph by removing unnecessary nodes and nodes.

In general, a node (and its parent node) is a candidate for removal if the node has no siblings and the node has no special properties.

If combine_siblings is true, sibling nodes may also be collapsed into a single node. This will further reduce scene graph complexity, sometimes substantially, at the cost of reduced spatial separation.

Returns the number of nodes removed from the graph.

Definition at line 70 of file sceneGraphReducer.cxx.

Referenced by NodePath::clear_depth_write(), and NodePath::set_depth_write().

int SceneGraphReducer::flatten_siblings PandaNode parent_node  )  [protected]
 

Attempts to collapse together any pairs of siblings of the indicated node that share the same properties.

Definition at line 327 of file sceneGraphReducer.cxx.

References NULL.

void SceneGraphReducer::r_apply_attribs PandaNode node,
const AccumulatedAttribs attribs,
int  attrib_types,
GeomTransformer transformer
[protected]
 

The recursive implementation of apply_attribs().

Definition at line 114 of file sceneGraphReducer.cxx.

Referenced by ~SceneGraphReducer().

int SceneGraphReducer::r_flatten PandaNode grandparent_node,
PandaNode parent_node,
bool  combine_siblings
[protected]
 

The recursive implementation of flatten().

Definition at line 245 of file sceneGraphReducer.cxx.


Member Data Documentation

GeomTransformer SceneGraphReducer::_transformer [private]
 

Definition at line 102 of file sceneGraphReducer.h.

Referenced by ~SceneGraphReducer().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:54:56 2003 for Panda by doxygen1.3