From Wang Rui, "Attached is the osgTerrain wrappers, based on the latest SVN version

of OSG. I modified the osgDB::InputStream and OutputStream and the
PagedLOD wrapper as well. Now all seems to work fine with paged
scenes. I've tested with the puget terrain data and the osgdem
application from VPB:
# osgdem --xx 10 --yy 10 -t ps_texture_4k.tif --xx 10 --yy 10 -d
ps_height_4k.tif -l 8 -v 0.1 -o puget.osgb

As the ive plugin does, The PagedLOD wrapper now automatically add the
latest file path to PagedLODs' databasePath member, to help them find
correct child positions. I also changed the image storage strategy of
the OutputStream class, to store them inline by default. The osgt
extension should also work, in case the image files are also written
to the disk.
"
This commit is contained in:
Robert Osfield 2010-02-25 17:53:51 +00:00
parent 26e68926f7
commit 605ad76691
19 changed files with 399 additions and 13 deletions

View File

@ -69,6 +69,7 @@ public:
bool isBinary() const { return _in->isBinary(); }
bool getUseFloatMatrix() const { return _useFloatMatrix; }
const osgDB::Options* getOptions() const { return _options.get(); }
// Serialization related functions
InputStream& operator>>( bool& b ) { _in->readBool(b); checkStream(); return *this; }
@ -163,6 +164,7 @@ protected:
std::vector<std::string> _fields;
osg::ref_ptr<InputIterator> _in;
osg::ref_ptr<InputException> _exception;
osg::ref_ptr<const osgDB::Options> _options;
};
void InputStream::throwException( const std::string& msg )

View File

@ -77,6 +77,7 @@ public:
bool isBinary() const { return _out->isBinary(); }
const std::string& getSchemaName() const { return _schemaName; }
const osgDB::Options* getOptions() const { return _options.get(); }
void setWriteImageHint( WriteImageHint hint ) { _writeImageHint = hint; }
WriteImageHint getWriteImageHint() const { return _writeImageHint; }
@ -172,6 +173,7 @@ protected:
std::stringstream _compressSource;
osg::ref_ptr<OutputIterator> _out;
osg::ref_ptr<OutputException> _exception;
osg::ref_ptr<const osgDB::Options> _options;
};
void OutputStream::throwException( const std::string& msg )

View File

