SPIN Framework
|
00001 // ----------------------------------------------------------------------------- 00002 // | ___ ___ _ _ _ ___ _ | 00003 // | / __>| . \| || \ | | __>_ _ ___ ._ _ _ ___ _ _ _ ___ _ _ | |__ | 00004 // | \__ \| _/| || | | _>| '_><_> || ' ' |/ ._>| | | |/ . \| '_>| / / | 00005 // | <___/|_| |_||_\_| |_| |_| <___||_|_|_|\___.|__/_/ \___/|_| |_\_\ | 00006 // | | 00007 // |---------------------------------------------------------------------------| 00008 // 00009 // http://spinframework.sourceforge.net 00010 // Copyright (C) 2009 Mike Wozniewski, Zack Settel 00011 // 00012 // Developed/Maintained by: 00013 // Mike Wozniewski (http://www.mikewoz.com) 00014 // Zack Settel (http://www.sheefa.net/zack) 00015 // 00016 // Principle Partners: 00017 // Shared Reality Lab, McGill University (http://www.cim.mcgill.ca/sre) 00018 // La Societe des Arts Technologiques (http://www.sat.qc.ca) 00019 // 00020 // Funding by: 00021 // NSERC/Canada Council for the Arts - New Media Initiative 00022 // Heritage Canada 00023 // Ministere du Developpement economique, de l'Innovation et de l'Exportation 00024 // 00025 // ----------------------------------------------------------------------------- 00026 // This file is part of the SPIN Framework. 00027 // 00028 // SPIN Framework is free software: you can redistribute it and/or modify 00029 // it under the terms of the GNU Lesser General Public License as published by 00030 // the Free Software Foundation, either version 3 of the License, or 00031 // (at your option) any later version. 00032 // 00033 // SPIN Framework is distributed in the hope that it will be useful, 00034 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00035 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00036 // GNU Lesser General Public License for more details. 00037 // 00038 // You should have received a copy of the GNU Lesser General Public License 00039 // along with SPIN Framework. If not, see <http://www.gnu.org/licenses/>. 00040 // ----------------------------------------------------------------------------- 00041 00042 #ifndef __NODE_VISITORS_H__ 00043 #define __NODE_VISITORS_H__ 00044 00045 #include <osg/NodeVisitor> 00046 00047 #include <string> 00048 #include <iostream> 00049 00050 namespace osg { 00051 class Node; 00052 class Texture2D; 00053 class TextureRectangle; 00054 class Sequence; 00055 class Switch; 00056 class PositionAttitudeTransform; 00057 class Geode; 00058 class MatrixTransform; 00059 } 00060 00061 namespace spin 00062 { 00063 00073 class SearchVisitor : public osg::NodeVisitor 00074 { 00075 public: 00076 SearchVisitor(); 00077 00078 virtual void apply(osg::Node &searchNode); 00079 00080 virtual void apply(osg::Group &searchNode); 00081 virtual void apply(osg::Geode &searchNode); 00082 virtual void apply(osg::MatrixTransform &searchNode); 00083 virtual void apply(osg::PositionAttitudeTransform &searchNode); 00084 virtual void apply(osg::Switch &searchNode); 00085 virtual void apply(osg::Sequence &searchNode); 00086 00087 // search for node with given name starting at the search node 00088 void searchNode(osg::Node* searchFromMe, std::string searchName); 00089 00090 osg::ref_ptr<osg::Group> getGroup(); 00091 osg::ref_ptr<osg::MatrixTransform> getMT(); 00092 osg::ref_ptr<osg::Geode> getGeode(); 00093 osg::ref_ptr<osg::PositionAttitudeTransform> getPAT(); 00094 osg::ref_ptr<osg::Switch> getSwitchNode(); 00095 osg::ref_ptr<osg::Sequence> getSequenceNode(); 00096 00097 private: 00098 std::string searchForName; 00099 00100 osg::ref_ptr<osg::Group> GroupNode; 00101 osg::ref_ptr<osg::Geode> GeodeNode; 00102 osg::ref_ptr<osg::MatrixTransform> MTNode; 00103 osg::ref_ptr<osg::PositionAttitudeTransform> PATNode; 00104 osg::ref_ptr<osg::Switch> SwitchNode; 00105 osg::ref_ptr<osg::Sequence> SequenceNode; 00106 }; 00107 00108 typedef std::vector< osg::ref_ptr<osg::Node> > NodeList; 00109 00110 // FIXME: is the definition below OK? 00116 class NodeSearcher : public osg::NodeVisitor 00117 { 00118 public: 00119 NodeSearcher(NodeList& list); 00120 00121 virtual void apply(osg::Node& node); 00122 00127 void search(osg::Node* subgraph, std::string s); 00128 00129 std::string _searchName; 00130 NodeList& _nodeList; 00131 00132 protected: 00133 NodeSearcher& operator = (const NodeSearcher&) { return *this; } 00134 }; 00135 00139 class DebugVisitor : public osg::NodeVisitor 00140 { 00141 public: 00142 DebugVisitor(); 00143 00147 void print(osg::Node* subgraph); 00148 00149 virtual void apply(osg::Node &node); 00150 virtual void apply(osg::PositionAttitudeTransform &node); 00151 virtual void apply(osg::Geode &node); 00152 virtual void apply(osg::Group &node); 00153 }; 00154 00158 class UpdateSceneVisitor : public osg::NodeVisitor 00159 { 00160 public: 00161 UpdateSceneVisitor(); 00162 virtual void apply(osg::Node &node); 00163 virtual void apply(osg::Group &node); 00164 }; 00165 00166 typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList; 00167 00171 class TextureStateSetFinder : public osg::NodeVisitor 00172 { 00173 public: 00174 TextureStateSetFinder(StateSetList& list); 00175 virtual void apply(osg::Node& node); 00176 virtual void apply(osg::Geode& geode); 00177 virtual void apply(osg::StateSet* stateset); 00178 00179 /* 00180 inline void apply(osg::Image* img) 00181 { 00182 if (img) 00183 { 00184 std::cout << " adding image: " << img->getFileName() << std::endl; 00185 _imageList.push_back(img); 00186 } 00187 } 00188 */ 00189 00190 StateSetList& _statesetList; 00191 00192 protected: 00193 TextureStateSetFinder& operator = (const TextureStateSetFinder&); 00194 }; 00195 00196 } // end of namespace spin 00197 00198 #endif // __NODE_VISITORS_H__