From Don Tidrow, Added support for locally referenced origins.

This commit is contained in:
Robert Osfield
2005-09-27 14:48:09 +00:00
parent 600349dce8
commit 2092016c7b
6 changed files with 140 additions and 67 deletions

View File

@@ -2,6 +2,7 @@
#include <osg/Object>
#include <osg/Node>
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osgDB/Registry>
#include <osgDB/FileUtils>
#include <iostream>
@@ -94,6 +95,15 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin
pagedLOD->setNumChildrenThatCannotBeExpired(1);
pagedLOD->setTileId(x,y,lod);
const trpgHeader* header = archive->GetHeader();
trpgHeader::trpgTileType tileType;
header->GetTileOriginType(tileType);
if(tileType == trpgHeader::TileLocal)
{
osg::Vec3d sw(info.bbox._min);
pagedLOD->setCenter(info.center - sw);
}
return pagedLOD.get();
}
else
@@ -114,54 +124,89 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin
int sizeX, sizeY;
archive->getLODSize(lod+1,sizeX,sizeY);
const trpgHeader* header = archive->GetHeader();
trpgHeader::trpgTileType tileType;
header->GetTileOriginType(tileType);
TXPArchive::TileInfo parentInfo;
archive->getTileInfo(x,y,lod,parentInfo);
for (int ix = 0; ix < 2; ix++)
for (int iy = 0; iy < 2; iy++)
{
int tileX = x*2+ix;
int tileY = y*2+iy;
int tileLOD = lod+1;
TXPArchive::TileInfo info;
if (!archive->getTileInfo(tileX,tileY,tileLOD,info))
continue;
osg::ref_ptr<osg::Node> tileContent = getTileContent(info,tileX,tileY,tileLOD,archive);
tileContent->setName("TileContent");
if (tileLOD < (numLods-1))
for (int iy = 0; iy < 2; iy++)
{
char pagedLODfile[1024];
sprintf(pagedLODfile,"%s\\subtiles%d_%dx%d_%d.txp",
archive->getDir(),
tileLOD,
tileX,
tileY,
archive->getId()
);
int tileX = x*2+ix;
int tileY = y*2+iy;
int tileLOD = lod+1;
osg::ref_ptr<TXPPagedLOD> pagedLOD = new TXPPagedLOD;
// not use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out.
pagedLOD->addChild(tileContent.get(),info.minRange,osg::maximum(info.maxRange,1e7));
pagedLOD->setFileName(1,pagedLODfile);
pagedLOD->setRange(1,0,info.minRange);
pagedLOD->setCenter(info.center);
pagedLOD->setRadius(info.radius);
pagedLOD->setPriorityOffset(0,numLods-lod);
pagedLOD->setPriorityScale(0,1.0f);
pagedLOD->setNumChildrenThatCannotBeExpired(1);
pagedLOD->setTileId(tileX,tileY,tileLOD);
TXPArchive::TileInfo info;
if (!archive->getTileInfo(tileX,tileY,tileLOD,info))
continue;
osg::ref_ptr<osg::Node> tileContent = getTileContent(info,tileX,tileY,tileLOD,archive);
tileContent->setName("TileContent");
if (tileLOD < (numLods-1))
{
char pagedLODfile[1024];
sprintf(pagedLODfile,"%s\\subtiles%d_%dx%d_%d.txp",
archive->getDir(),
tileLOD,
tileX,
tileY,
archive->getId()
);
osg::ref_ptr<TXPPagedLOD> pagedLOD = new TXPPagedLOD;
// not use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out.
pagedLOD->addChild(tileContent.get(),info.minRange,osg::maximum(info.maxRange,1e7));
pagedLOD->setFileName(1,pagedLODfile);
pagedLOD->setRange(1,0,info.minRange);
pagedLOD->setCenter(info.center);
pagedLOD->setRadius(info.radius);
pagedLOD->setPriorityOffset(0,numLods-lod);
pagedLOD->setPriorityScale(0,1.0f);
pagedLOD->setNumChildrenThatCannotBeExpired(1);
pagedLOD->setTileId(tileX,tileY,tileLOD);
if(tileType == trpgHeader::TileLocal)
{
osg::Vec3d center(info.center - parentInfo.bbox._min);
osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min);
sw[2] = 0.0;
pagedLOD->setCenter(center - sw);
osg::Matrix offset;
offset.setTrans(sw);
osg::MatrixTransform *tform = new osg::MatrixTransform(offset);
tform->addChild(pagedLOD.get());
subtiles->addChild(tform);
}
else
subtiles->addChild(pagedLOD.get());
}
else
{
subtiles->setUserData(new TileIdentifier(tileX,tileY,tileLOD));
if(tileType == trpgHeader::TileLocal)
{
osg::Vec3d center(info.center - parentInfo.bbox._min);
osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min);
sw[2] = 0.0;
osg::Matrix offset;
offset.setTrans(sw);
osg::MatrixTransform *tform = new osg::MatrixTransform(offset);
tform->addChild(tileContent.get());
subtiles->addChild(tform);
}
else
subtiles->addChild(tileContent.get());
}
subtiles->addChild(pagedLOD.get());
}
else
{
subtiles->setUserData(new TileIdentifier(tileX,tileY,tileLOD));
subtiles->addChild(tileContent.get());
}
}
//osg::notify(osg::NOTICE) << "Subtiles for " << x << " " << y << " " << lod << " lodaded" << std::endl;
return subtiles.get();
@@ -185,11 +230,11 @@ TXPArchive *ReaderWriterTXP::getArchive(int id, const std::string& dir)
if (archive == NULL)
{
#ifdef _WIN32
const char _PATHD = '\\';
const char _PATHD = '\\';
#elif defined(macintosh)
const char _PATHD = ':';
const char _PATHD = ':';
#else
const char _PATHD = '/';
const char _PATHD = '/';
#endif
std::string archiveName = dir+_PATHD+"archive.txp";
archive = new TXPArchive;
@@ -338,14 +383,9 @@ osg::Node* SeamFinder::seamReplacement(osg::Node* node)
if (delta.y()<0.0) --dy; // south
else ++dy; // north
}
TXPSeamLOD* seam = new TXPSeamLOD(
_x,
_y,
lod,
dx,
dy
);
seam->addChild(loRes->getChild(0)); // low res
TXPSeamLOD* seam = new TXPSeamLOD(_x, _y, lod, dx, dy);
seam->addChild(loRes->getChild(0)); // low res
if (hiRes)
{
seam->addChild(hiRes->getChild(0)); // high res

View File

@@ -49,6 +49,18 @@ TXPArchive::~TXPArchive()
}
void TXPArchive::getExtents(osg::BoundingBox& extents)
{
TileInfo sw, ne;
trpg2iPoint tileExtents;
this->GetHeader()->GetLodSize(0, tileExtents);
this->getTileInfo(0, 0, 0, sw);
this->getTileInfo(tileExtents.x-1, tileExtents.y-1, 0, ne);
extents.set(sw.bbox._min, sw.bbox._max);
extents.expandBy(ne.bbox);
}
bool TXPArchive::openFile(const std::string& archiveName)
{

View File

@@ -103,9 +103,9 @@ public:
osg::Vec3 center;
double minRange;
double maxRange;
double lod0Range;
double lod0Range;
float radius;
osg::Vec3 size;
osg::Vec3 size;
osg::BoundingBox bbox;
};
bool getTileInfo(int x, int y, int lod, TileInfo& info);
@@ -127,10 +127,11 @@ public:
}
// Returns the extents of the archive
inline void getExtents(osg::BoundingBox& extents)
{
extents.set(_swExtents.x,_swExtents.y,0.0f,_neExtents.x,_neExtents.y,0.0f);
}
// FIXME - Needs to change for databases that aren't flat-earth
void getExtents(osg::BoundingBox& extents);
// {
// extents.set(_swExtents.x,_swExtents.y,0.0f,_neExtents.x,_neExtents.y,0.0f);
// }
// Returns the origin of the archive
inline void getOrigin(double& x, double& y)