@ -27,6 +27,7 @@ InputStream::InputStream( const osgDB::Options* options )
: _byteSwap(0), _useFloatMatrix(false), _forceReadingImage(false)
{
if ( !options ) return;
_options = options;
std::string schema;
StringList optionList;

View File

@ -25,6 +25,7 @@ OutputStream::OutputStream( const osgDB::Options* options )
: _writeImageHint(WRITE_USE_IMAGE_HINT)
{
if ( !options ) return;
_options = options;
StringList optionList;
split( options->getOptionString(), optionList );
@ -323,10 +324,10 @@ void OutputStream::writeImage( const osg::Image* img )
case OutputStream::WRITE_EXTERNAL_FILE: decision = IMAGE_EXTERNAL; break;
case OutputStream::WRITE_USE_EXTERNAL: decision = IMAGE_WRITE_OUT; break;
default:
if ( img->getWriteHint()==osg::Image::STORE_INLINE && isBinary() )
if ( img->getWriteHint()==osg::Image::EXTERNAL_FILE )
decision = IMAGE_EXTERNAL;
else if ( isBinary() )
decision = IMAGE_INLINE_DATA;
else if ( img->getWriteHint()==osg::Image::EXTERNAL_FILE )
decision = IMAGE_WRITE_OUT;
break;
}

View File

@ -34,4 +34,5 @@ SET(TARGET_COMMON_LIBRARIES
ADD_SUBDIRECTORY(osg)
ADD_SUBDIRECTORY(osgParticle)
ADD_SUBDIRECTORY(osgTerrain)
ADD_SUBDIRECTORY(osgText)

View File

@ -2,6 +2,41 @@
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
#include <osgDB/Options>
// _databasePath
static bool checkDatabasePath( const osg::PagedLOD& node )
{
return true;
}
static bool readDatabasePath( osgDB::InputStream& is, osg::PagedLOD& node )
{
bool hasPath; is >> hasPath;
if ( !hasPath )
{
if ( is.getOptions() && !is.getOptions()->getDatabasePathList().empty() )
{
const std::string& optionPath = is.getOptions()->getDatabasePathList().front();
if ( !optionPath.empty() ) node.setDatabasePath( optionPath );
}
}
else
{
std::string path; is.readWrappedString( path );
node.setDatabasePath( path );
}
return true;
}
static bool writeDatabasePath( osgDB::OutputStream& os, const osg::PagedLOD& node )
{
os << (!node.getDatabasePath().empty());
if ( !node.getDatabasePath().empty() )
os.writeWrappedString( node.getDatabasePath() );
os << std::endl;
return true;
}
// _perRangeDataList
static bool checkRangeDataList( const osg::PagedLOD& node )
@ -15,16 +50,18 @@ static bool readRangeDataList( osgDB::InputStream& is, osg::PagedLOD& node )
for ( unsigned int i=0; i<size; ++i )
{
std::string name; is.readWrappedString( name );
float offset, scale;
double timeStamp;
int frameNumber;
is >> offset >> scale >> timeStamp >> frameNumber;
node.setFileName( i, name );
}
is >> osgDB::END_BRACKET;
size = 0; is >> osgDB::PROPERTY("PriorityList") >> size >> osgDB::BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
float offset, scale;
is >> offset >> scale;
node.setPriorityOffset( i, offset );
node.setPriorityScale( i, scale );
node.setTimeStamp( i, timeStamp );
node.setFrameNumber( i, frameNumber );
}
is >> osgDB::END_BRACKET;
return true;
@ -37,8 +74,15 @@ static bool writeRangeDataList( osgDB::OutputStream& os, const osg::PagedLOD& no
for ( unsigned int i=0; i<size; ++i )
{
os.writeWrappedString( node.getFileName(i) );
os << node.getPriorityOffset(i) << node.getPriorityScale(i)
<< node.getTimeStamp(i) << node.getFrameNumber(i) << std::endl;
os << std::endl;
}
os << osgDB::END_BRACKET << std::endl;
size = node.getNumPriorityOffsets();
os << osgDB::PROPERTY("PriorityList") << size << osgDB::BEGIN_BRACKET << std::endl;
for ( unsigned int i=0; i<size; ++i )
{
os << node.getPriorityOffset(i) << node.getPriorityScale(i) << std::endl;
}
os << osgDB::END_BRACKET << std::endl;
return true;
@ -94,7 +138,7 @@ REGISTER_OBJECT_WRAPPER( PagedLOD,
{
// Note: osg::Group is not in the list to prevent recording dynamic loaded children
ADD_STRING_SERIALIZER( DatabasePath, "" ); // _databasePath
ADD_USER_SERIALIZER( DatabasePath ); // _databasePath
ADD_INT_SERIALIZER( FrameNumberOfLastTraversal, 0 ); // _frameNumberOfLastTraversal
ADD_UINT_SERIALIZER( NumChildrenThatCannotBeExpired, 0 ); // _numChildrenThatCannotBeExpired
ADD_BOOL_SERIALIZER( DisableExternalChildrenPaging, false ); // _disableExternalChildrenPaging

View File

@ -0,0 +1,7 @@
FILE(GLOB TARGET_SRC *.cpp)
FILE(GLOB TARGET_H *.h)
SET(TARGET_ADDED_LIBRARIES osgTerrain )
#### end var setup ###
SETUP_PLUGIN(osgterrain)

View File

@ -0,0 +1,41 @@
#include <osgTerrain/Layer>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
static bool checkLayers( const osgTerrain::CompositeLayer& layer )
{
return layer.getNumLayers()>0;
}
static bool readLayers( osgDB::InputStream& is, osgTerrain::CompositeLayer& layer )
{
unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgTerrain::Layer* child = dynamic_cast<osgTerrain::Layer*>( is.readObject() );
if ( child ) layer.addLayer( child );
}
is >> osgDB::END_BRACKET;
return true;
}
static bool writeLayers( osgDB::OutputStream& os, const osgTerrain::CompositeLayer& layer )
{
unsigned int size = layer.getNumLayers();
os << size << osgDB::BEGIN_BRACKET << std::endl;
for ( unsigned int i=0; i<size; ++i )
{
os << layer.getLayer(i);
}
os << osgDB::END_BRACKET << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( osgTerrain_CompositeLayer,
new osgTerrain::CompositeLayer,
osgTerrain::CompositeLayer,
"osg::Object osgTerrain::Layer osgTerrain::CompositeLayer" )
{
ADD_USER_SERIALIZER( Layers ); // _layers
}

View File

@ -0,0 +1,12 @@
#include <osgTerrain/Layer>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_ContourLayer,
new osgTerrain::ContourLayer,
osgTerrain::ContourLayer,
"osg::Object osgTerrain::Layer osgTerrain::ContourLayer" )
{
ADD_OBJECT_SERIALIZER( TransferFunction, osg::TransferFunction1D, NULL ); // _tf
}

View File

@ -0,0 +1,44 @@
#include <osgTerrain/GeometryTechnique>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
static bool checkFilterMatrix( const osgTerrain::GeometryTechnique& tech )
{
return true;
}
static bool readFilterMatrix( osgDB::InputStream& is, osgTerrain::GeometryTechnique& tech )
{
osg::Matrix3 matrix;
is >> osgDB::BEGIN_BRACKET;
for ( int r=0; r<3; ++r )
{
is >> matrix(r, 0) >> matrix(r, 1) >> matrix(r, 2);
}
is >> osgDB::END_BRACKET;
tech.setFilterMatrix( matrix );
return true;
}
static bool writeFilterMatrix( osgDB::OutputStream& os, const osgTerrain::GeometryTechnique& tech )
{
const osg::Matrix3& matrix = tech.getFilterMatrix();
os << osgDB::BEGIN_BRACKET << std::endl;
for ( int r=0; r<3; ++r )
{
os << matrix(r, 0) << matrix(r, 1) << matrix(r, 2) << std::endl;
}
os << osgDB::END_BRACKET << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( osgTerrain_GeometryTechnique,
new osgTerrain::GeometryTechnique,
osgTerrain::GeometryTechnique,
"osg::Object osgTerrain::TerrainTechnique osgTerrain::GeometryTechnique" )
{
ADD_FLOAT_SERIALIZER( FilterBias, 0.0f ); // _filterBias
ADD_FLOAT_SERIALIZER( FilterWidth, 0.1f ); // _filterWidth
ADD_USER_SERIALIZER( FilterMatrix ); // _filterMatrix
}

View File

@ -0,0 +1,12 @@
#include <osgTerrain/Layer>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_HeightFieldLayer,
new osgTerrain::HeightFieldLayer,
osgTerrain::HeightFieldLayer,
"osg::Object osgTerrain::Layer osgTerrain::HeightFieldLayer" )
{
ADD_OBJECT_SERIALIZER( HeightField, osg::HeightField, NULL ); // _heightField
}

View File

@ -0,0 +1,12 @@
#include <osgTerrain/Layer>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_ImageLayer,
new osgTerrain::ImageLayer,
osgTerrain::ImageLayer,
"osg::Object osgTerrain::Layer osgTerrain::ImageLayer" )
{
ADD_IMAGE_SERIALIZER( Image, osg::Image, NULL ); // _image
}

View File

@ -0,0 +1,67 @@
#include <osgTerrain/Layer>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
static bool checkValidDataOperator( const osgTerrain::Layer& layer )
{
return layer.getValidDataOperator()!=NULL;
}
static bool readValidDataOperator( osgDB::InputStream& is, osgTerrain::Layer& layer )
{
unsigned int type; is >> type;
switch ( type )
{
case 1:
{
float value; is >> value;
layer.setValidDataOperator( new osgTerrain::NoDataValue(value) );
}
break;
case 2:
{
float min, max; is >> min >> max;
layer.setValidDataOperator( new osgTerrain::ValidRange(min, max) );
}
break;
default:
break;
}
return true;
}
static bool writeValidDataOperator( osgDB::OutputStream& os, const osgTerrain::Layer& layer )
{
const osgTerrain::NoDataValue* ndv = dynamic_cast<const osgTerrain::NoDataValue*>( layer.getValidDataOperator() );
if ( ndv )
{
os << (unsigned int)1 << ndv->getValue() << std::endl;
return true;
}
const osgTerrain::ValidRange* vr = dynamic_cast<const osgTerrain::ValidRange*>( layer.getValidDataOperator() );
if ( vr )
{
os << (unsigned int)2 << vr->getMinValue() << vr->getMaxValue() << std::endl;
return true;
}
os << (unsigned int)0 << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( osgTerrain_Layer,
new osgTerrain::Layer,
osgTerrain::Layer,
"osg::Object osgTerrain::Layer" )
{
ADD_STRING_SERIALIZER( FileName, "" ); // _filename
ADD_OBJECT_SERIALIZER( Locator, osgTerrain::Locator, NULL ); // _locator
ADD_UINT_SERIALIZER( MinLevel, 0 ); // _minLevel
ADD_UINT_SERIALIZER( MaxLevel, MAXIMUM_NUMBER_OF_LEVELS ); // _maxLevel
ADD_USER_SERIALIZER( ValidDataOperator ); // _validDataOperator
ADD_VEC4_SERIALIZER( DefaultValue, osg::Vec4() ); // _defaultValue
ADD_GLENUM_SERIALIZER( MinFilter, osg::Texture::FilterMode, osg::Texture::LINEAR_MIPMAP_LINEAR ); // _minFilter
ADD_GLENUM_SERIALIZER( MagFilter, osg::Texture::FilterMode, osg::Texture::LINEAR ); // _magFilter
}

View File

@ -0,0 +1,23 @@
#include <osgTerrain/Locator>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_Locator,
new osgTerrain::Locator,
osgTerrain::Locator,
"osg::Object osgTerrain::Locator" )
{
BEGIN_ENUM_SERIALIZER( CoordinateSystemType, PROJECTED );
ADD_ENUM_VALUE( GEOCENTRIC );
ADD_ENUM_VALUE( GEOGRAPHIC );
ADD_ENUM_VALUE( PROJECTED );
END_ENUM_SERIALIZER(); // _coordinateSystemType
ADD_STRING_SERIALIZER( Format, "" ); // _format
ADD_STRING_SERIALIZER( CoordinateSystem, "" ); // _cs
ADD_OBJECT_SERIALIZER( EllipsoidModel, osg::EllipsoidModel, NULL ); // _ellipsoidModel
ADD_MATRIXD_SERIALIZER( Transform, osg::Matrixd() ); // _transform
ADD_BOOL_SERIALIZER( DefinedInFile, false ); // _definedInFile
ADD_BOOL_SERIALIZER( TransformScaledByResolution, false ); // _transformScaledByResolution
}

View File

@ -0,0 +1,12 @@
#include <osgTerrain/Layer>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_ProxyLayer,
new osgTerrain::ProxyLayer,
osgTerrain::ProxyLayer,
"osg::Object osgTerrain::Layer osgTerrain::ProxyLayer" )
{
ADD_OBJECT_SERIALIZER( Implementation, osgTerrain::Layer, NULL ); // _implementation
}

View File

@ -0,0 +1,12 @@
#include <osgTerrain/Layer>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_SwitchLayer,
new osgTerrain::SwitchLayer,
osgTerrain::SwitchLayer,
"osg::Object osgTerrain::Layer osgTerrain::CompositeLayer osgTerrain::SwitchLayer" )
{
ADD_INT_SERIALIZER( ActiveLayer, -1 ); // _activeLayer
}

