Changeset 881

Show
Ignore:
Timestamp:
03/05/08 18:49:43
Author:
robert
Message:

Introduced new scheme for computing the destination graph used when building the vpbmaste tasks list

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/vpb/DataSet

    r859 r881  
    5656    public: 
    5757 
    58  
    5958        typedef std::map<unsigned int,CompositeDestination*> Row; 
    6059        typedef std::map<unsigned int,Row> Level; 
     
    163162        osg::Node* getDestinationRootNode() { return _rootNode.get(); } 
    164163         
     164 
     165        typedef std::pair<unsigned int, unsigned int> TilePair; 
     166        typedef std::map<TilePair, unsigned int> TilePairMap; 
     167         
     168        bool createTileMap(unsigned int level, TilePairMap& tilepairMap); 
     169 
    165170        bool generateTasks(TaskManager* taskManager); 
    166171 
  • trunk/src/vpb/DataSet.cpp

    r880 r881  
    385385        parent->_type = LOD; 
    386386        parent->addChild(destinationGraph); 
    387          
    388 #if 0 
    389         unsigned int numParentTiles = parent->_tiles.size();        
    390         if (numParentTiles==0) 
    391         { 
    392             log(osg::NOTICE,"Parent in DestinationGraph has no tiles"); 
    393         } 
    394         else if (numParentTiles==1) 
    395         { 
    396             DestinationTile::Sources& sources = parent->_tiles.front()->_sources; 
    397             tile->_sources = sources; 
    398         } 
    399         else 
    400         { 
    401             log(osg::NOTICE,"Parent in DestinationGraph has %i tiles", numParentTiles); 
    402             DestinationTile::Sources& sources = parent->_tiles.front()->_sources; 
    403             tile->_sources = sources; 
    404         } 
    405 #endif 
    406  
    407387    } 
    408388 
     
    469449 
    470450        if (k>highestLevelFound) highestLevelFound = k; 
    471  
    472         // log(osg::NOTICE,"     opt level = %i",k); 
    473451 
    474452        int startLevel = 0; // getGenerateSubtile() ? getSubtileLevel() : 0; 
     
    22942272}; 
    22952273 
     2274bool 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 
    22962353bool DataSet::generateTasks(TaskManager* taskManager) 
    22972354{ 
     
    24422499                                        getDistributedBuildSecondarySplitLevel(); 
    24432500 
    2444     computeDestinationGraphFromSources(bottomDistributedBuildLevel+1); 
    2445  
    2446     if (!_destinationGraph.valid()) return false; 
    2447  
     2501 
     2502#if 1 
     2503    if (!prepareForDestinationGraphCreation()) return false; 
    24482504 
    24492505    // initialize various tasks related settings 
     
    24782534            app<<" --log "<<logfile.str(); 
    24792535        } 
    2480 #if 0             
    2481         else 
    2482         { 
    2483             app<<" > /dev/null"; 
    2484         } 
    2485 #endif             
    24862536 
    24872537        taskManager->addTask(taskfile.str(), app.str(), sourceFile); 
     
    24922542    if (getDistributedBuildSecondarySplitLevel()!=0) 
    24932543    { 
     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 
    24942665        CollectSubtiles cs(getDistributedBuildSplitLevel()-1); 
    24952666        _destinationGraph->accept(cs); 
     
    25212692                app<<" --log "<<logfile.str(); 
    25222693            } 
    2523     #if 0 
    2524             else 
    2525             { 
    2526                 app<<" > /dev/null"; 
    2527             } 
    2528     #endif 
     2694 
    25292695            taskManager->addTask(taskfile.str(), app.str(), sourceFile); 
    25302696        } 
     
    25332699    // create the bottom level split 
    25342700    {     
     2701 
    25352702        // bottom set of tasks 
    25362703        CollectSubtiles cs(bottomDistributedBuildLevel-1); 
     
    25622729                app<<" --log "<<logfile.str(); 
    25632730            } 
    2564     #if 0 
    2565             else 
    2566             { 
    2567                 app<<" > /dev/null"; 
    2568             } 
    2569     #endif 
     2731 
    25702732            taskManager->addTask(taskfile.str(), app.str(), sourceFile); 
    25712733        } 
    25722734    } 
     2735#endif 
    25732736 
    25742737    return false;