Hi Torben,

On Wed, Feb 10, 2010 at 2:32 PM, Torben Dannhauer
<[email protected]> wrote:
> thank you, I'm spending my whole day in that issue, but my knowledge about 
> the plugin arcitecture is still very small. :(
>
> Is any documentation about that architecture available?

For the old style .osg the code is the documentation :-)

The old DotOSgWrapper architecture that VPB still uses is now
deprecated, but I will be porting it across to the new scheme
implementation by Wang Rui.  He has already posted a wiki page for the
new scheme:

http://www.openscenegraph.org/projects/osg/wiki/Support/KnowledgeBase/SerializationSupport

Not much to you w.r.t this particular regression, but at least we're
moving forward with documentation as well as feature.

> this way many people could dive deeper into OSG solving bugs would be easier.

There is always a need for docs, always a need for fixing bugs, always
a need for more features, always a need for performance, always a need
for less memory footprint...lots of pressures all round.  What we need
is a conning machine which provides us all with clones that don't
require a salary, food, water or shelter.

For this particular regression it looks like the osgTerrain dotosg
wrapper isn't being loaded automatically as it should be for some
reason.  I can for the load of this wrapper and VPB starts working
again, but it is rather hacking a fix to the problem in unrelated code
rather than fixing the bug.  Attached is hack fix to
src/vpb/DatabaseBuilderIO.cpp that will get VPB back working.  I will
look into why osgDB isn't loading the osgTerrain dotosg wrapper as
this will be the source of bug.

Robert.
/* -*-c++-*- VirtualPlanetBuilder - Copyright (C) 1998-2009 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/

#include <vpb/DatabaseBuilder>

#include <iostream>
#include <string>
#include <map>

#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>

#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>

#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>

using namespace vpb;


//////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  DatabaseBuilder IO support
//

bool DatabaseBuilder_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool DatabaseBuilder_writeLocalData(const osg::Object &obj, osgDB::Output &fw);

osgDB::RegisterDotOsgWrapperProxy DatabaseBuilder_Proxy
(
    new vpb::DatabaseBuilder,
    "DatabaseBuilder",
    "DatabaseBuilder Object",
    DatabaseBuilder_readLocalData,
    DatabaseBuilder_writeLocalData
);


bool DatabaseBuilder_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
    vpb::DatabaseBuilder& db = static_cast<vpb::DatabaseBuilder&>(obj);
    bool itrAdvanced = false;
    
    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<BuildOptions>());
    if (readObject.valid())
    {
        db.setBuildOptions(dynamic_cast<BuildOptions*>(readObject.get()));
    }
    
    return itrAdvanced;
}

bool DatabaseBuilder_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
    const vpb::DatabaseBuilder& db = static_cast<const vpb::DatabaseBuilder&>(obj);

    if (db.getBuildOptions())
    {
        fw.writeObject(*db.getBuildOptions());
    }


    return true;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  VPBReaderWriter
//
                        

class VPBReaderWriter : public osgDB::ReaderWriter
{
    public:
    
        VPBReaderWriter()
        {
            supportsExtension("vpb","VirtualPlanetBuilder source format");
            supportsExtension("source","VirtualPlanetBuilder source format");

            osg::notify(osg::NOTICE)<<"Constructing VPBReaderWriter()"<<std::endl;

#if 1
            std::string filename = osgDB::Registry::instance()->createLibraryNameForExtension("deprecated_osgTerrain");
            if (osgDB::Registry::instance()->loadLibrary(filename)==osgDB::Registry::LOADED)
            {
                OSG_NOTIFY(osg::NOTICE)<<"Constructor VPBReaderWriter() - loaded OK"<<std::endl;
            }
            else
            {
                OSG_NOTIFY(osg::NOTICE)<<"Constructor VPBReaderWriter() - failed to load"<<std::endl;
            }
#endif
        }
        
        virtual const char* className() const { return "VPB Reader/Writer"; }

        virtual bool acceptsExtension(const std::string& extension) const
        {
            return osgDB::equalCaseInsensitive(extension,"vpb") || osgDB::equalCaseInsensitive(extension,"source");
        }

        virtual ReadResult readNode(const std::string& file, const Options* opt) const
        {
            osg::notify(osg::NOTICE)<<"VPBReaderWriter::readNode("<<file<<")"<<std::endl;


            std::string ext = osgDB::getFileExtension(file);
            if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

            std::string fileName = osgDB::findDataFile( file, opt );
            if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;

            // code for setting up the database path so that internally referenced file are searched for on relative paths.
            osg::ref_ptr<Options> local_opt = opt ? static_cast<Options*>(opt->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
            local_opt->setDatabasePath(osgDB::getFilePath(fileName));

            std::ifstream fin(fileName.c_str());
            if (fin)
            {
                osg::notify(osg::NOTICE)<<"   readNode("<<file<<")"<<std::endl;
                return readNode(fin, local_opt.get());
            }
            return 0L;
                        
        }
        
        virtual ReadResult readNode(std::istream& fin, const Options* options) const
        {
            fin.imbue(std::locale::classic());

            osgDB::Input fr;
            fr.attach(&fin);
            fr.setOptions(options);
            
            typedef std::vector<osg::Node*> NodeList;
            NodeList nodeList;

            // load all nodes in file, placing them in a group.
            while(!fr.eof())
            {
                osg::Node *node = fr.readNode();
                if (node) nodeList.push_back(node);
                else fr.advanceOverCurrentFieldOrBlock();
            }

            if  (nodeList.empty())
            {
                return ReadResult("No data loaded");
            }
            else if (nodeList.size()==1)
            {
                return nodeList.front();
            }
            else
            {
                osg::Group* group = new osg::Group;
                group->setName("import group");
                for(NodeList::iterator itr=nodeList.begin();
                    itr!=nodeList.end();
                    ++itr)
                {
                    group->addChild(*itr);
                }
                return group;
            }

        }

        virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
        {
            std::string ext = osgDB::getFileExtension(fileName);
            if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;


            osgDB::Output fout(fileName.c_str());
            if (fout)
            {
                fout.setOptions(options);

                fout.imbue(std::locale::classic());

                // setPrecision(fout,options);

                fout.writeObject(node);
                fout.close();
                return WriteResult::FILE_SAVED;
            }
            return WriteResult("Unable to open file for output");
        }
};
        

// now register with Registry to instantiate the above
// reader/writer.
REGISTER_OSGPLUGIN(vpb, VPBReaderWriter)
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to