| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osgViewer/Viewer> |
|---|
| 20 | |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | |
|---|
| 23 | #include <osg/Texture2D> |
|---|
| 24 | #include <osg/TexEnv> |
|---|
| 25 | #include <osg/TexGen> |
|---|
| 26 | |
|---|
| 27 | #include <osgDB/Registry> |
|---|
| 28 | #include <osgDB/ReadFile> |
|---|
| 29 | |
|---|
| 30 | #include <osgFX/MultiTextureControl> |
|---|
| 31 | |
|---|
| 32 | #include <osgGA/TerrainManipulator> |
|---|
| 33 | |
|---|
| 34 | #include <osgUtil/Optimizer> |
|---|
| 35 | |
|---|
| 36 | #include <iostream> |
|---|
| 37 | |
|---|
| 38 | template<class T> |
|---|
| 39 | class FindTopMostNodeOfTypeVisitor : public osg::NodeVisitor |
|---|
| 40 | { |
|---|
| 41 | public: |
|---|
| 42 | FindTopMostNodeOfTypeVisitor(): |
|---|
| 43 | osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), |
|---|
| 44 | _foundNode(0) |
|---|
| 45 | {} |
|---|
| 46 | |
|---|
| 47 | void apply(osg::Node& node) |
|---|
| 48 | { |
|---|
| 49 | T* result = dynamic_cast<T*>(&node); |
|---|
| 50 | if (result) |
|---|
| 51 | { |
|---|
| 52 | _foundNode = result; |
|---|
| 53 | } |
|---|
| 54 | else |
|---|
| 55 | { |
|---|
| 56 | traverse(node); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | T* _foundNode; |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | template<class T> |
|---|
| 64 | T* findTopMostNodeOfType(osg::Node* node) |
|---|
| 65 | { |
|---|
| 66 | if (!node) return 0; |
|---|
| 67 | |
|---|
| 68 | FindTopMostNodeOfTypeVisitor<T> fnotv; |
|---|
| 69 | node->accept(fnotv); |
|---|
| 70 | |
|---|
| 71 | return fnotv._foundNode; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | int main( int argc, char **argv ) |
|---|
| 75 | { |
|---|
| 76 | |
|---|
| 77 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | osgViewer::Viewer viewer; |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
|---|
| 84 | |
|---|
| 85 | if (!rootnode) |
|---|
| 86 | { |
|---|
| 87 | osg::notify(osg::NOTICE)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; |
|---|
| 88 | return 1; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode); |
|---|
| 92 | if (csn) |
|---|
| 93 | { |
|---|
| 94 | osg::notify(osg::NOTICE)<<"Found CSN"<<csn<<std::endl; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | osgFX::MultiTextureControl* mtc = findTopMostNodeOfType<osgFX::MultiTextureControl>(rootnode); |
|---|
| 98 | if (mtc) |
|---|
| 99 | { |
|---|
| 100 | osg::notify(osg::NOTICE)<<"Found MTC "<<mtc<<std::endl; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | viewer.setCameraManipulator(new osgGA::TerrainManipulator); |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | viewer.setSceneData( rootnode ); |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | viewer.realize(); |
|---|
| 111 | |
|---|
| 112 | return viewer.run(); |
|---|
| 113 | } |
|---|