void ossimQtStaticTileImageCache::flush(const ossimIrect& rect)
{
   if(rect == getCacheRect())
   {
      std::fill(theValidTileArray.begin(),
                theValidTileArray.end(),
                false);
//      theCache.fill(0);
   }
   else
   {
      int x = 0;
      int y = 0;
      int upperX = 0;
      int upperY = 0;
      ossimIrect tempRect = rect;
      tempRect.stretchToTileBoundary(theTileSize);

      upperX = tempRect.lr().x;
      upperY = tempRect.lr().y;
      for(y = tempRect.ul().y; y < upperY; y+=theTileSize.y)
      {
         for(x = tempRect.ul().x; x < upperX; x+=theTileSize.x)
         {
            ossim_int32 idx = getTileIndex(x, y);
            if(idx >= 0)
            {
               theValidTileArray[idx] = false; 
            }
         }
      }
   }
}
int VisibilityManager::getCoordVisibility(const Coordinate coord, const TeamID team) const {
	Coordinate tile = this->getTileCoords(coord);
	int k = getTileIndex(tile, team);
	int a = k<0 ?  0 : this->visibilityTimeGrid[k];
	return std::min(255, 16*a);
	//return std::min(255, 16*this->visibilityTimeGrid.at(std::make_pair(this->getTileCoords(coord), team)) );
}
void ossimGui::StaticTileImageCache::flush(const ossimIrect& rect)
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex);
   if(rect == getRect())
   {
      std::fill(m_validTileArray.begin(),
                m_validTileArray.end(),
                false);
   }
   else
   {
      int x = 0;
      int y = 0;
      int upperX = 0;
      int upperY = 0;
      ossimIrect tempRect = rect;
      tempRect.stretchToTileBoundary(m_tileSize);

      upperX = tempRect.lr().x;
      upperY = tempRect.lr().y;
      for(y = tempRect.ul().y; y < upperY; y+=m_tileSize.y)
      {
         for(x = tempRect.ul().x; x < upperX; x+=m_tileSize.x)
         {
            ossim_int32 idx = getTileIndex(m_cacheRect, m_numberOfTiles, x, y);
            if(idx >= 0)
            {
               m_validTileArray[idx] = false; 
            }
         }
      }
   }
}
Example #4
0
/*
 * Remove the given tile from the group.
 */
