#include <OSGMakeTransparentGraphOp.h>

Public Member Functions | |
| MakeTransparentGraphOp (const char *name="MakeTransparent") | |
| GraphOp * | create () |
| bool | traverse (NodePtr &node) |
| void | setParams (const std::string params) |
| std::string | usage (void) |
Main methods | |
| const std::string & | getName (void) |
| void | setName (const char *name) |
Exclusion | |
| void | addToExcludeList (NodePtr &node) |
| void | addToExcludeList (const std::string &name) |
| void | removeFromExcludeList (NodePtr &node) |
| void | removeFromExcludeList (const std::string &name) |
| void | clearExcludeList (void) |
| bool | isInExcludeListNodes (NodePtr &node) |
| bool | isInExcludeListNames (const std::string &name) |
| bool | isInExcludeList (NodePtr &node) |
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< MaterialObject > | MaterialObjectList |
| 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) |
| void | applyTransparency (MaterialPtr m) |
Private Attributes | |
| MaterialObjectMap | _materialObjects |
| Real32 | _transparency |
Classes | |
| class | MaterialObject |
Definition at line 59 of file OSGMakeTransparentGraphOp.h.
typedef std::list<MaterialObject> osg::MakeTransparentGraphOp::MaterialObjectList [private] |
Definition at line 122 of file OSGMakeTransparentGraphOp.h.
typedef std::map<MaterialPtr, MaterialObjectList> osg::MakeTransparentGraphOp::MaterialObjectMap [private] |
Definition at line 123 of file OSGMakeTransparentGraphOp.h.
| MakeTransparentGraphOp::MakeTransparentGraphOp | ( | const char * | name = "MakeTransparent" |
) |
Definition at line 49 of file OSGMakeTransparentGraphOp.cpp.
Referenced by create().
00050 : GraphOp(name), 00051 _transparency(0.5) 00052 { 00053 }
| static const char* osg::MakeTransparentGraphOp::getClassname | ( | void | ) | [inline, static] |
| GraphOp * MakeTransparentGraphOp::create | ( | ) | [virtual] |
Implements osg::GraphOp.
Definition at line 55 of file OSGMakeTransparentGraphOp.cpp.
References MakeTransparentGraphOp().
00056 { 00057 return new MakeTransparentGraphOp(); 00058 }
| bool MakeTransparentGraphOp::traverse | ( | NodePtr & | root | ) | [virtual] |
Reimplemented from osg::GraphOp.
Definition at line 70 of file OSGMakeTransparentGraphOp.cpp.
References _materialObjects, applyTransparency(), osg::AttachmentContainerPtr::dcast(), osg::deepClone(), osg::NullFC, and osg::GraphOp::traverse().
00071 { 00072 // Find the materials. 00073 if (!GraphOp::traverse(node)) { 00074 return false; 00075 } 00076 00077 // Now do the merge. 00078 MaterialObjectMap::iterator itr = _materialObjects.begin(); 00079 for (; itr != _materialObjects.end(); ++itr) 00080 { 00081 MaterialPtr oldMaterial = itr->first; 00082 MaterialPtr newMaterial = MaterialPtr::dcast(deepClone(oldMaterial)); 00083 if (newMaterial != NullFC) 00084 { 00085 std::cout << "Applying transparency: "; 00086 00087 applyTransparency(newMaterial); 00088 00089 // Put the new material in the objects in this subtree. 00090 MaterialObjectList& currentList = itr->second; 00091 MaterialObjectList::iterator i = currentList.begin(); 00092 for (; i != currentList.end(); ++i) 00093 { 00094 i->setMaterial(newMaterial); 00095 } 00096 } 00097 } 00098 00099 return true; 00100 }
| void MakeTransparentGraphOp::setParams | ( | const std::string | params | ) | [virtual] |
Implements osg::GraphOp.
Definition at line 103 of file OSGMakeTransparentGraphOp.cpp.
References _transparency, FWARNING, and osg::GraphOp::ParamSet::getUnusedParams().
00104 { 00105 ParamSet ps(params); 00106 00107 ps("transparency", _transparency); 00108 00109 std::string out = ps.getUnusedParams(); 00110 if(out.length()) 00111 { 00112 FWARNING(("MakeTransparentGraphOp doesn't have parameters '%s'.\n", 00113 out.c_str())); 00114 } 00115 }
| std::string MakeTransparentGraphOp::usage | ( | void | ) | [virtual] |
Implements osg::GraphOp.
Definition at line 117 of file OSGMakeTransparentGraphOp.cpp.
00118 { 00119 return 00120 "MakeTransparent: make used Materials transparent\n" 00121 " Based on MaterialMergeGraphOp, merges Materials and sets their\n" 00122 " transparency.\n" 00123 "Params: name (type, default)\n" 00124 " transparency (Real32, 0.5f): transparency value\n"; 00125 }
| Action::ResultE MakeTransparentGraphOp::traverseEnter | ( | NodePtr & | node | ) | [private, virtual] |
Implements osg::GraphOp.
Definition at line 127 of file OSGMakeTransparentGraphOp.cpp.
References addObject(), osg::Action::Continue, osg::AttachmentContainerPtr::dcast(), osg::NodePtr::getCore(), and osg::NullFC.
00128 { 00129 GeometryPtr geo = GeometryPtr::dcast(node->getCore()); 00130 if (geo != NullFC) 00131 { 00132 addObject(MaterialObject(geo)); 00133 return Action::Continue; 00134 } 00135 00136 MaterialGroupPtr mg = MaterialGroupPtr::dcast(node->getCore()); 00137 if (mg != NullFC) 00138 { 00139 addObject(MaterialObject(mg)); 00140 return Action::Continue; 00141 } 00142 00143 // Otherwise, keep looking. 00144 return Action::Continue; 00145 }
| Action::ResultE MakeTransparentGraphOp::traverseLeave | ( | NodePtr & | node, | |
| Action::ResultE | res | |||
| ) | [private, virtual] |
| void MakeTransparentGraphOp::addObject | ( | MaterialObject | m | ) | [private] |
Definition at line 152 of file OSGMakeTransparentGraphOp.cpp.
References _materialObjects, osg::MakeTransparentGraphOp::MaterialObject::getMaterial(), and osg::NullFC.
Referenced by traverseEnter().
00153 { 00154 MaterialPtr mat = m.getMaterial(); 00155 if (mat == NullFC) 00156 return; 00157 00158 _materialObjects[mat].push_back(m); 00159 }
| void MakeTransparentGraphOp::applyTransparency | ( | MaterialPtr | m | ) | [private] |
Definition at line 185 of file OSGMakeTransparentGraphOp.cpp.
References _transparency, osg::beginEditCP(), osg::AttachmentContainerPtr::dcast(), osg::endEditCP(), GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and osg::NullFC.
Referenced by traverse().
00185 { 00186 00187 SimpleMaterialPtr sm = SimpleMaterialPtr::dcast(m); 00188 if (sm != NullFC) { 00189 std::cout << "SimpleMaterial" << std::endl; 00190 beginEditCP(sm); 00191 sm->setTransparency(1.0f - (1.0f - sm->getTransparency()) * 00192 _transparency); 00193 sm->setColorMaterial(GL_NONE); 00194 endEditCP(sm); 00195 00196 PolygonChunkPtr polygonChunk = getOrAddChunk<PolygonChunk>(sm); 00197 beginEditCP(polygonChunk); 00198 polygonChunk->setCullFace(GL_BACK); 00199 endEditCP(polygonChunk); 00200 return; 00201 } 00202 00203 ChunkMaterialPtr cm = ChunkMaterialPtr::dcast(m); 00204 if (cm != NullFC) { 00205 std::cout << "ChunkMaterial" << std::endl; 00206 BlendChunkPtr blendChunk = getOrAddChunk<BlendChunk>(cm); 00207 beginEditCP(blendChunk); 00208 blendChunk->setColor(Color4f(1, 1, 1, 1.f - _transparency)); 00209 blendChunk->setSrcFactor(GL_CONSTANT_ALPHA); 00210 blendChunk->setDestFactor(GL_ONE_MINUS_CONSTANT_ALPHA); 00211 endEditCP(blendChunk); 00212 return; 00213 } 00214 }
| 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] |
| 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 }
Definition at line 125 of file OSGMakeTransparentGraphOp.h.
Referenced by addObject(), and traverse().
Definition at line 127 of file OSGMakeTransparentGraphOp.h.
Referenced by applyTransparency(), and setParams().
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().
1.5.5