Changeset 890

Show
Ignore:
Timestamp:
03/11/08 13:48:27
Author:
robert
Message:

Added LayerInheritance? paramter to BuildOptions? and use of this in the source reading and scene building code in Destination.cpp

Files:

Legend:

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

    r859 r890  
    250250        void setBuildOptionsString(const std::string& str) { _buildOptionsString = str; } 
    251251        const std::string& getBuildOptionsString() const { return _buildOptionsString; } 
     252 
     253        enum LayerInheritance 
     254        { 
     255            INHERIT_LOWEST_AVAILABLE, 
     256            INHERIT_NEAREST_AVAILABLE, 
     257            NO_INHERITANCE 
     258        }; 
     259         
     260        void setLayerInheritance(LayerInheritance inheritance) { _layerInheritance = inheritance; } 
     261        LayerInheritance getLayerInheritance() const { return _layerInheritance; } 
     262 
    252263         
    253264    protected: 
     
    310321         
    311322        std::string                                 _buildOptionsString; 
     323 
     324        LayerInheritance                            _layerInheritance; 
    312325}; 
    313326 
  • trunk/src/vpb/BuildOptions.cpp

    r874 r890  
    7272    _numReadThreadsToCoresRatio = 0.0f; 
    7373    _numWriteThreadsToCoresRatio = 0.0f; 
     74     
     75    _layerInheritance = INHERIT_NEAREST_AVAILABLE; 
    7476} 
    7577 
     
    144146     
    145147    _buildOptionsString = rhs._buildOptionsString; 
     148     
     149    _layerInheritance = rhs._layerInheritance; 
    146150} 
    147151 
  • trunk/src/vpb/BuildOptionsIO.cpp

    r859 r890  
    218218 
    219219        ADD_STRING_PROPERTY(BuildOptionsString); 
     220 
     221        { AEP(LayerInheritance); AEV(INHERIT_LOWEST_AVAILABLE); AEV(INHERIT_NEAREST_AVAILABLE); AEV(NO_INHERITANCE); } 
     222 
    220223    } 
    221224     
  • trunk/src/vpb/Destination.cpp

    r888 r890  
    10541054    _stateset = new osg::StateSet; 
    10551055 
    1056     bool updateBaseTextureToCurrentValidImage = true; 
    1057     osg::Texture* baseTexture = 0; 
    10581056    for(layerNum=0; 
    10591057        layerNum<_imagery.size(); 
     
    10781076 
    10791077        osg::Texture2D* texture = new osg::Texture2D; 
    1080          
    1081         if (updateBaseTextureToCurrentValidImage || baseTexture==0) baseTexture=texture; 
    10821078         
    10831079        texture->setImage(image); 
     
    11791175    } 
    11801176     
    1181     // now fill in any blank texture units. 
    1182     bool fillInAllTextureUnits = true; 
    1183     if (fillInAllTextureUnits) 
    1184     { 
    1185         for(layerNum=0; 
    1186             layerNum<_dataSet->getNumOfTextureLevels(); 
    1187             ++layerNum) 
    1188         { 
    1189             bool applyBaseTexture = false; 
    1190             if (layerNum>=_imagery.size()) applyBaseTexture=true; 
    1191             else  
    1192             { 
    1193                 ImageData& imageData = _imagery[layerNum]; 
    1194                 if (!imageData._imagery.valid() || !imageData._imagery->_image.valid())  
     1177    switch(_dataSet->getLayerInheritance()) 
     1178    { 
     1179        case(BuildOptions::INHERIT_LOWEST_AVAILABLE): 
     1180        { 
     1181            osg::StateAttribute* texture = 0; 
     1182            // first look for an available texture  
     1183            for(layerNum=0; 
     1184                layerNum<_dataSet->getNumOfTextureLevels() && texture==0; 
     1185                ++layerNum) 
     1186            { 
     1187                texture = _stateset->getTextureAttribute(layerNum,osg::StateAttribute::TEXTURE); 
     1188            } 
     1189 
     1190            if (texture) 
     1191            {             
     1192                // now fill in any blanks 
     1193                for(layerNum=0; 
     1194                    layerNum<_dataSet->getNumOfTextureLevels(); 
     1195                    ++layerNum) 
    11951196                { 
    1196                     applyBaseTexture=true; 
     1197                    if (!_stateset->getTextureAttribute(layerNum,osg::StateAttribute::TEXTURE)) 
     1198                    { 
     1199                        _stateset->setTextureAttributeAndModes(layerNum,texture,osg::StateAttribute::ON); 
     1200                    } 
    11971201                } 
    11981202            } 
    1199             if (applyBaseTexture)         
    1200                 _stateset->setTextureAttributeAndModes(layerNum,baseTexture,osg::StateAttribute::ON); 
    1201         } 
    1202     } 
     1203            break; 
     1204        } 
     1205        case(BuildOptions::INHERIT_NEAREST_AVAILABLE): 
     1206        { 
     1207            osg::StateAttribute* texture = 0; 
     1208            unsigned int noBlanks = 0; 
     1209            for(int layerNum=0; 
     1210                layerNum<_dataSet->getNumOfTextureLevels(); 
     1211                ++layerNum) 
     1212            { 
     1213                osg::StateAttribute* localTexture = _stateset->getTextureAttribute(layerNum,osg::StateAttribute::TEXTURE); 
     1214                if (localTexture) texture = localTexture; 
     1215                else if (texture) _stateset->setTextureAttributeAndModes(layerNum,texture,osg::StateAttribute::ON); 
     1216                else ++noBlanks; 
     1217            } 
    12031218         
     1219            if (noBlanks>0 && noBlanks != _dataSet->getNumOfTextureLevels()) 
     1220            { 
     1221                // inherit downards to fill in any blanks 
     1222                for(int layerNum=_dataSet->getNumOfTextureLevels()-1; 
     1223                    layerNum>=0; 
     1224                    --layerNum) 
     1225                { 
     1226                    osg::StateAttribute* localTexture = _stateset->getTextureAttribute(layerNum,osg::StateAttribute::TEXTURE); 
     1227                    if (localTexture) texture = localTexture; 
     1228                    else if (texture) _stateset->setTextureAttributeAndModes(layerNum,texture,osg::StateAttribute::ON); 
     1229                } 
     1230            } 
     1231            break; 
     1232        } 
     1233        case(BuildOptions::NO_INHERITANCE): 
     1234        { 
     1235            // do nothing.. 
     1236            break; 
     1237        } 
     1238    } 
    12041239    return _stateset.get(); 
    12051240} 
     
    14301465     
    14311466 
    1432     osgTerrain::ImageLayer* baseLayer = 0; 
    1433     bool updateLayerTextureToCurrentValidLayer = true; 
    1434      
    14351467    // assign the imagery 
    14361468    for(unsigned int layerNum=0; 
     
    14481480 
    14491481            terrain->setColorLayer(layerNum, imageLayer); 
    1450  
    1451             if (updateLayerTextureToCurrentValidLayer || baseLayer==0) 
    1452             { 
    1453                 baseLayer = imageLayer; 
    1454             } 
    1455         } 
    1456     } 
    1457  
    1458     // copy layer into any blanks 
    1459     if (baseLayer) 
    1460     { 
    1461         for(unsigned int layerNum=0; 
    1462             layerNum<_dataSet->getNumOfTextureLevels(); 
    1463             ++layerNum) 
    1464         { 
    1465             if (terrain->getColorLayer(layerNum)==0) 
    1466             { 
    1467                 terrain->setColorLayer(layerNum, baseLayer); 
    1468             } 
    1469         }     
    1470     } 
     1482        } 
     1483    } 
     1484 
     1485    switch(_dataSet->getLayerInheritance()) 
     1486    { 
     1487        case(BuildOptions::INHERIT_LOWEST_AVAILABLE): 
     1488        { 
     1489            osgTerrain::Layer* layer = 0; 
     1490            // first look for an available Layer 
     1491            for(unsigned int layerNum=0; 
     1492                layerNum<_dataSet->getNumOfTextureLevels() && layer==0; 
     1493                ++layerNum) 
     1494            { 
     1495                layer = terrain->getColorLayer(layerNum); 
     1496            } 
     1497 
     1498            if (layer) 
     1499            {             
     1500                // now fill in any blanks 
     1501                for(unsigned int layerNum=0; 
     1502                    layerNum<_dataSet->getNumOfTextureLevels(); 
     1503                    ++layerNum) 
     1504                { 
     1505                    if (!terrain->getColorLayer(layerNum)) 
     1506                    { 
     1507                        terrain->setColorLayer(layerNum,layer); 
     1508                    } 
     1509                } 
     1510            } 
     1511            break; 
     1512        } 
     1513        case(BuildOptions::INHERIT_NEAREST_AVAILABLE): 
     1514        { 
     1515            osgTerrain::Layer* layer = 0; 
     1516            unsigned int noBlanks = 0; 
     1517            for(int layerNum=0; 
     1518                layerNum<_dataSet->getNumOfTextureLevels(); 
     1519                ++layerNum) 
     1520            { 
     1521                osgTerrain::Layer* localLayer = terrain->getColorLayer(layerNum); 
     1522                if (localLayer) layer = localLayer; 
     1523                else if (layer) terrain->setColorLayer(layerNum, layer); 
     1524                else ++noBlanks; 
     1525            } 
     1526         
     1527            if (noBlanks>0 && noBlanks != _dataSet->getNumOfTextureLevels()) 
     1528            { 
     1529                // inherit downards to fill in any blanks 
     1530                for(int layerNum=_dataSet->getNumOfTextureLevels()-1; 
     1531                    layerNum>=0; 
     1532                    --layerNum) 
     1533                { 
     1534                    osgTerrain::Layer* localLayer = terrain->getColorLayer(layerNum); 
     1535                    if (localLayer) layer = localLayer; 
     1536                    else if (layer) terrain->setColorLayer(layerNum, layer); 
     1537                } 
     1538            } 
     1539            break; 
     1540        } 
     1541        case(BuildOptions::NO_INHERITANCE): 
     1542        { 
     1543            // do nothing.. 
     1544            break; 
     1545        } 
     1546    } 
     1547 
    14711548     
    14721549    // assign the terrain technique that will be used to render the terrain tile. 
     
    21622239            { 
    21632240                unsigned int layerNum = source->getLayer(); 
    2164  
    2165                 if (layerNum==0) 
     2241                switch(_dataSet->getLayerInheritance()) 
    21662242                { 
    2167                     // copy the base layer 0 into layer 0 and all subsequent layers to provide a backdrop. 
    2168                     for(unsigned int i=0;i<_imagery.size();++i) 
     2243                    case(BuildOptions::INHERIT_LOWEST_AVAILABLE): 
    21692244                    { 
    2170                         if (_imagery[i]._imagery.valid()
     2245                        if (layerNum==0
    21712246                        { 
    2172                             data->read(*(_imagery[i]._imagery)); 
     2247                            // copy the base layer 0 into layer 0 and all subsequent layers to provide a backdrop. 
     2248                            for(unsigned int i=0;i<_imagery.size();++i) 
     2249                            { 
     2250                                if (_imagery[i]._imagery.valid()) 
     2251                                { 
     2252                                    data->read(*(_imagery[i]._imagery)); 
     2253                                } 
     2254                            } 
    21732255                        } 
     2256                        else 
     2257                        { 
     2258                            // copy specific layer. 
     2259                            if (layerNum<_imagery.size() && _imagery[layerNum]._imagery.valid()) 
     2260                            { 
     2261                                data->read(*(_imagery[layerNum]._imagery)); 
     2262                            } 
     2263                        } 
     2264                        break; 
    21742265                    } 
    2175                 } 
    2176                 else 
    2177                 { 
    2178                     // copy specific layer. 
    2179                     if (layerNum<_imagery.size() && _imagery[layerNum]._imagery.valid()) 
     2266                    case(BuildOptions::INHERIT_NEAREST_AVAILABLE): 
    21802267                    { 
    2181                         data->read(*(_imagery[layerNum]._imagery)); 
     2268                        // copy the current layer into this and all subsequent layers to provide a backdrop. 
     2269                        for(unsigned int i=layerNum;i<_imagery.size();++i) 
     2270                        { 
     2271                            if (_imagery[i]._imagery.valid()) 
     2272                            { 
     2273                                data->read(*(_imagery[i]._imagery)); 
     2274                            } 
     2275                        } 
     2276                        break; 
    21822277                    } 
    2183                 } 
     2278                    case(BuildOptions::NO_INHERITANCE): 
     2279                    { 
     2280                        if (layerNum<_imagery.size() && _imagery[layerNum]._imagery.valid()) 
     2281                        { 
     2282                            data->read(*(_imagery[layerNum]._imagery)); 
     2283                        } 
     2284                        break; 
     2285                    } 
     2286                }                     
    21842287                break; 
    21852288            }