From 247327ef31dec859cec48c46159daacd12e10dd3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 14 Jul 2005 21:04:40 +0000 Subject: [PATCH] Updates --- examples/osgpagedlod/osgpagedlod.cpp | 89 ++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/examples/osgpagedlod/osgpagedlod.cpp b/examples/osgpagedlod/osgpagedlod.cpp index 1ce8304bf..19e04ebaa 100644 --- a/examples/osgpagedlod/osgpagedlod.cpp +++ b/examples/osgpagedlod/osgpagedlod.cpp @@ -10,12 +10,54 @@ #include #include #include +#include #include #include #include +class NameVistor : public osg::NodeVisitor +{ +public: + NameVistor(): + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), + _count(0) + { + } + + virtual void apply(osg::Node& node) + { + std::ostringstream os; + os << node.className() << "_"<<_count++; + + node.setName(os.str()); + + traverse(node); + } + + unsigned int _count; +}; + +class CheckVisitor : public osg::NodeVisitor +{ +public: + CheckVisitor(): + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) + { + } + + virtual void apply(osg::PagedLOD& plod) + { + std::cout<<"PagedLOD "<getNumRanges()<2) + { + osg::notify(osg::NOTICE)<<"Leaving LOD with one child as is."<getRangeList(); - typedef std::map< osg::LOD::MinMaxPair , unsigned int > MinMaxPairMap; + typedef std::multimap< osg::LOD::MinMaxPair , unsigned int > MinMaxPairMap; MinMaxPairMap rangeMap; unsigned int pos = 0; for(osg::LOD::RangeList::const_iterator ritr = originalRangeList.begin(); ritr != originalRangeList.end(); ++ritr, ++pos) { - rangeMap[*ritr] = pos; + rangeMap.insert(std::multimap< osg::LOD::MinMaxPair , unsigned int >::value_type(*ritr, pos)); } pos = 0; @@ -105,10 +154,9 @@ public: mitr != rangeMap.rend(); ++mitr, ++pos) { - if (pos==0) + if (pos==0 && !_makeAllChildrenPaged) { plod->addChild(lod->getChild(mitr->second), mitr->first.first, mitr->first.second); - osg::notify(osg::NOTICE)<<" adding staight child"<addChild(lod->getChild(mitr->second), mitr->first.first, mitr->first.second, os.str()); - osg::notify(osg::NOTICE)<<" adding tiled subgraph"<setCenter(plod->getBound().center()); - plod->setCenter(plod->getBound().center()); + } } @@ -140,7 +187,7 @@ public: LODSet _lodSet; std::string _basename; std::string _extension; - + bool _makeAllChildrenPaged; }; @@ -155,6 +202,8 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" creates a hierachy of files for paging which can be later loaded by viewers."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + arguments.getApplicationUsage()->addCommandLineOption("-o","set the output file (defaults to output.ive)"); + arguments.getApplicationUsage()->addCommandLineOption("--makeAllChildrenPaged","Force all children of LOD to be written out as external PagedLOD children"); // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) @@ -163,6 +212,13 @@ int main( int argc, char **argv ) return 1; } + std::string outputfile("output.ive"); + while (arguments.read("-o",outputfile)) {} + + + bool makeAllChildrenPaged = false; + while (arguments.read("--makeAllChildrenPaged")) { makeAllChildrenPaged = true; } + // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); @@ -188,13 +244,22 @@ int main( int argc, char **argv ) return 1; } - ConvertToPageLODVistor converter("tile",".ive"); + std::string basename( osgDB::getNameLessExtension(outputfile) ); + std::string ext = '.'+ osgDB::getFileExtension(outputfile); + + ConvertToPageLODVistor converter(basename,ext, makeAllChildrenPaged); model->accept(converter); converter.convert(); + NameVistor nameNodes; + model->accept(nameNodes); + + //CheckVisitor checkNodes; + //model->accept(checkNodes); + if (model.valid()) { - osgDB::writeNodeFile(*model,"tile.ive"); + osgDB::writeNodeFile(*model,outputfile); WriteOutPagedLODSubgraphsVistor woplsv; model->accept(woplsv);