Commit Graph

16 Commits

Author SHA1 Message Date
Robert Osfield
48020eed9e Introduced typedef's to make the code more readble and maintanable 2013-06-24 09:02:32 +00:00
Robert Osfield
4044fd5a74 From Wang Rui, "The file attached includes two new features for the serialization IO functionality. First, custom serializer version control should work now, just by defining a new REGISTER_CUSTOM_OBJECT_WRAPPER macro. For example:
// A custom class
namespace CustomDomain {

class MyGroup : public osg::Group
{
public:
    META_Node( CustomDomain, MyGroup );

    void setMyName( const std::string& n );
    const std::string& getMyName() const;

    void setMyID( int id );
    int getMyID() const;

    ...
};

}

// The serialization wrapper using a custom domain name
REGISTER_CUSTOM_OBJECT_WRAPPER( MyDomain,
                                CustomDomain_MyGroup,
                                new CustomDomain::MyGroup,
                                CustomDomain::MyGroup,
                                "osg::Object osg::Node osg::Group CustomDomain::MyGroup" )
{
    ADD_STRING_SERIALIZER( MyName, std::string() );
    {
        UPDATE_TO_VERSION_SCOPED( 1 );  // Updated for a new domain version
        ADD_INT_SERIALIZER( MyID, 0 );
    }
}

Save the class instance as follows:
osgDB::writeNodeFile( *myGroup, "serializer_test.osgt", new osgDB::Options("CustomDomains=MyDomain:1") );

The output file will include the domain version definition and all the class data, and can be read back. We can also force setting the domain version by the CustomDomains option while reading the saved files. If we save the class instance without any options, MyID will be ignored because the default domain version is 0.

This may help third-party libraries like osgEarth to maintain their own serializers without regarding to the OSG soversion changes.

Another feature added is a more robust binary format, which in fact adds a size-offset at each block's beginning. When there are problems or unsupported data types while reading, we can now directly jump to the block end indicated by the offset value. So a .osgb file will automatically ignore bad data and read remains as normal (at present it will fail at all). This feature will not break the backward compatibility, and can be disabled by setting "RobustBinaryFormat=false" while writing out.

Hope these changes can work smoothly with present and future community projects. Maybe we should also consider have an osgserializer example to test and demonstrate all things we can do now."
2013-06-24 08:48:55 +00:00
Robert Osfield
ae2b6669ea Added Vec*b, Vec4ub, Vec*s, Vec*i, Vec*ui serializers 2013-06-03 13:13:18 +00:00
Robert Osfield
5e315d5fab From Wang Rui, "I'd like to submit the changes that will put ObjectProperty and ObjectMark variables into the InputStream/OutputStream class instead of static ones. This should avoid the threading problem and won't repeatedly reallocate memory for the properties. Some of the wrappers will be slightly modified to use the property variable stored in the InputStream/OutputStream as well." 2012-04-05 13:53:47 +00:00
Robert Osfield
14a563dc9f Ran script to remove trailing spaces and tabs 2012-03-21 17:36:20 +00:00
Robert Osfield
de040e44a0 From Rafa Gata, I've been playing around with serializers in order to use it as a
"generic" property mechanism for osg::Object.

The main problem I have found is that InputStream and OutputStream
only takes the stream when you call start method, and in that case it
attaches to the stream buffer some stuff, useful for files but not for
runtime/gui usage. I have added a simple setInputIterator and
setOutputIterator to the classes so now you can easily serialize
values without version and other stuff.

Writing matrix:
osgDB::OutputStream os(0);
std::stringstream sstream;
os.setOutputIterator(new AsciiOutputIterator(&sstream));
os << matrix;
std::string value = sstream.str();

Reading matrix:
osgDB::InputStream is(0);
std::stringstream sstream(value);
is.setInputIterator(new AsciiInputIterator(&sstream));
osg::Matrixf mat2;
is >> mat2;

From Robert Osfield, added doxygen comments to clarify the role of the methods.
2011-05-16 08:50:59 +00:00
Robert Osfield
bc6a94c5b3 From Michael Platings, "I've attached a fix for a subtle bug that causes animations (and quite possibly other things) to be serialized incorrectly.
For the following code:

#define MYMACRO(NAME) myOutputStream << #NAME;
MYMACRO(Group)

you would expect that "Group" would be output. However, as there are many overloaded operator<< functions, none of which take a const char* argument, the function that's actually called is operator<<(bool). Hence what actually gets output is "TRUE".
An actual example of this is in serializers\osgAnimation\Animation.cpp, WRITE_CHANNEL_FUNC2.

So the simple solution to this is to add operator<<(const char*), attached.
"
2011-01-18 16:14:24 +00:00
Robert Osfield
d9a133476a Refactored the handling of readImage/writeImage/readObject/writeObject to avoid double setting of unique ID's, fixing the problem in reading/writing files with images 2010-09-23 16:12:05 +00:00
Robert Osfield
42527fe859 From Wang Rui, "I'd like to submit my inbuilt schema data support of
the OutputStream/InputStream implementations, which was just finished
last weekend with a few tests on Windows and Ubuntu. Hope it could
work and get more feedbacks soon.

I've added a new option "SchemaData" to the osg2 plugin. Developers
may test the new feature with the command line:

# osgconv cow.osg cow.osgb -O SchemaData

It will record all serializer properties used in the scene graph, at
the beginning of the generated file. And when osgviewer and user
applications is going to read the osgb file, the inbuilt data will be
automatically read and applied first, to keep backwards compatibility
partly. This will not affect osgb files generated with older versions.
"
2010-05-12 20:02:31 +00:00
Robert Osfield
e082b01f26 From Wang Rui, "I've initially added the XML support of the new native osg format,
using osgDB::XmlParser. The extension for XML-formatted scenes is
.osgx, corresponding to .osgb for binary and .osgt for ascii. It could
either be rendered in osgviewer or edited by common web browsers and
xml editors because of a range of changes to fit the XML syntax. For
example, the recorded class names are slight modified, from
'osg::Geode' to 'osg--Geode'.

To quickly get an XML file:
# ./osgconv cow.osg cow.osgx

The StreamOperator header, InputStreram and OutputStream classes are
modified to be more portable for triple ascii/binary/XML formats. I
also fixed a bug in readImage()/writeImage() to share image objects if
needed.

The ReaderWriterOSG2 class now supports all three formats and
reading/writing scene objects (not nodes or images), thanks to
Torben's advice before.
"
2010-03-10 13:48:41 +00:00
Robert Osfield
605ad76691 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.
"
2010-02-25 17:53:51 +00:00
Robert Osfield
5b1ca779e4 Added OutputStream::writeSize and InputStream::readSize methods to help out with ensure that 32bit and 64bit builds all
use the same 32bit type for sizes.
2010-02-10 17:03:09 +00:00
Robert Osfield
0a9263d50e 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."
2010-01-27 17:09:05 +00:00
Robert Osfield
a520e8b6bd From Wang Rui, refactored the InputStream/OutputStream operations so that the binar/ascii foramts are implemented via subclasses. 2010-01-25 11:03:21 +00:00
Robert Osfield
f1bd2eaf04 From Wang Rui, added exports for windows build 2010-01-21 09:25:45 +00:00
Robert Osfield
219696f1ee 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
2010-01-20 20:13:33 +00:00