Changeset 932
- Timestamp:
- 09/05/08 12:48:40
- Files:
-
- trunk/applications/osgdem/osgdem.cpp (modified) (3 diffs)
- trunk/applications/vpbmaster/vpbmaster.cpp (modified) (2 diffs)
- trunk/include/vpb/BuildOptions (modified) (1 diff)
- trunk/include/vpb/DataSet (modified) (1 diff)
- trunk/include/vpb/Destination (modified) (4 diffs)
- trunk/include/vpb/Source (modified) (3 diffs)
- trunk/include/vpb/TaskManager (modified) (1 diff)
- trunk/src/vpb/DataSet.cpp (modified) (5 diffs)
- trunk/src/vpb/Destination.cpp (modified) (19 diffs)
- trunk/src/vpb/Source.cpp (modified) (2 diffs)
- trunk/src/vpb/TaskManager.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/applications/osgdem/osgdem.cpp
r925 r932 205 205 206 206 double duration = 0.0; 207 207 208 208 // generate the database 209 209 if (terrain.valid()) … … 237 237 vpb::sync(); 238 238 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()); 249 272 250 273 if (taskFile.valid()) 251 274 { 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 262 278 result = 1; 263 279 … … 267 283 printf("Caught exception.\n"); 268 284 269 taskFile->setStatus(vpb::Task::FAILED); 285 if (taskFile.valid()) 286 { 287 taskFile->setStatus(vpb::Task::FAILED); 288 } 270 289 271 290 result = 1; trunk/applications/vpbmaster/vpbmaster.cpp
r901 r932 94 94 } 95 95 96 if (buildWithoutSlaves) 96 97 int result = 0; 98 99 std::string buildProblems = taskManager->checkBuildValidity(); 100 if (buildProblems.empty()) 97 101 { 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 } 99 147 } 100 148 else 101 149 { 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 } 106 153 107 taskManager->setSourceFileName(sourceFileName);108 taskManager->generateTasksFromSource();109 110 taskManager->writeSource(sourceFileName);111 taskManager->writeTasks(tasksOutputFileName, true);112 154 113 taskManager->log(osg::NOTICE,"Generated tasks file = %s",tasksOutputFileName.c_str());114 }115 116 // make sure the OS writes changes to disk117 vpb::sync();118 119 if (taskManager->hasMachines())120 {121 taskManager->run();122 }123 else124 {125 taskManager->log(osg::NOTICE,"Cannot run build without machines assigned, please pass in a machines definiation file via --machines <file>.");126 }127 }128 129 155 double duration = osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()); 130 156 … … 134 160 vpb::sync(); 135 161 136 return 0;162 return result; 137 163 } 138 164 trunk/include/vpb/BuildOptions
r929 r932 28 28 namespace vpb 29 29 { 30 31 30 32 31 class VPB_EXPORT BuildOptions : public osg::Object trunk/include/vpb/DataSet
r908 r932 199 199 std::string getTaskName(unsigned int level, unsigned int X, unsigned int Y) const; 200 200 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(); 201 204 202 205 protected: trunk/include/vpb/Destination
r931 r932 125 125 void computeMaximumSourceResolution(CompositeSource* sourceGraph); 126 126 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); 128 128 bool computeTerrainResolution(unsigned int& numColumns, unsigned int& numRows, double& resX, double& resY); 129 129 … … 198 198 _image_maxSourceResolutionX(0.0f), 199 199 _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 } 200 212 201 213 typedef std::map<std::string, ImageData> LayerSetImageDataMap; … … 208 220 }; 209 221 210 std::vector<ImageData> _imagery;211 222 std::vector<ImageSet> _imageLayerSet; 212 223 213 inline ImageData& getImageData(unsigned int layer )214 { 215 if (layer>=_image ry.size()) _imagery.resize(layer+1);216 return _image ry[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]; 217 228 } 218 229 … … 222 233 return _imageLayerSet[layer]; 223 234 } 235 236 inline unsigned int getNumLayers() const { return _imageLayerSet.size(); } 224 237 225 238 osg::ref_ptr<DestinationData> _terrain; trunk/include/vpb/Source
r930 r932 25 25 namespace vpb 26 26 { 27 28 // forward declare 29 class BuildOptions; 30 27 31 class VPB_EXPORT Source : public osg::Referenced, public SpatialProperties 28 32 { … … 83 87 Type getType() const { return _type; } 84 88 85 void setSetName(const std::string& setname) { _setname = setname; } 89 void setSetName(const std::string& setname, BuildOptions* bo); 90 86 91 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; } 87 95 88 96 void setFileName(const std::string& filename) { _filename = filename; } … … 214 222 215 223 std::string _setname; 224 std::string _switchSetName; 216 225 std::string _filename; 217 226 bool _temporaryFile; trunk/include/vpb/TaskManager
r908 r932 135 135 void setOutOfDateTasksToPending(); 136 136 137 /** Check the build validity, return an empty string if everything is OK, on error return the error string.*/ 138 std::string checkBuildValidity(); 139 137 140 protected: 138 141 trunk/src/vpb/DataSet.cpp
r931 r932 1971 1971 // need to read locator. 1972 1972 vpb::Source* source = new vpb::Source(type, hfl->getFileName()); 1973 source->setSetName(hfl->getSetName() );1973 source->setSetName(hfl->getSetName(), this); 1974 1974 source->setLayer(layerNum); 1975 1975 source->setMinLevel(layer->getMinLevel()); … … 1998 1998 // need to read locator 1999 1999 vpb::Source* source = new vpb::Source(type, iml->getFileName()); 2000 source->setSetName(iml->getSetName() );2000 source->setSetName(iml->getSetName(), this); 2001 2001 source->setLayer(layerNum); 2002 2002 source->setMinLevel(layer->getMinLevel()); … … 2027 2027 2028 2028 vpb::Source* source = new vpb::Source(type, pl->getFileName()); 2029 source->setSetName(pl->getSetName() );2029 source->setSetName(pl->getSetName(), this); 2030 2030 source->setLayer(layerNum); 2031 2031 source->setMinLevel(layer->getMinLevel()); … … 2061 2061 { 2062 2062 vpb::Source* source = new vpb::Source(type, compositeLayer->getFileName(i)); 2063 source->setSetName(compositeLayer->getSetName(i) );2063 source->setSetName(compositeLayer->getSetName(i), this); 2064 2064 source->setMinLevel(layer->getMinLevel()); 2065 2065 source->setMaxLevel(layer->getMaxLevel()); … … 2948 2948 return 0; 2949 2949 } 2950 2951 std::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 101 101 { 102 102 for(unsigned int layerNum=0; 103 layerNum< _imagery.size();103 layerNum<getNumLayers(); 104 104 ++layerNum) 105 105 { 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 } 114 121 } 115 122 } … … 166 173 } 167 174 175 std::string sourceSetName; 176 if (_dataSet->isOptionalLayerSet(source->getSetName())) 177 { 178 sourceSetName = source->getSetName(); 179 } 180 168 181 switch(source->getType()) 169 182 { 170 183 case(Source::IMAGE): 171 184 { 172 ImageData& imageData = getImageData(source->getLayer() );185 ImageData& imageData = getImageData(source->getLayer(), sourceSetName); 173 186 if (imageData._image_maxSourceResolutionX==0.0f) imageData._image_maxSourceResolutionX=sourceResolutionX; 174 187 else imageData._image_maxSourceResolutionX=osg::minimum(imageData._image_maxSourceResolutionX,sourceResolutionX); … … 209 222 } 210 223 211 bool DestinationTile::computeImageResolution(unsigned int layer, unsigned int& numColumns, unsigned int& numRows, double& resX, double& resY) 212 { 213 ImageData& imageData = getImageData(layer); 224 bool 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 214 229 if (imageData._image_maxSourceResolutionX!=0.0f && imageData._image_maxSourceResolutionY!=0.0f && 215 230 _image_maxNumColumns!=0 && _image_maxNumRows!=0) … … 236 251 numColumns = 4; 237 252 numRows = 4; 238 253 239 254 // round to nearest power of two above or equal to the required resolution 240 255 while (numColumns<numColumnsRequired) numColumns *= 2; 241 256 while (numRows<numRowsRequired) numRows *= 2; 242 257 243 258 // set up properly for vector and raster (previously always vector) 244 259 // assume raster if _dataType not set (default for Destination Tile) … … 253 268 resY = (_extents.yMax()-_extents.yMin())/(double)numRows; 254 269 } 255 256 return true; 257 } 258 return false; 270 result = true; 271 } 272 return result; 259 273 } 260 274 … … 306 320 double texture_dx, texture_dy; 307 321 for(unsigned int layerNum=0; 308 layerNum< _imagery.size();322 layerNum<getNumLayers(); 309 323 ++layerNum) 310 324 { 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 } 336 356 } 337 357 } … … 462 482 463 483 for(unsigned int layerNum=0; 464 layerNum< _imagery.size();484 layerNum<getNumLayers(); 465 485 ++layerNum) 466 486 { … … 476 496 { 477 497 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) 482 504 { 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 } 484 510 } 485 511 } … … 678 704 679 705 for(unsigned int layerNum=0; 680 layerNum< _imagery.size();706 layerNum<getNumLayers(); 681 707 ++layerNum) 682 708 { 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 } 786 820 } 787 821 } … … 1064 1098 if (_stateset.valid()) return _stateset.get(); 1065 1099 1066 if (_image ry.empty()) return 0;1100 if (_imageLayerSet.empty()) return 0; 1067 1101 1068 1102 unsigned int numValidImagerLayers = 0; 1069 1103 unsigned int layerNum; 1070 1104 for(layerNum=0; 1071 layerNum< _imagery.size();1105 layerNum<getNumLayers(); 1072 1106 ++layerNum) 1073 1107 { 1074 if (_imagery[layerNum]._imageDestination.valid() && 1075 _imagery[layerNum]._imageDestination->_image.valid()) 1108 if (getImageSet(layerNum).valid()) 1076 1109 { 1077 1110 ++numValidImagerLayers; … … 1084 1117 1085 1118 for(layerNum=0; 1086 layerNum< _imagery.size();1119 layerNum<getNumLayers(); 1087 1120 ++layerNum) 1088 1121 { 1089 ImageData& imageData = _imagery[layerNum]; 1122 ImageSet& imageSet = getImageSet(layerNum); 1123 if (imageSet._layerSetImageDataMap.empty()) continue; 1124 1125 ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 1090 1126 if (!imageData._imageDestination.valid() || !imageData._imageDestination->_image.valid()) continue; 1091 1127 … … 1496 1532 // assign the imagery 1497 1533 for(unsigned int layerNum=0; 1498 layerNum< _imagery.size();1534 layerNum<getNumLayers(); 1499 1535 ++layerNum) 1500 1536 { 1501 ImageData& imageData = _imagery[layerNum]; 1537 ImageSet& imageSet = getImageSet(layerNum); 1538 if (imageSet._layerSetImageDataMap.empty()) continue; 1539 1540 ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 1502 1541 if (imageData._imageDestination.valid() && imageData._imageDestination->_image.valid()) 1503 1542 { … … 1875 1914 { 1876 1915 for(unsigned int layerNum=0; 1877 layerNum< _imagery.size();1916 layerNum<getNumLayers(); 1878 1917 ++layerNum) 1879 1918 { 1880 ImageData& imageData = _imagery[layerNum]; 1919 ImageSet& imageSet = getImageSet(layerNum); 1920 if (imageSet._layerSetImageDataMap.empty()) continue; 1921 1922 ImageData& imageData = imageSet._layerSetImageDataMap.begin()->second; 1881 1923 if (imageData._imageDestination.valid() && imageData._imageDestination->_image.valid()) 1882 1924 { … … 2282 2324 { 2283 2325 // 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) 2285 2327 { 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()) 2287 2333 { 2288 data->read(*( _imagery[i]._imageDestination));2334 data->read(*(imageData._imageDestination)); 2289 2335 } 2290 2336 } … … 2293 2339 { 2294 2340 // 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()) 2296 2346 { 2297 data->read(*( _imagery[layerNum]._imageDestination));2347 data->read(*(imageData._imageDestination)); 2298 2348 } 2299 2349 } … … 2303 2353 { 2304 2354 // 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) 2306 2356 { 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
