Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::MaterialMergeGraphOp Class Reference
[Geometry]

#include <OSGMaterialMergeGraphOp.h>

Inheritance diagram for osg::MaterialMergeGraphOp:

osg::GraphOp List of all members.

Public Member Functions

 MaterialMergeGraphOp (const char *name="MaterialMerge")
GraphOpcreate ()
bool traverse (NodePtr &node)
void setParams (const std::string params)
std::string usage (void)

Static Public Member Functions

static const char * getClassname (void)

Protected Attributes

std::list< NodePtr_excludeListNodes
std::list< std::string > _excludeListNames

Private Types

typedef std::list< MaterialObjectMaterialObjectList
typedef std::map< MaterialPtr,
MaterialObjectList
MaterialObjectMap

Private Member Functions

Action::ResultE traverseEnter (NodePtr &node)
Action::ResultE traverseLeave (NodePtr &node, Action::ResultE res)
void addObject (MaterialObject m)

Private Attributes

MaterialObjectMap _materialObjects

Classes

class  MaterialObject

Detailed Description

Merges equivalent materials in a scene.

Definition at line 59 of file OSGMaterialMergeGraphOp.h.


Member Typedef Documentation

typedef std::list<MaterialObject> osg::MaterialMergeGraphOp::MaterialObjectList [private]
 

Definition at line 119 of file OSGMaterialMergeGraphOp.h.

typedef std::map<MaterialPtr, MaterialObjectList> osg::MaterialMergeGraphOp::MaterialObjectMap [private]
 

Definition at line 120 of file OSGMaterialMergeGraphOp.h.


Constructor & Destructor Documentation

MaterialMergeGraphOp::MaterialMergeGraphOp const char *  name = "MaterialMerge"  ) 
 

Definition at line 58 of file OSGMaterialMergeGraphOp.cpp.

Referenced by create().

00059     : GraphOp(name)
00060 {
00061 }


Member Function Documentation

static const char* osg::MaterialMergeGraphOp::getClassname void   )  [inline, static]
 

Reimplemented from osg::GraphOp.

Definition at line 101 of file OSGMaterialMergeGraphOp.h.

00101 { return "MaterialMergeGraphOp"; };

GraphOp * MaterialMergeGraphOp::create  )  [virtual]
 

Implements osg::GraphOp.

Definition at line 63 of file OSGMaterialMergeGraphOp.cpp.

References MaterialMergeGraphOp().

00064 {
00065     return new MaterialMergeGraphOp();
00066 }

bool MaterialMergeGraphOp::traverse NodePtr node  )  [virtual]
 

Reimplemented from osg::GraphOp.

Definition at line 166 of file OSGMaterialMergeGraphOp.cpp.

References _materialObjects, equal(), next(), SINFO, and osg::GraphOp::traverse().

00167 {
00168     // Find the materials.
00169     if (!GraphOp::traverse(node)) {
00170         return false;
00171     }
00172 
00173     SINFO << "Number of materials before merge: " << _materialObjects.size() << std::endl;
00174 
00175     // Now do the merge.
00176     MaterialObjectMap::iterator itr = _materialObjects.begin();
00177     for (; itr != _materialObjects.end(); ++itr)
00178     {
00179         MaterialPtr current = itr->first;
00180         MaterialObjectList& currentList = itr->second;
00181 
00182         MaterialObjectMap::iterator walker = next(itr);
00183         while (walker != _materialObjects.end()) {
00184             // Store the next iterator in case we have to delete
00185             // 'walker' from the map.
00186             MaterialObjectMap::iterator nextStep = next(walker);
00187 
00188             if (equal(current, walker->first)) {
00189                 // Set the new objects to have the current material,
00190                 // and move the objects to the current list.
00191                 MaterialObjectList::iterator i = walker->second.begin();
00192                 for (; i != walker->second.end(); ++i) {
00193                     i->setMaterial(current);
00194                     currentList.push_back(*i);
00195                 }
00196                 _materialObjects.erase(walker);
00197             }
00198 
00199             walker = nextStep;
00200         }
00201     }
00202 
00203     SINFO << "Number of materials after merge: " << _materialObjects.size() << std::endl;
00204     return true;
00205 }

