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

Revision 11018, 2.0 kB (checked in by robert, 4 years ago)

From Wang Rui, "Changes:

1. Rewrite the reading/writing exception handlers to work like the ive
plugin exceptions.
2. Write a header writing/checking function in ReaderWriterOSG2.cpp,
which may help decide if the stream is ascii or binary. The
readInputIterator() function will return null pointer if the input
file is nither osgb nor osgt format, which indicates that the old .osg
format could be used here, in case we've merged the two plugins
together.
3. Add a new ForceReadingImage? option in the InputStream?, which will
allocate an empty image object with the filename if specifed external
image file is missed. It may be useful for format converting in some
cases.
4. Add new osgParticle wrappers, as well as some modification to the
osgParticle headers, for instance, change isEnabled() to getEnabled().
5. Some fixes to the osg serialization wrappers."

  • 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    osg::FloatArray* array = dynamic_cast<osg::FloatArray*>( is.readArray() );
35    if ( array )
36    {
37        unsigned int numCols = shape.getNumColumns(), numRows = shape.getNumRows();
38        if ( array->size()<numRows*numCols ) return false;
39       
40        unsigned int index = 0;
41        for ( unsigned int r=0; r<numRows; ++r )
42        {
43            for ( unsigned int c=0; c<numCols; ++c )
44                shape.setHeight( c, r, (*array)[index++] );
45        }
46    }
47    return true;
48}
49
50static bool writeHeights( osgDB::OutputStream& os, const osg::HeightField& shape )
51{
52    os.writeArray( shape.getFloatArray() );
53    return true;
54}
55
56REGISTER_OBJECT_WRAPPER( HeightField,
57                         new osg::HeightField,
58                         osg::HeightField,
59                         "osg::Object osg::Shape osg::HeightField" )
60{
61    ADD_USER_SERIALIZER( Area );  // _columns, _rows
62    ADD_VEC3_SERIALIZER( Origin, osg::Vec3() );  // _origin
63    ADD_FLOAT_SERIALIZER( XInterval, 0.0f );  // _dx
64    ADD_FLOAT_SERIALIZER( YInterval, 0.0f );  // _dy
65    ADD_FLOAT_SERIALIZER( SkirtHeight, 0.0f );  // _skirtHeight
66    ADD_UINT_SERIALIZER( BorderWidth, 0 );  // _borderWidth
67    ADD_QUAT_SERIALIZER( Rotation, osg::Quat() );  // _rotation
68    ADD_USER_SERIALIZER( Heights );  // _heights
69}
Note: See TracBrowser for help on using the browser.