Added support for tracking the directory of the output file whilst still maintaining

local file references within this directory.
This commit is contained in:
Robert Osfield 2005-10-27 10:48:44 +00:00
parent 601ac461a2
commit d2487e73e5
3 changed files with 40 additions and 18 deletions

View File

@ -264,8 +264,7 @@ int main( int argc, char **argv )
std::string archiveName;
while (arguments.read("-a",archiveName)) { dataset->setArchiveName(archiveName); }
dataset->setDestinationTileBaseName("output");
dataset->setDestinationTileExtension(".ive");
dataset->setDestinationName("output.ive");
unsigned int numLevels = 10;
@ -573,14 +572,7 @@ int main( int argc, char **argv )
else if (arguments.read(pos, "-o",filename))
{
std::cout<<"-o "<<filename<<std::endl;
std::string path = osgDB::getFilePath(filename);
std::string base = path.empty()?osgDB::getStrippedName(filename):
path +'/'+ osgDB::getStrippedName(filename);
std::string extension = '.'+osgDB::getLowerCaseFileExtension(filename);
dataset->setDestinationTileBaseName(base);
dataset->setDestinationTileExtension(extension);
dataset->setDestinationName(filename);
if (!currentCS.empty()) dataset->setDestinationCoordinateSystem(currentCS);

View File

@ -974,9 +974,12 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
/** Get the Archive if one is to being used.*/
osgDB::Archive* getArchive() { return _archive.get(); }
/** Set the DestinationTileBaseName and DestinationTileExtension from the passed in filename.*/
/** Set the Directory, DestinationTileBaseName and DestinationTileExtension from the passed in filename.*/
void setDestinationName(const std::string& filename);
void setDirectory(const std::string& directory);
const std::string& getDirectory() const { return _directory; }
void setDestinationTileBaseName(const std::string& basename) { _tileBasename = basename; }
const std::string& getDestinationTileBaseName() const { return _tileBasename; }
@ -1126,6 +1129,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
osg::BoundingBox _extents;
std::string _archiveName;
osg::ref_ptr<osgDB::Archive> _archive;
std::string _directory;
std::string _tileBasename;
std::string _tileExtension;
std::string _imageExtension;

View File

@ -3742,14 +3742,41 @@ 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 base = osgDB::getStrippedName(filename);
std::string extension = '.'+osgDB::getLowerCaseFileExtension(filename);
osg::notify(osg::NOTICE)<<"setDestinationName("<<filename<<")"<<std::endl;
osg::notify(osg::NOTICE)<<" path "<<path<<std::endl;
osg::notify(osg::NOTICE)<<" base "<<base<<std::endl;
osg::notify(osg::NOTICE)<<" extension "<<extension<<std::endl;
setDirectory(path);
setDestinationTileBaseName(base);
setDestinationTileExtension(extension);
}
void DataSet::setDirectory(const std::string& directory)
{
_directory = directory;
if (_directory.empty()) return;
#ifdef WIN32
// convert trailing forward slash if any to back slash.
if (_directory[_directory.size()-1]=='/') _directory[_directory.size()-1] = '\\';
// if no trailing back slash exists add one.
if (_directory[_directory.size()-1]!='\\') _directory.push_back('\\');
#else
// convert trailing back slash if any to forward slash.
if (_directory[_directory.size()-1]=='\\') _directory[_directory.size()-1] = '/';
// if no trailing forward slash exists add one.
if (_directory[_directory.size()-1]!='/') _directory.push_back('/');
#endif
osg::notify(osg::NOTICE)<<"directory name set "<<_directory<<std::endl;
}
void DataSet::addSource(Source* source)
{
if (!source) return;
@ -4414,7 +4441,7 @@ public:
if (image)
{
_dataSet->_writeImageFile(*image,image->getFileName().c_str());
_dataSet->_writeImageFile(*image,(_dataSet->getDirectory()+image->getFileName()).c_str());
}
}
}
@ -4435,7 +4462,7 @@ void DataSet::_writeRow(Row& row)
if (!parent->getSubTilesGenerated() && parent->areSubTilesComplete())
{
osg::ref_ptr<osg::Node> node = parent->createSubTileScene();
std::string filename = parent->getSubTileName();
std::string filename = _directory+parent->getSubTileName();
if (node.valid())
{
my_notify(osg::NOTICE)<<" writeSubTile filename="<<filename<<std::endl;
@ -4475,8 +4502,7 @@ void DataSet::_writeRow(Row& row)
node->addDescription(_comment);
}
//std::string filename = cd->_name + _tileExtension;
std::string filename = _tileBasename+_tileExtension;
std::string filename = _directory+_tileBasename+_tileExtension;
if (node.valid())
{
@ -4566,7 +4592,7 @@ void DataSet::_buildDestination(bool writeToDisk)
if (_destinationGraph.valid())
{
std::string filename = _tileBasename+_tileExtension;
std::string filename = _directory+_tileBasename+_tileExtension;
if (_archive.valid())
{