Hi Robert,

I was trying to use the archive output of osgdem without success when
I eventually found out that it was now disabled (the mailing list
archive tells me it is because of multithreaded write issues with
vpn). I then decided to use osgarchive to make it myself from the
generated output. However if one of the insert parameters is a
directory, it won't be able to find them. The attached versions
corrects this.

Index: osgarchive.cpp
===================================================================
--- osgarchive.cpp      (revision 9808)
+++ osgarchive.cpp      (working copy)
@@ -79,7 +79,12 @@
                 else if (fileType==osgDB::DIRECTORY)
                 {
                     osgDB::DirectoryContents directory =
osgDB::getDirectoryContents(arguments[pos]);
-
files.insert(files.end(),directory.begin(),directory.end());
+                    osgDB::DirectoryContents::iterator it = directory.begin();
+                    while( it != directory.end())
+                    {
+                        files.push_back(filePath + "/" + (*it));
+                        ++it;
+                    }
                 }
             }
             else


now "osgarchive --archive hf.osga --insert hf.ive hf_root_L0_X0_Y0"
will work as (I) expected.

However, when using the newly made osga archive, the PageLoader finds
only the first level of the generated PageLOD DB.
Let me detail a bit,  is the file layout inside hf.osga (I sorted to
have the first levels)

hf.ive
hf_root_L0_X0_Y0/hf_L0_X0_Y0_subtile.ive
hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive
hf_root_L0_X0_Y0/hf_L2_X0_Y0_subtile.ive
hf_root_L0_X0_Y0/hf_L2_X0_Y1_subtile.ive
hf_root_L0_X0_Y0/hf_L2_X1_Y0_subtile.ive
hf_root_L0_X0_Y0/hf_L2_X1_Y1_subtile.ive
...

"osgviewer hf.osga" will load hf.ive from the archive, then
hf_root_L0_X0_Y0/hf_L0_X0_Y0_subtile.ive also from the archive, but
then will never find  hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive (with
DEBUG_INFO turned on it is clear that the DatabasePager doesn't look
into the archive anymore for files)

Any idea of what's going wrong ? Maybe the attached hf.txt would help
(I snipped out the very verbose not related things )

regards,

--
Mathieu
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
[snip]

itr=''
FindFileInPath() : trying osgPlugins-2.9.0/osgdb_osga.so ...
itr='/usr/local/lib'
FindFileInPath() : trying /media/data/local/lib/osgPlugins-2.9.0/osgdb_osga.so 
...
FindFileInPath() : USING /media/data/local/lib/osgPlugins-2.9.0/osgdb_osga.so
Opened DynamicLibrary osgPlugins-2.9.0/osgdb_osga.so
FindFileInPath(/home/marache/hf.osga): returning /home/marache/hf.osga
Archive::Archive() open
OSGA_Archive::open() doEndianSwap=0
OSGA_Archive::open() Version=0
Read index block

[snip]

Read index block
    filename hf.ive pos=4124 size=17358
    filename hf_root_L0_X0_Y0/hf_L0_X0_Y0_subtile.ive pos=297210809 size=16721
    filename hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive pos=22673727 size=66887
    filename hf_root_L0_X0_Y0/hf_L2_X0_Y0_subtile.ive pos=241419768 size=66887
    filename hf_root_L0_X0_Y0/hf_L2_X0_Y1_subtile.ive pos=307875021 size=66887
    filename hf_root_L0_X0_Y0/hf_L2_X1_Y0_subtile.ive pos=198297746 size=50759
    filename hf_root_L0_X0_Y0/hf_L2_X1_Y1_subtile.ive pos=337169046 size=66887
    
[snip]
    
Now checking for plug-in osgPlugins-2.9.0/osgdb_ive.so
itr=''
FindFileInPath() : trying osgPlugins-2.9.0/osgdb_ive.so ...
itr='/usr/local/lib'
FindFileInPath() : trying /media/data/local/lib/osgPlugins-2.9.0/osgdb_ive.so 
...
FindFileInPath() : USING /media/data/local/lib/osgPlugins-2.9.0/osgdb_ive.so
Opened DynamicLibrary osgPlugins-2.9.0/osgdb_ive.so
OSGA_Archive::readObject(obj, hf.ive)
ive::DataInputStream.setLoadExternalReferenceFiles()=1
uncompressed ive stream

[snip]

Viewer::startThreading() - starting threading
Viewer::startThreading() - contexts.size()=1
Making scene thread safe
Doing add
Doing add
Doing add
  gc->getGraphicsThread()->startThread() 0x9cf6168
Set up threading
View::init()
Done DatabasePager::addLoadedDataToSceneGraph0.001ms,   0.001ms  objects0