View File

@@ -2,6 +2,7 @@
#include <osg/BoundingBox>
#include <osg/PagedLOD>
#include <osg/Timer>
#include <osg/MatrixTransform>
#include <osgUtil/CullVisitor>
#include <iostream>
@@ -51,8 +52,8 @@ void TXPNode::traverse(osg::NodeVisitor& nv)
{
switch(nv.getVisitorType())
{
case osg::NodeVisitor::CULL_VISITOR:
{
case osg::NodeVisitor::CULL_VISITOR:
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
if (cv)
@@ -91,11 +92,11 @@ void TXPNode::traverse(osg::NodeVisitor& nv)
updateEye(nv);
break;
}
case osg::NodeVisitor::UPDATE_VISITOR:
}
case osg::NodeVisitor::UPDATE_VISITOR:
updateSceneGraph();
break;
default:
default:
break;
}
Group::traverse(nv);
@@ -244,9 +245,28 @@ osg::Node* TXPNode::addPagedLODTile(int x, int y, int lod)
pagedLOD->setRadius(info.radius);
pagedLOD->setNumChildrenThatCannotBeExpired(1);
_nodesToAdd.push_back(pagedLOD);
return pagedLOD;
const trpgHeader* header = _archive->GetHeader();
trpgHeader::trpgTileType tileType;
header->GetTileOriginType(tileType);
if(tileType == trpgHeader::TileLocal)
{
// add in MatrixTransform node with Matrixd offsets
// get offsets from tile.bbox
osg::Vec3d sw(info.bbox._min);
sw[2] = 0.0;
osg::Matrix offset;
offset.setTrans(sw);
osg::MatrixTransform *tform = new osg::MatrixTransform(offset);
pagedLOD->setCenter(info.center - sw);
tform->addChild(pagedLOD);
_nodesToAdd.push_back(tform);
return tform;
}
else
{
_nodesToAdd.push_back(pagedLOD);
return pagedLOD;
}
}
void TXPNode::updateSceneGraph()

View File

@@ -1,3 +1,4 @@
// -*-c++-*-
/***************************************************************************
* December 2003
*

View File

@@ -1122,7 +1122,6 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
osg::ref_ptr<osg::Geometry> geometry;
// Get texture coordinates
;
int num_tex;
geom.GetNumTexCoordSets(num_tex);
std::vector< osg::ref_ptr<osg::Vec2Array> > tex_coords(num_tex);