osg::SceneFileHandler Class Reference

Brief OSGSceneFileHandler.

#include <OSGSceneFileHandler.h>

List of all members.

Progress



typedef void(* progresscbfp )(UInt32 p)
typedef void(* filenamecbfp )(const Char8 *fname)
void setReadProgressCB (progresscbfp fp, bool use_thread=true)
progresscbfp getReadProgressCB (void)
void setReadBeginCB (filenamecbfp fp)
filenamecbfp getReadBeginCB (void)
void setReadEndCB (filenamecbfp fp)
filenamecbfp getReadEndCB (void)
void updateReadProgress (void)
void updateReadProgress (UInt32 p)
void triggerReadBegin (const Char8 *fname)
void triggerReadEnd (const Char8 *fname)
void setWriteProgressCB (progresscbfp fp)
progresscbfp getWriteProgressCB (void)
void setWriteBeginCB (filenamecbfp fp)
filenamecbfp getWriteBeginCB (void)
void setWriteEndCB (filenamecbfp fp)
filenamecbfp getWriteEndCB (void)
void updateWriteProgress (UInt32 p)
void triggerWriteBegin (const Char8 *fname)
void triggerWriteEnd (const Char8 *fname)

Read



typedef NodePtr(* fileioreadcbfp )(SceneFileType *type, std::istream &is, const Char8 *ext)
virtual NodePtr read (std::istream &is, const Char8 *ext, GraphOpSeq *graphOpSeq=_defaultgraphOpSeq)
virtual FCPtrStore readTopNodes (std::istream &is, const Char8 *ext, GraphOpSeq *graphOpSeq=_defaultgraphOpSeq)
virtual NodePtr read (const Char8 *fileName, GraphOpSeq *graphOpSeq=_defaultgraphOpSeq)
virtual FCPtrStore readTopNodes (const Char8 *fileName, GraphOpSeq *graphOpSeq=_defaultgraphOpSeq)
void setReadCB (fileioreadcbfp fp)
fileioreadcbfp getReadCB (void)

Write



typedef bool(* fileiowritecbfp )(SceneFileType *type, const NodePtr &node, std::ostream &os, const Char8 *ext, bool compress)
virtual bool write (const NodePtr &node, std::ostream &os, const Char8 *ext, bool compress=false)
virtual bool write (const NodePtr &node, const Char8 *fileName, bool compress=false)
void setWriteCB (fileiowritecbfp fp)
fileiowritecbfp getWriteCB (void)

Member



static SceneFileHandler_the = NULL
static GraphOpSeq_defaultgraphOpSeq = NULL
FileTypeMap _suffixTypeMap
static bool addSceneFileType (SceneFileType &fileType)
static bool subSceneFileType (SceneFileType &fileType)

Public Types

typedef std::vector
< FieldContainerPtr
FCPtrStore

Public Member Functions

Destructors


virtual ~SceneFileHandler (void)
Get


virtual SceneFileTypegetFileType (const Char8 *fileNameOrExtension)
virtual int getSuffixList (std::list< const Char8 * > &suffixList, UInt32 flags=SceneFileType::OSG_READ_SUPPORTED|SceneFileType::OSG_WRITE_SUPPORTED)
PathHandler


virtual PathHandlergetPathHandler (void)
virtual void setPathHandler (PathHandler *pathHandler)
DefaultGraphOp


virtual GraphOpSeqgetDefaultGraphOp (void)
virtual void setDefaultGraphOp (GraphOpSeq *graphOpSeq)
Options


virtual bool setOptions (const Char8 *suffix, const Char8 *options)
virtual const Char8getOptions (const Char8 *suffix)
Debug


void print (void)

Static Public Member Functions

Class Get


static SceneFileHandlerthe (void)

Protected Types

typedef std::list
< SceneFileType * > 
FileTypeList
typedef std::map< IDString,
FileTypeList * > 
FileTypeMap

Protected Member Functions

Constructors


 SceneFileHandler (void)
 SceneFileHandler (const SceneFileHandler &obj)

Private Member Functions

std::string initPathHandler (const Char8 *fileName)
void operator= (const SceneFileHandler &source)
 prohibit default function (move to 'public' if needed)
void initReadProgress (std::istream &is)
void terminateReadProgress (void)

Static Private Member Functions

static void readProgress (void *data)

Private Attributes

progresscbfp _readProgressFP
filenamecbfp _readBeginFP
filenamecbfp _readEndFP
progressS _progressData
bool _readReady
bool _useProgressThread
progresscbfp _writeProgressFP
filenamecbfp _writeBeginFP
filenamecbfp _writeEndFP
PathHandler_pathHandler
PathHandler _defaultPathHandler
fileioreadcbfp _readFP
fileiowritecbfp _writeFP

Friends

class SceneFileType

Classes

struct  FindOverride
struct  progressS


Detailed Description

Definition at line 63 of file OSGSceneFileHandler.h.


Member Typedef Documentation

Definition at line 68 of file OSGSceneFileHandler.h.

typedef void(* osg::SceneFileHandler::filenamecbfp)(const Char8 *fname)

typedef NodePtr(* osg::SceneFileHandler::fileioreadcbfp)(SceneFileType *type, std::istream &is, const Char8 *ext)

typedef bool(* osg::SceneFileHandler::fileiowritecbfp)(SceneFileType *type, const NodePtr &node, std::ostream &os, const Char8 *ext, bool compress)

