Refactor osgTerrain::ProxyLayer so that it is now a pure Proxy, defering implementations
to an Implementation rather than a subclass of ProxyLayer. Updating the osgTerrain and GDAL plugins to comply with this refactor.
This commit is contained in:
@@ -32,11 +32,12 @@ _dataset(0), _gdalReader(0)
|
||||
DataSetLayer::DataSetLayer(const std::string& fileName):
|
||||
_dataset(0), _gdalReader(0)
|
||||
{
|
||||
openFile(fileName);
|
||||
setFileName(fileName);
|
||||
open();
|
||||
}
|
||||
|
||||
DataSetLayer::DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop):
|
||||
ProxyLayer(dataSetLayer), _gdalReader(dataSetLayer._gdalReader)
|
||||
Layer(dataSetLayer), _gdalReader(dataSetLayer._gdalReader)
|
||||
{
|
||||
if (dataSetLayer._dataset) open();
|
||||
}
|
||||
@@ -52,6 +53,9 @@ void DataSetLayer::open()
|
||||
|
||||
if (getFileName().empty()) return;
|
||||
|
||||
|
||||
osg::notify(osg::NOTICE)<<"DataSetLayer::open()"<<getFileName()<<std::endl;
|
||||
|
||||
_dataset = static_cast<GDALDataset*>(GDALOpen(getFileName().c_str(),GA_ReadOnly));
|
||||
|
||||
setUpLocator();
|
||||
@@ -59,6 +63,8 @@ void DataSetLayer::open()
|
||||
|
||||
void DataSetLayer::close()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"DataSetLayer::close()"<<getFileName()<<std::endl;
|
||||
|
||||
if (_dataset)
|
||||
{
|
||||
GDALClose(static_cast<GDALDatasetH>(_dataset));
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
namespace GDALPlugin {
|
||||
|
||||
class DataSetLayer : public osgTerrain::ProxyLayer
|
||||
class DataSetLayer : public osgTerrain::Layer
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -75,21 +75,14 @@ bool CompositeLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
|
||||
}
|
||||
else if (fr.matchSequence("ProxyLayer %s") || fr.matchSequence("ProxyLayer %w"))
|
||||
{
|
||||
osg::ref_ptr<osg::Object> image = osgDB::readObjectFile(std::string(fr[1].getStr())+".gdal");
|
||||
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(image.get());
|
||||
if (proxyLayer)
|
||||
{
|
||||
if (locator.valid())
|
||||
{
|
||||
proxyLayer->setLocator(locator.get());
|
||||
locator = 0;
|
||||
}
|
||||
osgTerrain::ProxyLayer* proxyLayer = new osgTerrain::ProxyLayer;
|
||||
proxyLayer->setFileName(fr[1].getStr());
|
||||
|
||||
if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
|
||||
if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
|
||||
if (locator.valid()) proxyLayer->setLocator(locator.get());
|
||||
if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
|
||||
if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
|
||||
|
||||
layer.addLayer(proxyLayer);
|
||||
}
|
||||
layer.addLayer(proxyLayer);
|
||||
|
||||
fr += 2;
|
||||
|
||||
|
||||
@@ -151,16 +151,14 @@ bool Terrain_readLocalData(osg::Object& obj, osgDB::Input &fr)
|
||||
|
||||
if (fr.matchSequence("ProxyLayer %s") || fr.matchSequence("ProxyLayer %w") )
|
||||
{
|
||||
osg::ref_ptr<osg::Object> image = osgDB::readObjectFile(std::string(fr[1].getStr())+".gdal");
|
||||
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(image.get());
|
||||
if (proxyLayer)
|
||||
{
|
||||
if (locator) proxyLayer->setLocator(locator);
|
||||
if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
|
||||
if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
|
||||
osgTerrain::ProxyLayer* proxyLayer = new osgTerrain::ProxyLayer;
|
||||
proxyLayer->setFileName(fr[1].getStr());
|
||||
|
||||
terrain.setElevationLayer(proxyLayer);
|
||||
}
|
||||
if (locator) proxyLayer->setLocator(locator);
|
||||
if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
|
||||
if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
|
||||
|
||||
terrain.setElevationLayer(proxyLayer);
|
||||
|
||||
fr += 2;
|
||||
|
||||
|
||||
@@ -364,3 +364,75 @@ ProxyLayer::~ProxyLayer()
|
||||
{
|
||||
}
|
||||
|
||||
void ProxyLayer::setFileName(const std::string& filename)
|
||||
{
|
||||
_filename = filename;
|
||||
if (_implementation.valid())
|
||||
{
|
||||
_implementation->setFileName(_filename);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int ProxyLayer::getNumColumns() const
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->getNumColumns();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
unsigned int ProxyLayer::getNumRows() const
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->getNumRows();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
bool ProxyLayer::transform(float offset, float scale)
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->transform(offset,scale);
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool ProxyLayer::getValue(unsigned int i, unsigned int j, float& value) const
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->getValue(i,j,value);
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool ProxyLayer::getValue(unsigned int i, unsigned int j, osg::Vec2& value) const
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->getValue(i,j,value);
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool ProxyLayer::getValue(unsigned int i, unsigned int j, osg::Vec3& value) const
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->getValue(i,j,value);
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool ProxyLayer::getValue(unsigned int i, unsigned int j, osg::Vec4& value) const
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->getValue(i,j,value);
|
||||
else return false;
|
||||
}
|
||||
|
||||
void ProxyLayer::dirty()
|
||||
{
|
||||
if (_implementation.valid()) _implementation->dirty();
|
||||
}
|
||||
|
||||
void ProxyLayer::setModifiedCount(unsigned int value)
|
||||
{
|
||||
if (_implementation.valid()) _implementation->setModifiedCount(value);
|
||||
};
|
||||
|
||||
unsigned int ProxyLayer::getModifiedCount() const
|
||||
{
|
||||
return _implementation.valid() ? _implementation->getModifiedCount() : 0;
|
||||
}
|
||||
|
||||
|
||||
osg::BoundingSphere ProxyLayer::computeBound() const
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->computeBound();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user