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:
parent
767bdf4d21
commit
828851c08a
@ -306,35 +306,40 @@ class OSGTERRAIN_EXPORT ProxyLayer : public Layer
|
|||||||
ProxyLayer(const ProxyLayer& proxyLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
ProxyLayer(const ProxyLayer& proxyLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||||
|
|
||||||
META_Object(osgTerrain, ProxyLayer);
|
META_Object(osgTerrain, ProxyLayer);
|
||||||
|
|
||||||
|
/** Set the implementation layer that does the actual work.*/
|
||||||
|
void setImplementation(Layer* layer) { _implementation = layer; }
|
||||||
|
|
||||||
|
/** Get the implementation layer that does the actual work.*/
|
||||||
|
Layer* getImplementation() { return _implementation.get(); }
|
||||||
|
|
||||||
/** Return if this ProxyLayer is attached to valid file handle.*/
|
/** Get the const implementation layer that does the actual work.*/
|
||||||
virtual bool isOpen() const { return false; }
|
const Layer* getImplementation() const { return _implementation.get(); }
|
||||||
|
|
||||||
/** Open a file.*/
|
virtual void setFileName(const std::string& filename);
|
||||||
void openFile(const std::string& fileName)
|
virtual const std::string& getFileName() const { return _filename; }
|
||||||
{
|
|
||||||
if (_filename!=fileName)
|
|
||||||
{
|
|
||||||
if (isOpen()) close();
|
|
||||||
|
|
||||||
_filename = fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isOpen()) open();
|
virtual unsigned int getNumColumns() const;
|
||||||
}
|
virtual unsigned int getNumRows() const;
|
||||||
|
|
||||||
|
virtual bool transform(float offset, float scale);
|
||||||
|
|
||||||
/** Open the any associated file handle.*/
|
virtual bool getValue(unsigned int i, unsigned int j, float& value) const;
|
||||||
virtual void open() {}
|
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec2& value) const;
|
||||||
|
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec3& value) const;
|
||||||
|
virtual bool getValue(unsigned int i, unsigned int j, osg::Vec4& value) const;
|
||||||
|
|
||||||
/** Open the any associated file handle.*/
|
virtual void dirty();
|
||||||
virtual void close() {}
|
virtual void setModifiedCount(unsigned int value);
|
||||||
|
virtual unsigned int getModifiedCount() const;
|
||||||
|
|
||||||
/** Extract an ImageLayer from the ProxyLayer.*/
|
virtual osg::BoundingSphere computeBound() const;
|
||||||
virtual ImageLayer* extractImageLayer(unsigned int /*sourceMinX*/, unsigned int /*sourceMinY*/, unsigned int /*sourceMaxX*/, unsigned int /*sourceMaxY*/, unsigned int /*targetWidth*/=0, unsigned int /*targetHeight*/=0) { return 0; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual ~ProxyLayer();
|
virtual ~ProxyLayer();
|
||||||
|
|
||||||
|
osg::ref_ptr<Layer> _implementation;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -32,11 +32,12 @@ _dataset(0), _gdalReader(0)
|
|||||||
DataSetLayer::DataSetLayer(const std::string& fileName):
|
DataSetLayer::DataSetLayer(const std::string& fileName):
|
||||||
_dataset(0), _gdalReader(0)
|
_dataset(0), _gdalReader(0)
|
||||||
{
|
{
|
||||||
openFile(fileName);
|
setFileName(fileName);
|
||||||
|
open();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSetLayer::DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop):
|
DataSetLayer::DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop):
|
||||||
ProxyLayer(dataSetLayer), _gdalReader(dataSetLayer._gdalReader)
|
Layer(dataSetLayer), _gdalReader(dataSetLayer._gdalReader)
|
||||||
{
|
{
|
||||||
if (dataSetLayer._dataset) open();
|
if (dataSetLayer._dataset) open();
|
||||||
}
|
}
|
||||||
@ -52,6 +53,9 @@ void DataSetLayer::open()
|
|||||||
|
|
||||||
if (getFileName().empty()) return;
|
if (getFileName().empty()) return;
|
||||||
|
|
||||||
|
|
||||||
|
osg::notify(osg::NOTICE)<<"DataSetLayer::open()"<<getFileName()<<std::endl;
|
||||||
|
|
||||||
_dataset = static_cast<GDALDataset*>(GDALOpen(getFileName().c_str(),GA_ReadOnly));
|
_dataset = static_cast<GDALDataset*>(GDALOpen(getFileName().c_str(),GA_ReadOnly));
|
||||||
|
|
||||||
setUpLocator();
|
setUpLocator();
|
||||||
@ -59,6 +63,8 @@ void DataSetLayer::open()
|
|||||||
|
|
||||||
void DataSetLayer::close()
|
void DataSetLayer::close()
|
||||||
{
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"DataSetLayer::close()"<<getFileName()<<std::endl;
|
||||||
|
|
||||||
if (_dataset)
|
if (_dataset)
|
||||||
{
|
{
|
||||||
GDALClose(static_cast<GDALDatasetH>(_dataset));
|
GDALClose(static_cast<GDALDatasetH>(_dataset));
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
namespace GDALPlugin {
|
namespace GDALPlugin {
|
||||||
|
|
||||||
class DataSetLayer : public osgTerrain::ProxyLayer
|
class DataSetLayer : public osgTerrain::Layer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -75,21 +75,14 @@ bool CompositeLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
|
|||||||
}
|
}
|
||||||
else if (fr.matchSequence("ProxyLayer %s") || fr.matchSequence("ProxyLayer %w"))
|
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 = new osgTerrain::ProxyLayer;
|
||||||
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(image.get());
|
proxyLayer->setFileName(fr[1].getStr());
|
||||||
if (proxyLayer)
|
|
||||||
{
|
|
||||||
if (locator.valid())
|
|
||||||
{
|
|
||||||
proxyLayer->setLocator(locator.get());
|
|
||||||
locator = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
|
if (locator.valid()) proxyLayer->setLocator(locator.get());
|
||||||
if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
|
if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
|
||||||
|
if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
|
||||||
|
|
||||||
layer.addLayer(proxyLayer);
|
layer.addLayer(proxyLayer);
|
||||||
}
|
|
||||||
|
|
||||||
fr += 2;
|
fr += 2;
|
||||||
|
|
||||||
|
@ -151,16 +151,14 @@ bool Terrain_readLocalData(osg::Object& obj, osgDB::Input &fr)
|
|||||||
|
|
||||||
if (fr.matchSequence("ProxyLayer %s") || fr.matchSequence("ProxyLayer %w") )
|
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 = new osgTerrain::ProxyLayer;
|
||||||
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(image.get());
|
proxyLayer->setFileName(fr[1].getStr());
|
||||||
if (proxyLayer)
|
|
||||||
{
|
|
||||||
if (locator) proxyLayer->setLocator(locator);
|
|
||||||
if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
|
|
||||||
if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
|
|
||||||
|
|
||||||
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;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user