Hi,

today I have to report a problem I encountered on storing a scene into
the 'bin' file format and subsequentially reading it two times. Below
you can find a very simple program showing the problem. Running this
program crashes on my vc-7.1 windows box. Actually, the problem has
something to do with Image which is shared among the multiple
TextureChunks. However, I was unable to track down the problem.

If I store the scene into the 'osb' file format instead of the 'bin'
file format I do not have problems.

What is the recommended binary file format. Which is the more robust
one. I read the entries in the mailing list but I  do not have enough
information to rate it against the 'bin' file format.

Dirk Reiners wrote Tue, 12 Sep 2006 
> OSB has proven to be relatively robust, so far. It provides some
support 
> for data transformers that allow backwards compatibility, it works 
> better than expected. I don't know how far we can push it, though. 
> Additions to existing things are relatively easy to handle (usually
you 
> have to do nothing), changes within a FieldContainer are usually
doable, 
> too, but I'm not sure how far we can stretch for splits and merges of 
> functionality.
> 
> In general it was not designed to be a well-defined, fixed exchange 
> format, but a rather slim abstraction layer on top of our internal
data 
> structures that allows efficient loading and storing. It is good
enough 
> for minor changes, but I would not expect to be able to use today's 
> files 15 years down the line. There are companies that use it 
> internally, but they have the data in other formats, too, and can 
> regenerate it if necessary.

With best regards,
Johannes

P.S.: Sample program. File locations and sample image needs to be
adjusted...

#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSceneFileHandler.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGImage.h>
#include <OpenSG/OSGTextureChunk.h>
#include <OpenSG/OSGSimpleMaterial.h>
#include <OpenSG/OSGMatrix.h>
#include <OpenSG/OSGMaterialGroup.h>
#include <OpenSG/OSGTransform.h>

int main(int argc, char **argv)
{
    using namespace osg;

    osgInit(argc,argv);

    ImagePtr image = Image::create();
    {
        CPEdit(image, FieldBits::AllFields);
        image->read("G:/Experimental/GraphicLab/Test/diffuse.jpg");
    }

    TextureChunkPtr texChunkPtr1 = TextureChunk::create();
    TextureChunkPtr texChunkPtr2 = TextureChunk::create(); 
    {
        CPEdit(texChunkPtr1, FieldBits::AllFields);
        texChunkPtr1->setImage(image); 
    }
    {
        CPEdit(texChunkPtr2, FieldBits::AllFields);
        texChunkPtr2->setImage(image); 
    }

    SimpleMaterialPtr mat1 = SimpleMaterial::create();
    SimpleMaterialPtr mat2 = SimpleMaterial::create();
    {
        CPEdit(mat1, FieldBits::AllFields);
        mat1->addChunk(texChunkPtr1);
    }
    {
        CPEdit(mat2, FieldBits::AllFields);
        mat2->addChunk(texChunkPtr2);
    }


    MaterialGroupPtr mgrp1 = MaterialGroup::create();
    MaterialGroupPtr mgrp2 = MaterialGroup::create();
    {
        CPEdit(mgrp1, FieldBits::AllFields);
        mgrp1->setMaterial(mat1);
    }
    {
        CPEdit(mgrp2, FieldBits::AllFields);
        mgrp2->setMaterial(mat2);
    }

    NodePtr node1 = makeTorus(10, 100, 16, 16);
    NodePtr node2 = makeTorus(10, 100, 16, 16);

    NodePtr materialNode1 = Node::create();
    NodePtr materialNode2 = Node::create();
    {
        CPEdit(materialNode1, FieldBits::AllFields);
        materialNode1->addChild(node1);
        materialNode1->setCore(mgrp1);
    }
    {
        CPEdit(materialNode2, FieldBits::AllFields);
        materialNode2->addChild(node2);
        materialNode2->setCore(mgrp2);
    }

    TransformPtr transformCore1 = Transform::create();
    TransformPtr transformCore2 = Transform::create();
    {
        Matrix m;
        CPEdit(transformCore1, FieldBits::AllFields);
        transformCore1->setMatrix(m);
    }
    {
        Matrix m;
        CPEdit(transformCore2, FieldBits::AllFields);
        transformCore2->setMatrix(m);
    }

    NodePtr transformNode1 = Node::create();
    NodePtr transformNode2 = Node::create();
    {
        CPEdit(transformNode1, FieldBits::AllFields);
        transformNode1->addChild(materialNode1);
        transformNode1->setCore(transformCore1);
    }
    {
        CPEdit(transformNode2, FieldBits::AllFields);
        transformNode2->addChild(materialNode2);
        transformNode2->setCore(transformCore2);
    }

    NodePtr groupNode = Node::create();
    {
        CPEdit(groupNode, FieldBits::AllFields);
        groupNode->setCore(Group::create());
        groupNode->addChild(transformNode1);
        groupNode->addChild(transformNode2);
    }

    std::string
sFNnode1("G:/Experimental/GraphicLab/Test/TexScene1.bin");
    std::string
sFNnode2("G:/Experimental/GraphicLab/Test/TexScene2.bin");

    bool r1 = SceneFileHandler::the().write(groupNode, sFNnode1.c_str(),
false);
   
    NodePtr nodereloaded =
SceneFileHandler::the().read(sFNnode1.c_str());

    bool r2 = SceneFileHandler::the().write(nodereloaded,
sFNnode2.c_str(), false);

    return 0;
}




____________
Virus checked by G DATA AntiVirusKit
Version: AVK 19.276 from 02.09.2008
Virus news: www.antiviruslab.com

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to