root/OpenSceneGraph/trunk/src/osgWrappers/serializers/osg/HeightField.cpp @ 10976

Revision 10976, 2.1 kB (checked in by robert, 5 years ago)

From Wang Rui, new native binary/ascii format infrastructure and wrappers.

From Robert Osfield, refactor of Wang Rui's original osg2 into 3 parts - parts placed into osgDB, the ReaderWriter? placed into src/osg/Plugin/osg and wrappers into src/osgWrappers/serializers/osg

  • Property svn:executable set to *
Line 
1#include <osg/Shape>
2#include <osgDB/ObjectWrapper>
3#include <osgDB/InputStream>
4#include <osgDB/OutputStream>
5
6// _columns, _rows
7static bool checkArea( const osg::HeightField& shape )
8{
9    return true;
10}
11
12static bool readArea( osgDB::InputStream& is, osg::HeightField& shape )
13{
14    unsigned int numCols, numRows;
15    is >> numCols >> numRows;
16    shape.allocate( numCols, numRows );
17    return true;
18}
19
20static bool writeArea( osgDB::OutputStream& os, const osg::HeightField& shape )
21{
22    os << shape.getNumColumns() << shape.getNumRows() << std::endl;
23    return true;
24}
25
26// _heights
27static bool checkHeights( const osg::HeightField& shape )
28{
29    return shape.getFloatArray()!=NULL;
30}
31
32static bool readHeights( osgDB::InputStream& is, osg::HeightField& shape )
33{
34    bool hasArray; is >> hasArray;
35    if ( !hasArray ) return true;
36   
37    osg::FloatArray* array = dynamic_cast<osg::FloatArray*>( is.readArray() );
38    if ( array )
39    {
40        unsigned int numCols = shape.getNumColumns(), numRows = shape.getNumRows();
41        if ( array->size()<numRows*numCols ) return false;
42       
43        unsigned int index = 0;
44        for ( unsigned int r=0; r<numRows; ++r )
45        {
46            for ( unsigned int c=0; c<numCols; ++c )
47                shape.setHeight( c, r, (*array)[index++] );
48        }
49    }
50    return true;
51}
52
53static bool writeHeights( osgDB::OutputStream& os, const osg::HeightField& shape )
54{
55    os << (shape.getFloatArray()!=NULL);
56    os.writeArray( shape.getFloatArray() );
57    return true;
58}
59
60REGISTER_OBJECT_WRAPPER( HeightField,
61                         new osg::HeightField,
62                         osg::HeightField,
63                         "osg::Object osg::Shape osg::HeightField" )
64{
65    ADD_USER_SERIALIZER( Area );  // _columns, _rows
66    ADD_VEC3_SERIALIZER( Origin, osg::Vec3() );  // _origin
67    ADD_FLOAT_SERIALIZER( XInterval, 0.0f );  // _dx
68    ADD_FLOAT_SERIALIZER( YInterval, 0.0f );  // _dy
69    ADD_FLOAT_SERIALIZER( SkirtHeight, 0.0f );  // _skirtHeight
70    ADD_UINT_SERIALIZER( BorderWidth, 0 );  // _borderWidth
71    ADD_QUAT_SERIALIZER( Rotation, osg::Quat() );  // _rotation
72    ADD_USER_SERIALIZER( Heights );  // _heights
73}
Note: See TracBrowser for help on using the browser.