From 137605eba86c36c4930b71a8aece857db1377878 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 16 Jul 2009 10:12:33 +0000 Subject: [PATCH] Added support for using PagedLOD to managing loading of presentation preview and then the main presentation in the background paging thread --- applications/present3D/ReadShowFile.cpp | 8 +- src/osgPlugins/p3d/ReaderWriterP3D.cpp | 147 +++++++++++++++++++----- 2 files changed, 126 insertions(+), 29 deletions(-) diff --git a/applications/present3D/ReadShowFile.cpp b/applications/present3D/ReadShowFile.cpp index e0c21d8b9..580b0e9d4 100644 --- a/applications/present3D/ReadShowFile.cpp +++ b/applications/present3D/ReadShowFile.cpp @@ -182,10 +182,9 @@ osg::Node* p3d::readHoldingSlide(const std::string& filename) if (!osgDB::equalCaseInsensitive(ext,"xml") && !osgDB::equalCaseInsensitive(ext,"p3d")) return 0; - osg::ref_ptr options = new osgDB::ReaderWriter::Options; + osg::ref_ptr options = createOptions(0); options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE); - options->setOptionString("holding_slide"); - options->setPluginStringData("P3D_EVENTHANDLER","none"); + options->setOptionString("preview"); return osgDB::readNodeFile(filename, options.get()); } @@ -197,12 +196,15 @@ osg::Node* p3d::readPresentation(const std::string& filename,const osgDB::Reader !osgDB::equalCaseInsensitive(ext,"p3d")) return 0; osg::ref_ptr local_options = createOptions(options); + local_options->setOptionString("main"); + return osgDB::readNodeFile(filename, local_options.get()); } osg::Node* p3d::readShowFiles(osg::ArgumentParser& arguments,const osgDB::ReaderWriter::Options* options) { osg::ref_ptr local_options = createOptions(options); + local_options->setOptionString("main"); typedef std::vector< osg::ref_ptr > NodeList; NodeList nodeList; diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index 5747dcce5..d334679cf 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -115,6 +116,8 @@ public: ReadResult readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const; + osg::Node* parseXmlGraph(osgDB::XmlNode* root, bool readOnlyHoldingPage, osgDB::Options* options) const; + void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; @@ -1446,7 +1449,7 @@ class MyReadFileCallback : public virtual osgDB::ReadFileCallback osgDB::ReaderWriter::ReadResult readLocal(ObjectType type, const std::string& filename, const osgDB::Options* options) { - osg::notify(osg::INFO)<<"Trying local file "<getFileCache(); if (!fileCache) return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND; - osg::notify(osg::INFO)<<"Trying fileCache "<isFileAppropriateForFileCache(filename)) @@ -1513,7 +1516,7 @@ class MyReadFileCallback : public virtual osgDB::ReadFileCallback osgDB::ReaderWriter::ReadResult readServer(ObjectType type, const std::string& filename, const osgDB::Options* options) { - osg::notify(osg::INFO)<<"Trying server file "<getReaderWriterForExtension("curl"); @@ -1610,7 +1613,7 @@ class MyReadFileCallback : public virtual osgDB::ReadFileCallback if (!fileCache) fileCache = osgDB::Registry::instance()->getFileCache(); if (fileCache && !fileCache->isFileAppropriateForFileCache(filename)) fileCache = 0; - osg::notify(osg::INFO)<<"reading file "< local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; - //local_opt->setFindFileCallback(new MyFindFileCallback); local_opt->setReadFileCallback(new MyReadFileCallback); return readNode(input, local_opt.get()); @@ -1730,15 +1753,18 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(std::istream& fin, osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const { - bool readOnlyHoldingPage = options ? options->getOptionString()=="holding_slide" : false; + std::string fileName = options ? options->getPluginStringData("filename") : std::string(); + std::string extension = osgDB::getFileExtension(fileName); + std::string fileNameSansExtension = osgDB::getNameLessExtension(fileName); + std::string nestedExtension = osgDB::getFileExtension(fileNameSansExtension); + std::string fileNameSansNestedExtension = osgDB::getFileExtension(fileNameSansExtension); - // create a keyPosition just in case we need it. - osgPresentation::KeyPosition keyPosition; + bool readOnlyHoldingPage = nestedExtension=="preview" || (options && options->getOptionString()=="preview"); + bool readOnlyMainPresentation = nestedExtension=="main" || (options && options->getOptionString()=="main"); osg::ref_ptr doc = new osgDB::XmlNode; osgDB::XmlNode* root = 0; - doc->read(input); osg::notify(osg::INFO)<<"P3D xml file read, now building presentation scene graph."<children.begin(); + itr != root->children.end() && !hasHoldingSlide; + ++itr) + { + osgDB::XmlNode* cur = itr->get(); + if (cur->name == "holding_slide") + { + hasHoldingSlide = true; + } + } + + // if we are looking for a holding slide, but one isn't present return NULL. + if (readOnlyHoldingPage && !hasHoldingSlide) return 0; + + osg::notify(osg::NOTICE)<<"hasHoldingSlide "< presentation_node; + + + if (!readOnlyHoldingPage && !readOnlyMainPresentation) + { + if (fileName.empty()) hasHoldingSlide = false; + + osg::ref_ptr holdingslide_node = hasHoldingSlide ? parseXmlGraph(root, true, options) : 0; + + if (holdingslide_node.valid()) + { + double farDistance = 10000.0f; + + osg::ref_ptr pagedLOD = new osg::PagedLOD; + + pagedLOD->setDatabaseOptions(options); + + pagedLOD->addChild(holdingslide_node.get()); + pagedLOD->setRange(0,farDistance,2.0*farDistance); + + std::string fileNameToLoadMainPresentation = fileNameSansExtension + std::string(".main.")+extension; + + pagedLOD->setFileName(1,fileNameToLoadMainPresentation); + pagedLOD->setRange(1,0.0,farDistance); + + presentation_node = pagedLOD.get(); + + } + else + { + presentation_node = parseXmlGraph(root, false, options); + } + } + else + { + presentation_node = parseXmlGraph(root, readOnlyHoldingPage, options); + } + + if (presentation_node.valid()) + { + if (!options || options->getPluginStringData("P3D_EVENTHANDLER")!="none") + { + // if (!readOnlyHoldingPage && !readOnlyMainPresentation) + { + osgPresentation::SlideEventHandler* seh = new osgPresentation::SlideEventHandler; + seh->set(presentation_node.get()); + presentation_node->setEventCallback(seh); + } + } + return presentation_node.release(); + } + else + { + return osgDB::ReaderWriter::ReadResult::ERROR_IN_READING_FILE; + } +} + +osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode* root, bool readOnlyHoldingPage, osgDB::Options* options) const +{ osgPresentation::SlideShowConstructor constructor(options); + // create a keyPosition just in case we need it. + osgPresentation::KeyPosition keyPosition; + osgDB::FilePathList previousPaths = osgDB::getDataFilePathList(); bool readSlide = false; - for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); itr != root->children.end(); ++itr) @@ -1957,19 +2064,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Inp } } - osgDB::getDataFilePathList() = previousPaths; - - osg::ref_ptr presentation_node = constructor.takePresentation(); - - - if (!options || options->getPluginStringData("P3D_EVENTHANDLER")!="none") - { - osgPresentation::SlideEventHandler* seh = new osgPresentation::SlideEventHandler; - seh->set(presentation_node.get()); - presentation_node->setEventCallback(seh); - } - return presentation_node.release(); + return constructor.takePresentation(); } -