Changeset 932

Show
Ignore:
Timestamp:
09/05/08 12:48:40
Author:
robert
Message:

Added automatic detected of invalid database build configiurations

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/applications/osgdem/osgdem.cpp

    r925 r932  
    205205 
    206206    double duration = 0.0; 
    207  
     207     
    208208    // generate the database 
    209209    if (terrain.valid()) 
     
    237237            vpb::sync(); 
    238238 
    239             result = dataset->run(); 
    240  
    241             if (dataset->getBuildLog() && report) 
    242             { 
    243                 dataset->getBuildLog()->report(std::cout); 
    244             } 
    245              
    246             duration = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); 
    247              
    248             dataset->log(osg::NOTICE,"Elapsed time = %f",duration); 
     239            // check to make sure that the build itself is ready to run and confirgured correctly.             
     240            std::string buildProblems = dataset->checkBuildValidity(); 
     241            if (buildProblems.empty()) 
     242            { 
     243                result = dataset->run(); 
     244 
     245                if (dataset->getBuildLog() && report) 
     246                { 
     247                    dataset->getBuildLog()->report(std::cout); 
     248                } 
     249 
     250                duration = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); 
     251 
     252                dataset->log(osg::NOTICE,"Elapsed time = %f",duration); 
     253 
     254                if (taskFile.valid()) 
     255                { 
     256                    taskFile->setStatus(vpb::Task::COMPLETED); 
     257                } 
     258            } 
     259            else 
     260            { 
     261                dataset->log(osg::NOTICE,"Build configuration invalid : %s",buildProblems.c_str()); 
     262                if (taskFile.valid()) 
     263                { 
     264                    taskFile->setStatus(vpb::Task::FAILED); 
     265                } 
     266            } 
     267 
     268        } 
     269        catch(std::string str) 
     270        { 
     271            printf("Caught exception : %s\n",str.c_str()); 
    249272             
    250273            if (taskFile.valid()) 
    251274            { 
    252                 taskFile->setStatus(vpb::Task::COMPLETED); 
    253             } 
    254  
    255         } 
    256         catch(std::string str) 
    257         { 
    258             printf("Caught exception : %s\n",str.c_str()); 
    259              
    260             taskFile->setStatus(vpb::Task::FAILED); 
    261  
     275                taskFile->setStatus(vpb::Task::FAILED); 
     276            } 
     277             
    262278            result = 1; 
    263279 
     
    267283            printf("Caught exception.\n"); 
    268284             
    269             taskFile->setStatus(vpb::Task::FAILED); 
     285            if (taskFile.valid()) 
     286            { 
     287                taskFile->setStatus(vpb::Task::FAILED); 
     288            } 
    270289 
    271290            result = 1; 
  • trunk/applications/vpbmaster/vpbmaster.cpp

    r901 r932  
    9494    } 
    9595 
    96     if (buildWithoutSlaves) 
     96 
     97    int result = 0;     
     98     
     99    std::string buildProblems = taskManager->checkBuildValidity(); 
     100    if (buildProblems.empty()) 
    97101    { 
    98         taskManager->buildWithoutSlaves(); 
     102        try  
     103        { 
     104            if (buildWithoutSlaves) 
     105            { 
     106                taskManager->buildWithoutSlaves(); 
     107            } 
     108            else 
     109            { 
     110                if (!taskManager->hasTasks()) 
     111                { 
     112                    std::string sourceFileName = taskManager->getBuildName() + std::string("_master.source"); 
     113                    tasksOutputFileName = taskManager->getBuildName() + std::string("_master.tasks"); 
     114 
     115                    taskManager->setSourceFileName(sourceFileName); 
     116                    taskManager->generateTasksFromSource(); 
     117 
     118                    taskManager->writeSource(sourceFileName); 
     119                    taskManager->writeTasks(tasksOutputFileName, true); 
     120 
     121                    taskManager->log(osg::NOTICE,"Generated tasks file = %s",tasksOutputFileName.c_str()); 
     122                } 
     123 
     124                // make sure the OS writes changes to disk 
     125                vpb::sync(); 
     126 
     127                if (taskManager->hasMachines()) 
     128                { 
     129                    taskManager->run(); 
     130                } 
     131                else 
     132                { 
     133                    taskManager->log(osg::NOTICE,"Cannot run build without machines assigned, please pass in a machines definiation file via --machines <file>."); 
     134                } 
     135            } 
     136        } 
     137        catch(std::string str) 
     138        { 
     139            taskManager->log(osg::NOTICE,"Caught exception : %s",str.c_str()); 
     140            result = 1; 
     141        } 
     142        catch(...) 
     143        { 
     144            taskManager->log(osg::NOTICE,"Caught exception."); 
     145            result = 1; 
     146        } 
    99147    } 
    100148    else 
    101149    { 
    102         if (!taskManager->hasTasks()) 
    103         { 
    104             std::string sourceFileName = taskManager->getBuildName() + std::string("_master.source"); 
    105             tasksOutputFileName = taskManager->getBuildName() + std::string("_master.tasks"); 
     150        taskManager->log(osg::NOTICE,"Build configuration invalid : %s",buildProblems.c_str()); 
     151        result = 1; 
     152    } 
    106153 
    107             taskManager->setSourceFileName(sourceFileName); 
    108             taskManager->generateTasksFromSource(); 
    109  
    110             taskManager->writeSource(sourceFileName); 
    111             taskManager->writeTasks(tasksOutputFileName, true); 
    112154             
    113             taskManager->log(osg::NOTICE,"Generated tasks file = %s",tasksOutputFileName.c_str()); 
    114         } 
    115      
    116         // make sure the OS writes changes to disk 
    117         vpb::sync(); 
    118  
    119         if (taskManager->hasMachines()) 
    120         { 
    121             taskManager->run(); 
    122         } 
    123         else 
    124         { 
    125             taskManager->log(osg::NOTICE,"Cannot run build without machines assigned, please pass in a machines definiation file via --machines <file>."); 
    126         } 
    127     } 
    128      
    129155    double duration = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); 
    130156 
     
    134160    vpb::sync(); 
    135161 
    136     return 0
     162    return result
    137163} 
    138164 
  • trunk/include/vpb/BuildOptions

    r929 r932  
    2828namespace vpb 
    2929{ 
    30  
    3130 
    3231class VPB_EXPORT BuildOptions : public osg::Object 
  • trunk/include/vpb/DataSet

    r908 r932  
    199199        std::string getTaskName(unsigned int level, unsigned int X, unsigned int Y) const; 
    200200        std::string getSubtileName(unsigned int level, unsigned int X, unsigned int Y) const; 
     201         
     202        /** Check the build validity, return an empty string if everything is OK, on error return the error string.*/ 
     203        std::string checkBuildValidity(); 
    201204 
    202205    protected: 
  • trunk/include/vpb/Destination

    r931 r932  
    125125    void computeMaximumSourceResolution(CompositeSource* sourceGraph); 
    126126 
    127     bool computeImageResolution(unsigned int layer, unsigned int& numColumns, unsigned int& numRows, double& resX, double& resY); 
     127    bool computeImageResolution(unsigned int layer, const std::string& setname, unsigned int& numColumns, unsigned int& numRows, double& resX, double& resY); 
    128128    bool computeTerrainResolution(unsigned int& numColumns, unsigned int& numRows, double& resX, double& resY); 
    129129 
     
    198198            _image_maxSourceResolutionX(0.0f), 
    199199            _image_maxSourceResolutionY(0.0f) {} 
     200             
     201        bool valid() 
     202        { 
     203            for(LayerSetImageDataMap::iterator itr =_layerSetImageDataMap.begin(); 
     204                itr != _layerSetImageDataMap.end(); 
     205                ++itr) 
     206            { 
     207                if (itr->second._imageDestination.valid() && 
     208                    itr->second._imageDestination->_image.valid()) return true; 
     209            } 
     210            return false; 
     211        } 
    200212 
    201213        typedef std::map<std::string, ImageData> LayerSetImageDataMap; 
     
    208220    }; 
    209221 
    210     std::vector<ImageData>                      _imagery; 
    211222    std::vector<ImageSet>                       _imageLayerSet; 
    212223 
    213     inline ImageData& getImageData(unsigned int layer
    214     { 
    215         if (layer>=_imagery.size()) _imagery.resize(layer+1); 
    216         return _imagery[layer]; 
     224    inline ImageData& getImageData(unsigned int layer, const std::string& setname
     225    { 
     226        if (layer>=_imageLayerSet.size()) _imageLayerSet.resize(layer+1); 
     227        return _imageLayerSet[layer]._layerSetImageDataMap[setname]; 
    217228    } 
    218229 
     
    222233        return _imageLayerSet[layer]; 
    223234    } 
     235     
     236    inline unsigned int getNumLayers() const { return _imageLayerSet.size(); } 
    224237 
    225238    osg::ref_ptr<DestinationData>               _terrain; 
  • trunk/include/vpb/Source

    r930 r932  
    2525namespace vpb 
    2626{ 
     27 
     28// forward declare 
     29class BuildOptions; 
     30 
    2731class VPB_EXPORT Source : public osg::Referenced, public SpatialProperties 
    2832{ 
     
    8387    Type getType() const { return _type; } 
    8488 
    85     void setSetName(const std::string& setname) { _setname = setname; } 
     89    void setSetName(const std::string& setname, BuildOptions* bo); 
     90     
    8691    const std::string& getSetName() const { return _setname; } 
     92 
     93    void setSwitchSetName(const std::string& setname) { _switchSetName = setname; } 
     94    const std::string& getSwitchSetName() const { return _switchSetName; } 
    8795 
    8896    void setFileName(const std::string& filename) { _filename = filename; } 
     
    214222 
    215223    std::string                                 _setname; 
     224    std::string                                 _switchSetName; 
    216225    std::string                                 _filename; 
    217226    bool                                        _temporaryFile; 
  • trunk/include/vpb/TaskManager

    r908 r932  
    135135        void setOutOfDateTasksToPending(); 
    136136 
     137        /** Check the build validity, return an empty string if everything is OK, on error return the error string.*/ 
     138        std::string checkBuildValidity(); 
     139 
    137140    protected: 
    138141 
  • trunk/src/vpb/DataSet.cpp

    r931 r932  
    19711971        // need to read locator. 
    19721972        vpb::Source* source = new vpb::Source(type, hfl->getFileName()); 
    1973         source->setSetName(hfl->getSetName()); 
     1973        source->setSetName(hfl->getSetName(), this); 
    19741974        source->setLayer(layerNum); 
    19751975        source->setMinLevel(layer->getMinLevel()); 
     
    19981998        // need to read locator 
    19991999        vpb::Source* source = new vpb::Source(type, iml->getFileName()); 
    2000         source->setSetName(iml->getSetName()); 
     2000        source->setSetName(iml->getSetName(), this); 
    20012001        source->setLayer(layerNum); 
    20022002        source->setMinLevel(layer->getMinLevel()); 
     
    20272027 
    20282028        vpb::Source* source = new vpb::Source(type, pl->getFileName()); 
    2029         source->setSetName(pl->getSetName()); 
     2029        source->setSetName(pl->getSetName(), this); 
    20302030        source->setLayer(layerNum); 
    20312031        source->setMinLevel(layer->getMinLevel()); 
     
    20612061            { 
    20622062                vpb::Source* source = new vpb::Source(type, compositeLayer->getFileName(i)); 
    2063                 source->setSetName(compositeLayer->getSetName(i)); 
     2063                source->setSetName(compositeLayer->getSetName(i), this); 
    20642064                source->setMinLevel(layer->getMinLevel()); 
    20652065                source->setMaxLevel(layer->getMaxLevel()); 
     
    29482948    return 0; 
    29492949} 
     2950 
     2951std::string DataSet::checkBuildValidity() 
     2952{ 
     2953    bool isTerrain = getGeometryType()==BuildOptions::TERRAIN; 
     2954    bool containsOptionalLayers = !(getOptionalLayerSet().empty()); 
     2955 
     2956    if (containsOptionalLayers && !isTerrain) return std::string("Can not mix optional layers with POLYGONAL and HEIGHTFIELD builds, must use --terrain to enable optional layer support."); 
     2957 
     2958 
     2959    return std::string(); 
     2960} 
  • trunk/src/vpb/Destination.cpp

    r931 r932  
    101101{ 
    102102    for(unsigned int layerNum=0; 
    103         layerNum<_imagery.size(); 
     103        layerNum<getNumLayers(); 
    104104        ++layerNum) 
    105105    { 
    106         unsigned int texture_numColumns; 
    107         unsigned int texture_numRows; 
    108         double texture_dx; 
    109         double texture_dy; 
    110         if (computeImageResolution(layerNum,texture_numColumns,texture_numRows,texture_dx,texture_dy)) 
    111         { 
    112             if (texture_dx*resolutionSensitivityScale > _imagery[layerNum]._image_maxSourceResolutionX) needToDivideX = true; 
    113             if (texture_dy*resolutionSensitivityScale > _imagery[layerNum]._image_maxSourceResolutionY) needToDivideY = true; 
     106        ImageSet& imageSet = getImageSet(layerNum); 
     107        for(ImageSet::LayerSetImageDataMap::iterator itr = imageSet._layerSetImageDataMap.begin(); 
     108            itr != imageSet._layerSetImageDataMap.end(); 
     109            ++itr) 
     110        { 
     111            ImageData& imageData = itr->second; 
     112            unsigned int texture_numColumns; 
     113            unsigned int texture_numRows; 
     114            double texture_dx; 
     115            double texture_dy; 
     116            if (computeImageResolution(layerNum, itr->first, texture_numColumns,texture_numRows,texture_dx,texture_dy)) 
     117            { 
     118                if (texture_dx*resolutionSensitivityScale > imageData._image_maxSourceResolutionX) needToDivideX = true; 
     119                if (texture_dy*resolutionSensitivityScale > imageData._image_maxSourceResolutionY) needToDivideY = true; 
     120            } 
    114121        } 
    115122    } 
     
    166173            } 
    167174 
     175            std::string sourceSetName; 
     176            if (_dataSet->isOptionalLayerSet(source->getSetName())) 
     177            { 
     178                sourceSetName = source->getSetName(); 
     179            } 
     180 
    168181            switch(source->getType()) 
    169182            { 
    170183                case(Source::IMAGE): 
    171184                { 
    172                     ImageData& imageData = getImageData(source->getLayer()); 
     185                    ImageData& imageData = getImageData(source->getLayer(), sourceSetName); 
    173186                    if (imageData._image_maxSourceResolutionX==0.0f) imageData._image_maxSourceResolutionX=sourceResolutionX; 
    174187                    else imageData._image_maxSourceResolutionX=osg::minimum(imageData._image_maxSourceResolutionX,sourceResolutionX); 
     
    209222} 
    210223 
    211 bool DestinationTile::computeImageResolution(unsigned int layer, unsigned int& numColumns, unsigned int& numRows, double& resX, double& resY) 
    212 
    213     ImageData& imageData = getImageData(layer); 
     224bool DestinationTile::computeImageResolution(unsigned int layer, const std::string& setname, unsigned int& numColumns, unsigned int& numRows, double& resX, double& resY) 
     225
     226    bool result = false; 
     227    ImageData& imageData = getImageData(layer,setname); 
     228 
    214229    if (imageData._image_maxSourceResolutionX!=0.0f && imageData._image_maxSourceResolutionY!=0.0f && 
    215230        _image_maxNumColumns!=0 && _image_maxNumRows!=0) 
     
    236251        numColumns = 4; 
    237252        numRows = 4; 
    238          
     253 
    239254        // round to nearest power of two above or equal to the required resolution 
    240255        while (numColumns<numColumnsRequired) numColumns *= 2; 
    241256        while (numRows<numRowsRequired) numRows *= 2; 
    242          
     257 
    243258        // set up properly for vector and raster (previously always vector) 
    244259        // assume raster if _dataType not set (default for Destination Tile) 
     
    253268            resY = (_extents.yMax()-_extents.yMin())/(double)numRows; 
    254269        } 
    255          
    256         return true; 
    257     } 
    258     return false; 
     270        result = true; 
     271    }         
     272    return result; 
    259273} 
    260274 
     
    306320    double texture_dx, texture_dy; 
    307321    for(unsigned int layerNum=0; 
    308         layerNum<_imagery.size(); 
     322        layerNum<getNumLayers(); 
    309323        ++layerNum) 
    310324    { 
    311         if (computeImageResolution(layerNum,texture_numColumns,texture_numRows,texture_dx,texture_dy)) 
    312         { 
    313  
    314             ImageData& imageData = getImageData(layerNum); 
    315  
    316             imageData._imageDestination = new DestinationData(_dataSet); 
    317             imageData._imageDestination->_cs = _cs; 
    318             imageData._imageDestination->_extents = _extents; 
    319             imageData._imageDestination->_geoTransform.set(texture_dx,      0.0,               0.0,0.0, 
    320                                         0.0,             -texture_dy,       0.0,0.0, 
    321                                         0.0,             0.0,               1.0,1.0, 
    322                                         _extents.xMin(), _extents.yMax(),   0.0,1.0); 
    323  
    324  
    325             imageData._imageDestination->_image = new osg::Image; 
    326  
    327             std::string imageName(_name+_dataSet->getDestinationImageExtension()); 
    328             imageData._imageDestination->_image->setFileName(imageName.c_str()); 
    329  
    330             imageData._imageDestination->_image->allocateImage(texture_numColumns,texture_numRows,1,_pixelFormat,GL_UNSIGNED_BYTE); 
    331             unsigned char* data = imageData._imageDestination->_image->data(); 
    332             unsigned int totalSize = imageData._imageDestination->_image->getTotalSizeInBytesIncludingMipmaps(); 
    333             for(unsigned int i=0;i<totalSize;++i) 
    334             { 
    335                 *(data++) = 0; 
     325        ImageSet& imageSet = getImageSet(layerNum); 
     326        for(ImageSet::LayerSetImageDataMap::iterator itr = imageSet._layerSetImageDataMap.begin(); 
     327            itr != imageSet._layerSetImageDataMap.end(); 
     328            ++itr) 
     329        { 
     330            if (computeImageResolution(layerNum, itr->first,  
     331                                       texture_numColumns,texture_numRows,texture_dx,texture_dy)) 
     332            { 
     333 
     334                ImageData& imageData = itr->second; 
     335                imageData._imageDestination = new DestinationData(_dataSet); 
     336                imageData._imageDestination->_cs = _cs; 
     337                imageData._imageDestination->_extents = _extents; 
     338                imageData._imageDestination->_geoTransform.set(texture_dx,      0.0,               0.0,0.0, 
     339                                            0.0,             -texture_dy,       0.0,0.0, 
     340                                            0.0,             0.0,               1.0,1.0, 
     341                                            _extents.xMin(), _extents.yMax(),   0.0,1.0); 
     342 
     343 
     344                imageData._imageDestination->_image = new osg::Image; 
     345 
     346                std::string imageName(_name+_dataSet->getDestinationImageExtension()); 
     347                imageData._imageDestination->_image->setFileName(imageName.c_str()); 
     348 
     349                imageData._imageDestination->_image->allocateImage(texture_numColumns,texture_numRows,1,_pixelFormat,GL_UNSIGNED_BYTE); 
     350                unsigned char* data = imageData._imageDestination->_image->data(); 
     351                unsigned int totalSize = imageData._imageDestination->_image->getTotalSizeInBytesIncludingMipmaps(); 
     352                for(unsigned int i=0;i<totalSize;++i) 
     353                { 
     354                    *(data++) = 0; 
     355                } 
    336356            } 
    337357        } 
     
    462482 
    463483    for(unsigned int layerNum=0; 
    464         layerNum<_imagery.size(); 
     484        layerNum<getNumLayers(); 
    465485        ++layerNum) 
    466486    { 
     
    476496        { 
    477497            TileCornerPair& tcp = *itr; 
    478             if (layerNum<tcp.first->_imagery.size()) 
    479             { 
    480                 ImageData& imageData = tcp.first->_imagery[layerNum]; 
    481                 if (imageData._imageDestination.valid() && imageData._imageDestination->_image.valid()) 
     498            if (layerNum<tcp.first->getNumLayers()) 
     499            { 
     500                ImageSet& imageSet = getImageSet(layerNum); 
     501                for(ImageSet::LayerSetImageDataMap::iterator itr = imageSet._layerSetImageDataMap.begin(); 
     502                    itr != imageSet._layerSetImageDataMap.end(); 
     503                    ++itr) 
    482504                { 
    483                     imagesToProcess.push_back(ImageCornerPair(imageData._imageDestination->_image.get(),tcp.second)); 
     505                    ImageData& imageData = itr->second; 
     506                    if (imageData._imageDestination.valid() && imageData._imageDestination->_image.valid()) 
     507                    { 
     508                        imagesToProcess.push_back(ImageCornerPair(imageData._imageDestination->_image.get(),tcp.second)); 
     509                    } 
    484510                } 
    485511            } 
     
    678704     
    679705    for(unsigned int layerNum=0; 
    680         layerNum<_imagery.size(); 
     706        layerNum<getNumLayers(); 
    681707        ++layerNum) 
    682708    { 
    683         // do we have a image to equalize? 
    684         if (!_imagery[layerNum]._imageDestination.valid()) continue; 
    685          
    686         // does the neighbouring tile have an image to equalize? 
    687         if (layerNum>=tile2->_imagery.size()) continue; 
    688         if (!(tile2->_imagery[layerNum]._imageDestination.valid())) continue; 
    689      
    690  
    691         osg::Image* image1 = _imagery[layerNum]._imageDestination->_image.get(); 
    692         osg::Image* image2 = tile2->_imagery[layerNum]._imageDestination->_image.get(); 
    693  
    694         //log(osg::INFO,"Equalizing edge "<<edgeString(position)<<" of \t"<<_level<<"\t"<<_tileX<<"\t"<<_tileY 
    695         //         <<"  neighbour "<<tile2->_level<<"\t"<<tile2->_tileX<<"\t"<<tile2->_tileY); 
    696  
    697  
    698     //   if (_tileY==0) return; 
    699  
    700         if (image1 && image2 &&  
    701             image1->getPixelFormat()==image2->getPixelFormat() && 
    702             image1->getDataType()==image2->getDataType() && 
    703             image1->getPixelFormat()==GL_RGB && 
    704             image1->getDataType()==GL_UNSIGNED_BYTE) 
    705         { 
    706  
    707             //log(osg::INFO,"   Equalizing image1= "<<image1<<                         " with image2 = "<<image2); 
    708             //log(osg::INFO,"              data1 = 0x"<<std::hex<<(int)image1->data()<<" with data2  = 0x"<<(int)image2->data()); 
    709  
    710             unsigned char* data1 = 0; 
    711             unsigned char* data2 = 0; 
    712             unsigned int delta1 = 0; 
    713             unsigned int delta2 = 0; 
    714             int num = 0; 
    715  
    716             switch(position) 
    717             { 
    718             case LEFT: 
    719                 data1 = image1->data(0,1); // LEFT hand side 
    720                 delta1 = image1->getRowSizeInBytes(); 
    721                 data2 = image2->data(image2->s()-1,1); // RIGHT hand side 
    722                 delta2 = image2->getRowSizeInBytes(); 
    723                 num = (image1->t()==image2->t())?image2->t()-2:0; // note miss out corners. 
    724                 //log(osg::INFO,"       left "<<num); 
    725                 break; 
    726             case BELOW: 
    727                 data1 = image1->data(1,0); // BELOW hand side 
    728                 delta1 = 3; 
    729                 data2 = image2->data(1,image2->t()-1); // ABOVE hand side 
    730                 delta2 = 3; 
    731                 num = (image1->s()==image2->s())?image2->s()-2:0; // note miss out corners. 
    732                 //log(osg::INFO,"       below "<<num); 
    733                 break; 
    734             case RIGHT: 
    735                 data1 = image1->data(image1->s()-1,1); // LEFT hand side 
    736                 delta1 = image1->getRowSizeInBytes(); 
    737                 data2 = image2->data(0,1); // RIGHT hand side 
    738                 delta2 = image2->getRowSizeInBytes(); 
    739                 num = (image1->t()==image2->t())?image2->t()-2:0; // note miss out corners. 
    740                 //log(osg::INFO,"       right "<<num); 
    741                 break; 
    742             case ABOVE: 
    743                 data1 = image1->data(1,image1->t()-1); // ABOVE hand side 
    744                 delta1 = 3; 
    745                 data2 = image2->data(1,0); // BELOW hand side 
    746                 delta2 = 3; 
    747                 num = (image1->s()==image2->s())?image2->s()-2:0; // note miss out corners. 
    748                 //log(osg::INFO,"       above "<<num); 
    749                 break; 
    750             default : 
    751                 //log(osg::INFO,"       default "<<num); 
    752                 break; 
    753             } 
    754  
    755             for(int i=0;i<num;++i) 
    756             { 
    757                 unsigned char red =   (unsigned char)((((int)*data1+ (int)*data2)/2)); 
    758                 unsigned char green = (unsigned char)((((int)*(data1+1))+ (int)(*(data2+1)))/2); 
    759                 unsigned char blue =  (unsigned char)((((int)*(data1+2))+ (int)(*(data2+2)))/2); 
    760     #if 1 
    761                 *data1 = red; 
    762                 *(data1+1) = green; 
    763                 *(data1+2) = blue; 
    764  
    765                 *data2 = red; 
    766                 *(data2+1) = green; 
    767                 *(data2+2) = blue; 
    768     #endif 
    769  
    770     #if 0 
    771                 *data1 = 255; 
    772                 *(data1+1) = 0; 
    773                 *(data1+2) = 0; 
    774  
    775                 *data2 = 0; 
    776                 *(data2+1) = 0; 
    777                 *(data2+2) = 0; 
    778     #endif 
    779                 data1 += delta1; 
    780                 data2 += delta2; 
    781  
    782                 //log(osg::INFO,"    equalizing colour "<<(int)data1<<"  "<<(int)data2); 
    783  
    784             } 
    785  
     709        ImageSet& imageSet = getImageSet(layerNum); 
     710        for(ImageSet::LayerSetImageDataMap::iterator itr = imageSet._layerSetImageDataMap.begin(); 
     711            itr != imageSet._layerSetImageDataMap.end(); 
     712            ++itr) 
     713        { 
     714            ImageData& imageData1 = itr->second; 
     715            ImageData& imageData2 = tile2->getImageData(layerNum, itr->first); 
     716     
     717            // do we have a image to equalize? 
     718            if (!imageData1._imageDestination.valid()) continue; 
     719 
     720            // does the neighbouring tile have an image to equalize? 
     721            if (layerNum>=tile2->getNumLayers()) continue; 
     722            if (!(imageData2._imageDestination.valid())) continue; 
     723 
     724            osg::Image* image1 = imageData1._imageDestination->_image.get(); 
     725            osg::Image* image2 = imageData2._imageDestination->_image.get(); 
     726 
     727            //log(osg::INFO,"Equalizing edge "<<edgeString(position)<<" of \t"<<_level<<"\t"<<_tileX<<"\t"<<_tileY 
     728            //         <<"  neighbour "<<tile2->_level<<"\t"<<tile2->_tileX<<"\t"<<tile2->_tileY); 
     729 
     730 
     731        //   if (_tileY==0) return; 
     732 
     733            if (image1 && image2 &&  
     734                image1->getPixelFormat()==image2->getPixelFormat() && 
     735                image1->getDataType()==image2->getDataType() && 
     736                image1->getPixelFormat()==GL_RGB && 
     737                image1->getDataType()==GL_UNSIGNED_BYTE) 
     738            { 
     739 
     740                //log(osg::INFO,"   Equalizing image1= "<<image1<<                         " with image2 = "<<image2); 
     741                //log(osg::INFO,"              data1 = 0x"<<std::hex<<(int)image1->data()<<" with data2  = 0x"<<(int)image2->data()); 
     742 
     743                unsigned char* data1 = 0; 
     744                unsigned char* data2 = 0; 
     745                unsigned int delta1 = 0; 
     746                unsigned int delta2 = 0; 
     747                int num = 0; 
     748 
     749                switch(position) 
     750                { 
     751                case LEFT: 
     752                    data1 = image1->data(0,1); // LEFT hand side 
     753                    delta1 = image1->getRowSizeInBytes(); 
     754                    data2 = image2->data(image2->s()-1,1); // RIGHT hand side 
     755                    delta2 = image2->getRowSizeInBytes(); 
     756                    num = (image1->t()==image2->t())?image2->t()-2:0; // note miss out corners. 
     757                    //log(osg::INFO,"       left "<<num); 
     758                    break; 
     759                case BELOW: 
     760                    data1 = image1->data(1,0); // BELOW hand side 
     761                    delta1 = 3; 
     762                    data2 = image2->data(1,image2->t()-1); // ABOVE hand side 
     763                    delta2 = 3; 
     764                    num = (image1->s()==image2->s())?image2->s()-2:0; // note miss out corners. 
     765                    //log(osg::INFO,"       below "<<num); 
     766                    break; 
     767                case RIGHT: 
     768                    data1 = image1->data(image1->s()-1,1); // LEFT hand side 
     769                    delta1 = image1->getRowSizeInBytes(); 
     770                    data2 = image2->data(0,1); // RIGHT hand side 
     771                    delta2 = image2->getRowSizeInBytes(); 
     772                    num = (image1->t()==image2->t())?image2->t()-2:0; // note miss out corners. 
     773                    //log(osg::INFO,"       right "<<num); 
     774                    break; 
     775                case ABOVE: 
     776                    data1 = image1->data(1,image1->t()-1); // ABOVE hand side 
     777                    delta1 = 3; 
     778                    data2 = image2->data(1,0); // BELOW hand side 
     779                    delta2 = 3; 
     780                    num = (image1->s()==image2->s())?image2->s()-2:0; // note miss out corners. 
     781                    //log(osg::INFO,"       above "<<num); 
     782                    break; 
     783                default : 
     784                    //log(osg::INFO,"       default "<<num); 
     785                    break; 
     786                } 
     787 
     788                for(int i=0;i<num;++i) 
     789                { 
     790                    unsigned char red =   (unsigned char)((((int)*data1+ (int)*data2)/2)); 
     791                    unsigned char green = (unsigned char)((((int)*(data1+1))+ (int)(*(data2+1)))/2); 
     792                    unsigned char blue =  (unsigned char)((((int)*(data1+2))+ (int)(*(data2+2)))/2); 
     793        #if 1 
     794                    *data1 = red; 
     795                    *(data1+1) = green; 
     796                    *(data1+2) = blue; 
     797 
     798                    *data2 = red; 
     799                    *(data2+1) = green; 
     800                    *(data2+2) = blue; 
     801        #endif 
     802 
     803        #if 0 
     804                    *data1 = 255; 
     805                    *(data1+1) = 0; 
     806                    *(data1+2) = 0; 
     807 
     808                    *data2 = 0; 
     809                    *(data2+1) = 0; 
     810                    *(data2+2) = 0; 
     811        #endif 
     812                    data1 += delta1; 
     813                    data2 += delta2; 
     814 
     815                    //log(osg::INFO,"    equalizing colour "<<(int)data1<<"  "<<(int)data2); 
     816 
     817                } 
     818 
     819            } 
    786820        } 
    787821    } 
     
    10641098    if (_stateset.valid()) return _stateset.get(); 
    10651099 
    1066     if (_imagery.empty()) return 0; 
     1100    if (_imageLayerSet.empty()) return 0; 
    10671101 
    10681102    unsigned int numValidImagerLayers = 0; 
    10691103    unsigned int layerNum; 
    10701104    for(layerNum=0; 
    1071         layerNum<_imagery.size(); 
     1105        layerNum<getNumLayers(); 
    10721106        ++layerNum) 
    10731107    { 
    1074         if (_imagery[layerNum]._imageDestination.valid() &&  
    1075             _imagery[layerNum]._imageDestination->_image.valid()) 
     1108        if (getImageSet(layerNum).valid()) 
    10761109        { 
    10771110            ++numValidImagerLayers; 
     
    10841117 
    10851118    for(layerNum=0; 
    1086         layerNum<_imagery.size(); 
     1119        layerNum<getNumLayers(); 
    10871120        ++layerNum) 
    10881121    { 
    1089         ImageData& imageData = _imagery[layerNum]; 
     1122        ImageSet& imageSet = getImageSet(layerNum); 
     1123        if (imageSet._layerSetImageDataMap.empty()) continue; 
     1124                 
     1125        ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 
    10901126        if (!imageData._imageDestination.valid() || !imageData._imageDestination->_image.valid()) continue; 
    10911127         
     
    14961532    // assign the imagery 
    14971533    for(unsigned int layerNum=0; 
    1498         layerNum<_imagery.size(); 
     1534        layerNum<getNumLayers(); 
    14991535        ++layerNum) 
    15001536    { 
    1501         ImageData& imageData = _imagery[layerNum]; 
     1537        ImageSet& imageSet = getImageSet(layerNum); 
     1538        if (imageSet._layerSetImageDataMap.empty()) continue; 
     1539         
     1540        ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 
    15021541        if (imageData._imageDestination.valid() && imageData._imageDestination->_image.valid()) 
    15031542        {         
     
    18751914    { 
    18761915        for(unsigned int layerNum=0; 
    1877             layerNum<_imagery.size(); 
     1916            layerNum<getNumLayers(); 
    18781917            ++layerNum) 
    18791918        { 
    1880             ImageData& imageData = _imagery[layerNum]; 
     1919            ImageSet& imageSet = getImageSet(layerNum); 
     1920            if (imageSet._layerSetImageDataMap.empty()) continue; 
     1921                         
     1922            ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 
    18811923            if (imageData._imageDestination.valid() && imageData._imageDestination->_image.valid())  
    18821924            { 
     
    22822324                        { 
    22832325                            // copy the base layer 0 into layer 0 and all subsequent layers to provide a backdrop. 
    2284                             for(unsigned int i=0;i<_imagery.size();++i) 
     2326                            for(unsigned int i=0;i<getNumLayers();++i) 
    22852327                            { 
    2286                                 if (_imagery[i]._imageDestination.valid()) 
     2328                                ImageSet& imageSet = getImageSet(i); 
     2329                                if (imageSet._layerSetImageDataMap.empty()) continue; 
     2330 
     2331                                ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 
     2332                                if (imageData._imageDestination.valid()) 
    22872333                                { 
    2288                                     data->read(*(_imagery[i]._imageDestination)); 
     2334                                    data->read(*(imageData._imageDestination)); 
    22892335                                } 
    22902336                            } 
     
    22932339                        { 
    22942340                            // copy specific layer. 
    2295                             if (layerNum<_imagery.size() && _imagery[layerNum]._imageDestination.valid()) 
     2341                            ImageSet& imageSet = getImageSet(layerNum); 
     2342                            if (imageSet._layerSetImageDataMap.empty()) break; 
     2343                             
     2344                            ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 
     2345                            if (layerNum<getNumLayers() && imageData._imageDestination.valid()) 
    22962346                            { 
    2297                                 data->read(*(_imagery[layerNum]._imageDestination)); 
     2347                                data->read(*(imageData._imageDestination)); 
    22982348                            } 
    22992349                        } 
     
    23032353                    { 
    23042354                        // copy the current layer into this and all subsequent layers to provide a backdrop. 
    2305                         for(unsigned int i=layerNum;i<_imagery.size();++i) 
     2355                        for(unsigned int i=layerNum;i<getNumLayers();++i) 
    23062356                        { 
    2307                             if (_imagery[i]._imageDestination.valid()) 
     2357                            ImageSet& imageSet = getImageSet(i); 
     2358                            if (imageSet._layerSetImageDataMap.empty()) continue; 
     2359 
     2360                            ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 
     2361                    &nbs