void MaterialMergeGraphOp::setParams const std::string  params  )  [virtual]
 

Implements osg::GraphOp.

Definition at line 208 of file OSGMaterialMergeGraphOp.cpp.

References FWARNING.

00209 {
00210     ParamSet ps(params);   
00211     
00212     std::string out = ps.getUnusedParams();
00213     if(out.length())
00214     {
00215         FWARNING(("MaterialMergeGraphOp doesn't have parameters '%s'.\n",
00216                 out.c_str()));
00217     }
00218 }

std::string MaterialMergeGraphOp::usage void   )  [virtual]
 

Implements osg::GraphOp.

Definition at line 220 of file OSGMaterialMergeGraphOp.cpp.

00221 {
00222     return 
00223     "MaterialMerge: merge Materials in given subtree\n"
00224     "  Tries to find and merge equiavlent Materials to reduce the number\n"
00225     "  of Materials used.\n"
00226     ;
00227 }

Action::ResultE MaterialMergeGraphOp::traverseEnter NodePtr node  )  [private, virtual]
 

Implements osg::GraphOp.

Definition at line 229 of file OSGMaterialMergeGraphOp.cpp.

References addObject(), osg::Action::Continue, osg::AttachmentContainerPtr::dcast(), osg::NodePtr::getCore(), and osg::NullFC.

00230 {
00231     GeometryPtr geo = GeometryPtr::dcast(node->getCore());
00232     if (geo != NullFC)
00233     {
00234         addObject(MaterialObject(geo));
00235         return Action::Continue;
00236     }
00237     
00238     MaterialGroupPtr mg = MaterialGroupPtr::dcast(node->getCore());
00239     if (mg != NullFC)
00240     {
00241         addObject(MaterialObject(mg));
00242         return Action::Continue;
00243     }
00244 
00245     // Otherwise, keep looking.
00246     return Action::Continue;
00247 }

Action::ResultE MaterialMergeGraphOp::traverseLeave NodePtr node,
Action::ResultE  res
[private, virtual]
 

Implements osg::GraphOp.

Definition at line 249 of file OSGMaterialMergeGraphOp.cpp.

00250 {
00251     return res;
00252 }

void MaterialMergeGraphOp::addObject MaterialObject  m  )  [private]
 

Definition at line 254 of file OSGMaterialMergeGraphOp.cpp.

References _materialObjects, osg::MaterialMergeGraphOp::MaterialObject::getMaterial(), and osg::NullFC.

Referenced by traverseEnter().

00255 {
00256     MaterialPtr mat = m.getMaterial();
00257     if (mat == osg::NullFC)
00258         return;
00259 
00260     _materialObjects[mat].push_back(m);
00261 }

const std::string & GraphOp::getName void   )  [inherited]
 

Definition at line 112 of file OSGGraphOp.cpp.

References osg::GraphOp::_name.

Referenced by osg::GraphOpFactory::registerOp(), and osg::GraphOpFactory::unRegisterOp().

00113 {
00114     return _name;
00115 };

void GraphOp::setName const char *  name  )  [inherited]
 

Definition at line 117 of file OSGGraphOp.cpp.

References osg::GraphOp::_name.

00118 {
00119     _name = name;
00120 };

void GraphOp::addToExcludeList NodePtr node  )  [inherited]
 

Definition at line 124 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNodes, and osg::GraphOp::isInExcludeListNodes().

Referenced by osg::MergeGraphOp::excludeListLeave(), and osg::GraphOpSeq::setGraphOps().

00125 {
00126     if (!isInExcludeListNodes(node))
00127         _excludeListNodes.push_back(node);
00128 }