typedef std::list< SceneFileType *> osg::SceneFileHandler::FileTypeList [protected]

Definition at line 202 of file OSGSceneFileHandler.h.

typedef std::map<IDString, FileTypeList *> osg::SceneFileHandler::FileTypeMap [protected]

Definition at line 203 of file OSGSceneFileHandler.h.


Constructor & Destructor Documentation

SceneFileHandler::~SceneFileHandler ( void   )  [virtual]

Definition at line 972 of file OSGSceneFileHandler.cpp.

00973 {
00974 }

SceneFileHandler::SceneFileHandler ( void   )  [protected]

constructors & destructors

Definition at line 899 of file OSGSceneFileHandler.cpp.

References _defaultgraphOpSeq, _progressData, osg::SceneFileHandler::progressS::is, osg::SceneFileHandler::progressS::length, and osg::GraphOpSeq::setGraphOps().

00899                                         :
00900     _readProgressFP(NULL),
00901     _readBeginFP(NULL),
00902     _readEndFP(NULL),
00903     _progressData(),
00904     _readReady(false),
00905     _useProgressThread(false),
00906     _writeProgressFP(NULL),
00907     _writeBeginFP(NULL),
00908     _writeEndFP(NULL),
00909     _pathHandler(NULL),
00910     _defaultPathHandler(),
00911     _readFP(NULL),
00912     _writeFP(NULL)
00913 {
00914     _progressData.length = 0;
00915     _progressData.is = NULL;
00916 
00917     if(_defaultgraphOpSeq == NULL)
00918     {
00919         // Set default optimizations
00920         _defaultgraphOpSeq = new GraphOpSeq;
00921         _defaultgraphOpSeq->setGraphOps("Stripe() SharePtr(includes=Material,StateChunk)");
00922     }
00923 
00924 }

SceneFileHandler::SceneFileHandler ( const SceneFileHandler obj  )  [protected]

constructors & destructors

Definition at line 946 of file OSGSceneFileHandler.cpp.

References SWARNING.

00947 {
00948     SWARNING << "In copy constructor; I shouldn't be in this corner" << std::endl;
00949 }


Member Function Documentation

SceneFileHandler & SceneFileHandler::the ( void   )  [static]

SceneFileType * SceneFileHandler::getFileType ( const Char8 fileNameOrExtension  )  [virtual]

Definition at line 131 of file OSGSceneFileHandler.cpp.

References _suffixTypeMap, p, osg::IDString::set(), and osg::IDString::toLower().

Referenced by getOptions(), read(), setOptions(), and write().

00132 {
00133     const Char8 separator = '.';
00134 
00135     if(fileNameOrExtension == NULL)
00136         return NULL;
00137 
00138     std::string fe = fileNameOrExtension;
00139     
00140     Int32 p = fe.rfind(separator);
00141     
00142     std::string ext;
00143     
00144     if(p != -1)
00145         ext = fe.substr(p+1, fe.length() - p - 1);
00146     else
00147         ext = fe; // extension without '.'
00148     
00149     // skip .gz extension
00150     if(ext == "gz")
00151     {
00152         fe = fe.substr(0, p);
00153         p = fe.rfind(separator);
00154         if(p != -1)
00155             ext = fe.substr(p+1, fe.length() - p - 1);
00156         else
00157             ext = fe;
00158     }
00159     
00160     IDString suffix;
00161     suffix.set(ext.c_str());
00162     suffix.toLower();
00163 
00164     FileTypeMap::iterator sI = _suffixTypeMap.find(suffix);
00165     SceneFileType *type = (sI == _suffixTypeMap.end()) ? 0 : sI->second->front();
00166 
00167     return type;
00168 }

Int32 SceneFileHandler::getSuffixList ( std::list< const Char8 * > &  suffixList,
UInt32  flags = SceneFileType::OSG_READ_SUPPORTED | SceneFileType::OSG_WRITE_SUPPORTED 
) [virtual]

Definition at line 175 of file OSGSceneFileHandler.cpp.

References _suffixTypeMap, and osg::SceneFileType::getFlags().

00177 {
00178     Int32                 count = 0;
00179     FileTypeMap::iterator sI;
00180 
00181     suffixList.clear();
00182     
00183     for ( sI = _suffixTypeMap.begin(); sI != _suffixTypeMap.end(); ++sI)
00184     {
00185         SceneFileType *type = sI->second->front();
00186         if((type->getFlags() & flags) == flags)
00187         {
00188             suffixList.push_back(sI->first.str());
00189             count++;
00190         }
00191     }
00192 
00193     return count;
00194 }

void SceneFileHandler::setReadProgressCB ( progresscbfp  fp,
bool  use_thread = true 
)

Definition at line 986 of file OSGSceneFileHandler.cpp.

References _readProgressFP, _useProgressThread, and terminateReadProgress().

00987 {
00988     if(use_thread)
00989     {
00990         terminateReadProgress();
00991     }
00992     else
00993     {
00994         // check if setReadProgressCB was called before with use_thread enabled.
00995         if(_useProgressThread)
00996             terminateReadProgress();
00997     }
00998 
00999     _readProgressFP = fp;
01000     _useProgressThread = use_thread;
01001 }

SceneFileHandler::progresscbfp SceneFileHandler::getReadProgressCB ( void   ) 

