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

EggMaterialCollection Class Reference

This is a collection of materials by MRef name. More...

#include <eggMaterialCollection.h>

List of all members.

Public Types

typedef OrderedMaterials::const_iterator iterator
typedef iterator const_iterator
typedef OrderedMaterials::size_type size_type
typedef pmap< PT_EggMaterial,
PT_EggMaterial
MaterialReplacement

Public Member Functions

 EggMaterialCollection ()
 EggMaterialCollection (const EggMaterialCollection &copy)
EggMaterialCollection & operator= (const EggMaterialCollection &copy)
 ~EggMaterialCollection ()
void clear ()
 Removes all materials from the collection.

int extract_materials (EggGroupNode *node)
 Walks the egg hierarchy beginning at the indicated node, and removes any EggMaterials encountered in the hierarchy, adding them to the collection.

EggGroupNode::iterator insert_materials (EggGroupNode *node)
 Adds a series of EggMaterial nodes to the beginning of the indicated node to reflect each of the materials in the collection.

EggGroupNode::iterator insert_materials (EggGroupNode *node, EggGroupNode::iterator position)
 Adds a series of EggMaterial nodes to the beginning of the indicated node to reflect each of the materials in the collection.

int find_used_materials (EggNode *node)
 Walks the egg hierarchy beginning at the indicated node, looking for materials that are referenced by primitives but are not already members of the collection, adding them to the collection.

void remove_unused_materials (EggNode *node)
 Removes any materials from the collection that aren't referenced by any primitives in the indicated egg hierarchy.

int collapse_equivalent_materials (int eq, EggGroupNode *node)
 Walks through the collection and collapses together any separate materials that are equivalent according to the indicated equivalence factor, eq (see EggMaterial::is_equivalent_to()).

int collapse_equivalent_materials (int eq, MaterialReplacement &removed)
 Walks through the collection and collapses together any separate materials that are equivalent according to the indicated equivalence factor, eq (see EggMaterial::is_equivalent_to()).

void uniquify_mrefs ()
 Guarantees that each material in the collection has a unique MRef name.

void sort_by_mref ()
 Sorts all the materials into alphabetical order by MRef name.

iterator begin () const
iterator end () const
bool empty () const
size_type size () const
bool add_material (EggMaterial *material)
 Explicitly adds a new material to the collection.

bool remove_material (EggMaterial *material)
 Explicitly removes a material from the collection.

EggMaterialcreate_unique_material (const EggMaterial &copy, int eq)
 Creates a new material if there is not already one equivalent (according to eq, see EggMaterial::is_equivalent_to()) to the indicated material, or returns the existing one if there is.

EggMaterialfind_mref (const string &mref_name) const
 Returns the material with the indicated MRef name, or NULL if no material matches.


Static Public Member Functions

void replace_materials (EggGroupNode *node, const MaterialReplacement &replace)
 Walks the egg hierarchy, changing out any reference to a material appearing on the left side of the map with its corresponding material on the right side.


Private Types

typedef pmap< PT_EggMaterial,
int > 
Materials
typedef vector_PT_EggMaterial OrderedMaterials

Private Attributes

Materials _materials
OrderedMaterials _ordered_materials


Detailed Description

This is a collection of materials by MRef name.

It can extract the materials from an egg file and sort them all together; it can also manage the creation of unique materials and the assignment of unique MRef names.

Definition at line 49 of file eggMaterialCollection.h.


Member Typedef Documentation

typedef iterator EggMaterialCollection::const_iterator
 

Definition at line 61 of file eggMaterialCollection.h.

typedef OrderedMaterials::const_iterator EggMaterialCollection::iterator
 

Definition at line 60 of file eggMaterialCollection.h.

typedef pmap<PT_EggMaterial, PT_EggMaterial > EggMaterialCollection::MaterialReplacement
 

Definition at line 64 of file eggMaterialCollection.h.

typedef pmap<PT_EggMaterial, int> EggMaterialCollection::Materials [private]
 

Definition at line 56 of file eggMaterialCollection.h.

typedef vector_PT_EggMaterial EggMaterialCollection::OrderedMaterials [private]
 

Definition at line 57 of file eggMaterialCollection.h.

