Changeset 8313
- Timestamp:
- 05/12/08 18:59:04
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/applications/osgfilecache/CMakeLists.txt
r8297 r8313 2 2 SET(TARGET_SRC osgfilecache.cpp ) 3 3 4 SET(TARGET_ADDED_LIBRARIES osgTerrain ) 5 4 6 #### end var setup ### 5 7 SETUP_APPLICATION(osgfilecache) OpenSceneGraph/trunk/applications/osgfilecache/osgfilecache.cpp
r8298 r8313 13 13 #include <osg/ArgumentParser> 14 14 #include <osg/ApplicationUsage> 15 #include <osg/CoordinateSystemNode> 16 #include <osg/io_utils> 17 18 #include <osgTerrain/TerrainTile> 15 19 16 20 #include <osgDB/Archive> … … 22 26 #include <algorithm> 23 27 28 #include <signal.h> 29 30 static bool s_ExitApplication = false; 31 24 32 class LoadDataVisitor : public osg::NodeVisitor 25 33 { 26 34 public: 35 27 36 28 37 LoadDataVisitor(unsigned int maxNumLevels=0): … … 31 40 _currentLevel(0) {} 32 41 42 void apply(osg::CoordinateSystemNode& cs) 43 { 44 std::cout<<"CoordinateSystemNode "<<std::endl; 45 46 if (!s_ExitApplication) traverse(cs); 47 } 48 49 void apply(osg::Group& group) 50 { 51 osgTerrain::TerrainTile* terrainTile = dynamic_cast<osgTerrain::TerrainTile*>(&group); 52 osgTerrain::Locator* locator = terrainTile ? terrainTile->getLocator() : 0; 53 if (locator) 54 { 55 std::cout<<" Found terrain locator "<<locator<<std::endl; 56 osg::Vec3d l00(0.0,0.0,0.0); 57 osg::Vec3d l10(1.0,0.0,0.0); 58 osg::Vec3d l11(1.0,1.0,0.0); 59 osg::Vec3d l01(0.0,1.0,0.0); 60 61 osg::Vec3d w00, w10, w11, w01; 62 63 locator->convertLocalToModel(l00, w00); 64 locator->convertLocalToModel(l10, w10); 65 locator->convertLocalToModel(l11, w11); 66 locator->convertLocalToModel(l01, w01); 67 68 if (locator->getEllipsoidModel() && 69 locator->getCoordinateSystemType()==osgTerrain::Locator::GEOCENTRIC) 70 { 71 convertXYZToLatLongHeight(locator->getEllipsoidModel(), w00); 72 convertXYZToLatLongHeight(locator->getEllipsoidModel(), w10); 73 convertXYZToLatLongHeight(locator->getEllipsoidModel(), w11); 74 convertXYZToLatLongHeight(locator->getEllipsoidModel(), w01); 75 } 76 77 osg::notify(osg::NOTICE)<<" w00 = "<<w00<<std::endl; 78 osg::notify(osg::NOTICE)<<" w10 = "<<w10<<std::endl; 79 osg::notify(osg::NOTICE)<<" w11 = "<<w11<<std::endl; 80 osg::notify(osg::NOTICE)<<" w01 = "<<w01<<std::endl; 81 } 82 83 if (!s_ExitApplication) traverse(group); 84 } 85 33 86 void apply(osg::PagedLOD& plod) 34 87 { 35 88 if (_currentLevel>_maxLevels) return; 89 90 if (s_ExitApplication) return; 36 91 37 92 ++_currentLevel; 38 93 39 94 std::cout<<"Found PagedLOD "<<plod.getNumFileNames()<<std::endl; 95 96 // first compute the bounds of this subgraph 97 for(unsigned int i=0; i<plod.getNumFileNames(); ++i) 98 { 99 if (plod.getFileName(i).empty()) 100 { 101 std::cout<<" search local subgraph"<<std::endl; 102 traverse(plod); 103 } 104 } 105 40 106 for(unsigned int i=0; i<plod.getNumFileNames(); ++i) 41 107 { … … 57 123 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filename); 58 124 59 if ( node.valid()) node->accept(*this);125 if (!s_ExitApplication && node.valid()) node->accept(*this); 60 126 } 61 127 } … … 65 131 66 132 protected: 133 134 void convertXYZToLatLongHeight(osg::EllipsoidModel* em, osg::Vec3d& v) 135 { 136 em->convertXYZToLatLongHeight(v.x(), v.y(), v.z(), 137 v.x(), v.y(), v.z()); 138 139 v.x() = osg::RadiansToDegrees(v.x()); 140 v.y() = osg::RadiansToDegrees(v.y()); 141 } 67 142 68 143 unsigned int _maxLevels; … … 70 145 }; 71 146 147 static void signalHandler(int sig) 148 { 149 printf("\nCaught signal %d, requesting exit...\n\n",sig); 150 s_ExitApplication = true; 151 } 72 152 73 153 int main( int argc, char **argv ) 74 154 { 155 #ifndef _WIN32 156 signal(SIGHUP, signalHandler); 157 signal(SIGQUIT, signalHandler); 158 signal(SIGKILL, signalHandler); 159 signal(SIGUSR1, signalHandler); 160 signal(SIGUSR2, signalHandler); 161 #endif 162 signal(SIGABRT, signalHandler); 163 signal(SIGINT, signalHandler); 164 signal(SIGTERM, signalHandler); 165 166 75 167 // use an ArgumentParser object to manage the program arguments. 76 168 osg::ArgumentParser arguments(&argc,argv); … … 113 205 loadedModel->accept(ldv); 114 206 207 if (s_ExitApplication) 208 { 209 std::cout<<"osgfilecache cleanly exited in response to signal."<<std::endl; 210 } 211 115 212 return 0; 116 213 }
