#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Will have to replace these // #include using namespace geoworld; using namespace mars; using namespace std; using namespace genesis; namespace po = boost::program_options; template< typename T > ostream & operator << (ostream & print, const BBox< T > & bbox) { print << "[" << bbox.left << "x" << bbox.top << ", " << bbox.right << "x" << bbox.bottom << "]"; return print; } class ConsoleListener : public geoworld::ISynthesisSessionListener { public: virtual void onRaster( GeoWorld * const pWorld ) { cout << "Rastering..." << std::endl; } virtual void onRejects( GeoWorld * const pWorld, const MorphList & rejects ) { cout << "Rejects: " << std::endl; for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i) cout << "\t- " << (*i)->getTypeName() << std::endl; cout << std::endl; } virtual void onInitMorph( GeoWorld * const pWorld, const GeoMorph * pMorph ) { cout << "Initialize Morph: " << pMorph->getTypeName(); const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph); if (NULL != pBGM) { cout << ", bbox=" << pBGM->getBBox(); } cout << std::endl; } virtual void onGenerate( GeoWorld * const pWorld ) { cout << "Generating world at LOD " << pWorld->getLOD() << std::endl; } virtual void onDoMorph (GeoWorld * const pWorld, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal) { cout << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal << std::endl; } virtual void onCreateMiddleTier (GeoWorld * const pWorld, const std::string & sFileName) { cout << "Generating Pageable-World File \"" << sFileName << "\"" << std::endl; } virtual void onGenerateMiddleTier (GeoWorld * const pWorld, const PagedGeoWorld * const pPgWorld) { cout << "Dumping a sample" << std::endl; const LockedGWSection * pSection = pPgWorld->lockro(-500, -500, 2000, 1000); *pSection >> GLOBALDEM; DUMP_GLOBALDEM(); pPgWorld->unlock(pSection); } virtual void onPrepareMorphs( GeoWorld * const pWorld, const MorphList & morphs ) { cout << "Chosen morphs: " << std::endl; for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i) cout << "\t- " << (*i)->getTypeName() << std::endl; cout << std::endl; } virtual void onPrepareMorphs2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & morphs ) { cout << "P" << nPass << ": " << "Chosen morphs: " << std::endl; for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i) cout << "\t- " << (*i)->getTypeName() << std::endl; cout << std::endl; } virtual void onInitMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const GeoMorph * pMorph ) { cout << "P" << nPass << ": " << "Initialize Morph: " << pMorph->getTypeName(); const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph); if (NULL != pBGM) { cout << ", bbox=" << pBGM->getBBox(); } cout << std::endl; } virtual void onDoMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal ) { cout << "P" << nPass << ": " << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal << std::endl; } virtual void onRaster2( PagedGeoWorld * const pPgWorld, const unsigned short nPass ) { cout << "P" << nPass << ": " << "Rastering..." << std::endl; } virtual void onPass2( PagedGeoWorld * const pPgWorld, const unsigned short nPass ) { cout << "Begin pass #" << nPass << std::endl; } virtual void onGenerate2( PagedGeoWorld * const pPgWorld ) { cout << "Generating world at LOD " << pPgWorld->getLOD() << std::endl; } virtual void onRejects2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & rejects ) { cout << "P" << nPass << ": " << "Rejects: " << std::endl; for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i) cout << "\t- " << (*i)->getTypeName() << std::endl; cout << std::endl; } virtual void onGenerateGeoHostLayers (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth) { cout << "Generating Geology Host layers..." << std::endl; } virtual void onSpawnMinerals (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth) { cout << "Generating some minerals..." << std::endl; } virtual void onSpawnMinerals2 (PagedGeoWorld * const pPgWorld, const unsigned short nPass, DepositSynthesizer * const pDepSynth) { cout << "Generating some minerals..." << std::endl; } }; int main (int argc, char * argv[]) { po::options_description desc("Available options"); desc.add_options() ("help", "How to use this utility") ("cf", po::value(), "Configuration files directory") ("output-file", po::value< string >(), "output file"); po::positional_options_description positionals; positionals.add("output-file", -1); po::variables_map args; po::store( po::command_line_parser(argc, argv) .options(desc) .positional(positionals) .run(), args ); po::notify(args); if (args.count("help")) { cout << desc << std::endl; return 1; } std::string cf = ".", outputFile = "mytest.pgw"; if (args.count("cf")) cf = args["cf"].as(); if (args.count("output-file")) outputFile = args["output-file"].as(); Log::getSingleton().setLevel(Log::Debug); Log::getSingleton().addSettings(Log_File | Log_Line); std::ifstream in(cf + "/gmfactories.yaml", std::ios_base::in); if (!in) { cerr << "Missing factories yaml" << std::endl; return -1; } DefaultGMRegistry registry; YAMLGeoMorphConfigReader cfgin(in); /*time_t t; time(&t); srand(t); const unsigned int nSeed = rand(); srand(nSeed); LOGN << nSeed;*/ registry.configure(cfgin); //registry.unregisterFactory("mountains"); //registry.unregisterFactory("outflowchannels"); //registry.unregisterFactory("volcano"); //registry.unregisterFactory("crater"); //registry.unregisterFactory("winderosion"); SynthesisSession sess; ConsoleListener listener; std::ifstream incfg(cf + "/genesis.yaml", std::ios::in), indepsynthcfg(cf + "/depsynth.yaml", std::ios::in); const std::string mineralsYaml = cf + "/minerals.yaml", classesYaml = cf + "/classes.yaml"; auto minerals = MineralsYAMLReader(mineralsYaml.c_str(), classesYaml.c_str(), NULL); auto deposits = YAMLDepositSynthCfgReader (indepsynthcfg); auto cfg = YAMLSynthSessCfgReader(incfg); if ( sess.init( minerals, deposits, cfg ) ) { sess.setTileDim(128); sess.addListener(&listener); sess.generate(outputFile, registry, 4000, 2000, 20000); } else { cerr << "Error during initialization" << std::endl; return 42; } /* #ifdef _GWDEBUG const PagedGeoWorld & world = sess.getWorld(); const unsigned int nXI = world.getWorldWidth() >> 3, nYI = world.getWorldHeight() >> 3; for (unsigned int j = 0; j < world.getWorldHeight(); j += nYI) for (unsigned int i = 0; i < world.getWorldWidth(); i += nXI) { const LockedGWSection * pSection = world.lockro(i, j, nXI, nYI, false); *pSection >> GLOBALDEM; DUMP_GLOBALDEM(); world.unlock(pSection); } #endif*/ cout << "Finished." << std::endl; std::cin.get(); return 0; }