Added convinience methods.

This commit is contained in:
Robert Osfield 2004-09-10 13:31:37 +00:00
parent 6b2e17fe14
commit e5ea972cff
2 changed files with 68 additions and 10 deletions

View File

@ -47,7 +47,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
{
public:
static std::string coordinateSystemStringToWTK(const std::string& coordinateSystem);
class Source;
@ -232,6 +232,17 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
void setGeoTransform(osg::Matrixd& transform) { _geoTransform = transform; }
osg::Matrixd& getGeoTransform() { return _geoTransform; }
void setGeoTransformFromRange(double xMin, double xMax, double yMin, double yMax)
{
_geoTransform.makeIdentity();
_geoTransform(0,0) = xMax-xMin;
_geoTransform(3,0) = xMin;
_geoTransform(1,1) = yMax-yMin;
_geoTransform(3,1) = yMin;
}
void assignCoordinateSystemAndGeoTransformAccordingToParameterPolicy();
@ -914,7 +925,10 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
void setDestinationExtents(const osg::BoundingBox& extents) { _extents = extents; }
void setDestinationGeoTransform(const osg::Matrixd& geoTransform) { _geoTransform = geoTransform; }
/** Set the DestinationTileBaseName and DestinationTileExtension from the passed in filename.*/
void setDestinationName(const std::string& filename);
void setDestinationTileBaseName(const std::string& basename) { _tileBasename = basename; }
const std::string& getDestinationTileBaseName() const { return _tileBasename; }
@ -990,10 +1004,10 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
void populateDestinationGraphFromSources();
void createDestination(unsigned int numLevels);
void writeDestination();
void buildDestination() { _buildDestination(false); }
void writeDestination() { _buildDestination(true); }
osg::Node* getDestinationRootNode() { return _rootNode.get(); }
@ -1005,11 +1019,13 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
void _readRow(Row& row);
void _equalizeRow(Row& row);
void _writeRow(Row& row);
osg::Node* decorateWithCoordinateSystemNode(osg::Node* subgraph);
void _buildDestination(bool writeToDisk);
void init();
osg::Node* decorateWithCoordinateSystemNode(osg::Node* subgraph);
osg::ref_ptr<CompositeSource> _sourceGraph;
osg::ref_ptr<CompositeDestination> _destinationGraph;

View File

@ -44,6 +44,33 @@
using namespace osgTerrain;
std::string osgTerrain::DataSet::coordinateSystemStringToWTK(const std::string& coordinateSystem)
{
std::string wtkString;
CPLErrorReset();
OGRSpatialReferenceH hSRS = OSRNewSpatialReference( NULL );
if( OSRSetFromUserInput( hSRS, coordinateSystem.c_str() ) == OGRERR_NONE )
{
char *pszResult = NULL;
OSRExportToWkt( hSRS, &pszResult );
if (pszResult) wtkString = pszResult;
CPLFree(pszResult);
}
else
{
osg::notify(osg::WARN)<<"Warning: coordinateSystem string not recognised."<<std::endl;
}
OSRDestroySpatialReference( hSRS );
return wtkString;
}
enum CoordinateSystemType
{
@ -2987,6 +3014,17 @@ void DataSet::init()
}
}
void DataSet::setDestinationName(const std::string& filename)
{
std::string path = osgDB::getFilePath(filename);
std::string base = path.empty()?osgDB::getStrippedName(filename):
path +'/'+ osgDB::getStrippedName(filename);
std::string extension = '.'+osgDB::getLowerCaseFileExtension(filename);
setDestinationTileBaseName(base);
setDestinationTileExtension(extension);
}
void DataSet::addSource(Source* source)
{
if (!source) return;
@ -3612,6 +3650,10 @@ void DataSet::_writeRow(Row& row)
{
osg::notify(osg::WARN)<<" faild to write node for tile = "<<cd->_level<<" X="<<cd->_tileX<<" Y="<<cd->_tileY<<" filename="<<filename<<std::endl;
}
// record the top nodes as the rootNode of the database
_rootNode = node;
}
}
}
@ -3648,7 +3690,7 @@ osg::Node* DataSet::decorateWithCoordinateSystemNode(osg::Node* subgraph)
}
void DataSet::writeDestination()
void DataSet::_buildDestination(bool writeToDisk)
{
if (_destinationGraph.valid())
{
@ -3670,7 +3712,7 @@ void DataSet::writeDestination()
_rootNode->addDescription(_comment);
}
osgDB::writeNodeFile(*_rootNode,filename);
if (writeToDisk) osgDB::writeNodeFile(*_rootNode,filename);
}
else // _databaseType==PagedLOD_DATABASE
{
@ -3703,7 +3745,7 @@ void DataSet::writeDestination()
}
_equalizeRow(prev_itr->second);
_writeRow(prev_itr->second);
if (writeToDisk) _writeRow(prev_itr->second);
}
}
osg::notify(osg::NOTICE)<<"completed DataSet::writeDestination("<<filename<<")"<<std::endl;