diff --git a/include/osgTerrain/Layer b/include/osgTerrain/Layer index 21bf93270..e2c1613e5 100644 --- a/include/osgTerrain/Layer +++ b/include/osgTerrain/Layer @@ -297,6 +297,30 @@ class OSGTERRAIN_EXPORT ProxyLayer : public Layer META_Object(osgTerrain, ProxyLayer); + /** Return if this ProxyLayer is attached to valid file handle.*/ + virtual bool isOpen() const { return false; } + + /** Open a file.*/ + void openFile(const std::string& fileName) + { + if (_filename!=fileName) + { + if (isOpen()) close(); + + _filename = fileName; + } + + if (!isOpen()) open(); + } + + /** Open the any associated file handle.*/ + virtual void open() {} + + /** Open the any associated file handle.*/ + virtual void close() {} + + /** Extract an ImageLayer from the ProxyLayer.*/ + virtual ImageLayer* extractImageLayer(unsigned int /*minX*/, unsigned int /*minY*/, unsigned int /*maxX*/, unsigned int /*maxY*/) { return 0; } protected: diff --git a/include/osgTerrain/TileSystem b/include/osgTerrain/TileSystem new file mode 100644 index 000000000..5b5f33fc8 --- /dev/null +++ b/include/osgTerrain/TileSystem @@ -0,0 +1,62 @@ +/* -*-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 OSGTERRAIN_TILESYSTEM +#define OSGTERRAIN_TILESYSTEM 1 + +#include +#include +#include + +namespace osgTerrain { + + +/** TileSystem provides the mechanism for computing the position in space of tiles.*/ +class OSGTERRAIN_EXPORT TileSystem : public osg::Object +{ + public: + + TileSystem(); + + TileSystem(const TileSystem&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgTerrain, TileSystem); + + protected: + + virtual ~TileSystem(); +}; + +class TileID : public osg::Object +{ + public: + + TileID(); + + TileID(const TileID&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgTerrain, TileID); + + protected: + + virtual ~TileID(); + + osg::observer_ptr _tileSystem; + int _layer; + int _x; + int _y; +}; + +} + +#endif diff --git a/src/osgPlugins/gdal/DataSetLayer.cpp b/src/osgPlugins/gdal/DataSetLayer.cpp index 895d0ec7c..2fa240d92 100644 --- a/src/osgPlugins/gdal/DataSetLayer.cpp +++ b/src/osgPlugins/gdal/DataSetLayer.cpp @@ -13,28 +13,51 @@ #include "DataSetLayer.h" +#include + using namespace GDALPlugin; -DataSetLayer::DataSetLayer() +DataSetLayer::DataSetLayer(): + _dataset(0) { - _dataset = 0; } -DataSetLayer::DataSetLayer(const std::string& fileName) +DataSetLayer::DataSetLayer(const std::string& fileName): + _dataset(0) { - setFileName(fileName); - _dataset = (GDALDataset*)GDALOpen(fileName.c_str(),GA_ReadOnly); + openFile(fileName); } DataSetLayer::DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop): ProxyLayer(dataSetLayer) { - _dataset = (GDALDataset*)GDALOpen(getFileName().c_str(),GA_ReadOnly); + if (dataSetLayer._dataset) open(); } DataSetLayer::~DataSetLayer() { - if (_dataset) delete _dataset; + close(); +} + +void DataSetLayer::open() +{ + if (_dataset) return; + + if (getFileName().empty()) return; + + _dataset = static_cast(GDALOpen(getFileName().c_str(),GA_ReadOnly)); + + setUpLocator(); +} + +void DataSetLayer::close() +{ + if (_dataset) + { + GDALClose(static_cast(_dataset)); + + _dataset = 0; + } } unsigned int DataSetLayer::getNumColumns() const @@ -47,3 +70,16 @@ unsigned int DataSetLayer::getNumRows() const return _dataset!=0 ? _dataset->GetRasterYSize() : 0; } +osgTerrain::ImageLayer* DataSetLayer::extractImageLayer(unsigned int minX, unsigned int minY, unsigned int maxX, unsigned int maxY) +{ + if (!_dataset || maxX dataset = new GDALPlugin::DataSetLayer(fileName); - if (dataset->valid()) return dataset.release(); + if (dataset->isOpen()) return dataset.release(); return ReadResult::FILE_NOT_HANDLED; } diff --git a/src/osgTerrain/CMakeLists.txt b/src/osgTerrain/CMakeLists.txt index cc72978e3..21f4becfd 100644 --- a/src/osgTerrain/CMakeLists.txt +++ b/src/osgTerrain/CMakeLists.txt @@ -12,6 +12,7 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/Layer ${HEADER_PATH}/Terrain ${HEADER_PATH}/TerrainTechnique + ${HEADER_PATH}/TileSystem ${HEADER_PATH}/GeometryTechnique ${HEADER_PATH}/ValidDataOperator ${HEADER_PATH}/Version @@ -25,6 +26,7 @@ ADD_LIBRARY(${LIB_NAME} Locator.cpp Terrain.cpp TerrainTechnique.cpp + TileSystem.cpp GeometryTechnique.cpp Version.cpp ) diff --git a/src/osgTerrain/TileSystem.cpp b/src/osgTerrain/TileSystem.cpp new file mode 100644 index 000000000..177478bdc --- /dev/null +++ b/src/osgTerrain/TileSystem.cpp @@ -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. +*/ + +#include + +using namespace osgTerrain; + +TileSystem::TileSystem() +{ +} + +TileSystem::TileSystem(const TileSystem& tileSystem,const osg::CopyOp& copyop): + osg::Object(tileSystem) +{ +} + +TileSystem::~TileSystem() +{ +} + +TileID::TileID(): + _tileSystem(0), + _layer(-1), + _x(-1), + _y(-1) +{ +} + +TileID::TileID(const TileID& tileID,const osg::CopyOp& copyop): + osg::Object(tileID), + _tileSystem(tileID._tileSystem), + _layer(tileID._layer), + _x(tileID._x), + _y(tileID._y) +{ +} + +TileID::~TileID() +{ +} + diff --git a/src/osgWrappers/osgTerrain/Layer.cpp b/src/osgWrappers/osgTerrain/Layer.cpp index 3771bb8c1..3825670d3 100644 --- a/src/osgWrappers/osgTerrain/Layer.cpp +++ b/src/osgWrappers/osgTerrain/Layer.cpp @@ -592,5 +592,30 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ProxyLayer) __C5_char_P1__className, "return the name of the object's class type. ", "Must be defined by derived classes. "); + I_Method0(bool, isOpen, + Properties::VIRTUAL, + __bool__isOpen, + "Return if this ProxyLayer is attached to valid file handle. ", + ""); + I_Method1(void, openFile, IN, const std::string &, fileName, + Properties::NON_VIRTUAL, + __void__openFile__C5_std_string_R1, + "Open a file. ", + ""); + I_Method0(void, open, + Properties::VIRTUAL, + __void__open, + "Open the any associated file handle. ", + ""); + I_Method0(void, close, + Properties::VIRTUAL, + __void__close, + "Open the any associated file handle. ", + ""); + I_Method4(osgTerrain::ImageLayer *, extractImageLayer, IN, unsigned, int, IN, unsigned, int, IN, unsigned, int, IN, unsigned, int, + Properties::VIRTUAL, + __ImageLayer_P1__extractImageLayer__unsigned__unsigned__unsigned__unsigned, + "Extract an ImageLayer from the ProxyLayer. ", + ""); END_REFLECTOR diff --git a/src/osgWrappers/osgTerrain/TileSystem.cpp b/src/osgWrappers/osgTerrain/TileSystem.cpp new file mode 100644 index 000000000..f47636608 --- /dev/null +++ b/src/osgWrappers/osgTerrain/TileSystem.cpp @@ -0,0 +1,98 @@ +// *************************************************************************** +// +// Generated automatically by genwrapper. +// Please DO NOT EDIT this file! +// +// *************************************************************************** + +#include +#include +#include +#include + +#include +#include +#include + +// Must undefine IN and OUT macros defined in Windows headers +#ifdef IN +#undef IN +#endif +#ifdef OUT +#undef OUT +#endif + +BEGIN_OBJECT_REFLECTOR(osgTerrain::TileID) + I_DeclaringFile("osgTerrain/TileSystem"); + I_BaseType(osg::Object); + I_Constructor0(____TileID, + "", + ""); + I_ConstructorWithDefaults2(IN, const osgTerrain::TileID &, x, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY, + ____TileID__C5_TileID_R1__C5_osg_CopyOp_R1, + "", + ""); + I_Method0(osg::Object *, cloneType, + Properties::VIRTUAL, + __osg_Object_P1__cloneType, + "Clone the type of an object, with Object* return type. ", + "Must be defined by derived classes. "); + I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop, + Properties::VIRTUAL, + __osg_Object_P1__clone__C5_osg_CopyOp_R1, + "Clone an object, with Object* return type. ", + "Must be defined by derived classes. "); + I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj, + Properties::VIRTUAL, + __bool__isSameKindAs__C5_osg_Object_P1, + "", + ""); + I_Method0(const char *, libraryName, + Properties::VIRTUAL, + __C5_char_P1__libraryName, + "return the name of the object's library. ", + "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. "); + I_Method0(const char *, className, + Properties::VIRTUAL, + __C5_char_P1__className, + "return the name of the object's class type. ", + "Must be defined by derived classes. "); +END_REFLECTOR + +BEGIN_OBJECT_REFLECTOR(osgTerrain::TileSystem) + I_DeclaringFile("osgTerrain/TileSystem"); + I_BaseType(osg::Object); + I_Constructor0(____TileSystem, + "", + ""); + I_ConstructorWithDefaults2(IN, const osgTerrain::TileSystem &, x, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY, + ____TileSystem__C5_TileSystem_R1__C5_osg_CopyOp_R1, + "", + ""); + I_Method0(osg::Object *, cloneType, + Properties::VIRTUAL, + __osg_Object_P1__cloneType, + "Clone the type of an object, with Object* return type. ", + "Must be defined by derived classes. "); + I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop, + Properties::VIRTUAL, + __osg_Object_P1__clone__C5_osg_CopyOp_R1, + "Clone an object, with Object* return type. ", + "Must be defined by derived classes. "); + I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj, + Properties::VIRTUAL, + __bool__isSameKindAs__C5_osg_Object_P1, + "", + ""); + I_Method0(const char *, libraryName, + Properties::VIRTUAL, + __C5_char_P1__libraryName, + "return the name of the object's library. ", + "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. "); + I_Method0(const char *, className, + Properties::VIRTUAL, + __C5_char_P1__className, + "return the name of the object's class type. ", + "Must be defined by derived classes. "); +END_REFLECTOR +