From c81b02bca4b800f0e8f574a90a1a70ba94fd0799 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 12 May 2008 16:59:04 +0000 Subject: [PATCH] Added signal handling code, and prelimary lat/long computation --- applications/osgfilecache/CMakeLists.txt | 2 + applications/osgfilecache/osgfilecache.cpp | 99 +++++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/applications/osgfilecache/CMakeLists.txt b/applications/osgfilecache/CMakeLists.txt index 2857510df..3e2582532 100644 --- a/applications/osgfilecache/CMakeLists.txt +++ b/applications/osgfilecache/CMakeLists.txt @@ -1,5 +1,7 @@ SET(TARGET_SRC osgfilecache.cpp ) +SET(TARGET_ADDED_LIBRARIES osgTerrain ) + #### end var setup ### SETUP_APPLICATION(osgfilecache) diff --git a/applications/osgfilecache/osgfilecache.cpp b/applications/osgfilecache/osgfilecache.cpp index 90cdd787d..989eb553b 100644 --- a/applications/osgfilecache/osgfilecache.cpp +++ b/applications/osgfilecache/osgfilecache.cpp @@ -12,6 +12,10 @@ #include #include #include +#include +#include + +#include #include #include @@ -21,22 +25,84 @@ #include #include +#include + +static bool s_ExitApplication = false; + class LoadDataVisitor : public osg::NodeVisitor { public: + LoadDataVisitor(unsigned int maxNumLevels=0): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _maxLevels(maxNumLevels), _currentLevel(0) {} + void apply(osg::CoordinateSystemNode& cs) + { + std::cout<<"CoordinateSystemNode "<(&group); + osgTerrain::Locator* locator = terrainTile ? terrainTile->getLocator() : 0; + if (locator) + { + std::cout<<" Found terrain locator "<convertLocalToModel(l00, w00); + locator->convertLocalToModel(l10, w10); + locator->convertLocalToModel(l11, w11); + locator->convertLocalToModel(l01, w01); + + if (locator->getEllipsoidModel() && + locator->getCoordinateSystemType()==osgTerrain::Locator::GEOCENTRIC) + { + convertXYZToLatLongHeight(locator->getEllipsoidModel(), w00); + convertXYZToLatLongHeight(locator->getEllipsoidModel(), w10); + convertXYZToLatLongHeight(locator->getEllipsoidModel(), w11); + convertXYZToLatLongHeight(locator->getEllipsoidModel(), w01); + } + + osg::notify(osg::NOTICE)<<" w00 = "< node = osgDB::readNodeFile(filename); - if (node.valid()) node->accept(*this); + if (!s_ExitApplication && node.valid()) node->accept(*this); } } @@ -65,13 +131,39 @@ public: protected: + void convertXYZToLatLongHeight(osg::EllipsoidModel* em, osg::Vec3d& v) + { + em->convertXYZToLatLongHeight(v.x(), v.y(), v.z(), + v.x(), v.y(), v.z()); + + v.x() = osg::RadiansToDegrees(v.x()); + v.y() = osg::RadiansToDegrees(v.y()); + } + unsigned int _maxLevels; unsigned int _currentLevel; }; +static void signalHandler(int sig) +{ + printf("\nCaught signal %d, requesting exit...\n\n",sig); + s_ExitApplication = true; +} int main( int argc, char **argv ) { +#ifndef _WIN32 + signal(SIGHUP, signalHandler); + signal(SIGQUIT, signalHandler); + signal(SIGKILL, signalHandler); + signal(SIGUSR1, signalHandler); + signal(SIGUSR2, signalHandler); +#endif + signal(SIGABRT, signalHandler); + signal(SIGINT, signalHandler); + signal(SIGTERM, signalHandler); + + // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); @@ -112,6 +204,11 @@ int main( int argc, char **argv ) loadedModel->accept(ldv); + if (s_ExitApplication) + { + std::cout<<"osgfilecache cleanly exited in response to signal."<