int main(int argc, char **argv) { osg::Timer_t startTick = osg::Timer::instance()->tick(); osg::ArgumentParser arguments(&argc, argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() + " application is utility tools which can be used to generate paged geospatial terrain databases."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName() + " [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help", "Display this information"); arguments.getApplicationUsage()->addCommandLineOption("--version", "Display version information"); arguments.getApplicationUsage()->addCommandLineOption("--cache <filename>", "Read the cache file to use a look up for locally cached files."); vpb::Commandline commandline; commandline.getUsage(*arguments.getApplicationUsage()); if (arguments.read("--version")) { std::cout << "VirtualPlanetBuilder/osgdem version " << vpbGetVersion() << std::endl; return 0; } if (arguments.read("--version-number")) { std::cout << vpbGetVersion() << std::endl; return 0; } std::string runPath; if (arguments.read("--run-path", runPath)) { vpb::chdir(runPath.c_str()); } // if user requests help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } // if user requests list of supported formats write it out to cout. if (arguments.read("--formats")) { std::cout << "Supported formats:" << std::endl; const vpb::System::SupportedExtensions &extensions = vpb::System::instance()->getSupportExtensions(); for (vpb::System::SupportedExtensions::const_iterator itr = extensions.begin(); itr != extensions.end(); ++itr) { std::cout << " " << itr->first << " :"; bool first = true; if (itr->second.acceptedTypeMask & vpb::Source::IMAGE) { std::cout << " imagery"; first = false; } if (itr->second.acceptedTypeMask & vpb::Source::HEIGHT_FIELD) { if (!first) std::cout << ","; std::cout << " dem"; first = false; } if (itr->second.acceptedTypeMask & vpb::Source::MODEL) { if (!first) std::cout << ","; std::cout << " model"; first = false; } if (itr->second.acceptedTypeMask & vpb::Source::SHAPEFILE) { if (!first) std::cout << ","; std::cout << " shapefile"; first = false; } std::cout << " : " << itr->second.description << std::endl; } return 1; } vpb::System::instance()->readArguments(arguments); std::string taskFileName; osg::ref_ptr<vpb::Task> taskFile; while (arguments.read("--task", taskFileName)) { if (!taskFileName.empty()) { taskFile = new vpb::Task(taskFileName); taskFile->read(); taskFile->setStatus(vpb::Task::RUNNING); taskFile->setProperty("pid", vpb::getProcessID()); taskFile->write(); } } osg::ref_ptr<osgTerrain::TerrainTile> terrain = 0; //std::cout<<"PID="<<getpid()<<std::endl; std::string sourceName; while (arguments.read("-s", sourceName)) { std::string fileName = osgDB::findDataFile(sourceName); if (fileName.empty()) { osg::notify(osg::NOTICE) << "Error: osgdem running on \"" << vpb::getLocalHostName() << "\", could not find source file \"" << sourceName << "\"" << std::endl; char str[2048]; if (vpb::getCurrentWorkingDirectory(str, sizeof(str))) { osg::notify(osg::NOTICE) << " current working directory at time of error = " << str << std::endl; } osg::setNotifyLevel(osg::DEBUG_INFO); osg::notify(osg::NOTICE) << " now setting NotifyLevel to DEBUG, and re-running find:" << std::endl; osg::notify(osg::NOTICE) << std::endl; fileName = osgDB::findDataFile(sourceName); if (!fileName.empty()) { osg::notify(osg::NOTICE) << std::endl << "Second attempt at finding source file successful!" << std::endl << std::endl; } else { osg::notify(osg::NOTICE) << std::endl << "Second attempt at finding source file also failed." << std::endl << std::endl; } osg::setNotifyLevel(osg::NOTICE); return 1; } osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(fileName); if (node.valid()) { osgTerrain::TerrainTile *loaded_terrain = dynamic_cast<osgTerrain::TerrainTile *>(node.get()); if (loaded_terrain) { terrain = loaded_terrain; } else { osg::notify(osg::NOTICE) << "Error: source file \"" << sourceName << "\" not suitable terrain data." << std::endl; return 1; } } else { osg::notify(osg::NOTICE) << "Error: unable to load source file \"" << sourceName << "\"" << std::endl; osg::notify(osg::NOTICE) << " the file was found as \"" << fileName << "\"" << std::endl; osg::notify(osg::NOTICE) << " now setting NotifyLevel to DEBUG, and re-running load:" << std::endl; osg::notify(osg::NOTICE) << std::endl; osg::setNotifyLevel(osg::DEBUG_INFO); osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(fileName); if (node.valid()) { osg::notify(osg::NOTICE) << std::endl; osg::notify(osg::NOTICE) << "Second attempt to load source file \"" << sourceName << "\" successful!" << std::endl << std::endl; } else { osg::notify(osg::NOTICE) << std::endl; osg::notify(osg::NOTICE) << "Second attempt to load source file \"" << sourceName << "\" also failed." << std::endl << std::endl; } osg::setNotifyLevel(osg::NOTICE); return 1; } } if (!terrain) terrain = new osgTerrain::TerrainTile; std::string terrainOutputName; while (arguments.read("--so", terrainOutputName)) { } bool report = false; while (arguments.read("--report")) { report = true; } int result = commandline.read(std::cout, arguments, terrain.get()); if (result) return result; // any options left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occured when parsing the program aguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return 1; } std::string xodrName = vpb::System::instance()->getXodrName(); VPBRoad *road = NULL; if (!xodrName.empty()) { //sleep(20); VPBRoad *road = new VPBRoad(xodrName); } if (!terrainOutputName.empty()) { if (terrain.valid()) { osgDB::writeNodeFile(*terrain, terrainOutputName); // make sure the OS writes changes to disk vpb::sync(); } else { osg::notify(osg::NOTICE) << "Error: unable to create terrain output \"" << terrainOutputName << "\"" << std::endl; } return 1; } double duration = 0.0; // generate the database if (terrain.valid()) { try { vpb::DatabaseBuilder *db = dynamic_cast<vpb::DatabaseBuilder *>(terrain->getTerrainTechnique()); vpb::BuildOptions *bo = db ? db->getBuildOptions() : 0; if (bo) { osg::setNotifyLevel(osg::NotifySeverity(bo->getNotifyLevel())); } osg::ref_ptr<vpb::DataSet> dataset = new vpb::DataSet; if (bo && !(bo->getLogFileName().empty())) { dataset->setBuildLog(new vpb::BuildLog(bo->getLogFileName())); } if (taskFile.valid()) { dataset->setTask(taskFile.get()); } dataset->addTerrain(terrain.get()); // make sure the OS writes changes to disk vpb::sync(); // check to make sure that the build itself is ready to run and configured correctly. std::string buildProblems = dataset->checkBuildValidity(); if (buildProblems.empty()) { result = dataset->run(); if (dataset->getBuildLog() && report) { dataset->getBuildLog()->report(std::cout); } duration = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); dataset->log(osg::NOTICE, "Elapsed time = %f", duration); if (taskFile.valid()) { taskFile->setStatus(vpb::Task::COMPLETED); } } else { dataset->log(osg::NOTICE, "Build configuration invalid : %s", buildProblems.c_str()); if (taskFile.valid()) { taskFile->setStatus(vpb::Task::FAILED); } } } catch (std::string str) { printf("Caught exception : %s\n", str.c_str()); if (taskFile.valid()) { taskFile->setStatus(vpb::Task::FAILED); } result = 1; } catch (...) { printf("Caught exception.\n"); if (taskFile.valid()) { taskFile->setStatus(vpb::Task::FAILED); } result = 1; } } if (duration == 0) duration = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); if (taskFile.valid()) { taskFile->setProperty("duration", duration); taskFile->write(); } // make sure the OS writes changes to disk vpb::sync(); delete road; return result; }
int main(int argc, char** argv) { osg::ref_ptr<vpb::TaskManager> taskManager = vpb::System::instance()->getTaskManager(); #ifndef _WIN32 taskManager->setSignalAction(SIGHUP, vpb::TaskManager::COMPLETE_RUNNING_TASKS_THEN_EXIT); taskManager->setSignalAction(SIGQUIT, vpb::TaskManager::TERMINATE_RUNNING_TASKS_THEN_EXIT); taskManager->setSignalAction(SIGKILL, vpb::TaskManager::TERMINATE_RUNNING_TASKS_THEN_EXIT); taskManager->setSignalAction(SIGUSR1, vpb::TaskManager::RESET_MACHINE_POOL); taskManager->setSignalAction(SIGUSR2, vpb::TaskManager::UPDATE_MACHINE_POOL); #endif taskManager->setSignalAction(SIGABRT, vpb::TaskManager::TERMINATE_RUNNING_TASKS_THEN_EXIT); taskManager->setSignalAction(SIGINT, vpb::TaskManager::TERMINATE_RUNNING_TASKS_THEN_EXIT); taskManager->setSignalAction(SIGTERM, vpb::TaskManager::TERMINATE_RUNNING_TASKS_THEN_EXIT); osg::Timer_t startTick = osg::Timer::instance()->tick(); osg::ArgumentParser arguments(&argc,argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" application is utility tools which can be used to generate paged geospatial terrain databases."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("--version","Display version information"); arguments.getApplicationUsage()->addCommandLineOption("--cache <filename>","Read the cache file to use a look up for locally cached files."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); if (arguments.read("--version")) { std::cout<<"VirtualPlanetBuilder/vpbmaster version "<<vpbGetVersion()<<std::endl; return 0; } if (arguments.read("--version-number")) { std::cout<<vpbGetVersion()<<std::endl; return 0; } // if user requests help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } int result = 0; try { std::string runPath; if (arguments.read("--run-path",runPath)) { vpb::chdir(runPath.c_str()); taskManager->setRunPath(runPath); } // if user requests list of supported formats write it out to cout. if (arguments.read("--formats")) { std::cout<<"Supported formats:"<<std::endl; const vpb::System::SupportedExtensions& extensions = vpb::System::instance()->getSupportExtensions(); for(vpb::System::SupportedExtensions::const_iterator itr = extensions.begin(); itr != extensions.end(); ++itr) { std::cout<<" "<<itr->first<<" :"; bool first = true; if (itr->second.acceptedTypeMask & vpb::Source::IMAGE) { std::cout<<" imagery"; first = false; } if (itr->second.acceptedTypeMask & vpb::Source::HEIGHT_FIELD) { if (!first) std::cout<<","; std::cout<<" dem"; first = false; } if (itr->second.acceptedTypeMask & vpb::Source::MODEL) { if (!first) std::cout<<","; std::cout<<" model"; first = false; } if (itr->second.acceptedTypeMask & vpb::Source::SHAPEFILE) { if (!first) std::cout<<","; std::cout<<" shapefile"; first = false; } std::cout<< " : "<<itr->second.description<<std::endl; } return 1; } vpb::System::instance()->readArguments(arguments); taskManager->read(arguments); bool buildWithoutSlaves = false; while (arguments.read("--build")) { buildWithoutSlaves=true; } std::string tasksOutputFileName; while (arguments.read("--to",tasksOutputFileName)); // any options left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occured when parsing the program aguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); taskManager->exit(SIGTERM); return 1; } if (!tasksOutputFileName.empty()) { std::string sourceFileName = taskManager->getBuildName() + std::string("_master.source"); taskManager->setSourceFileName(sourceFileName); taskManager->generateTasksFromSource(); taskManager->writeSource(tasksOutputFileName); taskManager->writeTasks(tasksOutputFileName, true); taskManager->exit(SIGTERM); return 1; } std::string buildProblems = taskManager->checkBuildValidity(); if (buildProblems.empty()) { if (buildWithoutSlaves) { taskManager->buildWithoutSlaves(); } else { if (!taskManager->hasTasks()) { std::string sourceFileName = taskManager->getBuildName() + std::string("_master.source"); tasksOutputFileName = taskManager->getBuildName() + std::string("_master.tasks"); taskManager->setSourceFileName(sourceFileName); if (!taskManager->generateTasksFromSource()) { // nothing to do. taskManager->exit(SIGTERM); return 1; } taskManager->writeSource(sourceFileName); taskManager->writeTasks(tasksOutputFileName, true); taskManager->log(osg::NOTICE,"Generated tasks file = %s",tasksOutputFileName.c_str()); vpb::DatabaseBuilder* db = dynamic_cast<vpb::DatabaseBuilder*>(taskManager->getSource()->getTerrainTechnique()); vpb::BuildOptions* buildOptions = (db && db->getBuildOptions()) ? db->getBuildOptions() : 0; if (buildOptions) { std::stringstream sstr; sstr << buildOptions->getDirectory() <<buildOptions->getDestinationTileBaseName()<<buildOptions->getDestinationTileExtension()<<"."<<buildOptions->getRevisionNumber()<<".source"; taskManager->writeSource(sstr.str()); taskManager->log(osg::NOTICE,"Revsion source = %s",sstr.str().c_str()); } } // make sure the OS writes changes to disk vpb::sync(); if (taskManager->hasMachines()) { if(!taskManager->run()) { result = 1; } } else { taskManager->log(osg::NOTICE,"Cannot run build without machines assigned, please pass in a machines definition file via --machines <file>."); } } } else { taskManager->log(osg::NOTICE,"Build configuration invalid : %s",buildProblems.c_str()); result = 1; } double duration = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); taskManager->log(osg::NOTICE,"Total elapsed time = %f",duration); } catch(std::string str) { taskManager->log(osg::NOTICE,"Caught exception : %s",str.c_str()); result = 1; } catch(...) { taskManager->log(osg::NOTICE,"Caught exception."); result = 1; } // make sure the OS writes changes to disk vpb::sync(); taskManager->log(osg::NOTICE,"Run Complete."); taskManager->exit(SIGTERM); return result; }
int main(int argc, char **argv) { osg::ArgumentParser arguments(&argc, argv); // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() + " application is utility tools which can be used to generate paged geospatial terrain databases."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName() + " [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help", "Display this information"); arguments.getApplicationUsage()->addCommandLineOption("--version", "Display version information"); arguments.getApplicationUsage()->addCommandLineOption("--clean", "Clear the contents of the file cache"); arguments.getApplicationUsage()->addCommandLineOption("--cache", "Specify cache file to use"); arguments.getApplicationUsage()->addCommandLineOption("--reproject", "Carry out reprojections required for specified build sources."); arguments.getApplicationUsage()->addCommandLineOption("--add", "Add files from specified build sources to file cache."); arguments.getApplicationUsage()->addCommandLineOption("--overviews", "Build overviews for the source data."); arguments.getApplicationUsage()->addCommandLineOption("--report", "Report the contents of the file cache"); vpb::Commandline commandline; // if user requests help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); return 1; } if (arguments.read("--version")) { std::cout << "VirtualPlanetBuilder/vpbcache version " << vpbGetVersion() << std::endl; return 0; } if (arguments.read("--version-number")) { std::cout << vpbGetVersion() << std::endl; return 0; } // read any source input definitions osg::ref_ptr<osgTerrain::TerrainTile> terrain = new osgTerrain::TerrainTile; std::string filename; if (arguments.read("-s", filename)) { osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filename); if (node.valid()) { osgTerrain::TerrainTile *loaded_terrain = dynamic_cast<osgTerrain::TerrainTile *>(node.get()); if (loaded_terrain) { terrain = loaded_terrain; } else { vpb::log(osg::WARN, "Error: source file \"%s\" not suitable terrain data.", filename.c_str()); return 1; } } else { vpb::log(osg::WARN, "Error: unable to load source file \"%s\" not suitable terrain data.", filename.c_str()); return 1; } } int result = commandline.read(std::cout, arguments, terrain.get()); if (result) return result; vpb::System::instance()->readArguments(arguments); vpb::FileCache *fileCache = vpb::System::instance()->getFileCache(); if (!fileCache) { vpb::log(osg::WARN, "Error: no valid cache file specificed, please set one using --cache <filename> on command line."); return 1; } if (arguments.read("--clear")) { fileCache->clear(); } if (arguments.read("--add")) { fileCache->addSource(terrain.get()); } if (arguments.read("--reproject")) { fileCache->buildRequiredReprojections(terrain.get()); } if (arguments.read("--overviews")) { fileCache->buildOverviews(terrain.get()); } std::string machineName; while (arguments.read("--mirror", machineName)) { if (!vpb::System::instance()->getMachinePool()) { vpb::log(osg::WARN, "Error: no valid machines file specified, please set one using --machines <filename> on command line."); return 1; } vpb::Machine *machine = vpb::System::instance()->getMachinePool()->getMachine(machineName); if (machine) { fileCache->mirror(machine, terrain.get()); } else { osg::notify(osg::NOTICE) << "No suitable machine found" << std::endl; } } fileCache->sync(); if (arguments.read("--report")) { fileCache->report(std::cout); } // make sure the OS writes changes to disk vpb::sync(); // any options left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occured when parsing the program aguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return 1; } return 0; }