Definition at line 1003 of file OSGSceneFileHandler.cpp.

References _readProgressFP.

01004 {
01005     return _readProgressFP;
01006 }

void SceneFileHandler::setReadBeginCB ( SceneFileHandler::filenamecbfp  fp  ) 

Definition at line 1008 of file OSGSceneFileHandler.cpp.

References _readBeginFP.

01009 {
01010     _readBeginFP = fp;
01011 }

SceneFileHandler::filenamecbfp SceneFileHandler::getReadBeginCB ( void   ) 

Definition at line 1013 of file OSGSceneFileHandler.cpp.

References _readBeginFP.

01014 {
01015     return _readBeginFP;
01016 }

void SceneFileHandler::setReadEndCB ( SceneFileHandler::filenamecbfp  fp  ) 

Definition at line 1018 of file OSGSceneFileHandler.cpp.

References _readEndFP.

01019 {
01020     _readEndFP = fp;
01021 }

SceneFileHandler::filenamecbfp SceneFileHandler::getReadEndCB ( void   ) 

Definition at line 1023 of file OSGSceneFileHandler.cpp.

References _readEndFP.

01024 {
01025     return _readEndFP;
01026 }

void SceneFileHandler::updateReadProgress ( void   ) 

void SceneFileHandler::updateReadProgress ( UInt32  p  ) 

Definition at line 1128 of file OSGSceneFileHandler.cpp.

References _readProgressFP.

01129 {
01130     if(_readProgressFP == NULL)
01131         return;
01132 
01133     _readProgressFP(p);
01134 }

void SceneFileHandler::triggerReadBegin ( const Char8 fname  ) 

Definition at line 1028 of file OSGSceneFileHandler.cpp.

References _readBeginFP.

Referenced by read().

01029 {
01030     if(_readBeginFP != NULL)
01031       _readBeginFP(fname);
01032 }

void SceneFileHandler::triggerReadEnd ( const Char8 fname  ) 

Definition at line 1034 of file OSGSceneFileHandler.cpp.

References _readEndFP.

Referenced by read().

01035 {
01036     if(_readEndFP != NULL)
01037       _readEndFP(fname);
01038 }

void SceneFileHandler::setWriteProgressCB ( progresscbfp  fp  ) 

Definition at line 1138 of file OSGSceneFileHandler.cpp.

References _writeProgressFP.

01139 {
01140     _writeProgressFP = fp;
01141 }

SceneFileHandler::progresscbfp SceneFileHandler::getWriteProgressCB ( void   ) 

Definition at line 1143 of file OSGSceneFileHandler.cpp.

References _writeProgressFP.

01144 {
01145     return _writeProgressFP;
01146 }

void SceneFileHandler::setWriteBeginCB ( SceneFileHandler::filenamecbfp  fp  ) 

Definition at line 1148 of file OSGSceneFileHandler.cpp.

References _writeBeginFP.

01149 {
01150     _writeBeginFP = fp;
01151 }

SceneFileHandler::filenamecbfp SceneFileHandler::getWriteBeginCB ( void   ) 

Definition at line 1153 of file OSGSceneFileHandler.cpp.

References _writeBeginFP.

01154 {
01155     return _writeBeginFP;
01156 }

void SceneFileHandler::setWriteEndCB ( SceneFileHandler::filenamecbfp  fp  ) 

Definition at line 1158 of file OSGSceneFileHandler.cpp.

References _writeEndFP.

01159 {
01160     _writeEndFP = fp;
01161 }

SceneFileHandler::filenamecbfp SceneFileHandler::getWriteEndCB ( void   ) 

Definition at line 1163 of file OSGSceneFileHandler.cpp.

References _writeEndFP.

01164 {
01165     return _writeEndFP;
01166 }

void SceneFileHandler::updateWriteProgress ( UInt32  p  ) 

Definition at line 1181 of file OSGSceneFileHandler.cpp.

References _writeProgressFP.

Referenced by osg::VRMLWriteAction::updateProgress(), osg::VRMLWriteAction::write(), and write().

01182 {
01183     if(_writeProgressFP == NULL)
01184         return;
01185 
01186     _writeProgressFP(p);
01187 }

void SceneFileHandler::triggerWriteBegin ( const Char8 fname  ) 

Definition at line 1168 of file OSGSceneFileHandler.cpp.

References _writeBeginFP.

Referenced by write().

01169 {
01170     if(_writeBeginFP != NULL)
01171       _writeBeginFP(fname);
01172 }

void SceneFileHandler::triggerWriteEnd ( const Char8 fname  ) 

Definition at line 1174 of file OSGSceneFileHandler.cpp.

References _writeEndFP.

Referenced by write().

01175 {
01176     if(_writeEndFP != NULL)
01177       _writeEndFP(fname);
01178 }

NodePtr SceneFileHandler::read ( std::istream &  is,
const Char8 ext,
GraphOpSeq graphOpSeq = _defaultgraphOpSeq 
) [virtual]

Definition at line 201 of file OSGSceneFileHandler.cpp.

References _readFP, getFileType(), osg::SceneFileType::getName(), initReadProgress(), osg::isGZip(), osg::NullFC, osg::SceneFileType::read(), osg::GraphOpSeq::run(), SFATAL, SINFO, SWARNING, and terminateReadProgress().

Referenced by osg::VRMLInlineDesc::endNode(), osg::ProxyGroup::loadProc(), read(), readTopNodes(), and osg::ProxyGroup::startLoading().

