Changeset 854

Show
Ignore:
Timestamp:
01/22/08 17:56:58
Author:
robert
Message:

Completed work on automatic selection of split levels

Files:

Legend:

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

    r836 r854  
    197197        void setDistributedBuildSplitLevel(unsigned int level) { _distributedBuildSplitLevel = level; } 
    198198        unsigned int getDistributedBuildSplitLevel() const { return _distributedBuildSplitLevel; } 
     199 
     200        void setDistributedBuildSecondarySplitLevel(unsigned int level) { _distributedBuildSecondarySplitLevel = level; } 
     201        unsigned int getDistributedBuildSecondarySplitLevel() const { return _distributedBuildSecondarySplitLevel; } 
    199202 
    200203        void setRecordSubtileFileNamesOnLeafTile(bool recordSubtileFileNamesOnLeafTile) { _recordSubtileFileNamesOnLeafTile = recordSubtileFileNamesOnLeafTile; } 
     
    277280         
    278281        unsigned int                                _distributedBuildSplitLevel; 
     282        unsigned int                                _distributedBuildSecondarySplitLevel; 
     283 
    279284        bool                                        _recordSubtileFileNamesOnLeafTile; 
    280285        bool                                        _generateSubtile; 
  • trunk/include/vpb/DataSet

    r853 r854  
    215215        bool computeOptimumTileSystemDimensions(int& C1, int& R1); 
    216216        CompositeDestination* createDestinationTile(int level, int tileX, int tileY); 
    217          
    218         bool prepareForDestinationGraphCreation(); 
    219       
    220         int computeMaximumLevel(); 
     217        int computeMaximumLevel(int maxNumLevels); 
     218         
     219        bool prepareForDestinationGraphCreation();  
     220         
     221        void selectAppropriateSplitLevels(); 
    221222 
    222223        osg::ref_ptr<CompositeSource>               _sourceGraph; 
  • trunk/src/vpb/BuildOptions.cpp

    r836 r854  
    5757     
    5858    _distributedBuildSplitLevel = 0; 
     59    _distributedBuildSecondarySplitLevel = 0; 
    5960    _recordSubtileFileNamesOnLeafTile = false; 
    6061    _generateSubtile = false; 
     
    123124    _writeNodeBeforeSimplification = rhs._writeNodeBeforeSimplification; 
    124125    _distributedBuildSplitLevel = rhs._distributedBuildSplitLevel; 
     126    _distributedBuildSecondarySplitLevel = rhs._distributedBuildSecondarySplitLevel; 
    125127    _recordSubtileFileNamesOnLeafTile = rhs._recordSubtileFileNamesOnLeafTile; 
    126128    _generateSubtile = rhs._generateSubtile; 
  • trunk/src/vpb/BuildOptionsIO.cpp

    r836 r854  
    199199         
    200200        ADD_UINT_PROPERTY(DistributedBuildSplitLevel); 
     201        ADD_UINT_PROPERTY(DistributedBuildSecondarySplitLevel); 
    201202        ADD_BOOL_PROPERTY(RecordSubtileFileNamesOnLeafTile); 
    202203        ADD_BOOL_PROPERTY(GenerateSubtile); 
  • trunk/src/vpb/Commandline.cpp

    r836 r854  
    473473    usage.addCommandLineOption("--record-subtile-on-leaf-tiles","Enable the setting of the subtile file name of the leaf tiles."); 
    474474    usage.addCommandLineOption("--split","Set the distributed build split level."); 
     475    usage.addCommandLineOption("--splits","Set the distributed build primary and secondary split levels."); 
    475476    usage.addCommandLineOption("--run-path","Set the path that the build should be run from."); 
    476477    usage.addCommandLineOption("--notify-level","Set the notify level when logging messages."); 
     
    536537    { 
    537538        buildOptions->setDistributedBuildSplitLevel(splitLevel); 
     539    } 
     540 
     541    unsigned int secondarySplitLevel; 
     542    while(arguments.read("--splits",splitLevel, secondarySplitLevel)) 
     543    { 
     544        buildOptions->setDistributedBuildSplitLevel(splitLevel); 
     545        buildOptions->setDistributedBuildSecondarySplitLevel(secondarySplitLevel); 
    538546    } 
    539547 
  • trunk/src/vpb/DataSet.cpp

    r853 r854  
    212212} 
    213213 
     214int DataSet::computeMaximumLevel(int maxNumLevels) 
     215{ 
     216    int maxLevel = 0; 
     217    for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr) 
     218    { 
     219        Source* source = (*itr).get(); 
     220 
     221         
     222        SourceData* sd = (*itr)->getSourceData(); 
     223        if (!sd) 
     224        { 
     225            log(osg::NOTICE,"Skipping source %s as no data loaded from it.",source->getFileName().c_str()); 
     226            continue; 
     227        } 
     228         
     229        if (source->getType()!=Source::IMAGE && source->getType()!=Source::HEIGHT_FIELD) 
     230        { 
     231            // place models and shapefiles into a separate temporary source list and then process these after 
     232            // the main handling of terrain/imagery sources. 
     233            continue; 
     234             
     235        } 
     236 
     237        int k = 0; 
     238        if (!computeOptimumLevel(source, maxNumLevels-1, k)) continue; 
     239         
     240        if (k>maxLevel) 
     241        { 
     242            maxLevel = k; 
     243        } 
     244    } 
     245     
     246    return maxLevel; 
     247} 
     248 
    214249bool DataSet::computeOptimumTileSystemDimensions(int& C1, int& R1) 
    215250{ 
     
    386421     
    387422    _newDestinationGraph = true; 
    388  
    389     computeOptimumTileSystemDimensions(_C1,_R1); 
    390  
    391     log(osg::NOTICE,"      C1=%i R1=%i",_C1,_R1); 
    392      
     423    
    393424    typedef std::list< osg::ref_ptr<Source> > SourceList; 
    394425    SourceList modelSources; 
     
    11201151    _numTextureLevels = maxTextureUnit+1; 
    11211152 
     1153    computeOptimumTileSystemDimensions(_C1,_R1); 
    11221154 
    11231155    log(osg::INFO, "extents = xMin() %f %f",_destinationExtents.xMin(),_destinationExtents.xMax()); 
     
    11301162{ 
    11311163    if (!prepareForDestinationGraphCreation()) return; 
    1132  
    1133 #if 0 
    1134     if (!_sourceGraph) return; 
    1135  
    1136     // ensure we have a valid coordinate system 
    1137     if (_destinationCoordinateSystemString.empty()&& !getConvertFromGeographicToGeocentric()) 
    1138     { 
    1139         for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr) 
    1140         { 
    1141             SourceData* sd = (*itr)->getSourceData(); 
    1142             if (sd) 
    1143             { 
    1144                 if (sd->_cs.valid()) 
    1145                 { 
    1146                     _destinationCoordinateSystem = sd->_cs; 
    1147                     log(osg::INFO,"Setting coordinate system to %s",_destinationCoordinateSystem->getCoordinateSystem().c_str()); 
    1148                     break; 
    1149                 } 
    1150             } 
    1151         } 
    1152     } 
    1153      
    1154      
    1155     assignIntermediateCoordinateSystem(); 
    1156  
    1157     CoordinateSystemType destinateCoordSytemType = getCoordinateSystemType(_destinationCoordinateSystem.get()); 
    1158     if (destinateCoordSytemType==GEOGRAPHIC && !getConvertFromGeographicToGeocentric()) 
    1159     { 
    1160         // convert elevation into degrees. 
    1161         setVerticalScale(1.0f/111319.0f); 
    1162     } 
    1163  
    1164     // get the extents of the sources and 
    1165     _destinationExtents = _extents; 
    1166     _destinationExtents._isGeographic = destinateCoordSytemType==GEOGRAPHIC; 
    1167  
    1168     // sort the sources so that the lowest res tiles are drawn first. 
    1169     { 
    1170      
    1171 #if 0     
    1172         for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr) 
    1173         { 
    1174             Source* source = itr->get(); 
    1175             if (source) 
    1176             { 
    1177                 source->setSortValueFromSourceDataResolution(_intermediateCoordinateSystem.get()); 
    1178                 log(osg::INFO, "sort %s value %f",source->getFileName().c_str(),source->getSortValue()); 
    1179             } 
    1180              
    1181         } 
    1182          
    1183         // sort them so highest sortValue is first. 
    1184 #endif 
    1185         _sourceGraph->setSortValueFromSourceDataResolution(_intermediateCoordinateSystem.get()); 
    1186         _sourceGraph->sort(); 
    1187     } 
    1188  
    1189     if (!_destinationExtents.valid())  
    1190     { 
    1191         for(CompositeSource::source_iterator itr(_sourceGraph.get());itr.valid();++itr) 
    1192         { 
    1193             SourceData* sd = (*itr)->getSourceData(); 
    1194             if (sd) 
    1195             { 
    1196                 GeospatialExtents local_extents(sd->getExtents(_intermediateCoordinateSystem.get())); 
    1197                 log(osg::INFO, "local_extents = xMin() %f %f",local_extents.xMin(),local_extents.xMax()); 
    1198                 log(osg::INFO, "                yMin() %f %f",local_extents.yMin(),local_extents.yMax()); 
    1199                  
    1200                 if (destinateCoordSytemType==GEOGRAPHIC) 
    1201                 { 
    1202                     // need to clamp within -180 and 180 range. 
    1203                     if (local_extents.xMin()>180.0)  
    1204                     { 
    1205                         // shift back to -180 to 180 range 
    1206                         local_extents.xMin() -= 360.0; 
    1207                         local_extents.xMax() -= 360.0; 
    1208                     } 
    1209                     else if (local_extents.xMin()<-180.0)  
    1210                     { 
    1211                         // shift back to -180 to 180 range 
    1212                         local_extents.xMin() += 360.0; 
    1213                         local_extents.xMax() += 360.0; 
    1214                     } 
    1215                 } 
    1216  
    1217                 _destinationExtents.expandBy(local_extents); 
    1218             } 
    1219         } 
    1220     } 
    1221      
    1222  
    1223     if (destinateCoordSytemType==GEOGRAPHIC) 
    1224     { 
    1225         double xRange = _destinationExtents.xMax() - _destinationExtents.xMin(); 
    1226         if (xRange>360.0)  
    1227         { 
    1228             // clamp to proper 360 range. 
    1229             _destinationExtents.xMin() = -180.0; 
    1230             _destinationExtents.xMax() = 180.0; 
    1231         } 
    1232     } 
    1233      
    1234  
    1235     // compute the number of texture layers required. 
    1236     unsigned int maxTextureUnit = 0; 
    1237     for(CompositeSource::source_iterator sitr(_sourceGraph.get());sitr.valid();++sitr) 
    1238     { 
    1239         Source* source = sitr->get(); 
    1240         if (source)  
    1241         { 
    1242             if (maxTextureUnit<source->getLayer()) maxTextureUnit = source->getLayer(); 
    1243         } 
    1244     } 
    1245     _numTextureLevels = maxTextureUnit+1; 
    1246  
    1247  
    1248     log(osg::INFO, "extents = xMin() %f %f",_destinationExtents.xMin(),_destinationExtents.xMax()); 
    1249     log(osg::INFO, "          yMin() %f %f",_destinationExtents.yMin(),_destinationExtents.yMax()); 
    1250  
    1251 #endif 
    12521164 
    12531165    osg::Timer_t before = osg::Timer::instance()->tick(); 
     
    24092321} 
    24102322 
     2323void DataSet::selectAppropriateSplitLevels() 
     2324{ 
     2325    int maxLevel = computeMaximumLevel(getMaximumNumOfLevels()); 
     2326    log(osg::NOTICE,"Computed maximum source level = %i", maxLevel); 
     2327 
     2328    if (getDistributedBuildSplitLevel()==0) 
     2329    { 
     2330        if (getDistributedBuildSecondarySplitLevel()==0) 
     2331        { 
     2332            // need to compute both primary and secodary split levels 
     2333            if (maxLevel<10) 
     2334            { 
     2335                // just use primary split level 
     2336                setDistributedBuildSplitLevel((maxLevel * 2) / 5); 
     2337            } 
     2338            else 
     2339            { 
     2340                setDistributedBuildSplitLevel(maxLevel / 4); 
     2341                setDistributedBuildSecondarySplitLevel((maxLevel * 5) / 9); 
     2342            } 
     2343        } 
     2344        else 
     2345        { 
     2346            // need to compute the primary split level only 
     2347            setDistributedBuildSplitLevel(getDistributedBuildSecondarySplitLevel()/2); 
     2348        } 
     2349    } 
     2350    else 
     2351    { 
     2352        if (maxLevel>=10 && getDistributedBuildSecondarySplitLevel()==0) 
     2353        { 
     2354            // need to compute just the seconary split level 
     2355            setDistributedBuildSecondarySplitLevel( 
     2356                        getDistributedBuildSplitLevel() + 
     2357                        (maxLevel-getDistributedBuildSplitLevel())/2 ); 
     2358        } 
     2359        else 
     2360        { 
     2361            // primary and secondary split levels fully specified. 
     2362        } 
     2363    } 
     2364     
     2365    if (getDistributedBuildSplitLevel()>=maxLevel) 
     2366    { 
     2367        log(osg::NOTICE,"Warning: primary split level exceed maximum source level, switching off primary split level."); 
     2368        setDistributedBuildSplitLevel(0); 
     2369    } 
     2370     
     2371    if (getDistributedBuildSecondarySplitLevel()>=maxLevel) 
     2372    { 
     2373        log(osg::NOTICE,"Warning: secondary split level exceed maximum source level, switching off secondary split level."); 
     2374        setDistributedBuildSecondarySplitLevel(0); 
     2375    } 
     2376     
     2377    if (getDistributedBuildSecondarySplitLevel()!=0 && 
     2378        getDistributedBuildSecondarySplitLevel()<=getDistributedBuildSplitLevel()) 
     2379    { 
     2380        log(osg::NOTICE,"Warning: secondary split level is not permited to be lower than or equal to the primary split level, switching off secondary split level."); 
     2381        setDistributedBuildSecondarySplitLevel(0); 
     2382    } 
     2383 
     2384 
     2385    if (getDistributedBuildSecondarySplitLevel()==0) 
     2386    { 
     2387        log(osg::NOTICE,"Selected single split at %i",getDistributedBuildSplitLevel()); 
     2388    } 
     2389    else 
     2390    { 
     2391        log(osg::NOTICE,"Selected primary split at %i, secondary split at %i", 
     2392            getDistributedBuildSplitLevel(), 
     2393            getDistributedBuildSecondarySplitLevel()); 
     2394    } 
     2395     
     2396     
     2397} 
     2398 
     2399 
    24112400bool DataSet::generateTasks_new(TaskManager* taskManager) 
    24122401{ 
     
    24282417    if (!prepareForDestinationGraphCreation()) return false; 
    24292418 
    2430     computeOptimumTileSystemDimensions(_C1,_R1); 
    2431     log(osg::NOTICE,"      C1=%i R1=%i",_C1,_R1); 
    2432  
    2433  
    2434  
    24352419    log(osg::NOTICE,"OK, OK I now need something to do..."); 
    24362420     
    2437     log(osg::NOTICE,"First compute the maximum level required"); 
    2438     log(osg::NOTICE,"Then compute the appropriate split levels"); 
     2421    selectAppropriateSplitLevels(); 
     2422     
     2423    if (getDistributedBuildSplitLevel()==0) return false; 
     2424 
    24392425    log(osg::NOTICE,"Then generate the root task"); 
    24402426    log(osg::NOTICE,"Then generate the intermediate tasks if any"); 
     
    24512437bool DataSet::generateTasks_old(TaskManager* taskManager) 
    24522438{ 
     2439    if (!getLogFileName().empty()) 
     2440    { 
     2441        if (!getBuildLog()) setBuildLog(new BuildLog()); 
     2442     
     2443        getBuildLog()->openLogFile(getLogFileName()); 
     2444    } 
     2445 
     2446    if (getBuildLog()) 
     2447    { 
     2448        pushOperationLog(getBuildLog()); 
     2449    } 
     2450     
     2451    loadSources(); 
     2452 
     2453    if (!prepareForDestinationGraphCreation()) return false; 
     2454 
     2455    selectAppropriateSplitLevels(); 
     2456 
    24532457    if (getDistributedBuildSplitLevel()==0) return false; 
    24542458 
    2455     if (!getLogFileName().empty()) 
    2456     { 
    2457         if (!getBuildLog()) setBuildLog(new BuildLog()); 
    2458      
    2459         getBuildLog()->openLogFile(getLogFileName()); 
    2460     } 
    2461  
    2462     if (getBuildLog()) 
    2463     { 
    2464         pushOperationLog(getBuildLog()); 
    2465     } 
    2466      
    2467     loadSources(); 
    24682459 
    24692460    computeDestinationGraphFromSources(getDistributedBuildSplitLevel()+1); 
  • trunk/src/vpb/TaskManager.cpp

    r833 r854  
    103103    while (arguments.read("--build-name",_buildName)) {} 
    104104     
    105  
    106     DatabaseBuilder* db = dynamic_cast<DatabaseBuilder*>(_terrain->getTerrainTechnique()); 
    107     BuildOptions* bo = db->getBuildOptions(); 
    108     if (bo) 
    109     { 
    110         if (bo->getDistributedBuildSplitLevel()==0) 
    111         { 
    112             unsigned int maxLevel = bo->getMaximumNumOfLevels(); 
    113             unsigned int halfLevel = (maxLevel / 2); 
    114             if (halfLevel>=1) 
    115             { 
    116                 bo->setDistributedBuildSplitLevel(osg::minimum(halfLevel,4u)); 
    117             } 
    118         } 
    119     } 
    120      
    121     log(osg::NOTICE,"setDistributedBuildSplitLevel=%d",bo->getDistributedBuildSplitLevel()); 
    122  
    123105    if (!terrainOutputName.empty()) 
    124106    {