void tileGroup::removeTile(tile* t) {
	int index = getTileIndex(t);
    list<tile*>::iterator it = tiles.begin();
	if (index >= 0) {
		advance(it, index);
		tiles.erase(it);
	}
}
ossim_int32 ossimGui::StaticTileImageCache::getTileIndex(const ossimIrect& rect,
                                                      const ossimIpt& numberOfTiles,
                                                      const ossimIpt& origin)const
{
   return getTileIndex(rect,
                       numberOfTiles,
                       origin.x,
                       origin.y);
}
bool ossimGui::StaticTileImageCache::isValid(const ossimIpt& pt)const
{
   ossim_int32 idx = getTileIndex(pt);

   if(idx >= 0)
   {
      return m_validTileArray[idx];
   }

   return false;
}
bool ossimGui::StaticTileImageCache::addTile(const QImage& image)
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex);
   bool result = false;
   
   ossimIrect tileRect(image.offset().x(),
                       image.offset().y(),
                       image.offset().x() + (image.width()-1),
                       image.offset().y() + (image.height()-1));
   ossimIrect cacheRect = m_cacheRect;
   
   if(tileRect.intersects(cacheRect))
   {
      ossimIrect clipRect = tileRect.clipToRect(cacheRect);
      
      // now fill the clipped rect
      ossim_uint32 srcY = clipRect.ul().y-tileRect.ul().y;
      ossim_uint32 srcX = clipRect.ul().x-tileRect.ul().x;
      ossim_uint32 destY = clipRect.ul().y-cacheRect.ul().y;
      ossim_uint32 destX = clipRect.ul().x-cacheRect.ul().x;
      ossimIpt offset = tileRect.ul() - cacheRect.ul();
      ossim_uint32 x,y;
      for(y = 0; y < clipRect.height(); ++y)
      {
         ossim_uint32* cachePtr = ((ossim_uint32*)m_cache->scanLine(y+destY))+destX;
         ossim_uint32* tilePtr  = ((ossim_uint32*)image.scanLine(y+srcY))+srcX;
         for(x = 0; x < clipRect.width(); ++x)
         {
            *cachePtr = *tilePtr;
            ++cachePtr;
            ++tilePtr;
         }
      }
      ossimIpt tilePoint(tileRect.ul());

      for(y = 0; y < tileRect.height(); y+=m_tileSize.y)
      {
         tilePoint.x = tileRect.ul().x;
         for(x = 0; x < tileRect.width(); x+=m_tileSize.x)
         {
            ossim_int32 idx = getTileIndex(m_cacheRect, m_numberOfTiles, tilePoint);
            if(idx>=0)
            {
               m_validTileArray[idx] = true;
            }
            tilePoint.x+= m_tileSize.x;
         }
         tilePoint.y+=m_tileSize.y;
      }
      result = true;      
   }
   
   return result;
}
void VisibilityManager::decrementTileVisibility(const Coordinate center, const TeamID team) {
	for (int i = -visibilityRadius ; i<=visibilityRadius ; i++ ) {
		for (int j = -visibilityRadius ; j<=visibilityRadius ; j++ ) {
			Coordinate coord(center.x+i, center.y+j);
			if (pythagoreanDistanceLessThan(center, coord, VisibilityManager::visibilityRadius)) {
				int k = getTileIndex(coord, team);
				if (k>0) // if on board
					this->visibilityGrid[k]--;
			}
		}
	}
}
Example #9
0
void init(SDL_Renderer* renderer)
{
	input_show_debug_rect = false;

    worldMap.Load("test.map");
    //worldMap.NewMap(32, 32);
	
	reset_view();
	tileset = IMG_LoadTexture(renderer, "tileset.png");
	SDL_QueryTexture(tileset, NULL, NULL, &tilesetRect.get()->w, &tilesetRect.get()->h);
	TILESET_WIDTH = tilesetRect.get()->w / tileSizeX;
	TILESET_HEIGHT = tilesetRect.get()->h / tileSizeY;

	TILES_EDITOR[0] = getTileIndex(0, 0, TILESET_WIDTH);
	TILES_EDITOR[1] = getTileIndex(0, 6, TILESET_WIDTH);
	TILES_EDITOR[2] = getTileIndex(4, 11, TILESET_WIDTH);
	TILES_EDITOR[3] = getTileIndex(4, 8, TILESET_WIDTH);
	TILES_EDITOR[4] = getTileIndex(8, 12, TILESET_WIDTH);
	for (int i = 0; i < NB_TILES_EDITOR; i++) {
		std::cout << "editor[" << i << "]= " << TILES_EDITOR[i] << "\n";
	}
}
bool ossimGui::StaticTileImageCache::getTile(const ossimIpt& pt,
                                      QImage& image)const
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex);
   bool result = false;
   ossimIpt tileOrigin = getTileOrigin(pt);
   ossimIrect cacheRect = getRect();

   if((image.width() != m_tileSize.x)||
      (image.height() != m_tileSize.y))
   {
      image = QImage(m_tileSize.x,
                     m_tileSize.y,
                     QImage::Format_RGB32);
   }
   if(cacheRect.pointWithin(tileOrigin))
   {
      ossimIpt delta(tileOrigin.x - cacheRect.ul().x,
                     tileOrigin.y - cacheRect.ul().y);

      if((delta.x >= 0)&&(delta.y >= 0))
      {
         image = m_cache->copy(tileOrigin.x - cacheRect.ul().x,
                               tileOrigin.y - cacheRect.ul().y,
                               m_tileSize.x,
                               m_tileSize.y);
	 ossim_int32 idx = getTileIndex(m_cacheRect, m_numberOfTiles, pt);
	 if(idx >=0)
	   {
	     result = m_validTileArray[idx];
	   }
      }
      else
      {
         image.fill(0);
      }
   }
   else
   {
      image.fill(0);
   }

   return result;
}
bool ossimQtStaticTileImageCache::getTile(const ossimIpt& pt,
                                      QImage& image)const
{
  bool result = false;
   ossimIpt tileOrigin = getTileOrigin(pt);
   ossimIrect cacheRect = getCacheRect();

   if((image.width() != theTileSize.x)||
      (image.height() != theTileSize.y))
   {
      image.create(theTileSize.x,
                   theTileSize.y,
                   32);
   }
   if(cacheRect.pointWithin(tileOrigin))
   {
      ossimIpt delta(tileOrigin.x - cacheRect.ul().x,
                     tileOrigin.y - cacheRect.ul().y);

      if((delta.x >= 0)&&(delta.y >= 0))
      {
         image = theCache.copy(tileOrigin.x - cacheRect.ul().x,
                               tileOrigin.y - cacheRect.ul().y,
                               theTileSize.x,
                               theTileSize.y);
	 ossim_int32 idx = getTileIndex(pt);
	 if(idx >=0)
	   {
	     result = theValidTileArray[idx];
	   }
      }
      else
      {
         image.fill(0);
      }
   }
   else
   {
      image.fill(0);
   }

   return result;
}
bool ossimQtStaticTileImageCache::addTile(QImage& image)
{
   bool result = false;
   
   if(((image.offset().x()%theTileSize.x)==0)&&
      ((image.offset().y()%theTileSize.y)==0)&&
      (image.width() == theTileSize.x)&&
      (image.height() == theTileSize.y))
   {
      ossimIrect tileRect(image.offset().x(),
                          image.offset().y(),
                          image.offset().x() + (image.width()-1),
                          image.offset().y() + (image.height()-1));
      ossimIrect cacheRect = getCacheRect();

      if(tileRect.completely_within(cacheRect))
      {
         QRgb* tilePtr = (QRgb*)image.bits();
         ossimIpt offset = tileRect.ul() - cacheRect.ul();
         int x = 0;
         int y = 0;
         for(y = 0; y < theTileSize.y; ++y)
         {
            QRgb* cachePtr = ((QRgb*)theCache.scanLine(y+offset.y))+offset.x;
            for(x = 0; x < theTileSize.x; ++x)
            {
               *cachePtr = *tilePtr;
               ++cachePtr;
               ++tilePtr;
            }
         }
         ossim_int32 idx = getTileIndex(tileRect.ul());

         theValidTileArray[idx] = true;
         
         result = true;

      }
   }

   return result;
}
void Spartan6Die::process() {
	if( been_processed == true )
		return;
	been_processed = true;


	tile_coord_lookup.resize( tiles.size()+1 );

	// create 2D tile coordiante look-up table
	for( auto& ti : tiles ) {
		tile_coord_lookup[ getTileIndex(ti.x(), ti.y()) ] = &ti;
	}

	verbose( "tile_coord_lookup table build for %i tiles\n", (int)tiles.size() );

	// clockdomains go across the die
	// Each clockdoman can have a diffrent set of majors!
	// 	  Wolf never found this as the sx9 part was symmetrical, sx25 isn't

	clockdomains.resize( num_physical_rows );

	// tile row coordinates
	// scan row 10 (skip 2 row for bottom and half a row of clb to get to the hclk)
	// each physical row is 17 tile rows
	// plus have to adjust in second half for center row (1 rows of a REGH )
	//      the clock row before the center is slightly different in ints tile types


	// scan wolf style major columns from actual tile columns
	// Logic are 2 INT + XM | XL
	// BRAM = 3
	// DSP = 3
	// LEFT = 5
	// RIGHT = 5
	// Scan from middle of first row (tile row 10)	
	int pr = 0;
	for( auto& cd : clockdomains ) {
		auto& row_major = cd.majors;

		int y = 10 + (17 * pr) + ((pr < (num_physical_rows+1)/2) ? 0 : 1);
		cd.top_tile_row = y - 10;

		int x = 0;
		// first 5 should have HCLK_IOI_LTERM
		bool found_lterm = false;
		for( x = 0;x < 5; x++ ) {
			const auto tile = tile_coord_lookup[ getTileIndex(x,y) ];
			verbose( "<%i,%i> tile type %s\n", tile->tile_col, tile->tile_row, to_string(tile->type).c_str() );
			assert( tile->tile_col == x && tile->tile_row == y);
			if( tile->type == Spartan6TileTypes::HCLK_IOI_LTERM || 
				tile->type == Spartan6TileTypes::HCLK_IOI_LTERM_BOT25 // this only happens on the row before the center marker
				) {
				found_lterm = true;
				break;
			}
		}
		assert( found_lterm == true );
		row_major.push_back( MajorType::LTERM );
		x = 5;

		bool found_rterm = false;
		// scan until we hit right
		while( (x < num_tile_rows) &&  (found_rterm == false) ) { 

			const auto tile = tile_coord_lookup[ getTileIndex(x,y) ];
			verbose( "<%i,%i> tile type %s\n", tile->tile_col, tile->tile_row, to_string(tile->type).c_str() );
			switch( tile->type ) {
				case Spartan6TileTypes::HCLK_IOIR_INT:
				case Spartan6TileTypes::HCLK_IOI_RTERM:
					row_major.push_back( MajorType::RTERM );
					found_rterm = true;
					break;
				case Spartan6TileTypes::HCLK_CLB_XM_INT: // Spartan 6 always have switch matrix before logic
					assert( tile_coord_lookup[ getTileIndex(x+1,y) ]->type == Spartan6TileTypes::HCLK_CLB_XM_CLE );
					row_major.push_back( MajorType::CLB_XM);
					x+=2; // CLB_XM are two rows INT + CLE
				break;
				case Spartan6TileTypes::HCLK_CLB_XL_INT: // Spartan 6 always have switch matrix before logic
					assert( tile_coord_lookup[ getTileIndex(x+1,y) ]->type == Spartan6TileTypes::HCLK_CLB_XL_CLE );
					row_major.push_back( MajorType::CLB_XL);
					x+=2; // CLB_XL are two rows INT + CLE
				break;
				case Spartan6TileTypes::HCLK_CLB_XM_CLE_FOLD: // folds seem to have the switch matrix after?
					assert( tile_coord_lookup[ getTileIndex(x+1,y) ]->type == Spartan6TileTypes::HCLK_CLB_XM_INT );
					row_major.push_back( MajorType::CLB_XM_FOLD); 
					x+=2; // CLB_XM_FOLD are two rows CLE_FOLD INT
					break;
				case Spartan6TileTypes::HCLK_CLB_XL_CLE_FOLD: // folds seem to have the switch matrix after?
					assert( tile_coord_lookup[ getTileIndex(x+1,y) ]->type == Spartan6TileTypes::HCLK_CLB_XL_INT );
					row_major.push_back( MajorType::CLB_XL_FOLD);
					x+=2; // CLB_XL_FOLD are two rows CLE_FOLD + INT
				break;
				case Spartan6TileTypes::BRAM_HCLK_FEEDTHRU:
					assert( tile_coord_lookup[ getTileIndex(x+1,y) ]->type == Spartan6TileTypes::BRAM_HCLK_FEEDTHRU_INTER );
					assert( tile_coord_lookup[ getTileIndex(x+2,y) ]->type == Spartan6TileTypes::HCLK_BRAM_FEEDTHRU );
					row_major.push_back( MajorType::BRAM);
					x+=3; // BRAM are three rows
				break;
				case Spartan6TileTypes::DSP_INT_HCLK_FEEDTHRU:
					assert( tile_coord_lookup[ getTileIndex(x+1,y) ]->type == Spartan6TileTypes::DSP_CLB_HCLK_FEEDTHRU );
					assert( tile_coord_lookup[ getTileIndex(x+2,y) ]->type == Spartan6TileTypes::DSP_HCLK_FEEDTHRU_TOP );
					row_major.push_back( MajorType::DSP);
					x+=3; // DSP are three rows
				break;
				case Spartan6TileTypes::CMT_HCLK_BOT25: // TODO what is this?
				case Spartan6TileTypes::NULL_TILE:
					row_major.push_back( MajorType::NULL_TYPE );
					x+=1;
				break;

				case Spartan6TileTypes::REG_V_HCLK_BOT25:
				case Spartan6TileTypes::REG_V_HCLK:
					row_major.push_back( MajorType::CENTER );				
					x+=1;
				break;
				case Spartan6TileTypes::HCLK_CLB_XM_CLE: 
					// this should always follow an XM_INT but in one case it doesn't, this makes no sense as all CLE
					// need an switch matrix, but apparently if the torc DB is right, there is one that doesn't.. hmmm
					// for now ignore it but odd very odd... its after a fold which might mean something?
					// problem is will it screw up minor counting...
					x+=1;		
				break;
				default:
					x+=1;
					error( "Unknown tile type in major scan %s\n", to_string(tile->type).c_str() );
			}
		}

		// interesting using torc db seems that center is a 2 minor, wheras wolf thought it was 4
		// the other 2 are showing up as a standard logic XL which also is more symmetrical. so
		// I think torc db is right

		debug( "Physical row %i Majors ", pr );
		uint16_t& total_minors = cd.frame_count;
		total_minors = 0;
		uint16_t majorCount = 0;
		for( auto ma : row_major ) {
			debug( "%s (%i), ", to_string(ma).c_str(), get_num_minors(ma) );
			if( ma == MajorType::CENTER ) {
				cd.center_major_index = majorCount;
			}
			if( ma == MajorType::RTERM ) {
				cd.right_major_index = majorCount;				
			}
			total_minors += get_num_minors(ma);
			majorCount++;
		}

		debug ("\n");
		debug("minors per row %i\n", total_minors );


		pr++; // next physical row
	}


}
bool VisibilityManager::tileIsVisibleToTeam(const Coordinate tile, const TeamID team) const {
	int k = getTileIndex(tile, team);
	if (k<0) return false;
	else return (bool)this->visibilityTimeGrid[team*w*h + tile.x*h + tile.y];
}
bool VisibilityManager::coordIsVisibleToTeam(const Coordinate location, const TeamID team) const {
	Coordinate tile = this->getTileCoords(location);
	int k = getTileIndex(tile, team);
	if (k<0) return false;
	else return (bool)this->visibilityTimeGrid[k];
}
Example #16
0
//width and heigth are in 'pixels'
vector<float> getElevations(float _lat,float _lng,int width,int height,float vscale,float rot, int waterDrop, int baseHeight, int stepSize){
	int tileNumber = 0;
	string tileName = "";
	ifstream file;
	vector<float> outList(width*height);

	file.open("../Terrain2STL-master/hgt_files/N44W070.hgt");

	int h;
	char number [2];

	int t = getTileIndex(_lat,_lng);

	//let's go with mercator space for now (Terrain2STL style)
	for(int x = 0; x<width; x++){
		for(int y = 0; y<height; y++){
			float u = (float)y/1200 - (float)height/1200;
			float v = (float)x/1200;

			u *= stepSize;
			v *= stepSize;

			//get the lat and lng for each point
			float lat = _lat + u*cos(rot) + v*sin(rot);
			float lng = _lng + v*cos(rot) - u*sin(rot);

			//interpolate - maybe skip for rot0=0?

			float elevations[2][2];
			for(int a = 0; a < 2; a++){		//x coord for Interpolation
				for(int b = 0; b < 2; b++){ //

					//interesting bit of code here.
					//floor(...)/1200 as no distortion but cannot handle tile edges
					//x+float() handles edges well but with distortion
					//lat+(float)b/1200
					float intlat = floor(lat*1200+b)/1200.0+0.000598907;	//magic number??
					float intlng = floor(lng*1200+a)/1200.0;
					//floor(lng*1200+a)/1200;

					if(getTileIndex(intlat, intlng)!=tileNumber){
						tileNumber = getTileIndex(intlat, intlng);
						tileName = getTile(intlat, intlng);

						file.close();
			      file.open(tileName.c_str(),ios::in|ios::binary);
					}

					int p = (int) (1201*(intlng-floor(intlng)));		//x or lng component
					p += (int)(1201*(ceil(intlat)-intlat))* 1201;	//y or lat component

					file.seekg(p*2,ios::beg);
			    file.read(number,2);
			    h = number[1];
			    if(h<0){
			      h = h+255;
			    }
			    h+= number[0]*256;
					if(h==0){
						h-= waterDrop/vscale;
					}
					elevations[a][b]= (float)h;
				}
			}
			float fracLat = lat-floor(lat*1200)/1200;
			float fracLng = lng-floor(lng*1200)/1200;
			fracLat *= 1200;
			fracLng *= 1200;
			float westLng = elevations[0][0]*(1-fracLat)  +  elevations[0][1]*fracLat;
			float eastLng = elevations[1][0]*(1-fracLat)  +  elevations[1][1]*fracLat;

			//not sure about this....
			float intHeight = westLng*(1-fracLng) + eastLng*fracLng;

			//if(t!=getTileIndex(lat,lng)){
			//	intHeight=0;
			//}
			//float intHeight = (elevations[0][0]+elevations[0][1]+elevations[1][0]+elevations[1][1])/4;
			outList.at(y*width+x) = intHeight*vscale+baseHeight;
		}
	}
	file.close();
	clog << "Done getting elevations\n";
	return outList;
}
int VisibilityManager::getTileVisibility(const Coordinate tile, const TeamID team) const {
	int k = getTileIndex(tile, team);
	int a = k<0 ? 0 : this->visibilityTimeGrid[team*w*h + tile.x*h + tile.y];
	return std::min(255, 64+12*a);
}
ossim_int32 ossimGui::StaticTileImageCache::getTileIndex(ossim_int32 x,
                                                      ossim_int32 y)const
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex);
   return getTileIndex(m_cacheRect, m_numberOfTiles, x, y);
}
ossim_int32 ossimGui::StaticTileImageCache::getTileIndex(const ossimIpt& origin)const
{
   return getTileIndex(origin.x,
                       origin.y);
}
Example #20
0
Tile* TileMap::getTileByPos(float x, float y)
{
	sf::Vector2i ind = getTileIndex(x, y);
	return getTileByIndex(ind.x, ind.y);
}
void ossimGui::StaticTileImageCache::setRect(const ossimIrect& newRect)
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex);
   ossimIrect tempRect = newRect;
   m_actualRect = newRect;
   tempRect.stretchToTileBoundary(m_tileSize);

   ossimIrect currentRect = m_cacheRect;

   m_cacheRect = tempRect;
   if(currentRect != tempRect)
   {
      if(!currentRect.intersects(tempRect))
      {
         if((currentRect.width()  != tempRect.width()) ||
            (currentRect.height() != tempRect.height()))
         {
            delete m_cache;
            m_cache = new QImage(tempRect.width(),
                                 tempRect.height(),
                                 QImage::Format_RGB32);
         }
         m_cache->fill(0);
         m_cache->setOffset(QPoint(tempRect.ul().x,
                                   tempRect.ul().y));
         currentRect = m_cacheRect;
         m_numberOfTiles.x = currentRect.width()/m_tileSize.x;
         m_numberOfTiles.y = currentRect.height()/m_tileSize.y;
         m_validTileArray.resize(m_numberOfTiles.x*m_numberOfTiles.y);
         std::fill(m_validTileArray.begin(),
                   m_validTileArray.end(),
                   false);
      }
      else
      {
         ossimIrect intersectionRect = currentRect.clipToRect(tempRect);
         ossimIpt offset = tempRect.ul() - currentRect.ul();
         
         ossimIpt oldNumberOfTiles = m_numberOfTiles;
         std::vector<bool> oldValidTileArray = m_validTileArray;
         ossimIrect  oldRect = currentRect;
         
         *m_cache = m_cache->copy(offset.x,
                                  offset.y,
                                  tempRect.width(),
                                  tempRect.height());
         
         m_cache->setOffset(QPoint(tempRect.ul().x,
                                   tempRect.ul().y));
         
         currentRect = m_cacheRect;
         m_numberOfTiles.x = currentRect.width()/m_tileSize.x;
         m_numberOfTiles.y = currentRect.height()/m_tileSize.y;

         
         m_validTileArray.resize(m_numberOfTiles.x*m_numberOfTiles.y);

         std::fill(m_validTileArray.begin(),
                   m_validTileArray.end(),
                   false);
         
         int x = 0;
         int y = 0;
         int urX = intersectionRect.ur().x;
         int lrY = intersectionRect.lr().y;
         
         for(x = intersectionRect.ul().x; x <= urX; x+=m_tileSize.x)
         {
            for(y = intersectionRect.ul().y; y <= lrY; y+=m_tileSize.y)
            {
               ossim_int32 idx    = getTileIndex(m_cacheRect, m_numberOfTiles, x, y);
               ossim_int32 oldIdx = getTileIndex(oldRect,
                                                 oldNumberOfTiles,
                                                 x,
                                                 y);
               if(idx > -1)
               {
                  if(oldIdx > -1)
                  {
                     m_validTileArray[idx] = oldValidTileArray[oldIdx];
                  }
               }
            }
         }
      }
   }
}
void ossimQtStaticTileImageCache::setRect(const ossimIrect& newRect)
{
   ossimIrect tempRect = newRect;

   tempRect.stretchToTileBoundary(theTileSize);

   ossimIrect currentRect = getCacheRect();

   if(currentRect != tempRect)
   {
      if(!currentRect.intersects(tempRect))
      {
         if((currentRect.width()  != tempRect.width()) ||
            (currentRect.height() != tempRect.height()))
         {
            theCache.create(tempRect.width(),
                            tempRect.height(),
                            32);
         }
         theCache.fill(0);
         theCache.setOffset(QPoint(tempRect.ul().x,
                                   tempRect.ul().y));
         currentRect = getCacheRect();
         theNumberOfTiles.x = currentRect.width()/theTileSize.x;
         theNumberOfTiles.y = currentRect.height()/theTileSize.y;
         theValidTileArray.resize(theNumberOfTiles.x*theNumberOfTiles.y);
         std::fill(theValidTileArray.begin(),
                   theValidTileArray.end(),
                   false);
      }
      else
      {
         ossimIrect intersectionRect = currentRect.clipToRect(tempRect);
         ossimIpt offset = tempRect.ul() - currentRect.ul();
         
         ossimIpt oldNumberOfTiles = theNumberOfTiles;
         std::vector<bool> oldValidTileArray = theValidTileArray;
         ossimIrect  oldRect = currentRect;
         
         theCache = theCache.copy(offset.x,
                                  offset.y,
                                  tempRect.width(),
                                  tempRect.height());
         
         theCache.setOffset(QPoint(tempRect.ul().x,
                                   tempRect.ul().y));
         
         currentRect = getCacheRect();
         theNumberOfTiles.x = currentRect.width()/theTileSize.x;
         theNumberOfTiles.y = currentRect.height()/theTileSize.y;

         
         theValidTileArray.resize(theNumberOfTiles.x*theNumberOfTiles.y);

         std::fill(theValidTileArray.begin(),
                   theValidTileArray.end(),
                   false);
         
         int x = 0;
         int y = 0;
         int urX = intersectionRect.ur().x;
         int lrY = intersectionRect.lr().y;
         
         for(x = intersectionRect.ul().x; x <= urX; x+=theTileSize.x)
         {
            for(y = intersectionRect.ul().y; y <= lrY; y+=theTileSize.y)
            {
               ossim_int32 idx    = getTileIndex(x, y);
               ossim_int32 oldIdx = getTileIndex(oldRect,
                                                 oldNumberOfTiles,
                                                 x,
                                                 y);
               if(idx > -1)
               {
                  if(oldIdx > -1)
                  {
                     theValidTileArray[idx] = oldValidTileArray[oldIdx];
                  }
               }
            }
         }
      }
   }
}