00203 {
00204     SceneFileType *type = getFileType(fileNameOrExtension);
00205     NodePtr        scene = NullFC;
00206 
00207     if(!fileNameOrExtension)
00208     {
00209         SWARNING << "cannot read NULL extension" << std::endl;
00210         return NullFC;
00211     }
00212 
00213     if (type)
00214     {
00215         SINFO << "try to read stream as " << type->getName() << std::endl;
00216     
00217         // check for fileio read callback
00218         if(_readFP != NULL)
00219         {
00220             initReadProgress(is);
00221             scene = _readFP(type, is, fileNameOrExtension);
00222             terminateReadProgress();
00223         }
00224         else
00225         {
00226             if(isGZip(is))
00227             {
00228                 SINFO << "Detected gzip compressed stream." << std::endl;
00229 
00230 #ifdef OSG_ZSTREAM_SUPPORTED
00231                 initReadProgress(is);
00232                 zip_istream unzipper(is);
00233                 scene = type->read(unzipper, fileNameOrExtension);
00234                 if(scene != NullFC)
00235                 {
00236                     if(unzipper.check_crc())
00237                         SINFO << "Compressed stream has correct checksum." << std::endl;
00238                     else
00239                         SFATAL << "Compressed stream has wrong checksum." << std::endl;
00240                 }
00241                 terminateReadProgress();
00242 #else
00243                 SFATAL << "Compressed streams are not supported! Configure with --enable-png --with-png=DIR options." << std::endl;
00244 #endif
00245             }
00246             else
00247             {
00248                 initReadProgress(is);
00249                 scene = type->read(is, fileNameOrExtension);
00250                 terminateReadProgress();
00251             }
00252         }
00253 
00254         if(scene != NullFC)
00255         {
00256             if(graphOpSeq != NULL)
00257                 graphOpSeq->run(scene);
00258 
00259             SINFO    << "read ok:"        << std::endl;
00260         }
00261         else
00262         {
00263             SWARNING << "could not read " << std::endl;
00264         }
00265     }
00266     else
00267     {
00268         SWARNING << "could not read unknown file format" << std::endl;
00269     }
00270 
00271     return scene;
00272 }

SceneFileHandler::FCPtrStore SceneFileHandler::readTopNodes ( std::istream &  is,
const Char8 ext,
GraphOpSeq graphOpSeq = _defaultgraphOpSeq 
) [virtual]

Definition at line 275 of file OSGSceneFileHandler.cpp.

References osg::Node::create(), osg::NodePtr::getCore(), osg::NullFC, read(), and osg::GraphOpSeq::run().

Referenced by readTopNodes().

00278 {
00279     std::vector<FieldContainerPtr> nodeVec;
00280     NodePtr scene = read(is, fileNameOrExtension);
00281     if(scene == NullFC)
00282         return nodeVec;
00283 
00284     while(scene->getNChildren() > 0)
00285     {
00286         NodePtr child = scene->getChild(0);
00287         NodePtr newChild = Node::create();
00288         while(child->getNChildren() > 0)
00289             newChild->addChild(child->getChild(0));
00290         newChild->setCore(child->getCore());
00291         if(graphOpSeq != NULL)
00292                 graphOpSeq->run(newChild);
00293         nodeVec.push_back(newChild);
00294         scene->subChild(child);
00295     }
00296 
00297     return nodeVec;
00298 }

NodePtr SceneFileHandler::read ( const Char8 fileName,
GraphOpSeq graphOpSeq = _defaultgraphOpSeq 
) [virtual]

Definition at line 300 of file OSGSceneFileHandler.cpp.

References _readFP, getFileType(), osg::SceneFileType::getName(), initPathHandler(), osg::NullFC, read(), osg::SceneFileType::readFile(), osg::GraphOpSeq::run(), SINFO, SWARNING, triggerReadBegin(), triggerReadEnd(), and updateReadProgress().

00302 {
00303     if(!fileName)
00304     {
00305         SWARNING << "cannot read NULL file" << std::endl;
00306         return NullFC;
00307     }
00308 
00309     std::string fullFilePath = initPathHandler(fileName);
00310     if(fullFilePath.empty())
00311     {
00312         if(_readFP != NULL)
00313         {
00314             // that's a fallback could be a url so the callback
00315             // can handle this correctly.
00316             SceneFileType *type = getFileType(fileName);
00317             if(type != NULL)
00318             {
00319                 // create a dummy stream with the bad flag set.
00320                 std::ifstream in;
00321                 in.setstate(std::ios::badbit);
00322                 return _readFP(type, in, fileName);
00323             }
00324             else
00325             {
00326                 SWARNING << "Couldn't open file " << fileName << std::endl;
00327                 return NullFC;
00328             }
00329         }
00330         else
00331         {
00332             SWARNING << "Couldn't open file " << fileName << std::endl;
00333             return NullFC;
00334         }
00335     }
00336 
00337     SceneFileType *type = getFileType(fullFilePath.c_str());
00338     NodePtr scene = NullFC;
00339 
00340     if (type)
00341     {
00342     triggerReadBegin(fullFilePath.c_str());
00343     updateReadProgress(0);
00344 
00345         SINFO << "try to read " << fullFilePath
00346               << " as "         << type->getName() << std::endl;
00347 
00348         std::ifstream in(fullFilePath.c_str(), std::ios::binary);
00349         
00350         if(in)
00351         {
00352             scene = read(in, fullFilePath.c_str(), graphOpSeq);
00353             in.close();
00354 
00355             if(scene != NullFC)
00356         {
00357                 triggerReadEnd(fullFilePath.c_str());
00358                 return scene;
00359         }
00360         }
00361         else
00362         {
00363             SWARNING << "Couldn't open input stream for file " << fullFilePath << std::endl;
00364         }
00365 
00366 
00367 
00368 #ifndef OSG_DISABLE_DEPRECATED
00369         // Ok stream interface didn't work try via filename
00370         if(scene == NullFC)
00371             scene = type->readFile(fullFilePath.c_str());
00372 
00373         if (scene != NullFC)
00374         {
00375             if(graphOpSeq != NULL)
00376                 graphOpSeq->run(scene);
00377 
00378             SINFO    << "read ok:"        << std::endl;
00379         }
00380         else
00381         {
00382             SWARNING << "could not read " << std::endl;
00383         }
00384 #endif
00385     }
00386     else
00387     {
00388         SWARNING << "could not read "       << fullFilePath
00389                  << "; unknown file format" << std::endl;
00390     }
00391 
00392     return scene;
00393 }