typedef OrderedMaterials::size_type EggMaterialCollection::size_type
 

Definition at line 62 of file eggMaterialCollection.h.

Referenced by empty().


Constructor & Destructor Documentation

EggMaterialCollection::EggMaterialCollection  ) 
 

Definition at line 39 of file eggMaterialCollection.cxx.

EggMaterialCollection::EggMaterialCollection const EggMaterialCollection &  copy  ) 
 

Definition at line 50 of file eggMaterialCollection.cxx.

References _materials, and _ordered_materials.

EggMaterialCollection::~EggMaterialCollection  ) 
 

Definition at line 78 of file eggMaterialCollection.cxx.

References _ordered_materials.


Member Function Documentation

bool EggMaterialCollection::add_material EggMaterial material  ) 
 

Explicitly adds a new material to the collection.

Returns true if the material was added, false if it was already there or if there was some error.

Definition at line 477 of file eggMaterialCollection.cxx.

Referenced by EggGroupNode::r_transform_vertices().

EggMaterialCollection::iterator EggMaterialCollection::begin  )  const [inline]
 

Definition at line 23 of file eggMaterialCollection.I.

References _ordered_materials.

void EggMaterialCollection::clear  ) 
 

Removes all materials from the collection.

Definition at line 90 of file eggMaterialCollection.cxx.

References EggGroupNode::find_materials().

int EggMaterialCollection::collapse_equivalent_materials int  eq,
EggMaterialCollection::MaterialReplacement removed
 

Walks through the collection and collapses together any separate materials that are equivalent according to the indicated equivalence factor, eq (see EggMaterial::is_equivalent_to()).

The return value is the number of materials removed.

This flavor of collapse_equivalent_materials() does not adjust any primitives in the egg hierarchy; instead, it fills up the 'removed' map with an entry for each removed material, mapping it back to the equivalent retained material. It's up to the user to then call replace_materials() with this map, if desired, to apply these changes to the egg hierarchy.

Definition at line 341 of file eggMaterialCollection.cxx.

int EggMaterialCollection::collapse_equivalent_materials int  eq,
EggGroupNode node
 

Walks through the collection and collapses together any separate materials that are equivalent according to the indicated equivalence factor, eq (see EggMaterial::is_equivalent_to()).

The return value is the number of materials removed.

This flavor of collapse_equivalent_materials() automatically adjusts all the primitives in the egg hierarchy to refer to the new material pointers.

Definition at line 297 of file eggMaterialCollection.cxx.

References EggGroupNode::begin(), DCAST, EggGroupNode::end(), EggGroupNode::get_class_type(), EggPrimitive::get_class_type(), EggPrimitive::get_material(), EggPrimitive::has_material(), TypedObject::is_of_type(), EggGroupNode::iterator, PT, replace_materials(), EggPrimitive::set_material(), and tex.

Referenced by find_used_materials().

EggMaterial * EggMaterialCollection::create_unique_material const EggMaterial copy,
int  eq
 

Creates a new material if there is not already one equivalent (according to eq, see EggMaterial::is_equivalent_to()) to the indicated material, or returns the existing one if there is.

Definition at line 547 of file eggMaterialCollection.cxx.

bool EggMaterialCollection::empty  )  const [inline]
 

Definition at line 35 of file eggMaterialCollection.I.

References _materials, _ordered_materials, INLINE, nassertr, and size_type.

EggMaterialCollection::iterator EggMaterialCollection::end  )  const [inline]
 

Definition at line 30 of file eggMaterialCollection.I.

References _ordered_materials, and INLINE.

int EggMaterialCollection::extract_materials EggGroupNode node  ) 
 

Walks the egg hierarchy beginning at the indicated node, and removes any EggMaterials encountered in the hierarchy, adding them to the collection.

Returns the number of EggMaterials encountered.

Definition at line 110 of file eggMaterialCollection.cxx.

References _ordered_materials, EggGroupNode::insert(), and EggGroupNode::iterator.

Referenced by EggData::set_coordinate_system().

EggMaterial * EggMaterialCollection::find_mref const string &  mref_name  )  const
 

Returns the material with the indicated MRef name, or NULL if no material matches.

Definition at line 576 of file eggMaterialCollection.cxx.

