Added prelimarny support for reading archives via the .net plugin

This commit is contained in:
Robert Osfield 2004-11-13 16:21:48 +00:00
parent 06f1b602e7
commit ddb0d6bd4f
10 changed files with 75 additions and 17 deletions

View File

@ -129,9 +129,11 @@ int main( int argc, char **argv )
itr!=files.end(); itr!=files.end();
++itr) ++itr)
{ {
std::cout<<"reading "<<*itr<<std::endl;
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(*itr); osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(*itr);
if (obj.valid()) if (obj.valid())
{ {
std::cout<<" write to archive "<<*itr<<std::endl;
archive->writeObject(*obj, *itr); archive->writeObject(*obj, *itr);
} }
} }

View File

@ -26,7 +26,10 @@ int main( int argc, char **argv )
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line paramters");
arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available");
arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindigs.");
// construct the viewer. // construct the viewer.
@ -39,9 +42,13 @@ int main( int argc, char **argv )
viewer.getUsage(*arguments.getApplicationUsage()); viewer.getUsage(*arguments.getApplicationUsage());
// if user request help write it out to cout. // if user request help write it out to cout.
if (arguments.read("-h") || arguments.read("--help")) bool helpAll = arguments.read("--help-all");
unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) |
((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) |
((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 );
if (helpType)
{ {
arguments.getApplicationUsage()->write(std::cout); arguments.getApplicationUsage()->write(std::cout, helpType);
return 1; return 1;
} }

View File

@ -36,9 +36,12 @@ class OSGDB_EXPORT Archive : public ReaderWriter
virtual bool acceptsExtension(const std::string& /*extension*/) { return true; } virtual bool acceptsExtension(const std::string& /*extension*/) { return true; }
/** open the archive.*/ /** open the archive for reading, writing or to create an empty archive for writing to.*/
virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096) = 0; virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096) = 0;
/** open the archive for reading.*/
virtual bool open(std::istream& fin) = 0;
/** close the archive.*/ /** close the archive.*/
virtual void close() = 0; virtual void close() = 0;

View File

@ -161,8 +161,12 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
CREATE CREATE
}; };
/** open an archive for reading, writing or or to create an empty archive for writing to.*/
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
/** open an archive for reading.*/
virtual ReadResult openArchive(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }

View File

