From 0ed71961d48453f59e0e882b96e722f57d79fbdf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 13 May 2008 12:36:39 +0000 Subject: [PATCH] Further work on computing of lat/long range of PagedLOD subgraphs --- applications/osgfilecache/osgfilecache.cpp | 117 +++++++++++++++++++-- 1 file changed, 109 insertions(+), 8 deletions(-) diff --git a/applications/osgfilecache/osgfilecache.cpp b/applications/osgfilecache/osgfilecache.cpp index 989eb553b..5f174571e 100644 --- a/applications/osgfilecache/osgfilecache.cpp +++ b/applications/osgfilecache/osgfilecache.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -43,11 +44,17 @@ public: { std::cout<<"CoordinateSystemNode "<(&group); osgTerrain::Locator* locator = terrainTile ? terrainTile->getLocator() : 0; if (locator) @@ -57,14 +64,14 @@ public: osg::Vec3d l10(1.0,0.0,0.0); osg::Vec3d l11(1.0,1.0,0.0); osg::Vec3d l01(0.0,1.0,0.0); - + osg::Vec3d w00, w10, w11, w01; - + locator->convertLocalToModel(l00, w00); locator->convertLocalToModel(l10, w10); locator->convertLocalToModel(l11, w11); locator->convertLocalToModel(l01, w01); - + if (locator->getEllipsoidModel() && locator->getCoordinateSystemType()==osgTerrain::Locator::GEOCENTRIC) { @@ -78,20 +85,47 @@ public: osg::notify(osg::NOTICE)<<" w10 = "<_maxLevels) return; if (s_ExitApplication) return; ++_currentLevel; - std::cout<<"Found PagedLOD "<asGeometry(); + if (geom) + { + osg::Vec3Array* vertices = dynamic_cast(geom->getVertexArray()); + if (vertices) updateBound(*vertices); + } + } + } + protected: + inline void pushMatrix(osg::Matrix& matrix) { _matrixStack.push_back(matrix); } + + inline void popMatrix() { _matrixStack.pop_back(); } + void convertXYZToLatLongHeight(osg::EllipsoidModel* em, osg::Vec3d& v) { em->convertXYZToLatLongHeight(v.x(), v.y(), v.z(), @@ -139,9 +192,57 @@ protected: v.x() = osg::RadiansToDegrees(v.x()); v.y() = osg::RadiansToDegrees(v.y()); } + + void initBound() + { + _min.set(DBL_MAX, DBL_MAX); + _max.set(-DBL_MAX, -DBL_MAX); + } - unsigned int _maxLevels; - unsigned int _currentLevel; + void updateBound(osg::Vec3d& v) + { + if (v.x() < _min.x()) _min.x() = v.x(); + if (v.y() < _min.y()) _min.y() = v.y(); + if (v.x() > _max.x()) _max.x() = v.x(); + if (v.y() > _max.y()) _max.y() = v.y(); + } + + void updateBound(osg::Vec3Array& vertices) + { + // set up matrix + osg::Matrix matrix; + if (!_matrixStack.empty()) matrix = _matrixStack.back(); + + // set up ellipsoid model + osg::EllipsoidModel* em = !_csnStack.empty() ? _csnStack.back()->getEllipsoidModel() : 0; + + for(osg::Vec3Array::iterator itr = vertices.begin(); + itr != vertices.end(); + ++itr) + { + osg::Vec3d v = osg::Vec3d(*itr) * matrix; + if (em) convertXYZToLatLongHeight(em, v); + + updateBound(v); + } + } + + bool isCulled() + { + std::cout<<"isCulled() _min = "<<_min<<" _max = "<<_max< MatrixStack; + typedef std::vector CSNStack; + + unsigned int _maxLevels; + unsigned int _currentLevel; + MatrixStack _matrixStack; + CSNStack _csnStack; + + osg::Vec2d _min; + osg::Vec2d _max; }; static void signalHandler(int sig)