Added osg::PagedLOD and osgProducer::DatabasePager class, and linked up osgProducer::Viewer

to manage the pager.
This commit is contained in:
Robert Osfield
2003-07-08 14:44:00 +00:00
parent 9239173019
commit c2eabe1d4b
21 changed files with 810 additions and 59 deletions

View File

@@ -34,6 +34,7 @@ CXXFILES =\
Node.cpp\
Object.cpp\
OccluderNode.cpp\
PagedLOD.cpp\
Point.cpp\
PolygonMode.cpp\
PolygonOffset.cpp\

View File

@@ -0,0 +1,125 @@
#include "osg/PagedLOD"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool PagedLOD_readLocalData(Object& obj, Input& fr);
bool PagedLOD_writeLocalData(const Object& obj, Output& fw);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_PagedLODProxy
(
new osg::PagedLOD,
"PagedLOD",
"Object Node LOD PagedLOD",
&PagedLOD_readLocalData,
&PagedLOD_writeLocalData
);
bool PagedLOD_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
PagedLOD& lod = static_cast<PagedLOD&>(obj);
bool matchFirst;
if ((matchFirst=fr.matchSequence("FileNameList {")) || fr.matchSequence("FileNameList %i {"))
{
// set up coordinates.
int entry = fr[0].getNoNestedBrackets();
int capacity;
if (matchFirst)
{
fr += 2;
}
else if (fr[1].getInt(capacity))
{
lod.getFileNameList().reserve(capacity);
fr += 3;
}
unsigned int i=0;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
if (fr[0].isString() || fr[0].isQuotedString())
{
if (fr[0].getStr()) lod.setFileName(i,fr[0].getStr());
else lod.setFileName(i,"");
++fr;
++i;
}
else
{
++fr;
}
}
iteratorAdvanced = true;
++fr;
}
int num_children;
if (fr[0].matchWord("num_children") &&
fr[1].getInt(num_children))
{
// could allocate space for children here...
fr+=2;
iteratorAdvanced = true;
}
Node* node = NULL;
while((node=fr.readNode())!=NULL)
{
lod.addChild(node);
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
bool PagedLOD_writeLocalData(const Object& obj, Output& fw)
{
const PagedLOD& lod = static_cast<const PagedLOD&>(obj);
fw.indent() << "FileNameList "<<lod.getNumFileNames()<<" {"<< std::endl;
fw.moveIn();
unsigned int numChildrenToWriteOut = 0;
for(unsigned int i=0; i<lod.getNumFileNames();++i)
{
if (lod.getFileName(i).empty())
{
fw.indent() << "\"\"" << std::endl;
++numChildrenToWriteOut;
}
else
{
fw.indent() << lod.getFileName(i) << std::endl;
}
}
fw.moveOut();
fw.indent() << "}"<< std::endl;
fw.indent() << "num_children " << numChildrenToWriteOut << std::endl;
for(unsigned int i=0;i<lod.getNumChildren();++i)
{
if (lod.getFileName(i).empty())
{
fw.writeObject(*lod.getChild(i));
}
}
return true;
}