@ -11,6 +11,7 @@
#include <osgDB/ReadFile> #include <osgDB/ReadFile>
#include <osgDB/WriteFile> #include <osgDB/WriteFile>
#include <osgDB/FileUtils> #include <osgDB/FileUtils>
#include <osgDB/Archive>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
#include <osg/Group> #include <osg/Group>
#include <osg/Timer> #include <osg/Timer>
@ -85,11 +86,18 @@ class NetReader : public osgDB::ReaderWriter
enum ObjectType enum ObjectType
{ {
OBJECT, OBJECT,
ARCHIVE,
IMAGE, IMAGE,
HEIGHTFIELD, HEIGHTFIELD,
NODE NODE
}; };
virtual ReadResult openArchive(const std::string& fileName,ArchiveStatus status, unsigned int , const Options* options)
{
if (status!=READ) return ReadResult(ReadResult::FILE_NOT_HANDLED);
else return readFile(ARCHIVE,fileName,options);
}
virtual ReadResult readObject(const std::string& fileName, const Options* options) virtual ReadResult readObject(const std::string& fileName, const Options* options)
{ {
return readFile(OBJECT,fileName,options); return readFile(OBJECT,fileName,options);
@ -115,6 +123,7 @@ class NetReader : public osgDB::ReaderWriter
switch(objectType) switch(objectType)
{ {
case(OBJECT): return rw->readObject(fin,options); case(OBJECT): return rw->readObject(fin,options);
case(ARCHIVE): return rw->openArchive(fin,options);
case(IMAGE): return rw->readImage(fin,options); case(IMAGE): return rw->readImage(fin,options);
case(HEIGHTFIELD): return rw->readHeightField(fin,options); case(HEIGHTFIELD): return rw->readHeightField(fin,options);
case(NODE): return rw->readNode(fin,options); case(NODE): return rw->readNode(fin,options);
@ -127,7 +136,7 @@ class NetReader : public osgDB::ReaderWriter
{ {
osg::Timer_t start = osg::Timer::instance()->tick(); osg::Timer_t start = osg::Timer::instance()->tick();
osg::notify(osg::DEBUG_INFO) << "osgPlugin .net: start load" << inFileName << std::endl; osg::notify(osg::NOTICE) << "osgPlugin .net: start load" << inFileName << std::endl;
std::string hostname; std::string hostname;
std::string serverPrefix; std::string serverPrefix;
@ -196,6 +205,7 @@ class NetReader : public osgDB::ReaderWriter
return ReadResult::FILE_NOT_HANDLED; return ReadResult::FILE_NOT_HANDLED;
*/ */
std::string fileName; std::string fileName;
int index = inFileName.find(":"); int index = inFileName.find(":");
// If we haven't been given a hostname as an option // If we haven't been given a hostname as an option
@ -224,6 +234,10 @@ class NetReader : public osgDB::ReaderWriter
if( !serverPrefix.empty() ) if( !serverPrefix.empty() )
fileName = serverPrefix + '/' + fileName; fileName = serverPrefix + '/' + fileName;
osg::notify(osg::WARN) << "hostname " << hostname << std::endl;
osg::notify(osg::WARN) << "filename " << fileName << std::endl;
// Invoke the reader corresponding to the extension // Invoke the reader corresponding to the extension
osgDB::ReaderWriter *reader = osgDB::ReaderWriter *reader =
osgDB::Registry::instance()->getReaderWriterForExtension( osgDB::getFileExtension(fileName)); osgDB::Registry::instance()->getReaderWriterForExtension( osgDB::getFileExtension(fileName));
@ -248,9 +262,9 @@ class NetReader : public osgDB::ReaderWriter
} }
// Fetch from the network // Fetch from the network
iosockinet sio (sockbuf::sock_stream); osg::ref_ptr<iosockinet> sio = new iosockinet(sockbuf::sock_stream);
try { try {
sio->connect( hostname.c_str(), port ); sio->rdbuf()->connect( hostname.c_str(), port );
} }
catch( sockerr e ) catch( sockerr e )
{ {
@ -258,13 +272,13 @@ class NetReader : public osgDB::ReaderWriter
return ReadResult::FILE_NOT_FOUND; return ReadResult::FILE_NOT_FOUND;
} }
sio << "GET /" << fileName << " HTTP/1.1\n" << "Host:\n\n"; *sio << "GET /" << fileName << " HTTP/1.1\n" << "Host:\n\n";
sio.flush(); sio->flush();
char linebuff[256]; char linebuff[256];
do do
{ {
sio.getline( linebuff, sizeof( linebuff )); sio->getline( linebuff, sizeof( linebuff ));
std::istringstream iss(linebuff); std::istringstream iss(linebuff);
std::string directive; std::string directive;
@ -329,13 +343,20 @@ class NetReader : public osgDB::ReaderWriter
if( reader != 0L ) if( reader != 0L )
readResult = readFile(objectType, reader, sio, local_opt.get() ); readResult = readFile(objectType, reader, *sio, local_opt.get() );
double ms = osg::Timer::instance()->delta_m(start,osg::Timer::instance()->tick()); double ms = osg::Timer::instance()->delta_m(start,osg::Timer::instance()->tick());
osg::notify(osg::DEBUG_INFO) << "osgPlugin .net: " << fileName << osg::notify(osg::DEBUG_INFO) << "osgPlugin .net: " << fileName <<
" fetched from server. in" << ms <<" ms"<< std::endl; " fetched from server. in" << ms <<" ms"<< std::endl;
if (objectType==ARCHIVE && readResult.validArchive())
{
// attach the socket istream to the archive to keep it alive.
osgDB::Archive* archive = readResult.getArchive();
archive->setUserData(sio.get());
}
if( !localCacheDir.empty() && cacheMode & Write ) if( !localCacheDir.empty() && cacheMode & Write )
{ {
std::string cacheFile = localCacheDir + '/' + fileName; std::string cacheFile = localCacheDir + '/' + fileName;

View File

@ -11,6 +11,8 @@
#ifndef _SOCKINET_H #ifndef _SOCKINET_H
#define _SOCKINET_H #define _SOCKINET_H
#include <osg/Referenced>
#include "sockstream.h" #include "sockstream.h"
#if defined(__CYGWIN__) || !defined(WIN32) #if defined(__CYGWIN__) || !defined(WIN32)
@ -112,7 +114,7 @@ class isockinet: public isockstream
sockinetbuf* operator -> () { return rdbuf (); } sockinetbuf* operator -> () { return rdbuf (); }
}; };
class osockinet: public osockstream class osockinet: public osg::Referenced, public osockstream
{ {
public: public:
osockinet (const sockbuf::sockdesc& sd); osockinet (const sockbuf::sockdesc& sd);
@ -121,10 +123,9 @@ class osockinet: public osockstream
~osockinet (); ~osockinet ();
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); } sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
sockinetbuf* operator -> () { return rdbuf (); }
}; };
class iosockinet: public iosockstream class iosockinet: public osg::Referenced, public iosockstream
{ {
public: public:
iosockinet (const sockbuf::sockdesc& sd); iosockinet (const sockbuf::sockdesc& sd);
@ -133,7 +134,6 @@ class iosockinet: public iosockstream
~iosockinet (); ~iosockinet ();
sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); } sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
sockinetbuf* operator -> () { return rdbuf (); }
}; };
#endif // _SOCKINET_H #endif // _SOCKINET_H

View File

@ -353,6 +353,12 @@ bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsig
} }
} }
bool OSGA_Archive::open(std::istream& fin)
{
osg::notify(osg::NOTICE)<<"OSGA_Archive::open"<<std::endl;
return false;
}
void OSGA_Archive::close() void OSGA_Archive::close()
{ {
_input.close(); _input.close();

View File

@ -20,6 +20,9 @@ class OSGA_Archive : public osgDB::Archive
/** open the archive.*/ /** open the archive.*/
virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096); virtual bool open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSizeHint=4096);
/** open the archive for reading.*/
virtual bool open(std::istream& fin);
/** close the archive.*/ /** close the archive.*/
virtual void close(); virtual void close();