In 
DatabasePager::fileRquest(/home/marache/hf.osga/hf_root_L0_X0_Y0/hf_L0_X0_Y0_subtile.ive)
DatabasePager::startThread()
HANDLE_NON_HTTP: DatabasePager::DatabaseThread::run
HANDLE_NON_HTTP: _pager->_requestList.size()= 1 to delete = 0
Contains archive : 
/home/marache/hf.osga/hf_root_L0_X0_Y0/hf_L0_X0_Y0_subtile.ive
         archive : /home/marache/hf.osga
         filename : hf_root_L0_X0_Y0/hf_L0_X0_Y0_subtile.ive
OSGA_Archive::readObject(obj, hf_root_L0_X0_Y0/hf_L0_X0_Y0_subtile.ive)
ive::DataInputStream.setLoadExternalReferenceFiles()=1
uncompressed ive stream
HANDLE_ONLY_HTTP: DatabasePager::DatabaseThread::run
Doing run 0x9cf6168 isRunning()=1
OpenGL extensions supported by installed OpenGL drivers are:
    GL_ARB_color_buffer_float
    GL_ARB_depth_texture
    GL_ARB_draw_buffers
    
[snip]

    GL_SUN_slice_accum
OpenGL extension 'GL_ARB_vertex_program' is supported.
OpenGL extension 'GL_EXT_secondary_color' is supported.
OpenGL extension 'GL_EXT_fog_coord' is supported.
OpenGL extension 'GL_ARB_multitexture' is supported.
OpenGL extension 'GL_NV_occlusion_query' is supported.
OpenGL extension 'GL_ARB_occlusion_query' is supported.
OpenGL extension 'GL_EXT_timer_query' is supported.
OpenGL extension '' is not supported.
OpenGL extension 'GL_ARB_pixel_buffer_object' is supported.
Done DatabasePager::addLoadedDataToSceneGraphOpenGL extension 
'GL_ARB_fragment_program' is supported.
0.001ms,        0.019ms  objects1

