Added support for compute the extents on local NDC coordiantes of the
elevation and colour layers
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user