View File

@ -39,6 +39,18 @@ public:
return archive.get(); return archive.get();
} }
/** open an archive for reading.*/
virtual ReadResult openArchive(std::istream& fin,const Options*)
{
osg::ref_ptr<OSGA_Archive> archive = new OSGA_Archive;
if (!archive->open(fin))
{
return ReadResult(ReadResult::FILE_NOT_HANDLED);
}
return archive.get();
}
virtual ReadResult readImage(const std::string& file,const Options* options) virtual ReadResult readImage(const std::string& file,const Options* options)
{ {
ReadResult result = openArchive(file,osgDB::Archive::READ); ReadResult result = openArchive(file,osgDB::Archive::READ);

View File

@ -981,7 +981,7 @@ void ViewerEventHandler::getUsage(osg::ApplicationUsage& usage) const
usage.addKeyboardMouseBinding("f","Toggle fullscreen"); usage.addKeyboardMouseBinding("f","Toggle fullscreen");
usage.addKeyboardMouseBinding("h","Display help"); usage.addKeyboardMouseBinding("h","Display help");
usage.addKeyboardMouseBinding("o","Write scene graph to \"saved_model.osg\""); usage.addKeyboardMouseBinding("o","Write scene graph to \"saved_model.osg\"");
usage.addKeyboardMouseBinding("O PrtSrn","Write camera images to \"saved_image*.rgb\""); usage.addKeyboardMouseBinding("O PrtSrn","Write camera images to \"saved_image*.jpg\"");
usage.addKeyboardMouseBinding("s","Toggle instrumention"); usage.addKeyboardMouseBinding("s","Toggle instrumention");
usage.addKeyboardMouseBinding("v","Toggle block and vsync"); usage.addKeyboardMouseBinding("v","Toggle block and vsync");
usage.addKeyboardMouseBinding("z","Start recording camera path."); usage.addKeyboardMouseBinding("z","Start recording camera path.");