SceneFileHandler::FCPtrStore SceneFileHandler::readTopNodes ( const Char8 fileName,
GraphOpSeq graphOpSeq = _defaultgraphOpSeq 
) [virtual]

Definition at line 395 of file OSGSceneFileHandler.cpp.

References osg::Node::create(), osg::NodePtr::getCore(), initPathHandler(), osg::NullFC, read(), readTopNodes(), osg::GraphOpSeq::run(), and SWARNING.

00398 {
00399     std::vector<FieldContainerPtr> nodeVec;
00400 
00401     if(!fileName)
00402     {
00403         SWARNING << "cannot read NULL file" << std::endl;
00404         return nodeVec;
00405     }
00406 
00407     std::string fullFilePath = initPathHandler(fileName);
00408     if(fullFilePath.empty())
00409     {
00410         SWARNING << "Couldn't open file " << fileName << std::endl;
00411         return nodeVec;
00412     }
00413 
00414     std::ifstream in(fullFilePath.c_str(), std::ios::binary);
00415 
00416     if(in)
00417     {
00418         nodeVec = readTopNodes(in, fullFilePath.c_str(), graphOpSeq);
00419         in.close();
00420     }
00421     else
00422     {
00423         SWARNING << "Couldn't open input stream for file " << fullFilePath << std::endl;
00424     }
00425 
00426     // Ok stream interface didn't work try via filename
00427     if(nodeVec.empty())
00428     {
00429         NodePtr scene = read(fullFilePath.c_str());
00430         if(scene == NullFC)
00431             return nodeVec;
00432 
00433         while(scene->getNChildren() > 0)
00434         {
00435             NodePtr child = scene->getChild(0);
00436             NodePtr newChild = Node::create();
00437             while(child->getNChildren() > 0)
00438                 newChild->addChild(child->getChild(0));
00439             newChild->setCore(child->getCore());
00440             if(graphOpSeq != NULL)
00441                 graphOpSeq->run(newChild);
00442             nodeVec.push_back(newChild);
00443             scene->subChild(child);
00444         }
00445     }
00446 
00447     return nodeVec;
00448 }

void SceneFileHandler::setReadCB ( fileioreadcbfp  fp  ) 

Definition at line 450 of file OSGSceneFileHandler.cpp.

References _readFP.

00451 {
00452     _readFP = fp;
00453 }

SceneFileHandler::fileioreadcbfp SceneFileHandler::getReadCB ( void   ) 

Definition at line 455 of file OSGSceneFileHandler.cpp.

References _readFP.

00456 {
00457     return _readFP;
00458 }

bool SceneFileHandler::write ( const NodePtr node,
std::ostream &  os,
const Char8 ext,
bool  compress = false 
) [virtual]

Definition at line 480 of file OSGSceneFileHandler.cpp.

References _writeFP, getFileType(), osg::SceneFileType::getName(), SFATAL, SINFO, SWARNING, updateWriteProgress(), and osg::SceneFileType::write().

Referenced by write().

00482 {
00483     bool retCode = false;
00484     SceneFileType *type = getFileType(fileNameOrExtension);
00485 
00486     if(type)
00487     {
00488         updateWriteProgress(0);
00489         SINFO << "try to write stream as " << type->getName() << std::endl;
00490         
00491         if(_writeFP != NULL)
00492         {
00493             retCode = _writeFP(type, node, os, fileNameOrExtension, compress);
00494         }
00495         else
00496         {
00497             if(compress)
00498             {
00499 #ifdef OSG_ZSTREAM_SUPPORTED
00500                 SINFO << "writing compressed stream." << std::endl;
00501                 zip_ostream zipper(os, true);
00502                 retCode = type->write(node, zipper, fileNameOrExtension);
00503                 zipper.zflush();
00504 #else
00505                 SFATAL << "Compressed streams are not supported! Configure with --enable-png --with-png=DIR options." << std::endl;
00506 #endif
00507             }
00508             else
00509             {
00510                 retCode = type->write(node, os, fileNameOrExtension);
00511             }
00512         }
00513     }
00514     else
00515         SWARNING << "can't write stream unknown scene format" << std::endl;
00516 
00517     return retCode;
00518 }