void GraphOp::addToExcludeList const std::string &  name  )  [inherited]
 

Definition at line 130 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames, and osg::GraphOp::isInExcludeListNames().

00131 {
00132     if (!isInExcludeListNames(name))
00133         _excludeListNames.push_back(name);
00134 }

void GraphOp::removeFromExcludeList NodePtr node  )  [inherited]
 

Definition at line 136 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNodes.

00137 {
00138     _excludeListNodes.remove(node);
00139 }

void GraphOp::removeFromExcludeList const std::string &  name  )  [inherited]
 

Definition at line 141 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames.

00142 {
00143     _excludeListNames.remove(name);
00144 }

void GraphOp::clearExcludeList void   )  [inherited]
 

Definition at line 146 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames, and osg::GraphOp::_excludeListNodes.

00147 {
00148     _excludeListNames.clear();
00149     _excludeListNodes.clear();
00150 }

bool GraphOp::isInExcludeListNodes NodePtr node  )  [inherited]
 

Definition at line 152 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNodes.

Referenced by osg::GraphOp::addToExcludeList(), and osg::GraphOp::isInExcludeList().

00153 {
00154     std::list<NodePtr>::iterator list_iter;
00155     list_iter = std::find(_excludeListNodes.begin(),_excludeListNodes.end(),node);
00156 
00157     if (list_iter==_excludeListNodes.end()) 
00158         return false;
00159     else 
00160         return true;
00161 }

bool GraphOp::isInExcludeListNames const std::string &  name  )  [inherited]
 

Definition at line 163 of file OSGGraphOp.cpp.

References osg::GraphOp::_excludeListNames.

Referenced by osg::GraphOp::addToExcludeList(), and osg::GraphOp::isInExcludeList().

00164 {
00165     std::list<std::string>::iterator namelist_iter;
00166     namelist_iter = std::find(_excludeListNames.begin(),_excludeListNames.end(),name);
00167 
00168     if (namelist_iter==_excludeListNames.end()) 
00169         return false;
00170     else 
00171         return true;
00172 }

bool GraphOp::isInExcludeList NodePtr node  )  [inherited]
 

Definition at line 174 of file OSGGraphOp.cpp.

References osg::getName(), osg::GraphOp::isInExcludeListNames(), and osg::GraphOp::isInExcludeListNodes().

Referenced by osg::MergeGraphOp::processGeometries(), osg::MergeGraphOp::processGroups(), osg::MergeGraphOp::processTransformations(), osg::SplitGraphOp::splitNode(), and osg::SplitGraphOp::traverseLeave().

00175 {
00176     if (isInExcludeListNodes(node) || (OSG::getName(node)!=NULL && isInExcludeListNames(OSG::getName(node))))
00177         return true;
00178     else
00179         return false;
00180 }


Member Data Documentation

MaterialObjectMap osg::MaterialMergeGraphOp::_materialObjects [private]
 

Definition at line 122 of file OSGMaterialMergeGraphOp.h.

Referenced by addObject(), and traverse().

std::list<NodePtr> osg::GraphOp::_excludeListNodes [protected, inherited]
 

Definition at line 161 of file OSGGraphOp.h.

Referenced by osg::GraphOp::addToExcludeList(), osg::GraphOp::clearExcludeList(), osg::GraphOp::isInExcludeListNodes(), osg::MergeGraphOp::mergeOnce(), and osg::GraphOp::removeFromExcludeList().

std::list<std::string> osg::GraphOp::_excludeListNames [protected, inherited]
 

Definition at line 162 of file OSGGraphOp.h.

Referenced by osg::GraphOp::addToExcludeList(), osg::GraphOp::clearExcludeList(), osg::GraphOp::isInExcludeListNames(), and osg::GraphOp::removeFromExcludeList().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:14:09 2005 for OpenSG by  doxygen 1.4.3