| | 2274 | bool DataSet::createTileMap(unsigned int level, TilePairMap& tilepairMap) |
|---|
| | 2275 | { |
|---|
| | 2276 | osg::CoordinateSystemNode* cs = _intermediateCoordinateSystem.get(); |
|---|
| | 2277 | const GeospatialExtents& extents = _destinationExtents; |
|---|
| | 2278 | unsigned int maxImageSize = _maximumTileImageSize; |
|---|
| | 2279 | unsigned int maxTerrainSize = _maximumTileTerrainSize; |
|---|
| | 2280 | unsigned int maxNumLevels = getMaximumNumOfLevels(); |
|---|
| | 2281 | |
|---|
| | 2282 | // first populate the destination graph from imagery and DEM sources extents/resolution |
|---|
| | 2283 | for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr) |
|---|
| | 2284 | { |
|---|
| | 2285 | Source* source = (*itr).get(); |
|---|
| | 2286 | |
|---|
| | 2287 | if (source->getMinLevel()>maxNumLevels) |
|---|
| | 2288 | { |
|---|
| | 2289 | log(osg::NOTICE,"Skipping source %s as its min level excees destination max level.",source->getFileName().c_str()); |
|---|
| | 2290 | continue; |
|---|
| | 2291 | } |
|---|
| | 2292 | |
|---|
| | 2293 | SourceData* sd = (*itr)->getSourceData(); |
|---|
| | 2294 | if (!sd) |
|---|
| | 2295 | { |
|---|
| | 2296 | log(osg::NOTICE,"Skipping source %s as no data loaded from it.",source->getFileName().c_str()); |
|---|
| | 2297 | continue; |
|---|
| | 2298 | } |
|---|
| | 2299 | |
|---|
| | 2300 | const SpatialProperties& sp = sd->computeSpatialProperties(cs); |
|---|
| | 2301 | |
|---|
| | 2302 | if (!sp._extents.intersects(extents)) |
|---|
| | 2303 | { |
|---|
| | 2304 | // skip this source since it doesn't overlap this tile. |
|---|
| | 2305 | log(osg::NOTICE,"Skipping source %s as its extents don't overlap destination extents.",source->getFileName().c_str()); |
|---|
| | 2306 | continue; |
|---|
| | 2307 | } |
|---|
| | 2308 | |
|---|
| | 2309 | if (source->getType()!=Source::IMAGE && source->getType()!=Source::HEIGHT_FIELD) |
|---|
| | 2310 | { |
|---|
| | 2311 | continue; |
|---|
| | 2312 | } |
|---|
| | 2313 | |
|---|
| | 2314 | int k = 0; |
|---|
| | 2315 | if (!computeOptimumLevel(source, maxNumLevels-1, k)) continue; |
|---|
| | 2316 | |
|---|
| | 2317 | // skip if the tiles won't contribute to the tasks with high level number. |
|---|
| | 2318 | if (k<=level) continue; |
|---|
| | 2319 | |
|---|
| | 2320 | int i_min, i_max, j_min, j_max; |
|---|
| | 2321 | if (computeCoverage(sp._extents, level, i_min, j_min, i_max, j_max)) |
|---|
| | 2322 | { |
|---|
| | 2323 | for(int j=j_min; j<j_max;++j) |
|---|
| | 2324 | { |
|---|
| | 2325 | for(int i=i_min; i<i_max;++i) |
|---|
| | 2326 | { |
|---|
| | 2327 | TilePair tileID(i,j); |
|---|
| | 2328 | TilePairMap::iterator itr = tilepairMap.find(tileID); |
|---|
| | 2329 | if (itr != tilepairMap.end()) |
|---|
| | 2330 | { |
|---|
| | 2331 | if (k > itr->second) itr->second = k; |
|---|
| | 2332 | } |
|---|
| | 2333 | else |
|---|
| | 2334 | { |
|---|
| | 2335 | tilepairMap[TilePair(i,j)] = k; |
|---|
| | 2336 | } |
|---|
| | 2337 | } |
|---|
| | 2338 | } |
|---|
| | 2339 | } |
|---|
| | 2340 | } |
|---|
| | 2341 | |
|---|
| | 2342 | #if 0 |
|---|
| | 2343 | for(TilePairMap::iterator itr = tilepairMap.begin(); |
|---|
| | 2344 | itr != tilepairMap.end(); |
|---|
| | 2345 | ++itr) |
|---|
| | 2346 | { |
|---|
| | 2347 | log(osg::NOTICE,"Level %d TilePair (%d, %d) %d",level, itr->first.first, itr->first.second, itr->second); |
|---|
| | 2348 | } |
|---|
| | 2349 | #endif |
|---|
| | 2350 | |
|---|
| | 2351 | } |
|---|
| | 2352 | |
|---|
| | 2544 | unsigned int level = getDistributedBuildSplitLevel()-1; |
|---|
| | 2545 | |
|---|
| | 2546 | TilePairMap tilepairMap; |
|---|
| | 2547 | createTileMap(level, tilepairMap); |
|---|
| | 2548 | |
|---|
| | 2549 | for(TilePairMap::iterator itr = tilepairMap.begin(); |
|---|
| | 2550 | itr != tilepairMap.end(); |
|---|
| | 2551 | ++itr) |
|---|
| | 2552 | { |
|---|
| | 2553 | unsigned int tileX = itr->first.first; |
|---|
| | 2554 | unsigned int tileY = itr->first.second; |
|---|
| | 2555 | |
|---|
| | 2556 | std::ostringstream taskfile; |
|---|
| | 2557 | taskfile<<taskDirectory<<basename<<"_subtile_L"<<level<<"_X"<<tileX<<"_Y"<<tileY<<".task"; |
|---|
| | 2558 | |
|---|
| | 2559 | |
|---|
| | 2560 | std::ostringstream app; |
|---|
| | 2561 | app<<"osgdem --run-path "<<taskManager->getRunPath()<<" -s "<<sourceFile<<" --record-subtile-on-leaf-tiles -l "<<getDistributedBuildSecondarySplitLevel()<<" --subtile "<<level<<" "<<tileX<<" "<<tileY<<" --task "<<taskfile.str(); |
|---|
| | 2562 | |
|---|
| | 2563 | |
|---|
| | 2564 | if (!fileCacheName.empty()) |
|---|
| | 2565 | { |
|---|
| | 2566 | app<<" --cache "<<fileCacheName; |
|---|
| | 2567 | } |
|---|
| | 2568 | |
|---|
| | 2569 | if (logging) |
|---|
| | 2570 | { |
|---|
| | 2571 | std::ostringstream logfile; |
|---|
| | 2572 | |
|---|
| | 2573 | logfile<<taskDirectory<<basename<<"_subtile_L"<<level<<"_X"<<tileX<<"_Y"<<tileY<<".log"; |
|---|
| | 2574 | app<<" --log "<<logfile.str(); |
|---|
| | 2575 | } |
|---|
| | 2576 | |
|---|
| | 2577 | taskManager->addTask(taskfile.str(), app.str(), sourceFile); |
|---|
| | 2578 | } |
|---|
| | 2579 | } |
|---|
| | 2580 | |
|---|
| | 2581 | // create the bottom level split |
|---|
| | 2582 | { |
|---|
| | 2583 | unsigned int level = bottomDistributedBuildLevel-1; |
|---|
| | 2584 | |
|---|
| | 2585 | TilePairMap tilepairMap; |
|---|
| | 2586 | createTileMap(level, tilepairMap); |
|---|
| | 2587 | |
|---|
| | 2588 | for(TilePairMap::iterator itr = tilepairMap.begin(); |
|---|
| | 2589 | itr != tilepairMap.end(); |
|---|
| | 2590 | ++itr) |
|---|
| | 2591 | { |
|---|
| | 2592 | unsigned int tileX = itr->first.first; |
|---|
| | 2593 | unsigned int tileY = itr->first.second; |
|---|
| | 2594 | |
|---|
| | 2595 | std::ostringstream taskfile; |
|---|
| | 2596 | taskfile<<taskDirectory<<basename<<"_subtile_L"<<level<<"_X"<<tileX<<"_Y"<<tileY<<".task"; |
|---|
| | 2597 | |
|---|
| | 2598 | |
|---|
| | 2599 | std::ostringstream app; |
|---|
| | 2600 | app<<"osgdem --run-path "<<taskManager->getRunPath()<<" -s "<<sourceFile<<" --subtile "<<level<<" "<<tileX<<" "<<tileY<<" --task "<<taskfile.str(); |
|---|
| | 2601 | |
|---|
| | 2602 | if (!fileCacheName.empty()) |
|---|
| | 2603 | { |
|---|
| | 2604 | app<<" --cache "<<fileCacheName; |
|---|
| | 2605 | } |
|---|
| | 2606 | |
|---|
| | 2607 | if (logging) |
|---|
| | 2608 | { |
|---|
| | 2609 | std::ostringstream logfile; |
|---|
| | 2610 | |
|---|
| | 2611 | logfile<<taskDirectory<<basename<<"_subtile_L"<<level<<"_X"<<tileX<<"_Y"<<tileY<<".log"; |
|---|
| | 2612 | app<<" --log "<<logfile.str(); |
|---|
| | 2613 | } |
|---|
| | 2614 | |
|---|
| | 2615 | taskManager->addTask(taskfile.str(), app.str(), sourceFile); |
|---|
| | 2616 | } |
|---|
| | 2617 | } |
|---|
| | 2618 | |
|---|
| | 2619 | #else |
|---|
| | 2620 | |
|---|
| | 2621 | computeDestinationGraphFromSources(bottomDistributedBuildLevel+1); |
|---|
| | 2622 | |
|---|
| | 2623 | if (!_destinationGraph.valid()) return false; |
|---|
| | 2624 | |
|---|
| | 2625 | // initialize various tasks related settings |
|---|
| | 2626 | std::string sourceFile = taskManager->getSourceFileName(); |
|---|
| | 2627 | std::string basename = taskManager->getBuildName(); |
|---|
| | 2628 | std::string taskDirectory = getTaskDirectory(); |
|---|
| | 2629 | if (!taskDirectory.empty()) taskDirectory += "/"; |
|---|
| | 2630 | |
|---|
| | 2631 | std::string fileCacheName; |
|---|
| | 2632 | if (System::instance()->getFileCache()) fileCacheName = System::instance()->getFileCache()->getFileName(); |
|---|
| | 2633 | |
|---|
| | 2634 | bool logging = getNotifyLevel() > ALWAYS; |
|---|
| | 2635 | |
|---|
| | 2636 | |
|---|
| | 2637 | // create root task |
|---|
| | 2638 | { |
|---|
| | 2639 | std::ostringstream taskfile; |
|---|
| | 2640 | taskfile<<taskDirectory<<basename<<"_root_L0_X0_Y0.task"; |
|---|
| | 2641 | |
|---|
| | 2642 | std::ostringstream app; |
|---|
| | 2643 | app<<"osgdem --run-path "<<taskManager->getRunPath()<<" -s "<<sourceFile<<" --record-subtile-on-leaf-tiles -l "<<getDistributedBuildSplitLevel()<<" --task "<<taskfile.str(); |
|---|
| | 2644 | |
|---|
| | 2645 | if (!fileCacheName.empty()) |
|---|
| | 2646 | { |
|---|
| | 2647 | app<<" --cache "<<fileCacheName; |
|---|
| | 2648 | } |
|---|
| | 2649 | |
|---|
| | 2650 | if (logging) |
|---|
| | 2651 | { |
|---|
| | 2652 | std::ostringstream logfile; |
|---|
| | 2653 | logfile<<taskDirectory<<basename<<"_root_L0_X0_Y0.log"; |
|---|
| | 2654 | app<<" --log "<<logfile.str(); |
|---|
| | 2655 | } |
|---|
| | 2656 | |
|---|
| | 2657 | taskManager->addTask(taskfile.str(), app.str(), sourceFile); |
|---|
| | 2658 | } |
|---|
| | 2659 | |
|---|
| | 2660 | |
|---|
| | 2661 | // need to create an intermediate level if required. |
|---|
| | 2662 | if (getDistributedBuildSecondarySplitLevel()!=0) |
|---|
| | 2663 | { |
|---|
| | 2664 | |
|---|