bool SceneFileHandler::write ( const NodePtr node,
const Char8 fileName,
bool  compress = false 
) [virtual]

Definition at line 540 of file OSGSceneFileHandler.cpp.

References getFileType(), osg::SceneFileType::getName(), SINFO, SWARNING, triggerWriteBegin(), triggerWriteEnd(), updateWriteProgress(), write(), and osg::SceneFileType::writeFile().

00541 {
00542     bool retCode = false;
00543     SceneFileType *type = getFileType(fileName);
00544 
00545     if (type)
00546     {
00547         updateWriteProgress(0);
00548     triggerWriteBegin(fileName);
00549         SINFO << "try to write " << fileName << " as " << type->getName() << std::endl;
00550 
00551         std::ofstream out(fileName, std::ios::binary);
00552         if(out)
00553         {
00554             retCode = write(node, out, fileName, compress);
00555             out.close();
00556         }
00557         else
00558         {
00559             SWARNING << "Can not open output stream for file '" << fileName << "'!" << std::endl;
00560         }
00561     
00562 #ifndef OSG_DISABLE_DEPRECATED
00563         if(!retCode)
00564             retCode = type->writeFile(node, fileName);
00565 #endif
00566 
00567         if(!retCode)
00568             SWARNING << "Couldn't write " << fileName << std::endl;
00569     else
00570         triggerWriteEnd(fileName);
00571     }
00572     else
00573         SWARNING << "can't write " << fileName << "; unknown scene format" << std::endl;
00574 
00575     return retCode;
00576 }

void SceneFileHandler::setWriteCB ( fileiowritecbfp  fp  ) 

Definition at line 578 of file OSGSceneFileHandler.cpp.

References _writeFP.

00579 {
00580     _writeFP = fp;
00581 }

SceneFileHandler::fileiowritecbfp SceneFileHandler::getWriteCB ( void   ) 

Definition at line 583 of file OSGSceneFileHandler.cpp.

References _writeFP.

00584 {
00585     return _writeFP;
00586 }

PathHandler * SceneFileHandler::getPathHandler ( void   )  [virtual]

Returns the path handler used

Definition at line 591 of file OSGSceneFileHandler.cpp.

References _defaultPathHandler, and _pathHandler.

Referenced by osg::ProxyGroup::changed(), osg::VRMLInlineDesc::endNode(), initPathHandler(), osg::ImageFileHandler::read(), and osg::OBJSceneFileType::readMTL().

00592 {
00593     if(_pathHandler == NULL)
00594         return &_defaultPathHandler;
00595     else
00596         return _pathHandler;
00597 }

void SceneFileHandler::setPathHandler ( PathHandler pathHandler  )  [virtual]

Method to set the path handler.

Definition at line 603 of file OSGSceneFileHandler.cpp.

References _pathHandler.

00604 {
00605     _pathHandler = pathHandler;
00606 }

GraphOpSeq * SceneFileHandler::getDefaultGraphOp ( void   )  [virtual]

Definition at line 638 of file OSGSceneFileHandler.cpp.

References _defaultgraphOpSeq.

00639 {
00640     return _defaultgraphOpSeq;
00641 }

void SceneFileHandler::setDefaultGraphOp ( GraphOpSeq graphOpSeq  )  [virtual]

Definition at line 643 of file OSGSceneFileHandler.cpp.

References _defaultgraphOpSeq.

00644 {
00645     _defaultgraphOpSeq = graphOpSeq;
00646 }

bool SceneFileHandler::setOptions ( const Char8 suffix,
const Char8 options 
) [virtual]

Definition at line 649 of file OSGSceneFileHandler.cpp.

References getFileType(), and osg::SceneFileType::setOptions().

00650 {
00651     if(suffix == NULL)
00652         return false;
00653     
00654     SceneFileType *type = getFileType(suffix);
00655     if(type == NULL)
00656         return false;
00657     
00658     type->setOptions(options);
00659     
00660     return true;
00661 }

const Char8 * SceneFileHandler::getOptions ( const Char8 suffix  )  [virtual]

Definition at line 663 of file OSGSceneFileHandler.cpp.

References getFileType(), and osg::SceneFileType::getOptions().

00664 {
00665     if(suffix == NULL)
00666         return NULL;
00667     
00668     SceneFileType *type = getFileType(suffix);
00669     
00670     if(type == NULL)
00671         return NULL;
00672     
00673     return type->getOptions();
00674 }

void SceneFileHandler::print ( void   ) 

Definition at line 696 of file OSGSceneFileHandler.cpp.

References _suffixTypeMap, osg::SceneFileType::getFlags(), osg::SceneFileType::OSG_READ_SUPPORTED, and osg::SceneFileType::OSG_WRITE_SUPPORTED.

00697 {
00698     FileTypeMap::iterator sI;
00699 
00700     for(sI = _suffixTypeMap.begin(); sI != _suffixTypeMap.end(); sI++)
00701     {
00702         std::string rw;
00703         SceneFileType *type = sI->second->front();
00704         if((type->getFlags() & SceneFileType::OSG_READ_SUPPORTED) &&
00705            (type->getFlags() & SceneFileType::OSG_WRITE_SUPPORTED))
00706         {
00707             rw = "reader and writer";
00708         }
00709         else
00710         {
00711             if(type->getFlags() & SceneFileType::OSG_READ_SUPPORTED)
00712                 rw = "reader";
00713             if(type->getFlags() & SceneFileType::OSG_WRITE_SUPPORTED)
00714                 rw = "writer";
00715         }
00716         
00717         std::cerr << "suffix: " << sI->first.str()
00718                   << ", type: " << sI->second->front()->getName()
00719                   << " " << rw << std::endl;
00720     }
00721 }