int EggMaterialCollection::find_used_materials EggNode node  ) 
 

Walks the egg hierarchy beginning at the indicated node, looking for materials that are referenced by primitives but are not already members of the collection, adding them to the collection.

If this is called following extract_materials(), it can be used to pick up any additional material references that appeared in the egg hierarchy (but whose EggMaterial node was not actually part of the hierarchy).

If this is called in lieu of extract_materials(), it will fill up the collection with all of the referenced materials (and only the referenced materials), without destructively removing the EggMaterials from the hierarchy.

This also has the side effect of incrementing the internal usage count for a material in the collection each time a material reference is encountered. This side effect is taken advantage of by remove_unused_materials().

Definition at line 213 of file eggMaterialCollection.cxx.

References collapse_equivalent_materials(), and replace_materials().

Referenced by insert_materials().

EggGroupNode::iterator EggMaterialCollection::insert_materials EggGroupNode node,
EggGroupNode::iterator  position
 

Adds a series of EggMaterial nodes to the beginning of the indicated node to reflect each of the materials in the collection.

Returns an iterator representing the first position after the newly inserted materials.

Definition at line 150 of file eggMaterialCollection.cxx.

References _materials, _ordered_materials, EggGroupNode::begin(), DCAST, EggGroupNode::end(), find_used_materials(), EggGroupNode::get_class_type(), EggPrimitive::get_class_type(), EggPrimitive::get_material(), EggPrimitive::has_material(), TypedObject::is_of_type(), EggGroupNode::iterator, and tex.

EggGroupNode::iterator EggMaterialCollection::insert_materials EggGroupNode node  ) 
 

Adds a series of EggMaterial nodes to the beginning of the indicated node to reflect each of the materials in the collection.

Returns an iterator representing the first position after the newly inserted materials.

Definition at line 131 of file eggMaterialCollection.cxx.

EggMaterialCollection & EggMaterialCollection::operator= const EggMaterialCollection &  copy  ) 
 

Definition at line 64 of file eggMaterialCollection.cxx.

bool EggMaterialCollection::remove_material EggMaterial material  ) 
 

Explicitly removes a material from the collection.

Returns true if the material was removed, false if it wasn't there or if there was some error.

Definition at line 509 of file eggMaterialCollection.cxx.

void EggMaterialCollection::remove_unused_materials EggNode node  ) 
 

Removes any materials from the collection that aren't referenced by any primitives in the indicated egg hierarchy.

This also, incidentally, adds materials to the collection that had been referenced by primitives but had not previously appeared in the collection.

Definition at line 264 of file eggMaterialCollection.cxx.

References tex.

Referenced by EggData::set_coordinate_system().

void EggMaterialCollection::replace_materials EggGroupNode node,
const MaterialReplacement replace
[static]
 

Walks the egg hierarchy, changing out any reference to a material appearing on the left side of the map with its corresponding material on the right side.

This is most often done following a call to collapse_equivalent_materials(). It does not directly affect the Collection.

Definition at line 394 of file eggMaterialCollection.cxx.

References _materials.

Referenced by collapse_equivalent_materials(), and find_used_materials().

EggMaterialCollection::size_type EggMaterialCollection::size  )  const [inline]
 

Definition at line 40 of file eggMaterialCollection.I.

void EggMaterialCollection::sort_by_mref  ) 
 

Sorts all the materials into alphabetical order by MRef name.

Subsequent operations using begin()/end() will traverse in this sorted order.

Definition at line 459 of file eggMaterialCollection.cxx.

void EggMaterialCollection::uniquify_mrefs  ) 
 

Guarantees that each material in the collection has a unique MRef name.

This is essential before writing an egg file.

Definition at line 433 of file eggMaterialCollection.cxx.

References tex.


Member Data Documentation

Materials EggMaterialCollection::_materials [private]
 

Definition at line 111 of file eggMaterialCollection.h.

Referenced by EggMaterialCollection(), empty(), insert_materials(), and replace_materials().

OrderedMaterials EggMaterialCollection::_ordered_materials [private]
 

Definition at line 112 of file eggMaterialCollection.h.

Referenced by begin(), EggMaterialCollection(), empty(), end(), extract_materials(), insert_materials(), and ~EggMaterialCollection().


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