View File

@ -0,0 +1,13 @@
#include <osgTerrain/Terrain>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_Terrain,
new osgTerrain::Terrain,
osgTerrain::Terrain,
"osg::Object osg::Node osg::Group osgTerrain::Terrain" )
{
ADD_FLOAT_SERIALIZER( SampleRatio, 1.0f ); // _sampleRatio
ADD_FLOAT_SERIALIZER( VerticalScale, 1.0f ); // _verticalScale
}

View File

@ -0,0 +1,11 @@
#include <osgTerrain/TerrainTechnique>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgTerrain_TerrainTechnique,
new osgTerrain::TerrainTechnique,
osgTerrain::TerrainTechnique,
"osg::Object osgTerrain::TerrainTechnique" )
{
}

View File

@ -0,0 +1,69 @@
#include <osgTerrain/TerrainTile>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
// _tileID
static bool checkTileID( const osgTerrain::TerrainTile& tile )
{
return tile.getTileID().valid();
}
static bool readTileID( osgDB::InputStream& is, osgTerrain::TerrainTile& tile )
{
osgTerrain::TileID id;
is >> id.level >> id.x >> id.y;
tile.setTileID( id );
return true;
}
static bool writeTileID( osgDB::OutputStream& os, const osgTerrain::TerrainTile& tile )
{
const osgTerrain::TileID& id = tile.getTileID();
os << id.level << id.x << id.y << std::endl;
return true;
}
// _colorLayers
static bool checkColorLayers( const osgTerrain::TerrainTile& tile )
{
return tile.getNumColorLayers()>0;
}
static bool readColorLayers( osgDB::InputStream& is, osgTerrain::TerrainTile& tile )
{
unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i )
{
osgTerrain::Layer* layer = dynamic_cast<osgTerrain::Layer*>( is.readObject() );
if ( layer ) tile.setColorLayer( i, layer );
}
is >> osgDB::END_BRACKET;
return true;
}
static bool writeColorLayers( osgDB::OutputStream& os, const osgTerrain::TerrainTile& tile )
{
unsigned int size = tile.getNumColorLayers();
os << size << osgDB::BEGIN_BRACKET << std::endl;
for ( unsigned int i=0; i<size; ++i )
{
os << tile.getColorLayer(i);
}
os << osgDB::END_BRACKET << std::endl;
return true;
}
REGISTER_OBJECT_WRAPPER( osgTerrain_TerrainTile,
new osgTerrain::TerrainTile,
osgTerrain::TerrainTile,
"osg::Object osg::Node osg::Group osgTerrain::TerrainTile" )
{
ADD_USER_SERIALIZER( TileID ); // _tileID
ADD_OBJECT_SERIALIZER( TerrainTechnique, osgTerrain::TerrainTechnique, NULL ); // _terrainTechnique
ADD_OBJECT_SERIALIZER( Locator, osgTerrain::Locator, NULL ); // _locator
ADD_OBJECT_SERIALIZER( ElevationLayer, osgTerrain::Layer, NULL ); // _elevationLayer
ADD_USER_SERIALIZER( ColorLayers ); // _colorLayers
ADD_BOOL_SERIALIZER( RequiresNormals, true ); // _requiresNormals
ADD_BOOL_SERIALIZER( TreatBoundariesToValidDataAsDefaultValue, false ); // _treatBoundariesToValidDataAsDefaultValue
}