bool SceneFileHandler::addSceneFileType ( SceneFileType fileType  )  [static, protected]

Definition at line 773 of file OSGSceneFileHandler.cpp.

References _suffixTypeMap, osg::SceneFileType::doOverride(), osg::SceneFileType::getOverridePriority(), osg::IDString::set(), osg::SceneFileType::suffixList(), SWARNING, the(), osg::IDString::toLower(), and osg::SceneFileHandler::FindOverride::uiRefPriority.

Referenced by osg::SceneFileType::SceneFileType().

00774 {
00775     bool retCode = false;
00776 
00777     std::list<IDString>::iterator sI;
00778          FileTypeMap   ::iterator smI;
00779 
00780     IDString suffix;
00781 
00782     for(  sI  = fileType.suffixList().begin();
00783           sI != fileType.suffixList().end();
00784         ++sI)
00785     {
00786         suffix.set(sI->str());
00787         suffix.toLower();
00788 
00789         smI = the()._suffixTypeMap.find(suffix);
00790 
00791         if (smI != the()._suffixTypeMap.end())
00792         {
00793             if(fileType.doOverride() == true)
00794             {
00795                 FindOverride           overrideFinder;
00796                 FileTypeList::iterator lIt;
00797 
00798                 overrideFinder.uiRefPriority = fileType.getOverridePriority();
00799 
00800                 lIt = std::find_if(the()._suffixTypeMap[suffix]->begin(),
00801                                    the()._suffixTypeMap[suffix]->end(),
00802                                    overrideFinder);
00803 
00804                 the()._suffixTypeMap[suffix]->insert(lIt, &fileType);
00805 
00806                 SWARNING << "Added an file type with suffix "
00807                          << suffix
00808                          << " overriding "
00809                          << std::endl;
00810             }
00811             else
00812             {
00813                 the()._suffixTypeMap[suffix]->push_back(&fileType);
00814 
00815                 SWARNING << "Added an file type with suffix "
00816                          << suffix
00817                          << " non overriding at the end of the list"
00818                          << std::endl;
00819             }
00820         }
00821         else
00822         {
00823             FileTypeList *pTmpList = new FileTypeList;
00824 
00825             pTmpList->push_back(&fileType);
00826 
00827             the()._suffixTypeMap[suffix] = pTmpList;
00828 
00829             retCode = true;
00830         }
00831     }
00832 
00833     return retCode;
00834 }

bool SceneFileHandler::subSceneFileType ( SceneFileType fileType  )  [static, protected]

Definition at line 836 of file OSGSceneFileHandler.cpp.

References _suffixTypeMap, osg::IDString::set(), osg::SceneFileType::suffixList(), the(), and osg::IDString::toLower().

Referenced by osg::SceneFileType::~SceneFileType().

00837 {
00838     bool retCode = false;
00839 
00840     std::list<IDString>::iterator sI;
00841          FileTypeMap   ::iterator smI;
00842 
00843     IDString suffix;
00844 
00845     for(  sI  = fileType.suffixList().begin();
00846           sI != fileType.suffixList().end();
00847         ++sI)
00848     {
00849         suffix.set(sI->str());
00850         suffix.toLower();
00851 
00852         smI = the()._suffixTypeMap.find(suffix);
00853         if (smI != the()._suffixTypeMap.end())
00854         {
00855             the()._suffixTypeMap.erase(smI);
00856             retCode = true;
00857         }
00858     }
00859     return retCode;
00860 }

std::string SceneFileHandler::initPathHandler ( const Char8 fileName  )  [private]

Method to initialize the path handler.

Definition at line 611 of file OSGSceneFileHandler.cpp.

References _defaultPathHandler, _pathHandler, osg::PathHandler::clearBaseFile(), osg::PathHandler::clearPathList(), osg::PathHandler::findFile(), getPathHandler(), osg::PathHandler::push_frontCurrentDir(), osg::PathHandler::setBaseFile(), osg::ImageFileHandler::setPathHandler(), and osg::ImageFileHandler::the().

Referenced by read(), and readTopNodes().

00612 {
00613     std::string fullFilePath;
00614     if(_pathHandler != NULL)
00615     {
00616         // Set also a image path handler if not set.
00617         if(ImageFileHandler::the().getPathHandler() == NULL)
00618             ImageFileHandler::the().setPathHandler(_pathHandler);
00619         
00620         fullFilePath = _pathHandler->findFile(fileName);
00621     }
00622     else
00623     {
00624         // Set a default image path handler if not set.
00625         if(ImageFileHandler::the().getPathHandler() == NULL)
00626             ImageFileHandler::the().setPathHandler(&_defaultPathHandler);
00627 
00628         _defaultPathHandler.clearPathList();
00629         _defaultPathHandler.clearBaseFile();
00630         _defaultPathHandler.push_frontCurrentDir();
00631         fullFilePath = _defaultPathHandler.findFile(fileName);
00632         _defaultPathHandler.setBaseFile(fullFilePath.c_str());
00633     }
00634 
00635     return fullFilePath;
00636 }