OpenGL extension 'GL_EXT_framebuffer_object' is supported.
OpenGL extension 'GL_EXT_framebuffer_blit' is supported.
OpenGL extension 'GL_EXT_framebuffer_multisample' is supported.
OpenGL extension 'GL_NV_framebuffer_multisample_coverage' is supported.
OpenGL extension 'GL_EXT_packed_depth_stencil' is supported.
OpenGL extension 'GL_ARB_shader_objects' is supported.
In DatabasePager::fileRquest(OpenGL extension 
'hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.iveGL_ARB_vertex_shader)
' is supported.
HANDLE_NON_HTTP: _pager->_requestList.size()= 1 to delete = 0
itr='/usr/local/share/data'
FindFileInPath() : trying 
/usr/local/share/data/hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive ...
itr='/usr/local/share/data'
FindFileInPath() : trying /usr/local/share/data/hf_L1_X0_Y0_subtile.ive ...
OpenGL extension 'GL_ARB_fragment_shader' is supported.
OpenGL extension 'GL_ARB_shading_language_100' is supported.
OpenGL extension 'GL_EXT_geometry_shader4' is supported.
OpenGL extension 'GL_EXT_gpu_shader4' is supported.
glVersion=2.12, isGlslSupported=YES, glslLanguageVersion=1.2
OpenGL extension 'GL_ARB_vertex_program' is supported.
Setting up osg::Camera::FRAME_BUFFER
OpenGL extension '' is not supported.
Done DatabasePager::addLoadedDataToSceneGraph0.001ms,   0ms  objects0

Setting up osg::Camera::FRAME_BUFFER
DatabasePager::fileRequest(hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive) updating 
already assigned.
DatabasePager::fileRquest(hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive) orphaned, 
resubmitting.
HANDLE_NON_HTTP: _pager->_requestList.size()= 1 to delete = 0
itr='/usr/local/share/data'
FindFileInPath() : trying 
/usr/local/share/data/hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive ...
itr='/usr/local/share/data'
FindFileInPath() : trying /usr/local/share/data/hf_L1_X0_Y0_subtile.ive ...
Done DatabasePager::addLoadedDataToSceneGraph0.001ms,   0ms  objects0

DatabasePager::fileRequest(hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive) updating 
already assigned.
DatabasePager::fileRquest(hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive) orphaned, 
resubmitting.
HANDLE_NON_HTTP: _pager->_requestList.size()= 1 to delete = 0
itr='/usr/local/share/data'
FindFileInPath() : trying 
/usr/local/share/data/hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive ...
itr='/usr/local/share/data'
FindFileInPath() : trying /usr/local/share/data/hf_L1_X0_Y0_subtile.ive ...
Done DatabasePager::addLoadedDataToSceneGraph0.001ms,   0.001ms  objects0

DatabasePager::fileRequest(hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive) updating 
already assigned.
DatabasePager::fileRquest(hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive) orphaned, 
resubmitting.
HANDLE_NON_HTTP: _pager->_requestList.size()= 1 to delete = 0
itr='/usr/local/share/data'
FindFileInPath() : trying 
/usr/local/share/data/hf_root_L0_X0_Y0/hf_L1_X0_Y0_subtile.ive ...
itr='/usr/local/share/data'
FindFileInPath() : trying /usr/local/share/data/hf_L1_X0_Y0_subtile.ive ...
Done DatabasePager::addLoadedDataToSceneGraph0.001ms,   0ms  objects0
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
 *
 * This application is open source and may be redistributed and/or modified   
 * freely and without restriction, both in commericial and non commericial applications,
 * as long as this copyright notice is maintained.
 * 
 * This application 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.
*/

#include <osg/Timer>
#include <osg/ArgumentParser>
#include <osg/ApplicationUsage>

#include <osgDB/Archive>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgDB/FileUtils>

#include <iostream>
#include <algorithm>


int main( int argc, char **argv )
{
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);
    
    // set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is an application for collecting a set of seperate files into a single archive file that can be later read in OSG applications..");
    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
        
    // if user request help write it out to cout.
    if (arguments.read("-h") || arguments.read("--help"))
    {
        arguments.getApplicationUsage()->write(std::cout);
        return 1;
    }

    std::string archiveFilename;
    while (arguments.read("-a",archiveFilename) || arguments.read("--archive",archiveFilename))
    {
    }

    bool insert = false;
    while (arguments.read("-i") || arguments.read("--insert"))
    {
        insert = true;
    }
    
    bool extract = false;
    while (arguments.read("-e") || arguments.read("--extract"))
    {
        extract = true;
    }
    
    bool list = false;    
    while (arguments.read("-l") || arguments.read("--list"))
    {
        list = true;
    }

    typedef std::vector<std::string> FileNameList;
    FileNameList files;
    for(int pos=1;pos<arguments.argc();++pos)
    {
        if (!arguments.isOption(pos))
        {
            if (insert)
            {
                std::string filePath = osgDB::findDataFile(arguments[pos]);
                osgDB::FileType fileType = osgDB::fileType(filePath);
                if (fileType==osgDB::REGULAR_FILE)
                {
                    files.push_back(arguments[pos]);
                }
                else if (fileType==osgDB::DIRECTORY)
                {
                    osgDB::DirectoryContents directory = osgDB::getDirectoryContents(arguments[pos]);
                    osgDB::DirectoryContents::iterator it = directory.begin();
                    while( it != directory.end())
                    {
                        files.push_back(filePath + "/" + (*it));
                        ++it;
                    }
                }
            }
            else
            {
                files.push_back(arguments[pos]);
            }
        }
    }
    
    // any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized();

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return 1;
    }
    
    if (archiveFilename.empty())
    {
        std::cout<<"Please specify an archive name using --archive filename"<<std::endl;
        return 1;
    }

    if (!insert && !extract && !list)
    {
        std::cout<<"Please specify an operation on the archive, either --insert, --extract or --list"<<std::endl;
        return 1;
    }
    
    if (insert && extract)
    {
        std::cout<<"Cannot insert and extract files from the archive at one time, please use either --insert or --extract."<<std::endl;
        return 1;
    }

    osg::ref_ptr<osgDB::Archive> archive;

    if (insert)
    {
        archive = osgDB::openArchive(archiveFilename, osgDB::Archive::WRITE);
        
        if (archive.valid())
        {
            for (FileNameList::iterator itr=files.begin();
                itr!=files.end();
                ++itr)
            {
                std::cout<<"reading "<<*itr<<std::endl;
                osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(*itr);
                if (obj.valid())
                {
                    std::cout<<"  write to archive "<<*itr<<std::endl;
                    archive->writeObject(*obj, *itr);
                }
            }
        }
    }
    else 
    {
        archive = osgDB::openArchive(archiveFilename, osgDB::Archive::READ);
        
        if (extract && archive.valid())
        {
            for (FileNameList::iterator itr=files.begin();
                itr!=files.end();
                ++itr)
            {
                osg::Timer_t start = osg::Timer::instance()->tick();
                osgDB::ReaderWriter::ReadResult result = archive->readObject(*itr);
                osg::ref_ptr<osg::Object> obj = result.getObject();
                std::cout<<"readObejct time = "<<osg::Timer::instance()->delta_m(start,osg::Timer::instance()->tick())<<std::endl;
                if (obj.valid())
                {
                    osgDB::writeObjectFile(*obj, *itr);
                }
            }
        }
    }

    if (list && archive.valid())
    {        
        std::cout<<"List of files in archive:"<<std::endl;
        osgDB::Archive::FileNameList fileNames;
        if (archive->getFileNames(fileNames))
        {
            for(osgDB::Archive::FileNameList::const_iterator itr=fileNames.begin();
                itr!=fileNames.end();
                ++itr)
            {
                std::cout<<"    "<<*itr<<std::endl;
            }
        }
        
        std::cout<<std::endl;
        std::cout<<"Master file "<<archive->getMasterFileName()<<std::endl;
    }
    
    return 0;
}

_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to