Hi Ralf,
You'll need to write a custom NodeVisitor that traverses through the loaded
scene graph and picks out the TerrainTile using dyanmic cast. It just so
happens that I'm actually working on a ReadFileCallback/custom Visitor that
does pick out all the TerrainTile's in a subgraph (there will typically be
one, two or four due to the quad tree structure generated by VPB.)
The visitor looks like:
class FindTerrainTileVisitor : public osg::NodeVisitor
{
public:
FindTerrainTileVisitor():
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
}
void reset()
{
_terrainTiles.clear();
}
void apply(osg::Group& group)
{
osgTerrain::TerrainTile* terrainTile =
dynamic_cast<osgTerrain::TerrainTile*>(&group);
if (terrainTile)
{
_terrainTiles.push_back(terrainTile);
}
else
{
traverse(group);
}
}
typedef std::list< osg::ref_ptr<osgTerrain::TerrainTile> > TerrainTiles;
TerrainTiles _terrainTiles;
};
The custom ReadFileCallback's readNode method looks like:
virtual osgDB::ReaderWriter::ReadResult readNode(const std::string&
filename, const osgDB::ReaderWriter::Options* options)
{
osg::notify(osg::NOTICE)<<"Loading tile "<<filename<<std::endl;
osgDB::ReaderWriter::ReadResult result =
osgDB::Registry::instance()->readNodeImplementation(filename,options);
if (result.validNode())
{
FindTerrainTileVisitor fttv;
result.getNode()->accept(fttv);
for(FindTerrainTileVisitor::TerrainTiles::iterator itr =
fttv._terrainTiles.begin();
itr != fttv._terrainTiles.end();
++itr)
{
osgTerrain::TerrainTile* terrainTile = itr->get();
///.... my stuff omitted, put your stuff here
}
}
}
Robert.
On Thu, Apr 2, 2009 at 1:05 PM, Ralf Stokholm <[email protected]>wrote:
> Hi List
>
> Im trying to get the heightfiled data from a VPB terrain using
> ReadFileCallback.
>
> I use the code from readfile callback like this.
>
> class MyReadFileCallback : public osgDB::Registry::ReadFileCallback
> {
> public:
> virtual osgDB::ReaderWriter::ReadResult readNode(const
> std::string& fileName, const osgDB::ReaderWriter::Options* options)
> {
> // note when calling the Registry to do the read you have to
> call readNodeImplementation NOT readNode, as this will
> // cause on infinite recusive loop.
> osgDB::ReaderWriter::ReadResult result =
> osgDB::Registry::instance()->readNodeImplementation(fileName,options);
> if (result.validHeightField())
> {
> LOG_ERROR("Found a valid HeightField");
> }
> return result;
> }
> };
>
> The idea was simply to see if I had the heightfield available, but
> even though I have verified that it gets called it is never a valid
> heightfield.
>
> This is on a terrain build using VPB with the --TERRAIN option.
>
> Shouldent I be able to get the heightfieldnodes?
>
> Brgs.
>
> Ralf Stokholm
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org