Added support for compute the extents on local NDC coordiantes of the

elevation and colour layers
This commit is contained in:
Robert Osfield 2007-03-28 16:28:20 +00:00
parent b7967b7007
commit cb811aa7cd
4 changed files with 123 additions and 11 deletions

View File

@ -39,7 +39,6 @@ int main(int argc, char** argv)
osg::ref_ptr<osgTerrain::TerrainNode> terrain = new osgTerrain::TerrainNode;
osg::ref_ptr<osgTerrain::Locator> locator = new osgTerrain::EllipsoidLocator(-osg::PI, -osg::PI*0.5, 2.0*osg::PI, osg::PI, 0.0);
bool readParameter = false;
do
{
@ -57,7 +56,7 @@ int main(int argc, char** argv)
{
readParameter = true;
osg::notify(osg::NOTICE)<<"--hf "<<filename<<" x="<<x<<" y="<<y<<" w="<<w<<" h="<<h<<std::endl;
osg::notify(osg::NOTICE)<<"--hf "<<filename<<std::endl;
osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile(filename);
if (hf.valid())
@ -78,10 +77,10 @@ int main(int argc, char** argv)
}
if (arguments.read("-h",filename) || arguments.read("--elevation-image",filename))
if (arguments.read("-d",filename) || arguments.read("--elevation-image",filename))
{
readParameter = true;
osg::notify(osg::NOTICE)<<"--elevation-image "<<filename<<" x="<<x<<" y="<<y<<" w="<<w<<" h="<<h<<std::endl;
osg::notify(osg::NOTICE)<<"--elevation-image "<<filename<<std::endl;
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
if (image.valid())

View File

@ -34,7 +34,18 @@ class OSGTERRAIN_EXPORT Locator : public osg::Object
META_Object(osgTerrain, Locator);
virtual bool convertLocalToModel(const osg::Vec3d& /*local*/, osg::Vec3d& /*world*/) const { return false; }
virtual bool convertModelToWorld(const osg::Vec3d& /*world*/, osg::Vec3d& /*local*/) const { return false; }
virtual bool convertModelToLocal(const osg::Vec3d& /*world*/, osg::Vec3d& /*local*/) const { return false; }
static bool convertLocalCoordBetween(const Locator& source, const osg::Vec3d& sourceNDC,
const Locator& destination, osg::Vec3d& destinationNDC)
{
osg::Vec3d model;
if (!source.convertLocalToModel(sourceNDC, model)) return false;
if (!destination.convertModelToLocal(model, destinationNDC)) return false;
return true;
}
bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight);
protected:
@ -63,7 +74,7 @@ public:
const osg::EllipsoidModel* getEllipsoidModel() const { return _em.get(); }
bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const;
bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local) const;
bool convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const;
protected:

View File

