Further work on new ProxyLayer

This commit is contained in:
Robert Osfield 2007-08-29 16:29:05 +00:00
parent 2f895b839e
commit 9a9ffbe229
9 changed files with 317 additions and 10 deletions

View File

@ -297,6 +297,30 @@ class OSGTERRAIN_EXPORT ProxyLayer : public Layer
META_Object(osgTerrain, ProxyLayer); 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: protected:

View File

@ -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 <osgTerrain/Export>
#include <osg/Object>
#include <osg/observer_ptr>
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> _tileSystem;
int _layer;
int _x;
int _y;
};
}
#endif

View File

@ -13,28 +13,51 @@
#include "DataSetLayer.h" #include "DataSetLayer.h"
#include <osg/Notify>
using namespace GDALPlugin; 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); openFile(fileName);
_dataset = (GDALDataset*)GDALOpen(fileName.c_str(),GA_ReadOnly);
} }
DataSetLayer::DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop): DataSetLayer::DataSetLayer(const DataSetLayer& dataSetLayer,const osg::CopyOp& copyop):
ProxyLayer(dataSetLayer) ProxyLayer(dataSetLayer)
{ {
_dataset = (GDALDataset*)GDALOpen(getFileName().c_str(),GA_ReadOnly); if (dataSetLayer._dataset) open();
} }
DataSetLayer::~DataSetLayer() DataSetLayer::~DataSetLayer()
{ {
if (_dataset) delete _dataset; close();
}
void DataSetLayer::open()
{
if (_dataset) return;
if (getFileName().empty()) return;
_dataset = static_cast<GDALDataset*>(GDALOpen(getFileName().c_str(),GA_ReadOnly));
setUpLocator();
}
void DataSetLayer::close()
{
if (_dataset)
{
GDALClose(static_cast<GDALDatasetH>(_dataset));
_dataset = 0;
}
} }
unsigned int DataSetLayer::getNumColumns() const unsigned int DataSetLayer::getNumColumns() const
@ -47,3 +70,16 @@ unsigned int DataSetLayer::getNumRows() const
return _dataset!=0 ? _dataset->GetRasterYSize() : 0; 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<minX || maxY<minY) return 0;
osg::notify(osg::NOTICE)<<"DataSetLayer::extractImageLayer("<<minX<<", "<<minY<<", "<<maxX<<", "<<maxY<<") not yet implemented"<<std::endl;
return 0;
}
void DataSetLayer::setUpLocator()
{
osg::notify(osg::NOTICE)<<"DataSetLayer::setUpLocator()"<<std::endl;
}

View File

@ -33,15 +33,24 @@ class DataSetLayer : public osgTerrain::ProxyLayer
META_Object(GDALPlugin, DataSetLayer); META_Object(GDALPlugin, DataSetLayer);
bool valid() const { return _dataset!=0; } virtual bool isOpen() const { return _dataset!=0; }
virtual void open();
virtual void close();
virtual unsigned int getNumColumns() const; virtual unsigned int getNumColumns() const;
virtual unsigned int getNumRows() const; virtual unsigned int getNumRows() const;
virtual osgTerrain::ImageLayer* extractImageLayer(unsigned int minX, unsigned int minY, unsigned int maxX, unsigned int maxY);
protected: protected:
virtual ~DataSetLayer(); virtual ~DataSetLayer();
void setUpLocator();
GDALDataset* _dataset; GDALDataset* _dataset;
}; };

View File

@ -54,7 +54,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter
// open a DataSetLayer. // open a DataSetLayer.
osg::ref_ptr<GDALPlugin::DataSetLayer> dataset = new GDALPlugin::DataSetLayer(fileName); osg::ref_ptr<GDALPlugin::DataSetLayer> dataset = new GDALPlugin::DataSetLayer(fileName);
if (dataset->valid()) return dataset.release(); if (dataset->isOpen()) return dataset.release();
return ReadResult::FILE_NOT_HANDLED; return ReadResult::FILE_NOT_HANDLED;
} }

View File

@ -12,6 +12,7 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/Layer ${HEADER_PATH}/Layer
${HEADER_PATH}/Terrain ${HEADER_PATH}/Terrain
${HEADER_PATH}/TerrainTechnique ${HEADER_PATH}/TerrainTechnique
${HEADER_PATH}/TileSystem
${HEADER_PATH}/GeometryTechnique ${HEADER_PATH}/GeometryTechnique
${HEADER_PATH}/ValidDataOperator ${HEADER_PATH}/ValidDataOperator
${HEADER_PATH}/Version ${HEADER_PATH}/Version
@ -25,6 +26,7 @@ ADD_LIBRARY(${LIB_NAME}
Locator.cpp Locator.cpp
Terrain.cpp Terrain.cpp
TerrainTechnique.cpp TerrainTechnique.cpp
TileSystem.cpp
GeometryTechnique.cpp GeometryTechnique.cpp
Version.cpp Version.cpp
) )

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.
*/
#include <osgTerrain/TileSystem>
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()
{
}

View File

@ -592,5 +592,30 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ProxyLayer)
__C5_char_P1__className, __C5_char_P1__className,
"return the name of the object's class type. ", "return the name of the object's class type. ",
"Must be defined by derived classes. "); "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 END_REFLECTOR

View File

@ -0,0 +1,98 @@
// ***************************************************************************
//
// Generated automatically by genwrapper.
// Please DO NOT EDIT this file!
//
// ***************************************************************************
#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>
#include <osg/CopyOp>
#include <osg/Object>
#include <osgTerrain/TileSystem>
// 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