ossim_uint32 ossim::computeLevels(const ossimIrect& rect) { ossim_uint32 result = 0; ossim_uint32 stopDimension = 0; // Get the stop dimension from ossim preferences. const char* lookup = ossimPreferences::instance()-> findPreference(ossimKeywordNames::OVERVIEW_STOP_DIMENSION_KW); if (lookup) { stopDimension = ossimString(lookup).toUInt32(); } if (stopDimension == 0) { // Use the smallest default tile size. ossimIpt tileSize; ossim::defaultTileSize(tileSize); stopDimension = tileSize.x < tileSize.y ? tileSize.x : tileSize.y; } ossim_uint32 largestImageDimension = rect.width() > rect.height() ? rect.width() : rect.height(); while(largestImageDimension > stopDimension) { largestImageDimension /= 2; ++result; } return result; }
void ossim::getDims(const ossimIrect& rect, kdu_core::kdu_dims& dims) { dims.pos.x = rect.ul().x; dims.pos.y = rect.ul().y; dims.size.x = static_cast<int>(rect.width()); dims.size.y = static_cast<int>(rect.height()); }
void ImageViewManipulator::fit(const ossimIrect& inputRect, const ossimIrect& targetRect) { ossimImageGeometry* geom = asGeometry(); double scaleX = static_cast<double>(inputRect.width())/static_cast<double>(targetRect.width()); double scaleY = static_cast<double>(inputRect.height())/static_cast<double>(targetRect.height()); double largestScale = ossim::max(scaleX, scaleY); ossimDpt saveCenter = m_centerPoint; if(geom) { if(geom->getProjection()) { ossimDpt mpp = geom->getProjection()->getMetersPerPixel(); mpp.x*=largestScale; mpp.y*=largestScale; ossimMapProjection* mapProj = dynamic_cast<ossimMapProjection*>(geom->getProjection()); if(mapProj) { mapProj->setMetersPerPixel(mpp); } } } else { ossimImageViewAffineTransform* ivat = getObjectAs<ossimImageViewAffineTransform>(); if(ivat) { ossimDpt tempCenter; double x = 1.0/largestScale; double y = x; ivat->scale(x,y); } } m_centerPoint = saveCenter; setViewToChains(); m_scrollView->zoomAnnotation(); }
void ossimScaleFilter::runFilterTemplate(T dummy, const ossimIrect& imageRect, const ossimIrect& viewRect) { ossimRefPtr<ossimImageData> inputData = theInputConnection->getTile(imageRect); if(!inputData.valid() || !inputData->getBuf() || (inputData->getDataObjectStatus() == OSSIM_EMPTY)) { return; } ossim_int32 h = imageRect.height(); ossimRefPtr<ossimImageData> tempData = ossimImageDataFactory::instance()->create(NULL, inputData->getScalarType(), inputData->getNumberOfBands(), viewRect.width(), h); tempData->setOrigin(ossimIpt(viewRect.ul().x, imageRect.ul().y)); tempData->initialize(); if((m_ScaleFactor.x != 1.0)|| (m_BlurFactor != 1.0)) { runHorizontalFilterTemplate(dummy, inputData, tempData); tempData->validate(); } else { tempData->loadTile(inputData.get()); } if((m_ScaleFactor.y != 1.0)|| (m_BlurFactor != 1.0)) { runVerticalFilterTemplate(dummy, tempData, m_Tile); } else { m_Tile->loadTile(tempData.get()); } m_Tile->validate(); }
void ossimTableRemapper::allocate(const ossimIrect& rect) { //--- // It's either first getTile or we've had either a resize, so allocate // needed stuff... //--- destroy(); if (theInputConnection) { ossim_uint32 width = rect.width(); ossim_uint32 height = rect.height(); theTile = ossimImageDataFactory::instance()->create(this,this); theTile->setImageRectangle(rect); // theTile = // ossimImageDataFactory::instance()->create(this, // getOutputScalarType(), // getNumberOfOutputBands(), // width,x // height); theTile->initialize(); if (theInputScalarType != getOutputScalarType() && theTableType == ossimTableRemapper::NATIVE) { //--- // We need a temp tile so we can do two remaps // inputTile->remapTable->tmpTile then // tmpTile->normalize->theTile(unnormalize to new scalar)... //--- theTmpTile = ossimImageDataFactory::instance()->create(this, theInputScalarType, getNumberOfOutputBands(), width, height); theTmpTile->setMinPix(theTile->getMinPix(), theTile->getNumberOfBands()); theTmpTile->initialize(); } if (theTableType == ossimTableRemapper::NORMALIZED || theInputScalarType != theOutputScalarType) { theNormBuf = new ossim_float64[theTile->getSize()]; } } }
//************************************************************************************************** ossimIrect ossimScaleFilter::scaleRect(const ossimIrect input, const ossimDpt& scaleFactor)const { ossimIpt origin(ossim::round<int>(input.ul().x*scaleFactor.x), ossim::round<int>(input.ul().y*scaleFactor.y)); ossim_int32 w = ossim::round<int>(input.width()*scaleFactor.x); ossim_int32 h = ossim::round<int>(input.height()*scaleFactor.y); if(w < 1) w = 1; if(h < 1) h = 1; return ossimIrect(origin.x, origin.y, origin.x + (w-1), origin.y + (h-1)); }
ossimRefPtr<ossimImageData> ossimFftFilter::getTile(const ossimIrect& rect, ossim_uint32 resLevel) { if(!isSourceEnabled()) return ossimImageSourceFilter::getTile(rect, resLevel); ossimIrect tempRequest = rect; ossim_uint32 w = rect.width(); ossim_uint32 h = rect.height(); if(w & 1) ++w; if(h&1) ++h; tempRequest = ossimIrect(rect.ul().x, rect.ul().y, rect.ul().x + (w-1), rect.ul().y + (h-1)); ossimRefPtr<ossimImageData> inTile = theScalarRemapper->getTile(tempRequest, resLevel); if(!inTile.valid()) return inTile; if(!theTile.valid()) initialize(); if(!theTile.valid() || !inTile->getBuf()) return theTile; theTile->setImageRectangle(rect); ossimRefPtr<ossimImageData> tempTile = theTile; if(rect != tempRequest) { tempTile = (ossimImageData*)theTile->dup(); tempTile->setImageRectangle(tempRequest); } runFft(inTile, tempTile); if(tempTile != theTile) { theTile->loadTile(tempTile.get()); } theTile->validate(); return theTile; }
ossim_int32 ossimGui::StaticTileImageCache::getTileIndex(const ossimIrect& rect, const ossimIpt& numberOfTiles, ossim_int32 x, ossim_int32 y)const { ossimIpt ul = rect.ul(); ossimIpt delta = ossimIpt(x,y) - ul; if((delta.x < 0) || (delta.y < 0) || (delta.x >= (int)rect.width())|| (delta.y >= (int)rect.height())) { return -1; } delta.x /= m_tileSize.x; delta.y /= m_tileSize.y; return delta.y*numberOfTiles.x + delta.x; }
ossim_int32 ossimGui::StaticTileImageCache::computeTileId(const ossimIpt& origin, const ossimIrect& tileBounderyRect, const ossimIpt& tileSize) { ossim_uint32 numberOfTilesX = tileBounderyRect.width()/tileSize.x; ossimIpt ul = tileBounderyRect.ul(); ossimIpt delta = origin - ul; if((delta.x < 0) || (delta.y < 0) || (delta.x >= (int)tileBounderyRect.width())|| (delta.y >= (int)tileBounderyRect.height())) { return -1; } delta.x /= tileSize.x; delta.y /= tileSize.y; return delta.y*numberOfTilesX + delta.x; }
ossimRefPtr<ossimImageData> ossimImageChain::getTile( const ossimIrect& tileRect, ossim_uint32 resLevel) { if((theImageChainList.size() > 0)&&(isSourceEnabled())) { ossimImageSource* interface = PTR_CAST(ossimImageSource, theImageChainList[0].get()); if(interface) { // make sure we initialize in reverse order. // some source may depend on the initialization of // its inputs return interface->getTile(tileRect, resLevel); } } else { if(getInput(0)) { ossimImageSource* interface = PTR_CAST(ossimImageSource, getInput(0)); if(interface) { return interface->getTile(tileRect, resLevel); } } } if(theBlankTile.get()) { theBlankTile->setOrigin(tileRect.ul()); theBlankTile->setWidthHeight(tileRect.width(), tileRect.height()); } return theBlankTile; }
ossimString ossimNitfCommon::getCompressionRate(const ossimIrect& rect, ossim_uint32 bands, ossimScalarType scalar, ossim_uint64 lengthInBytes) { ossimString result(""); ossim_float64 uncompressedSize = ossim::scalarSizeInBytes(scalar) * rect.width() * rect.height() * bands; ossim_float64 bitsPerPix = ossim::getBitsPerPixel(scalar); ossim_float64 rate = ( bitsPerPix * (static_cast<ossim_float64>(lengthInBytes) / uncompressedSize) ); // Multiply by ten as there is an implied decimal point. rate *= 10.0; // Convert to string with zero precision. ossimString s = ossimString::toString(rate, 0); if (s.size()) { if (s.size() <= 3) { result = "N"; if (s.size() == 2) { result += "0"; } else if (s.size() == 1) { result += "00"; } result += s; } } return result; }
bool ossimPointCloudImageHandler::getTile(ossimImageData* result, ossim_uint32 resLevel) { // check for all systems go and valid args: if (!m_pch.valid() || !result || (result->getScalarType() != OSSIM_FLOAT32) || (result->getDataObjectStatus() == OSSIM_NULL) || m_gsd.hasNans()) { return false; } // Overviews achieved with GSD setting. This may be too slow. ossimDpt gsd (m_gsd); if (resLevel > 0) getGSD(gsd, resLevel); // Establish the ground and image rects for this tile: const ossimIrect img_tile_rect = result->getImageRectangle(); const ossimIpt tile_offset (img_tile_rect.ul()); const ossim_uint32 tile_width = img_tile_rect.width(); const ossim_uint32 tile_height = img_tile_rect.height(); const ossim_uint32 tile_size = img_tile_rect.area(); ossimGpt gnd_ul, gnd_lr; ossimDpt dpt_ul (img_tile_rect.ul().x - 0.5, img_tile_rect.ul().y - 0.5); ossimDpt dpt_lr (img_tile_rect.lr().x + 0.5, img_tile_rect.lr().y + 0.5); theGeometry->rnToWorld(dpt_ul, resLevel, gnd_ul); theGeometry->rnToWorld(dpt_lr, resLevel, gnd_lr); const ossimGrect gnd_rect (gnd_ul, gnd_lr); // Create array of buckets to store accumulated point data. ossim_uint32 numBands = result->getNumberOfBands(); if (numBands > getNumberOfInputBands()) { // This should never happen; ossimNotify(ossimNotifyLevel_FATAL) << "ossimPointCloudImageHandler::getTile() ERROR: \n" << "More bands were requested than was available from the point cloud source. Returning " << "blank tile." << endl; result->makeBlank(); return false; } std::map<ossim_int32, PcrBucket*> accumulator; // initialize a point block with desired fields as requested in the reader properties ossimPointBlock pointBlock (this); pointBlock.setFieldCode(componentToFieldCode()); m_pch->rewind(); ossimDpt ipt; ossimGpt pos; #define USE_GETBLOCK #ifdef USE_GETBLOCK m_pch->getBlock(gnd_rect, pointBlock); for (ossim_uint32 id=0; id<pointBlock.size(); ++id) { pos = pointBlock[id]->getPosition(); theGeometry->worldToRn(pos, resLevel, ipt); ipt.x = ossim::round<double,double>(ipt.x) - tile_offset.x; ipt.y = ossim::round<double,double>(ipt.y) - tile_offset.y; ossim_int32 bucketIndex = ipt.y*tile_width + ipt.x; if ((bucketIndex >= 0) && (bucketIndex < (ossim_int32)tile_size)) addSample(accumulator, bucketIndex, pointBlock[id]); } #else // using getFileBlock ossim_uint32 numPoints = m_pch->getNumPoints(); if (numPoints > ossimPointCloudHandler::DEFAULT_BLOCK_SIZE) numPoints = ossimPointCloudHandler::DEFAULT_BLOCK_SIZE; // Loop to read all point blocks: do { pointBlock.clear(); m_pch->getNextFileBlock(pointBlock, numPoints); //m_pch->normalizeBlock(pointBlock); for (ossim_uint32 id=0; id<pointBlock.size(); ++id) { // Check that each point in read block is inside the ROI before accumulating it: pos = pointBlock[id]->getPosition(); if (gnd_rect.pointWithin(pos)) { theGeometry->worldToRn(pos, resLevel, ipt); ipt.x = ossim::round<double,double>(ipt.x) - tile_offset.x; ipt.y = ossim::round<double,double>(ipt.y) - tile_offset.y; ossim_int32 bucketIndex = ipt.y*tile_width + ipt.x; if ((bucketIndex >= 0) && (bucketIndex < (ossim_int32)tile_size)) addSample(accumulator, bucketIndex, pointBlock[id]); } } } while (pointBlock.size() == numPoints); #endif // Finished accumulating, need to normalize and fill the tile. // We must always blank out the tile as we may not have a point for every pixel. normalize(accumulator); ossim_float32** buf = new ossim_float32*[numBands]; std::map<ossim_int32, PcrBucket*>::iterator accum_iter; ossim_float32 null_pixel = OSSIM_DEFAULT_NULL_PIX_FLOAT; result->setNullPix(null_pixel); for (ossim_uint32 band = 0; band < numBands; band++) { ossim_uint32 index = 0; buf[band] = result->getFloatBuf(band); for (ossim_uint32 y = 0; y < tile_height; y++) { for (ossim_uint32 x = 0; x < tile_width; x++) { accum_iter = accumulator.find(index); if (accum_iter != accumulator.end()) buf[band][index] = accum_iter->second->m_bucket[band]; else buf[band][index] = null_pixel; ++index; } } } delete [] buf; buf = 0; std::map<ossim_int32, PcrBucket*>::iterator pcr_iter = accumulator.begin(); while (pcr_iter != accumulator.end()) { delete pcr_iter->second; pcr_iter++; } result->validate(); return true; }
bool ossimLasReader::getTile(ossimImageData* result, ossim_uint32 resLevel) { // static const char MODULE[] = "ossimLibLasReader::getTile(ossimImageData*, level)"; bool status = false; if ( m_hdr && result && (result->getScalarType() == OSSIM_FLOAT32) && (result->getDataObjectStatus() != OSSIM_NULL) && !m_ul.hasNans() && !m_scale.hasNans() ) { status = true; const ossimIrect TILE_RECT = result->getImageRectangle(); const ossim_int32 TILE_HEIGHT = static_cast<ossim_int32>(TILE_RECT.height()); const ossim_int32 TILE_WIDTH = static_cast<ossim_int32>(TILE_RECT.width()); const ossim_int32 TILE_SIZE = static_cast<ossim_int32>(TILE_RECT.area()); const ossim_uint16 ENTRY = m_entry+1; // Get the scale for this resLevel: ossimDpt scale; getScale(scale, resLevel); // Set the starting upper left of upper left pixel for this tile. const ossimDpt UL_PROG_PT( m_ul.x - scale.x / 2.0 + TILE_RECT.ul().x * scale.x, m_ul.y + scale.y / 2.0 - TILE_RECT.ul().y * scale.y); //--- // Set the lower right to the edge of the tile boundary. This looks like an // "off by one" error but it's not. We want the ossimDrect::pointWithin to // catch any points in the last line sample. //--- const ossimDpt LR_PROG_PT( UL_PROG_PT.x + TILE_WIDTH * scale.x, UL_PROG_PT.y - TILE_HEIGHT * scale.y); const ossimDrect PROJ_RECT(UL_PROG_PT, LR_PROG_PT, OSSIM_RIGHT_HANDED); #if 0 /* Please leave for debug. (drb) */ cout << "m_ul: " << m_ul << "\nm_scale: " << m_scale << "\nscale: " << scale << "\nresult->getScalarType(): " << result->getScalarType() << "\nresult->getDataObjectStatus(): " << result->getDataObjectStatus() << "\nPROJ_RECT: " << PROJ_RECT << "\nTILE_RECT: " << TILE_RECT << "\nUL_PROG_PT: " << UL_PROG_PT << endl; #endif const ossim_float64 SCALE_X = m_hdr->getScaleFactorX(); const ossim_float64 SCALE_Y = m_hdr->getScaleFactorY(); const ossim_float64 SCALE_Z = m_hdr->getScaleFactorZ(); const ossim_float64 OFFSET_X = m_hdr->getOffsetX(); const ossim_float64 OFFSET_Y = m_hdr->getOffsetY(); const ossim_float64 OFFSET_Z = m_hdr->getOffsetZ(); // Create array of buckets. std::vector<ossimLasReader::Bucket> bucket( TILE_SIZE ); // Loop through the point data. ossimLasPointRecordInterface* lasPtRec = getNewPointRecord(); ossimDpt lasPt; m_str.clear(); m_str.seekg(m_hdr->getOffsetToPointData()); while ( m_str.good() ) { // m_str.read((char*)lasPtRec, 28); lasPtRec->readStream( m_str ); if ( lasPtRec->getReturnNumber() == ENTRY ) { lasPt.x = lasPtRec->getX() * SCALE_X + OFFSET_X; lasPt.y = lasPtRec->getY() * SCALE_Y + OFFSET_Y; if ( m_unitConverter ) { convertToMeters(lasPt.x); convertToMeters(lasPt.y); } if ( PROJ_RECT.pointWithin( lasPt ) ) { // Compute the bucket index: ossim_int32 line = static_cast<ossim_int32>((UL_PROG_PT.y - lasPt.y) / scale.y); ossim_int32 samp = static_cast<ossim_int32>((lasPt.x - UL_PROG_PT.x) / scale.x ); ossim_int32 bucketIndex = line * TILE_WIDTH + samp; // Range check and add if in there. if ( ( bucketIndex >= 0 ) && ( bucketIndex < TILE_SIZE ) ) { ossim_float64 z = lasPtRec->getZ() * SCALE_Z + OFFSET_Z; if ( m_unitConverter ) convertToMeters(z); bucket[bucketIndex].add( z ); } } } if ( m_str.eof() ) break; } delete lasPtRec; lasPtRec = 0; //--- // We must always blank out the tile as we may not have a point for every // point. //--- result->makeBlank(); ossim_float32* buf = result->getFloatBuf(); // Tile buffer to fill. // Fill the tile. Currently no band loop: for (ossim_int32 i = 0; i < TILE_SIZE; ++i) { buf[i] = bucket[i].getValue(); } // Revalidate. result->validate(); } return status; } // End: bool ossimLibLasReader::getTile(ossimImageData* result, ossim_uint32 resLevel)
ossimRefPtr<ossimImageData> ossimFeatherMosaic::getTile(const ossimIrect& tileRect, ossim_uint32 resLevel) { long w = tileRect.width(); long h = tileRect.height(); ossimIpt origin = tileRect.ul(); if(!isSourceEnabled()) { return ossimImageMosaic::getTile(tileRect, resLevel); } if(!theTile||!theAlphaSum||!theResult||!theInputFeatherInformation) { initialize(); if(!theTile||!theAlphaSum||!theResult||!theInputFeatherInformation) { return ossimImageMosaic::getTile(tileRect, resLevel); } } ossim_uint32 size = getNumberOfInputs(); theAlphaSum->setImageRectangle(tileRect); theResult->setImageRectangle(tileRect); if(size == 0) { return ossimRefPtr<ossimImageData>(); } if(size == 1) { return ossimImageMosaic::getTile(tileRect, resLevel); } 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(); } } theTile->setOrigin(origin); theTile->makeBlank(); switch(theTile->getScalarType()) { case OSSIM_UCHAR: { return combine(static_cast<ossim_uint8>(0), tileRect, resLevel); } case OSSIM_USHORT16: case OSSIM_USHORT11: { return combine(static_cast<ossim_uint16>(0), tileRect, resLevel); } case OSSIM_SSHORT16: { return combine(static_cast<ossim_sint16>(0), tileRect, resLevel); } case OSSIM_DOUBLE: case OSSIM_NORMALIZED_DOUBLE: { return combine(static_cast<double>(0), tileRect, resLevel); } case OSSIM_FLOAT: case OSSIM_NORMALIZED_FLOAT: { return combine(static_cast<float>(0), tileRect, resLevel); } case OSSIM_SCALAR_UNKNOWN: default: { ossimNotify(ossimNotifyLevel_WARN) << "ossimFeatherMosaic::getTile: error, unknown scalar type!!!" << std::endl; } } return ossimRefPtr<ossimImageData>(); }
ossimRefPtr<ossimImageData> ossimClosestToCenterCombiner::getTile(const ossimIrect& rect, ossim_uint32 resLevel) { ossim_uint32 layerIdx = 0; if(!isSourceEnabled()) { return ossimImageMosaic::getTile(rect, resLevel); } if(!theTile.valid()) { allocate(); if(!theTile.valid()) { return 0; } } theTile->setImageRectangle(rect); theTile->makeBlank(); std::vector<ossimClosestToCenterCombinerInfo > normTileList; ossimRefPtr<ossimImageData> currentTile = getNextNormTile(layerIdx, 0, rect); while(currentTile.valid()) { normTileList.push_back(ossimClosestToCenterCombinerInfo((ossimImageData*)currentTile->dup(), layerIdx)); currentTile = getNextNormTile(layerIdx, rect, resLevel); } if(normTileList.size() == 1) { theTile->copyNormalizedBufferToTile((ossim_float32*)normTileList[0].theTile->getBuf()); } else if(normTileList.size() > 1) { ossimRefPtr<ossimImageData> copyTile = ossimImageDataFactory::instance()->create(0, OSSIM_NORMALIZED_FLOAT); copyTile->setImageRectangleAndBands(rect, getNumberOfOutputBands()); copyTile->initialize(); ossim_int32 idx = 0; ossim_uint32 w = rect.width(); ossim_uint32 h = rect.height(); ossim_uint32 idxW = 0; ossim_uint32 idxH = 0; ossimIpt origin = rect.ul(); ossimIpt ulPt = rect.ul(); ossim_uint32 band = 0; ossim_uint32 bands = copyTile->getNumberOfBands(); ossim_uint32 srcBandIdx = 0; std::vector<ossim_float32*> bandList(bands); for(band = 0; band < bands; ++band) { bandList[band] = (ossim_float32*)copyTile->getBuf(band); } ossim_uint32 offset = 0; origin.y = ulPt.y; for(idxH = 0; idxH < h; ++idxH) { origin.x = ulPt.x; for(idxW = 0; idxW < w;++idxW) { idx = findIdx(normTileList, origin, offset); if(idx >=0) { ossim_uint32 tileBands = normTileList[idx].theTile->getNumberOfBands(); if (tileBands > 0) { tileBands -= 1; for(band = 0; band < bands; ++band) { srcBandIdx = ossim::min( tileBands, band ); bandList[band][offset] = *(((ossim_float32*)normTileList[idx].theTile->getBuf(srcBandIdx))+offset); } } } ++offset; ++origin.x; } ++origin.y; } theTile->copyNormalizedBufferToTile((ossim_float32*)copyTile->getBuf()); } theTile->validate(); return theTile; }
ossimRefPtr<ossimImageData> ossimAtCorrRemapper::getTile( const ossimIrect& tile_rect, ossim_uint32 resLevel) { #if 0 if (traceDebug()) { cout << "ossimAtCorrRemapper::getTile DEBUG:" << "\ntile_rect: " << tile_rect << endl; } #endif if (!isInitialized()||!theInputConnection) { cerr << "ossimAtCorrRemapper::getTile ERROR:" << "\nNot initialized!" << endl; return ossimRefPtr<ossimImageData>(); } if(!theTile.valid()) { initialize(); if(!theTile) { return ossimRefPtr<ossimImageData>(); } } // Fetch tile from pointer from the input source. ossimRefPtr<ossimImageData> inputTile = theInputConnection->getTile(tile_rect, resLevel); if (!inputTile.valid()) // Just in case... { return ossimRefPtr<ossimImageData>(); } // Check for remap bypass or empty / null input tile. ossimDataObjectStatus tile_status = inputTile->getDataObjectStatus(); if (!theEnableFlag || tile_status == OSSIM_NULL || tile_status == OSSIM_EMPTY) { return inputTile; } ossim_uint32 w = tile_rect.width(); ossim_uint32 h = tile_rect.height(); ossim_uint32 tw = theTile->getWidth(); ossim_uint32 th = theTile->getHeight(); ossim_uint32 bands = theTile->getNumberOfBands(); // Set the origin of the output tile. theTile->setOrigin(tile_rect.ul()); if(w*h != tw*th) { theTile->setWidthHeight(w, h); theTile->initialize(); if(theSurfaceReflectance) { delete [] theSurfaceReflectance; theSurfaceReflectance = NULL; } } if(!theSurfaceReflectance) { ossim_uint32 size = tw*th*bands; #if 0 if (traceDebug()) { cout << "ossimAtCorrRemapper::getTile DEBUG:" << "\ntile_rect: " << tile_rect << "\ntile width: " << tw << "\ntile height: " << th << "\nbands: " << bands << "\nBuffer size: " << size << endl; } #endif theSurfaceReflectance = new double[size]; } ossim_uint32 buffer_index = 0; ossimIpt ul = tile_rect.ul(); ossimIpt lr = tile_rect.lr(); const double MP = theTile->getMinNormalizedPix(); // Minimum normalized pix. double a, b, c; buffer_index = 0; cout << setprecision(6); for (ossim_uint32 band=0; band < bands; ++band) { for(ossim_sint32 idxy = ul.y; idxy <= lr.y; ++idxy) { for(ossim_sint32 idxx = ul.x; idxx <= lr.x; ++idxx) { double p = inputTile->getPix(buffer_index); if (p>0.0) { if(!theUseInterpolationFlag) { a = theXaArray[band]; b = theXbArray[band]; c = theXcArray[band]; } else { interpolate(ossimDpt(idxx, idxy), band, a, b, c); } if(theSensorType == "ls7ms") { double radiance_at_satellite = (theGainArray[band] * p) + theBiasArray[band]; double y = (radiance_at_satellite * a) - b; p = (y / (1.0 + (c * y)) ); } else if(theSensorType == "qbms") { double radiance_at_satellite = theCalCoefArray[band] * p / theBandWidthArray[band]; double y = (radiance_at_satellite * a) - b; p = (y / (1.0 + (c * y)) ); } else if(theSensorType == "ikms") { double radiance_at_satellite = p /((theCalCoefArray[band]/1.0)/ theBandWidthArray[band]); double y = (radiance_at_satellite * a) - b; p = (y / (1.0 + (c * y)) ); } // Note that "p" should now be normalized between 0.0 and 1.0; // *** // Since it wasn't null to start with clip / clamp between minimum // normalized pixel and one(max). // *** p = ( p > MP ? ( p < 1.0 ? p : 1.0) : MP ); // Scan the new tile and set the min / max. if (p < theMinPixelValue[band]) { theMinPixelValue[band] = p; } else if (p > theMaxPixelValue[band]) { theMaxPixelValue[band] = p; } theSurfaceReflectance[buffer_index] = p; } else { theSurfaceReflectance[buffer_index] = 0.0; // pixel was null... } ++buffer_index; } // End of sample loop... } // End of line loop... } // End of band loop... // Copy the buffer to the output tile at the same time unnormalizing it. theTile->copyNormalizedBufferToTile(theSurfaceReflectance); // Validate the output to set the tile status. theTile->validate(); return theTile; }
bool ossim_hdf5::crossesDateline( H5::DataSet& dataset, const ossimIrect& validRect ) { bool result = false; H5::DataSpace dataspace = dataset.getSpace(); // Number of dimensions of the input dataspace: const ossim_int32 DIM_COUNT = dataspace.getSimpleExtentNdims(); if ( DIM_COUNT == 2 ) { const ossim_uint32 ROWS = validRect.height(); const ossim_uint32 COLS = validRect.width(); // Get the extents. Assuming dimensions are same for lat lon dataset. std::vector<hsize_t> dimsOut(DIM_COUNT); dataspace.getSimpleExtentDims( &dimsOut.front(), 0 ); if ( (ROWS <= dimsOut[0]) && (COLS <= dimsOut[1]) ) { std::vector<hsize_t> inputCount(DIM_COUNT); std::vector<hsize_t> inputOffset(DIM_COUNT); inputCount[0] = 1; // row inputCount[1] = COLS; // col // Output dataspace dimensions. const ossim_int32 OUT_DIM_COUNT = 3; std::vector<hsize_t> outputCount(OUT_DIM_COUNT); outputCount[0] = 1; // single band outputCount[1] = 1; // single line outputCount[2] = COLS; // single sample // Output dataspace offset. std::vector<hsize_t> outputOffset(OUT_DIM_COUNT); outputOffset[0] = 0; outputOffset[1] = 0; outputOffset[2] = 0; ossimScalarType scalar = ossim_hdf5::getScalarType( &dataset ); if ( scalar == OSSIM_FLOAT32 ) { // See if we need to swap bytes: ossimEndian* endian = 0; if ( ( ossim::byteOrder() != ossim_hdf5::getByteOrder( &dataset ) ) ) { endian = new ossimEndian(); } // Native type: H5::DataType datatype = dataset.getDataType(); // Output dataspace always the same one line. H5::DataSpace bufferDataSpace( OUT_DIM_COUNT, &outputCount.front()); bufferDataSpace.selectHyperslab( H5S_SELECT_SET, &outputCount.front(), &outputOffset.front() ); //--- // Dataset sample has NULL lines at the end so scan for valid rect. // Use "<= -999" for test as per NOAA as it seems the NULL value is // fuzzy. e.g. -999.3. //--- // Buffer to hold a line: std::vector<ossim_float32> lineBuffer(validRect.width()); // Read the first line: inputOffset[0] = static_cast<hsize_t>(validRect.ul().y); inputOffset[1] = static_cast<hsize_t>(validRect.ul().x); dataspace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); dataset.read( &(lineBuffer.front()), datatype, bufferDataSpace, dataspace ); if ( endian ) { // If the endian pointer is initialized(not zero) swap the bytes. endian->swap( &(lineBuffer.front()), COLS ); } // Test the first line: result = ossim_hdf5::crossesDateline( lineBuffer ); if ( !result ) { // Test the last line: inputOffset[0] = static_cast<hsize_t>(validRect.ll().y); inputOffset[1] = static_cast<hsize_t>(validRect.ll().x); dataspace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); dataset.read( &(lineBuffer.front()), datatype, bufferDataSpace, dataspace ); result = ossim_hdf5::crossesDateline( lineBuffer ); } if ( endian ) { delete endian; endian = 0; } } else // Matches: if ( scalar == OSSIM_FLOAT32 ){...} { ossimNotify(ossimNotifyLevel_WARN) << "ossim_hdf5::crossesDateline WARNING!" << "\nUnhandled scalar type: " << ossimScalarTypeLut::instance()->getEntryString( scalar ) << std::endl; } } // Matches: if ( dimsOut... } // Matches: if ( IN_DIM_COUNT == 2 ) dataspace.close(); return result; } // End: ossim_hdf5::crossesDateline(...)
template <class T> void ossimWatermarkFilter::fill(T /* dummy */) { const ossimIrect TILE_RECT = theTile->getImageRectangle(); // We will only fill data within the input bounding rect. const ossimIrect CLIPPED_TILE_RECT = TILE_RECT.clipToRect(theInputBoundingRect); // Get the bounding rectangles. vector<ossimIrect> rects(0); getIntersectingRects(rects); if (rects.size() == 0) { return; } //--- // Have watermark rectangles that intersect this tile so we need to process. //--- ossim_uint32 band = 0; ossim_float64 inputPixWeight = 1.0 - theWatermarkWeight; // Get a pointers to the watermark buffers (wmBuf) and nulls wn. T** wmBuf = new T*[theWatermarkNumberOfBands]; for (band = 0; band < theWatermarkNumberOfBands; ++band) { wmBuf[band] = static_cast<T*>(theWatermark->getBuf(band)); } // Get a pointers to the output tile buffers and nulls in. T** otBuf = new T*[theInputNumberOfBands]; for (band = 0; band < theInputNumberOfBands; ++band) { otBuf[band] = static_cast<T*>(theTile->getBuf(band)); } // Get the width of the buffers for indexing. ossim_int32 wmWidth = static_cast<ossim_int32>(theWatermark->getWidth()); ossim_int32 otWidth = static_cast<ossim_int32>(theTile->getWidth()); const ossim_float64* wmNull = theWatermark->getNullPix(); const ossim_float64* otMin = theTile->getMinPix(); const ossim_float64* otMax = theTile->getMaxPix(); const ossim_float64* otNull = theTile->getNullPix(); // Control loop through intersecting rectangles. vector<ossimIrect>::const_iterator i = rects.begin(); while (i != rects.end()) { if ( (*i).intersects(CLIPPED_TILE_RECT) ) { //--- // This is the rectangle we want to fill relative to requesting // image space. //--- const ossimIrect CLIPPED_WATERMARRK_RECT = (*i).clipToRect(CLIPPED_TILE_RECT); ossim_int32 clipHeight = CLIPPED_WATERMARRK_RECT.height(); ossim_int32 clipWidth = CLIPPED_WATERMARRK_RECT.width(); // Compute the starting offset into the wmBuf and otBuf. ossim_int32 wmOffset = (CLIPPED_WATERMARRK_RECT.ul().y - (*i).ul().y) * wmWidth + CLIPPED_WATERMARRK_RECT.ul().x - (*i).ul().x; ossim_int32 otOffset = (CLIPPED_WATERMARRK_RECT.ul().y - TILE_RECT.ul().y)* otWidth + CLIPPED_WATERMARRK_RECT.ul().x - TILE_RECT.ul().x; // Line loop... for (ossim_int32 line = 0; line < clipHeight; ++line) { // Sample loop... for (ossim_int32 sample = 0; sample < clipWidth; ++sample) { // Output band control loop until all output bands are filled. ossim_uint32 otBand = 0; while (otBand < theInputNumberOfBands) { // Band loop through the watermark. for (ossim_uint32 wmBand = 0; wmBand < theWatermarkNumberOfBands; ++wmBand) { if (wmBuf[wmBand][wmOffset+sample] != wmNull[wmBand]) { // Apply the weight to the input pixel. ossim_float64 p1 = (otBuf[otBand][otOffset+sample] != otNull[otBand]) ? otBuf[otBand][otOffset+sample] * inputPixWeight : 0.0; // Apply the Weight to the watermark pixel. ossim_float64 p2 = wmBuf[wmBand][wmOffset+sample]*theWatermarkWeight; // Add them up. ossim_float64 p3 = p1 + p2; // Cast to output type with range checking. otBuf[otBand][otOffset+sample] = static_cast<T>( ( (p3 >= otMin[otBand]) ? (p3 < otMax[otBand] ? p3 : otMax[otBand]) : otNull[otBand]) ); } ++otBand; // We stop when we reach here. All output bands filled. if (otBand == theInputNumberOfBands) { break; } } // End of band through watermark. } // End of outer band loop. } // End of sample loop. wmOffset += wmWidth; otOffset += otWidth; } // End of line loop. } // End "if ( (*i).intersects(TILE_RECT) )" ++i; // Go to next rectangle to fill if any. } // End of "while (i != rects.end())" // Clean up. delete [] wmBuf; delete [] otBuf; theTile->validate(); }
bool ossimH5GridModel::setGridNodes( H5::DataSet* latDataSet, H5::DataSet* lonDataSet, const ossimIrect& validRect ) { bool status = false; if ( latDataSet && lonDataSet ) { m_crossesDateline = ossim_hdf5::crossesDateline( *lonDataSet, validRect ); if ( m_crossesDateline ) { theLonGrid.setDomainType(ossimDblGrid::WRAP_360); } else { theLonGrid.setDomainType(ossimDblGrid::WRAP_180); } // Get dataspace of the dataset. H5::DataSpace latDataSpace = latDataSet->getSpace(); H5::DataSpace lonDataSpace = lonDataSet->getSpace(); const ossim_int32 LAT_DIM_COUNT = latDataSpace.getSimpleExtentNdims(); const ossim_int32 LON_DIM_COUNT = lonDataSpace.getSimpleExtentNdims(); // Number of dimensions of the input dataspace: if ( ( LAT_DIM_COUNT == 2 ) && ( LON_DIM_COUNT == 2 ) ) { const ossim_uint32 ROWS = validRect.height(); const ossim_uint32 COLS = validRect.width(); const ossim_uint32 GRID_SIZE = 4; // Only grab every 4th value. //--- // Get the extents: // dimsOut[0] is height, dimsOut[1] is width: //--- std::vector<hsize_t> latDimsOut(LAT_DIM_COUNT); latDataSpace.getSimpleExtentDims( &latDimsOut.front(), 0 ); std::vector<hsize_t> lonDimsOut(LON_DIM_COUNT); lonDataSpace.getSimpleExtentDims( &lonDimsOut.front(), 0 ); // Verify valid rect within our bounds: if ( (ROWS <= latDimsOut[0] ) && (ROWS <= lonDimsOut[0] ) && (COLS <= latDimsOut[1] ) && (COLS <= lonDimsOut[1] ) ) { //---- // Initialize the ossimDblGrids: //--- ossimDpt dspacing (GRID_SIZE, GRID_SIZE); ossim_uint32 gridRows = ROWS / GRID_SIZE + 1; ossim_uint32 gridCols = COLS / GRID_SIZE + 1; // Round up if size doesn't fall on end pixel. if ( ROWS % GRID_SIZE) ++gridRows; if ( COLS % GRID_SIZE) ++gridCols; ossimIpt gridSize (gridCols, gridRows); // The grid as used in base class, has UV-space always at 0,0 origin ossimDpt gridOrigin(0.0,0.0); const ossim_float64 NULL_VALUE = -999.0; theLatGrid.setNullValue(ossim::nan()); theLonGrid.setNullValue(ossim::nan()); theLatGrid.initialize(gridSize, gridOrigin, dspacing); theLonGrid.initialize(gridSize, gridOrigin, dspacing); std::vector<hsize_t> inputCount(LAT_DIM_COUNT); std::vector<hsize_t> inputOffset(LAT_DIM_COUNT); inputOffset[0] = 0; // row is set below. inputOffset[1] = validRect.ul().x; // col inputCount[0] = 1; // row inputCount[1] = (hsize_t)COLS; // col // Output dataspace dimensions. Reading a line at a time. const ossim_int32 OUT_DIM_COUNT = 3; std::vector<hsize_t> outputCount(OUT_DIM_COUNT); outputCount[0] = 1; // band outputCount[1] = 1; // row outputCount[2] = COLS; // col // Output dataspace offset. std::vector<hsize_t> outputOffset(OUT_DIM_COUNT); outputOffset[0] = 0; outputOffset[1] = 0; outputOffset[2] = 0; ossimScalarType scalar = ossim_hdf5::getScalarType( latDataSet ); if ( scalar == OSSIM_FLOAT32 ) { // Set the return status to true if we get here... status = true; // See if we need to swap bytes: ossimEndian* endian = 0; if ( ( ossim::byteOrder() != ossim_hdf5::getByteOrder( latDataSet ) ) ) { endian = new ossimEndian(); } // Native type: H5::DataType latDataType = latDataSet->getDataType(); H5::DataType lonDataType = lonDataSet->getDataType(); // Output dataspace always the same, width of one line. H5::DataSpace bufferDataSpace( OUT_DIM_COUNT, &outputCount.front()); bufferDataSpace.selectHyperslab( H5S_SELECT_SET, &outputCount.front(), &outputOffset.front() ); // Arrays to hold a single line of latitude longitude values. vector<ossim_float32> latValue(COLS); vector<ossim_float32> lonValue(COLS); hsize_t row = 0; // Line loop: for ( ossim_uint32 y = 0; y < gridRows; ++y ) { // row = line in image space row = y*GRID_SIZE; if ( row < ROWS ) { inputOffset[0] = row + validRect.ul().y; latDataSpace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); lonDataSpace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); // Read data from file into the buffer. latDataSet->read( &(latValue.front()), latDataType, bufferDataSpace, latDataSpace ); lonDataSet->read( &(lonValue.front()), lonDataType, bufferDataSpace, lonDataSpace ); if ( endian ) { // If the endian pointer is initialized(not zero) swap the bytes. endian->swap( &(latValue.front()), COLS ); endian->swap( &(lonValue.front()), COLS ); } // Sample loop: hsize_t col = 0; for ( ossim_uint32 x = 0; x < gridCols; ++x ) { ossim_float32 lat = ossim::nan(); ossim_float32 lon = ossim::nan(); // col = sample in image space col = x*GRID_SIZE; if ( col < COLS ) { if ( (latValue[col] > NULL_VALUE)&&(lonValue[col] > NULL_VALUE) ) { lat = latValue[col]; lon = lonValue[col]; if ( m_crossesDateline ) { if ( lon < 0.0 ) lon += 360; } } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } } else // Last column is outside of image bounds. { // Get the last two latitude values: ossim_float32 lat1 = theLatGrid.getNode( x-2, y ); ossim_float32 lat2 = theLatGrid.getNode( x-1, y ); // Get the last two longitude values ossim_float32 lon1 = theLonGrid.getNode( x-2, y ); ossim_float32 lon2 = theLonGrid.getNode( x-1, y ); if ( ( lat1 > NULL_VALUE ) && ( lat2 > NULL_VALUE ) ) { // Delta between last two latitude grid values. ossim_float32 latSpacing = lat2 - lat1; // Compute: lat = lat2 + latSpacing; } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } if ( ( lon1 > NULL_VALUE ) && ( lon2 > NULL_VALUE ) ) { // Delta between last two longitude values. ossim_float32 lonSpacing = lon2 - lon1; // Compute: lon = lon2 + lonSpacing; // Check for wrap: if ( !m_crossesDateline && ( lon > 180 ) ) { lon -= 360.0; } } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } #if 0 /* Please leave for debug. (drb) */ cout << "lat1: " << lat1 << " lat2 " << lat2 << " lon1 " << lon1 << " lon2 " << lon2 << "\n"; #endif } // Assign the latitude and longitude. theLatGrid.setNode( x, y, lat ); theLonGrid.setNode( x, y, lon ); #if 0 /* Please leave for debug. (drb) */ cout << "x,y,col,row,lat,lon:" << x << "," << y << "," << col << "," << row << "," << theLatGrid.getNode(x, y) << "," << theLonGrid.getNode( x, y) << "\n"; #endif } // End sample loop. } else // Row is outside of image bounds: { // Sample loop: for ( ossim_uint32 x = 0; x < gridCols; ++x ) { ossim_float32 lat = ossim::nan(); ossim_float32 lon = ossim::nan(); ossim_float32 lat1 = theLatGrid.getNode( x, y-2 ); ossim_float32 lat2 = theLatGrid.getNode( x, y-1 ); ossim_float32 lon1 = theLonGrid.getNode( x, y-2 ); ossim_float32 lon2 = theLonGrid.getNode( x, y-1 ); if ( ( lon1 > NULL_VALUE ) && ( lon2 > NULL_VALUE ) ) { // Delta between last two longitude values. ossim_float32 lonSpacing = lon2 - lon1; // Compute: lon = lon2 + lonSpacing; // Check for wrap: if ( !m_crossesDateline && ( lon > 180 ) ) { lon -= 360.0; } } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } if ( ( lat1 > NULL_VALUE ) && ( lat2 > NULL_VALUE ) ) { // Delta between last two latitude values. ossim_float32 latSpacing = lat2 - lat1; lat = lat2 + latSpacing; } else // Nulls in grid! { std::string errMsg = "ossimH5GridModel::setGridNodes encountered nans!"; throw ossimException(errMsg); } #if 0 /* Please leave for debug. (drb) */ hsize_t col = x*GRID_SIZE; // Sample in image space cout << "lat1: " << lat1 << " lat2 " << lat2 << " lon1 " << lon1 << " lon2 " << lon2 << "\nx,y,col,row,lat,lon:" << x << "," << y << "," << col << "," << row << "," << lat << "," << lon << "\n"; #endif // Assign the latitude:: theLatGrid.setNode( x, y, lat ); // Assign the longitude. theLonGrid.setNode( x, y, lon ); } // End sample loop. } // Matches if ( row < imageRows ){...}else{ } // End line loop. latDataSpace.close(); lonDataSpace.close(); if ( status ) { theSeedFunction = ossim_hdf5::getBilinearProjection( *latDataSet,*lonDataSet, validRect ); // Bileaner projection to handle ossimDrect imageRect(validRect); initializeModelParams(imageRect); // debugDump(); } if ( endian ) { delete endian; endian = 0; } } // Matches: if ( scalar == OSSIM_FLOAT32 ) } // Matches: if ( (latDimsOut[0] == imageRows) ... } // Matches: if ( ( LAT_DIM_COUNT == 2 ) ... } // Matches: if ( latDataSet && lonDataSet return status; } // End: bool ossimH5GridModel::setGridNodes( H5::DataSet* latDataSet, ... )
void ossimH5GridModel::initializeModelParams(ossimIrect imageBounds) { theLatGrid.enableExtrapolation(); theLonGrid.enableExtrapolation(); theHeightEnabledFlag = false; // NOTE: it is assumed that the grid size and spacing is the same for ALL grids: ossimIpt gridSize (theLatGrid.size()); ossimDpt spacing (theLatGrid.spacing()); ossimDpt v[4]; v[0].lat = theLatGrid.getNode(0,0); v[0].lon = theLonGrid.getNode(0,0); v[1].lat = theLatGrid.getNode(gridSize.x-1, 0); v[1].lon = theLonGrid.getNode(gridSize.x-1, 0); v[2].lat = theLatGrid.getNode(gridSize.x-1, gridSize.y-1); v[2].lon = theLonGrid.getNode(gridSize.x-1, gridSize.y-1); v[3].lat = theLatGrid.getNode(0, gridSize.y-1); v[3].lon = theLonGrid.getNode(0, gridSize.y-1); if ( m_crossesDateline ) { // Longitude values between 0 and 360. m_boundGndPolygon = ossimPolygon(4, v); } // Guaranty longitude values are -180 to 180 for (int i=0; i<4; ++i) { if (v[i].lon > 180.0) v[i].lon -= 360.0; } theBoundGndPolygon = ossimPolygon(4, v); if ( !m_crossesDateline ) { // Longitude values between -180 and 180. m_boundGndPolygon = theBoundGndPolygon; } theImageSize = ossimDpt(imageBounds.width(), imageBounds.height()); theRefImgPt = imageBounds.midPoint(); theRefGndPt.lat = theLatGrid(theRefImgPt); theRefGndPt.lon = theLonGrid(theRefImgPt); ossimDpt ref_ip_dx (theRefImgPt.x+1.0, theRefImgPt.y ); ossimDpt ref_ip_dy (theRefImgPt.x , theRefImgPt.y+1.0); ossimGpt ref_gp_dx (theLatGrid(ref_ip_dx), theLonGrid(ref_ip_dx)); ossimGpt ref_gp_dy (theLatGrid(ref_ip_dy), theLonGrid(ref_ip_dy)); theGSD.x = theRefGndPt.distanceTo(ref_gp_dx); theGSD.y = theRefGndPt.distanceTo(ref_gp_dy); theMeanGSD = (theGSD.line + theGSD.samp)/2.0; theImageClipRect = imageBounds; // Image is clipped to valid rect so no sub image offset. theSubImageOffset = ossimDpt(0.0, 0.0); //imageBounds.ul(); theRefGndPt.limitLonTo180(); // debugDump(); } // End: initializeModelParams
ossimRefPtr<ossimImageData> ossimMemoryImageSource::getTile(const ossimIrect& rect, ossim_uint32 /* resLevel */) { if(!isSourceEnabled()||!m_image.valid()||m_boundingRect.hasNans()) return 0; if(!m_result.valid()) { m_result = new ossimImageData(0, getOutputScalarType(), getNumberOfOutputBands(), rect.width(), rect.height()); m_result->initialize(); } m_result->setImageRectangle(rect); m_result->makeBlank(); ossimIrect clampRect = m_image->getImageRectangle().clipToRect(rect); m_result->loadTile(m_image->getBuf(), m_boundingRect, OSSIM_BSQ); m_result->validate(); return m_result; }
ossimRefPtr<ossimImageData> ossimTileToIplFilter::getTile(const ossimIrect& tileRect, ossim_uint32 resLevel) { cout << "Getting Tile !" << endl; // Check input data sources for valid and null tiles ossimImageSource *imageSource = PTR_CAST(ossimImageSource, getInput(0)); ossimRefPtr<ossimImageData> imageSourceData; if (imageSource) imageSourceData = imageSource->getTile(tileRect, resLevel); if (!isSourceEnabled()) return imageSourceData; if (!theTile.valid()) { if(getInput(0)) { theTile = ossimImageDataFactory::instance()->create(this, this); theTile->initialize(); } } if (!imageSourceData.valid() || !theTile.valid()) return ossimRefPtr<ossimImageData>(); theTile->setOrigin(tileRect.ul()); if (theTile->getImageRectangle() != tileRect) { theTile->setImageRectangle(tileRect); theTile->initialize(); } IplImage *input = cvCreateImage(cvSize(tileRect.width(), tileRect.height()),IPL_DEPTH_8U,3); IplImage *output = cvCreateImage(cvSize(tileRect.width(),tileRect.height()),IPL_DEPTH_8U,3); cvZero(input); cvZero(output); // If 16 or 32 bits, downsample to 8 bits ossimScalarType inputType = imageSourceData->getScalarType(); if(inputType == OSSIM_UINT16 || inputType == OSSIM_USHORT11) CopyTileToIplImage(static_cast<ossim_uint16>(0), imageSourceData, input, tileRect); else CopyTileToIplImage(static_cast<ossim_uint8>(0), imageSourceData, input, tileRect); cvCopy(input, output); int bins = 256; int hsize[] = {bins}; float binVal; float sum=0; int firstIndexFlag = 1; /*// Create histogram of image CvHistogram *hist; hist = cvCreateHist(1, hsize, CV_HIST_ARRAY, 0, 1); cvCalcHist(&input, hist, 0, 0); cvNormalizeHist(hist, 100); binVal = cvQueryHistValue_1D(hist,1); */ // Determine the actual height and width of each tile ossimIrect fullImageRect; fullImageRect = imageSource->getBoundingRect(0); ossim_int32 tileHeight, tileWidth, imageWidth, imageHeight; tileHeight = tileRect.height(); tileWidth = tileRect.width(); imageWidth = fullImageRect.width(); imageHeight = fullImageRect.height(); ossim_int32 totRows, totCols; totRows = (ossim_uint32)round(imageHeight / tileHeight); totCols = (ossim_uint32)round(imageWidth / tileWidth); ossimIpt upperLeftTile = tileRect.ul(); if ((upperLeftTile.x + 1) > fullImageRect.ul().x + totCols * tileWidth) tileWidth = imageWidth - totCols * tileWidth; if ((upperLeftTile.y + 1) > fullImageRect.ul().y + totRows * tileHeight) tileHeight = imageHeight - totRows * tileHeight; //Begin Ship Detect Algorithim // Create sub-image to ignore zeros created by OSSIM // ie, the tile is 512x512 but on the edges, the information is only in 512x10 CvRect subRect = cvRect(0, 0, tileWidth, tileHeight); IplImage *subImg = cvCreateImage(cvSize(tileWidth, tileHeight),IPL_DEPTH_8U,3); cvSetImageROI(input, subRect); cvCopy(input, subImg); cvResetImageROI(input); showImage(subImg,input); cvReleaseImage(&input); cvReleaseImage(&output); return theTile; }