@ -12,6 +12,8 @@
*/
#include <osgTerrain/GeometryTechnique>
#include <osgTerrain/TerrainNode>
#include <osg/io_utils>
using namespace osgTerrain;
@ -32,24 +34,86 @@ void GeometryTechnique::init()
{
osg::notify(osg::NOTICE)<<"Doing init()"<<std::endl;
if (!_terrainNode) return;
osgTerrain::Layer* elevationLayer = _terrainNode->getElevationLayer();
osgTerrain::Layer* colorLayer = _terrainNode->getColorLayer();
osg::TransferFunction* colorTF = _terrainNode->getColorTransferFunction();
osg::notify(osg::NOTICE)<<"elevationLayer = "<<elevationLayer<<std::endl;
osg::notify(osg::NOTICE)<<"colorLayer = "<<colorLayer<<std::endl;
osg::notify(osg::NOTICE)<<"colorTF = "<<colorTF<<std::endl;
Locator* elevationLocator = elevationLayer ? elevationLayer->getLocator() : 0;
Locator* colorLocator = colorLayer ? colorLayer->getLocator() : 0;
Locator* masterLocator = elevationLocator ? elevationLocator : colorLocator;
if (!masterLocator)
{
osg::notify(osg::NOTICE)<<"Problem, no locator found in any of the terrain layers"<<std::endl;
return;
}
if (!elevationLocator) elevationLocator = masterLocator;
if (!colorLocator) colorLocator = masterLocator;
osg::Vec3d bottomLeftNDC(DBL_MAX, DBL_MAX, 0.0);
osg::Vec3d topRightNDC(-DBL_MAX, -DBL_MAX, 0.0);
if (elevationLayer)
{
if (elevationLocator!= masterLocator)
{
masterLocator->computeLocalBounds(*elevationLocator, bottomLeftNDC, topRightNDC);
}
else
{
bottomLeftNDC.x() = osg::minimum(bottomLeftNDC.x(), 0.0);
bottomLeftNDC.y() = osg::minimum(bottomLeftNDC.y(), 0.0);
topRightNDC.x() = osg::maximum(topRightNDC.x(), 1.0);
topRightNDC.y() = osg::maximum(topRightNDC.y(), 1.0);
}
}
if (colorLayer)
{
if (colorLocator!= masterLocator)
{
masterLocator->computeLocalBounds(*colorLocator, bottomLeftNDC, topRightNDC);
}
else
{
bottomLeftNDC.x() = osg::minimum(bottomLeftNDC.x(), 0.0);
bottomLeftNDC.y() = osg::minimum(bottomLeftNDC.y(), 0.0);
topRightNDC.x() = osg::maximum(topRightNDC.x(), 1.0);
topRightNDC.y() = osg::maximum(topRightNDC.y(), 1.0);
}
}
osg::notify(osg::NOTICE)<<"bottomLeftNDC = "<<bottomLeftNDC<<std::endl;
osg::notify(osg::NOTICE)<<"topRightNDC = "<<topRightNDC<<std::endl;
_geode = new osg::Geode;
_geometry = new osg::Geometry;
_geode->addDrawable(_geometry.get());
osg::Vec3Array* vertices = new osg::Vec3Array;
osg::Vec3Array* normals = new osg::Vec3Array;
osg::Vec2Array* texcoords = new osg::Vec2Array;
_dirty = false;
}
void GeometryTechnique::update(osgUtil::UpdateVisitor* nv)
{
osg::notify(osg::NOTICE)<<"Doing update"<<std::endl;
}
void GeometryTechnique::cull(osgUtil::CullVisitor* nv)
{
osg::notify(osg::NOTICE)<<"Doing cull"<<std::endl;
if (_geode.valid())
{
_geode->accept(*nv);
@ -58,7 +122,6 @@ void GeometryTechnique::cull(osgUtil::CullVisitor* nv)
void GeometryTechnique::cleanSceneGraph()
{
osg::notify(osg::NOTICE)<<"Cleaning scene graph"<<std::endl;
}
void GeometryTechnique::dirty()

View File

@ -13,6 +13,8 @@
#include <osgTerrain/Locator>
#include <list>
using namespace osgTerrain;
//////////////////////////////////////////////////////////////////////////////
@ -32,6 +34,43 @@ Locator::~Locator()
{
}
bool Locator::computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight)
{
typedef std::list<osg::Vec3d> Corners;
Corners corners;
osg::Vec3d cornerNDC;
if (Locator::convertLocalCoordBetween(source, osg::Vec3d(0.0,0.0,0.0), *this, cornerNDC))
{
corners.push_back(cornerNDC);
}
if (Locator::convertLocalCoordBetween(source, osg::Vec3d(1.0,0.0,0.0), *this, cornerNDC))
{
corners.push_back(cornerNDC);
}
if (Locator::convertLocalCoordBetween(source, osg::Vec3d(0.0,1.0,0.0), *this, cornerNDC))
{
corners.push_back(cornerNDC);
}
if (Locator::convertLocalCoordBetween(source, osg::Vec3d(1.0,1.0,0.0), *this, cornerNDC))
{
corners.push_back(cornerNDC);
}
for(Corners::iterator itr = corners.begin();
itr != corners.end();
++itr)
{
bottomLeft.x() = osg::minimum( bottomLeft.x(), itr->x());
bottomLeft.y() = osg::minimum( bottomLeft.y(), itr->y());
topRight.x() = osg::maximum( topRight.x(), itr->x());
topRight.y() = osg::maximum( topRight.y(), itr->y());
}
}
//////////////////////////////////////////////////////////////////////////////
//
@ -70,7 +109,7 @@ bool EllipsoidLocator::convertLocalToModel(const osg::Vec3d& local, osg::Vec3d&
return true;
}
bool EllipsoidLocator::convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local) const
bool EllipsoidLocator::convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const
{
double longitude, latitude, height;