void osg::SceneFileHandler::operator= ( const SceneFileHandler source  )  [private]

void SceneFileHandler::initReadProgress ( std::istream &  is  )  [private]

Definition at line 1040 of file OSGSceneFileHandler.cpp.

References _progressData, _readProgressFP, _readReady, _useProgressThread, osg::Thread::find(), osg::SceneFileHandler::progressS::is, osg::SceneFileHandler::progressS::length, readProgress(), osg::PThreadBase::runFunction(), and SWARNING.

Referenced by read().

01041 {
01042     if(_readProgressFP == NULL)
01043         return;
01044 
01045     // get length of the stream.
01046     _progressData.is = &is;
01047     is.seekg(0, std::ios::end);
01048     _progressData.length = is.tellg();
01049     is.seekg(0, std::ios::beg);
01050 
01051     _readReady = false;
01052     if(_useProgressThread)
01053     {
01054         Thread *pt = Thread::find("osg::FileIOReadProgressThread");
01055         if(pt == NULL)
01056             pt = OSG::Thread::get("osg::FileIOReadProgressThread");
01057 
01058         if(pt != NULL)
01059             pt->runFunction(readProgress, 0, NULL);
01060         else
01061             SWARNING << "Couldn't create read progress thread!" << std::endl;
01062     }
01063 }

void SceneFileHandler::terminateReadProgress ( void   )  [private]

Definition at line 1065 of file OSGSceneFileHandler.cpp.

References _progressData, _readProgressFP, _readReady, osg::Thread::find(), osg::SceneFileHandler::progressS::is, osg::BaseThread::join(), and osg::SceneFileHandler::progressS::length.

Referenced by read(), and setReadProgressCB().

01066 {
01067     if(_readProgressFP == NULL)
01068         return;
01069 
01070     _readReady = true;
01071     Thread *pt = Thread::find("osg::FileIOReadProgressThread");
01072     if(pt != NULL)
01073     {
01074         // terminate thread
01075         Thread::join(pt);
01076     }
01077 
01078     _progressData.length = 0;
01079     _progressData.is = NULL;
01080 }

void SceneFileHandler::readProgress ( void *  data  )  [static, private]

Definition at line 1082 of file OSGSceneFileHandler.cpp.

References _progressData, _readProgressFP, _readReady, _useProgressThread, osg::SceneFileHandler::progressS::is, osg::SceneFileHandler::progressS::length, osg::osgsleep(), p, and the().

Referenced by initReadProgress(), and updateReadProgress().

01083 {
01084     if(the()._readProgressFP == NULL || the()._progressData.is == NULL)
01085         return;
01086 
01087     UInt32 p = 0;
01088     while(p < 100 && !the()._readReady)
01089     {
01090         if(!the()._progressData.is->eof() &&
01091            !the()._progressData.is->bad())
01092         {
01093             UInt64 pos = the()._progressData.is->tellg();
01094             p = UInt32((pos * 100) / the()._progressData.length);
01095             if(p > 100)
01096                 p = 100;
01097         }
01098         else
01099         {
01100             p = 100;
01101         }
01102 
01103         the()._readProgressFP(p);
01104 
01105         if(the()._useProgressThread)
01106             osgsleep(100);
01107         else
01108             break;
01109     }
01110 
01111     if(the()._useProgressThread && p < 100)
01112     {
01113         the()._readProgressFP(100);
01114     }
01115 }


Friends And Related Function Documentation

friend class SceneFileType [friend]

Definition at line 238 of file OSGSceneFileHandler.h.


Member Data Documentation

SceneFileHandler * SceneFileHandler::_the = NULL [static, protected]

Definition at line 216 of file OSGSceneFileHandler.h.

Referenced by the().

GraphOpSeq * SceneFileHandler::_defaultgraphOpSeq = NULL [static, protected]

Definition at line 218 of file OSGSceneFileHandler.h.

Referenced by getDefaultGraphOp(), SceneFileHandler(), and setDefaultGraphOp().

Definition at line 256 of file OSGSceneFileHandler.h.

Referenced by getReadBeginCB(), setReadBeginCB(), and triggerReadBegin().

Definition at line 257 of file OSGSceneFileHandler.h.

Referenced by getReadEndCB(), setReadEndCB(), and triggerReadEnd().

Definition at line 260 of file OSGSceneFileHandler.h.

Referenced by initReadProgress(), readProgress(), and terminateReadProgress().

Definition at line 264 of file OSGSceneFileHandler.h.

Referenced by getWriteBeginCB(), setWriteBeginCB(), and triggerWriteBegin().

Definition at line 265 of file OSGSceneFileHandler.h.

Referenced by getWriteEndCB(), setWriteEndCB(), and triggerWriteEnd().

Definition at line 267 of file OSGSceneFileHandler.h.

Referenced by getPathHandler(), initPathHandler(), and setPathHandler().

Definition at line 268 of file OSGSceneFileHandler.h.

Referenced by getPathHandler(), and initPathHandler().

Definition at line 270 of file OSGSceneFileHandler.h.

Referenced by getReadCB(), read(), and setReadCB().

Definition at line 271 of file OSGSceneFileHandler.h.

Referenced by getWriteCB(), setWriteCB(), and write().


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:05:05 2008 for OpenSG by  doxygen 1.5.5