Added preliminary ProxLayer and DataSetLayer in GDAL plugin to aid integration

of GDAL reading into osgTerrain.
This commit is contained in:
Robert Osfield
2007-08-29 10:52:03 +00:00
parent f6650dd3bf
commit 71e7a65cca
5 changed files with 149 additions and 2 deletions

View File

@@ -286,6 +286,25 @@ class OSGTERRAIN_EXPORT CompositeLayer : public Layer
Layers _layers;
};
class OSGTERRAIN_EXPORT ProxyLayer : public Layer
{
public:
ProxyLayer();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
ProxyLayer(const ProxyLayer& proxyLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgTerrain, ProxyLayer);
protected:
virtual ~ProxyLayer() {}
};
}
#endif

View File

@@ -1,6 +1,13 @@
INCLUDE_DIRECTORIES( ${GDAL_INCLUDE_DIR} )
SET(TARGET_SRC ReaderWriterGDAL.cpp )
SET(TARGET_SRC
ReaderWriterGDAL.cpp
DataSetLayer.cpp
)
SET(TARGET_H
DataSetLayer.h
)
SET(TARGET_LIBRARIES_VARS GDAL_LIBRARY )

View File

@@ -0,0 +1,49 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include "DataSetLayer.h"
using namespace GDALPlugin;
DataSetLayer::DataSetLayer()
{
_dataset = 0;
}
DataSetLayer::DataSetLayer(const std::string& fileName)
{
setFileName(fileName);
_dataset = (GDALDataset*)GDALOpen(fileName.c_str(),GA_ReadOnly);
}
DataSetLayer::DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop):
ProxyLayer(dataSetLayer)
{
_dataset = (GDALDataset*)GDALOpen(getFileName().c_str(),GA_ReadOnly);
}
DataSetLayer::~DataSetLayer()
{
if (_dataset) delete _dataset;
}
unsigned int DataSetLayer::getNumColumns() const
{
return _dataset!=0 ? _dataset->GetRasterXSize() : 0;
}
unsigned int DataSetLayer::getNumRows() const
{
return _dataset!=0 ? _dataset->GetRasterYSize() : 0;
}

View File

@@ -0,0 +1,51 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef DATASETLAYER
#define DATASETLAYER 1
#include <osgTerrain/Layer>
#include <gdal_priv.h>
namespace GDALPlugin {
class DataSetLayer : public osgTerrain::ProxyLayer
{
public:
DataSetLayer();
DataSetLayer(const std::string& fileName);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(GDALPlugin, DataSetLayer);
bool valid() const { return _dataset!=0; }
virtual unsigned int getNumColumns() const;
virtual unsigned int getNumRows() const;
protected:
virtual ~DataSetLayer();
GDALDataset* _dataset;
};
}
#endif

View File

@@ -13,6 +13,8 @@
#include <gdal_priv.h>
#include "DataSetLayer.h"
#define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex)
// From easyrgb.com
@@ -35,6 +37,25 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
return osgDB::equalCaseInsensitive(extension,"gdal") || osgDB::equalCaseInsensitive(extension,"gdal");
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex);
osg::notify(osg::NOTICE) << "GDALPlugin : " << file << std::endl;
std::string fileName = osgDB::findDataFile( file, options );
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
initGDAL();
// open a DataSetLayer.
osg::ref_ptr<GDALPlugin::DataSetLayer> dataset = new GDALPlugin::DataSetLayer;
if (dataset->valid()) return dataset.release();
return ReadResult::FILE_NOT_HANDLED;
}
virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex);
@@ -721,7 +742,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
}
void initGDAL()
void initGDAL() const
{
static bool s_initialized = false;
if (!s_initialized)