void Player::toBoat(Display* display) { if(!((getCurrentTile(display) == display->getWaterHandle(1)) || getCurrentTile(display) == display->getWaterHandle(2))) { shipState = false; } if(keyboard->getState(SDLK_z)) { if((getNextTile(display) == display->getWaterHandle(1)) || (getNextTile(display) == display->getWaterHandle(2))) { shipState = true; goToNext(); } } }
// genNewTile() // Description: generate new tile in random slot void Game::genNewTile(){ int nSlot = m_grid.getSlotNo(); int randSlot = getRand() % nSlot; bool success = m_grid.setSlot(randSlot, getNextTile()); assert(success); setNextTile(); }
rspfRefPtr<rspfImageData> rspfTwoColorView::getTile(const rspfIrect& rect, rspf_uint32 resLevel) { rspf_uint32 tileIdx = 0; if(m_byPassFlag||!isSourceEnabled()) { return getNextTile(tileIdx, 0, rect, resLevel); } if(!m_twoColorTile.valid()) { allocate(); } if(!m_twoColorTile.valid()) { return m_twoColorTile; } m_twoColorTile->setImageRectangle(rect); m_twoColorTile->makeBlank(); rspfRefPtr<rspfImageData> newData = m_newInput->getTile(rect, resLevel); rspfRefPtr<rspfImageData> oldData = m_oldInput->getTile(rect, resLevel); runAlgorithm(newData.get(), oldData.get()); m_twoColorTile->validate(); return m_twoColorTile; }
// genInitTile() // Description: generate initial tile in random empty block void Game::genInitTile(){ int randBlk = getRand() % m_grid.getEmptyBlkNo() + 1; for(int i = 0;i < GRID_SIZE;i++){ if(m_grid[i] == EMPTY) randBlk--; if(randBlk == 0){ m_grid.setBlock(i, getNextTile()); setNextTile(); return; } } assert(FALSE); }
template <class T> ossimRefPtr<ossimImageData> ossimFeatherMosaic::combine( T, const ossimIrect& tileRect, ossim_uint32 resLevel) { ossimRefPtr<ossimImageData> currentImageData; ossim_uint32 band; long upperBound = theTile->getWidth()*theTile->getHeight(); long offset = 0; long row = 0; long col = 0; long numberOfTilesProcessed = 0; float *sumBand = static_cast<float*>(theAlphaSum->getBuf()); float *bandRes = NULL; ossimIpt point; theAlphaSum->fill(0.0); theResult->fill(0.0); T** srcBands = new T*[theLargestNumberOfInputBands]; T** destBands = new T*[theLargestNumberOfInputBands]; ossim_uint32 layerIdx = 0; currentImageData = getNextTile(layerIdx, 0, tileRect, resLevel); if(!currentImageData.valid()) { delete [] srcBands; delete [] destBands; return currentImageData; } ossim_uint32 minNumberOfBands = currentImageData->getNumberOfBands(); for(band = 0; band < minNumberOfBands; ++band) { srcBands[band] = static_cast<T*>(currentImageData->getBuf(band)); destBands[band] = static_cast<T*>(theTile->getBuf(band)); } // if the src is smaller than the destination in number // of bands we will just duplicate the last band. for(;band < theLargestNumberOfInputBands; ++band) { srcBands[band] = srcBands[minNumberOfBands - 1]; destBands[band] = static_cast<T*>(theTile->getBuf(band)); } // most of the time we will not overlap so let's // copy the first tile into destination and check later. // for(band = 0; band < theTile->getNumberOfBands();++band) { T* destBand = destBands[band]; T* srcBand = srcBands[band]; if(destBand&&srcBand) { for(offset = 0; offset < upperBound;++offset) { *destBand = *srcBand; ++srcBand; ++destBand; } } } theTile->setDataObjectStatus(currentImageData->getDataObjectStatus()); while(currentImageData.valid()) { ossimDataObjectStatus currentStatus = currentImageData->getDataObjectStatus(); point = currentImageData->getOrigin(); long h = (long)currentImageData->getHeight(); long w = (long)currentImageData->getWidth(); if( (currentStatus != OSSIM_EMPTY) && (currentStatus != OSSIM_NULL)) { ++numberOfTilesProcessed; offset = 0; minNumberOfBands = currentImageData->getNumberOfBands(); for(band = 0; band < minNumberOfBands; ++band) { srcBands[band] = static_cast<T*>(currentImageData->getBuf(band)); } // if the src is smaller than the destination in number // of bands we will just duplicate the last band. for(;band < theLargestNumberOfInputBands; ++band) { srcBands[band] = srcBands[minNumberOfBands - 1]; } if(currentStatus == OSSIM_PARTIAL) { for(row = 0; row < h; ++row) { for(col = 0; col < w; ++col) { if(!currentImageData->isNull(offset)) { double weight = computeWeight(layerIdx, ossimDpt(point.x+col, point.y+row)); for(band = 0; band < theLargestNumberOfInputBands; ++band) { bandRes = static_cast<float*>(theResult->getBuf(band)); bandRes[offset] += (srcBands[band][offset]*weight); } sumBand[offset] += weight; } ++offset; } } } else { offset = 0; for(row = 0; row < h; ++row) { for(col = 0; col < w; ++col) { double weight = computeWeight(layerIdx, ossimDpt(point.x+col, point.y+row)); for(band = 0; band < theLargestNumberOfInputBands; ++band) { bandRes = static_cast<float*>(theResult->getBuf(band)); bandRes[offset] += (srcBands[band][offset]*weight); } sumBand[offset] += weight; ++offset; } } } } currentImageData = getNextTile(layerIdx, tileRect, resLevel); } upperBound = theTile->getWidth()*theTile->getHeight(); if(numberOfTilesProcessed > 1) { const double* minPix = theTile->getMinPix(); const double* maxPix = theTile->getMaxPix(); const double* nullPix= theTile->getNullPix(); for(offset = 0; offset < upperBound;++offset) { for(band = 0; band < theTile->getNumberOfBands();++band) { T* destBand = static_cast<T*>(theTile->getBuf(band)); float* weightedBand = static_cast<float*>(theResult->getBuf(band)); // this should be ok to test 0.0 instead of // FLT_EPSILON range for 0 since we set it. if(sumBand[offset] != 0.0) { weightedBand[offset] = (weightedBand[offset])/sumBand[offset]; if(weightedBand[offset]<minPix[band]) { weightedBand[offset] = minPix[band]; } else if(weightedBand[offset] > maxPix[band]) { weightedBand[offset] = maxPix[band]; } } else { weightedBand[offset] = nullPix[band]; } destBand[offset] = static_cast<T>(weightedBand[offset]); } } theTile->validate(); } delete [] srcBands; delete [] destBands; return theTile; }
rspfRefPtr<rspfImageData> rspfBandMergeSource::getTile(const rspfIrect& tileRect, rspf_uint32 resLevel) { rspf_uint32 layerIdx = 0; if( ( getNumberOfInputs() == 1) || !isSourceEnabled() ) { return getNextTile(layerIdx, 0, tileRect, resLevel); } // test if initialized if(!theTile.get()) { allocate(); } if(!theTile.get()) { return getNextTile(layerIdx, 0, tileRect, resLevel); } long w = tileRect.width(); long h = tileRect.height(); long tileW = theTile->getWidth(); long tileH = theTile->getHeight(); if((w != tileW)|| (h != tileH)) { theTile->setWidth(w); theTile->setHeight(h); if((w*h)!=(tileW*tileH)) { theTile->initialize(); } else { theTile->makeBlank(); } } else { theTile->makeBlank(); } theTile->setOrigin(tileRect.ul()); rspf_uint32 currentBand = 0; rspf_uint32 maxBands = theTile->getNumberOfBands(); rspf_uint32 inputIdx = 0; for(inputIdx = 0; inputIdx < getNumberOfInputs(); ++inputIdx) { rspfImageSource* input = PTR_CAST(rspfImageSource, getInput(inputIdx)); rspfRefPtr<rspfImageData> currentTile = 0; if(input) { currentTile = input->getTile(tileRect, resLevel); } else { currentTile = 0; } rspf_uint32 maxInputBands = 0; if(!currentTile.get()) { maxInputBands = 1; } else if(currentTile->getNumberOfBands() == 0) { maxInputBands = 1; } else { maxInputBands = currentTile->getNumberOfBands(); } for(rspf_uint32 band = 0; ( (band < maxInputBands) && (currentBand < maxBands)); ++band) { // clear the band with the actual NULL theTile->fill(currentBand, theTile->getNullPix(band)); if(currentTile.valid()) { if((currentTile->getDataObjectStatus() != RSPF_NULL) && (currentTile->getDataObjectStatus() != RSPF_EMPTY)) { memmove(theTile->getBuf(currentBand), currentTile->getBuf(band), currentTile->getSizePerBandInBytes()); } } ++currentBand; } } theTile->validate(); return theTile; }
template <class T> ossimRefPtr<ossimImageData> ossimBlendMosaic::combine( T, const ossimIrect& tileRect, ossim_uint32 resLevel) { ossimRefPtr<ossimImageData> currentImageData=NULL; ossim_uint32 band; double currentWeight = 1.0; double previousWeight = 1.0; // double sumOfWeights = 1; long offset = 0; long row = 0; long col = 0; ossim_uint32 layerIdx = 0; currentImageData = getNextTile(layerIdx, 0, tileRect, resLevel); if(!currentImageData.get()) // if we don't have one then return theTile { return theTile; } T** srcBands = new T*[theLargestNumberOfInputBands]; T** destBands = new T*[theLargestNumberOfInputBands]; T* nullPix = new T[theTile->getNumberOfBands()]; previousWeight = theWeights[layerIdx]; // // now get the previous weight and then combine the two into one. // let's assign the bands for(band = 0; band < theLargestNumberOfInputBands; ++band) { destBands[band] = static_cast<T*>(theTile->getBuf(band)); nullPix[band] = static_cast<T>(theTile->getNullPix(band)); } while(currentImageData.get()) { ossimDataObjectStatus currentStatus = currentImageData->getDataObjectStatus(); // set the current weight for the current tile. currentWeight = theWeights[layerIdx]; // sumOfWeights = previousWeight+currentWeight; if( (currentStatus != OSSIM_EMPTY) && (currentStatus != OSSIM_NULL)) { long h = (long)currentImageData->getHeight(); long w = (long)currentImageData->getWidth(); offset = 0; ossim_uint32 minNumberOfBands = currentImageData->getNumberOfBands(); // let's assign the bands for(band = 0; band < minNumberOfBands; ++band) { srcBands[band] = static_cast<T*>(currentImageData->getBuf(band)); } for(;band < theLargestNumberOfInputBands; ++band) { srcBands[band] = srcBands[minNumberOfBands - 1]; } if(currentStatus == OSSIM_PARTIAL) { for(row = 0; row < h; ++row) { for(col = 0; col < w; ++col) { if(!currentImageData->isNull(offset)) { for(band = 0; band < theLargestNumberOfInputBands; ++band) { if(destBands[band][offset] != nullPix[band]) { // destBands[band][offset] = static_cast<T>((destBands[band][offset]*(1.0-currentWeight) + // srcBands[band][offset]*currentWeight)); destBands[band][offset] = static_cast<T>((destBands[band][offset]*previousWeight + srcBands[band][offset]*currentWeight)/(previousWeight+currentWeight)); } else { destBands[band][offset] = srcBands[band][offset]; } } } ++offset; } } } else { for(row = 0; row < h; ++row) { for(col = 0; col < w; ++col) { for(band = 0; band < theLargestNumberOfInputBands; ++band) { if(destBands[band][offset] != nullPix[band]) { destBands[band][offset] = static_cast<T>((destBands[band][offset]*previousWeight+ srcBands[band][offset]*currentWeight)/(previousWeight + currentWeight)); } else { destBands[band][offset] = srcBands[band][offset]; } } ++offset; } } } } currentImageData = getNextTile(layerIdx, tileRect, resLevel); previousWeight = (previousWeight+currentWeight)/2.0; } delete [] srcBands; delete [] destBands; delete [] nullPix; theTile->validate(); return theTile; }