ossimRefPtr<ossimImageData> ossimImageToPlaneNormalFilter::getTile( const ossimIrect& tileRect, ossim_uint32 resLevel) { if(!isSourceEnabled()||!theInputConnection) { return ossimImageSourceFilter::getTile(tileRect, resLevel); } if(!theTile.valid()) { initialize(); } if(!theTile.valid()) { return ossimImageSourceFilter::getTile(tileRect, resLevel); } theTile->setImageRectangle(tileRect); theBlankTile->setImageRectangle(tileRect); ossimIrect requestRect(tileRect.ul().x - 1, tileRect.ul().y - 1, tileRect.lr().x + 1, tileRect.lr().y + 1); ossimRefPtr<ossimImageData> input = theInputConnection->getTile(requestRect, resLevel); if(!input||(input->getDataObjectStatus()==OSSIM_EMPTY)||!input->getBuf()) { return theBlankTile; } double oldScaleX = theXScale; double oldScaleY = theYScale; if(resLevel > 0) { ossimDpt scaleFactor; theInputConnection->getDecimationFactor(resLevel, scaleFactor); if(!scaleFactor.hasNans()) { theXScale *= scaleFactor.x; theYScale *= scaleFactor.y; } } computeNormals(input, theTile); theXScale = oldScaleX; theYScale = oldScaleY; theTile->validate(); return theTile; }
void oms::SingleImageChain::setImageCut(const ossimIrect& rect) { std::vector<ossimDpt> pointList(4); pointList[0] = rect.ul(); pointList[1] = rect.ur(); pointList[2] = rect.lr(); pointList[3] = rect.ll(); setImageCut(pointList); }
ossimPolygon::ossimPolygon(const ossimIrect& rect) : theVertexList(4), theCurrentVertex(0), theOrderingType(OSSIM_CLOCKWISE_ORDER) { theVertexList[0] = rect.ul(); theVertexList[1] = rect.ur(); theVertexList[2] = rect.lr(); theVertexList[3] = rect.ll(); }
//******************************************************************* // Public Constructor: ossimDrect // //******************************************************************* ossimDrect::ossimDrect(const ossimIrect& rect) : theUlCorner(rect.ul()), theUrCorner(rect.ur()), theLrCorner(rect.lr()), theLlCorner(rect.ll()), theOrientMode(rect.orientMode()) { if(rect.isNan()) { makeNan(); } }
void ossimImageDataHelper::fill(T /* dummyVariable */, const double* values, const ossimIrect& region) { T* buf = reinterpret_cast<T*>(theImageData->getBuf()); ossim_int32 blockLength=theImageData->getWidth()*theImageData->getHeight(); ossim_int32 bandOffset = 0; ossim_int32 miny,maxy; ossim_int32 minx, maxx; ossim_int32 y = 0; miny = region.ul().y-theOrigin.y; maxy = region.lr().y-theOrigin.y; minx = region.ul().x-theOrigin.x; maxx = region.lr().x-theOrigin.x; ossim_int32 rowOffset = (miny)*theImageData->getWidth(); ossim_int32 startX = minx; ossim_int32 endX = maxx; ossim_int32 bands = (ossim_int32)theImageData->getNumberOfBands(); for (y = miny; (y <= maxy); ++y) { startX=minx; while(startX <= endX) { bandOffset = 0; int band = 0; for(band = 0; band < bands;++band) { buf[rowOffset+bandOffset+startX] = (T)(values[band]); bandOffset += blockLength; } ++startX; } rowOffset += theImageData->getWidth(); } }
void ossimQtRoiRectAnnotator::setRoiRect(const ossimIrect& rect) { if (thePoints.size() != 2) { thePoints.resize(2); } thePoints[0] = rect.ul(); thePoints[1] = rect.lr(); if (theImageWidget) { theImageWidget->refreshGraphics(); } }
ossimDrect shapefileClip::LineSampleToWorld(ossimIrect rect, ossimRefPtr<ossimImageGeometry> ImageGeom) { ossimGpt gp1; ossimGpt gp2; ossimGpt gp3; ossimGpt gp4; ImageGeom->localToWorld(rect.ul(), gp1); ImageGeom->localToWorld(rect.ur(), gp2); ImageGeom->localToWorld(rect.lr(), gp3); ImageGeom->localToWorld(rect.ll(), gp4); ossimDrect boundsRect(ossimDpt(gp1.lond(), gp1.latd()), ossimDpt(gp2.lond(), gp2.latd()), ossimDpt(gp3.lond(), gp3.latd()), ossimDpt(gp4.lond(), gp4.latd()), OSSIM_RIGHT_HANDED); return boundsRect; }
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; }
//******************************************************************* // Private Method: //******************************************************************* bool ossimAdrgTileSource::fillBuffer(const ossimIrect& /* tile_rect */, const ossimIrect& clip_rect, ossimImageData* tile) { //*** // Shift the upper left corner of the "clip_rect" to the an even chunk // boundry. //*** ossimIpt tileOrigin = clip_rect.ul(); adjustToStartOfTile(tileOrigin); //*** // Calculate the number of tiles needed in the line/sample directions. //*** ossim_int32 size_in_x = clip_rect.lr().x - tileOrigin.x + 1; ossim_int32 size_in_y = clip_rect.lr().y - tileOrigin.y + 1; ossim_int32 tiles_in_x_dir = size_in_x / ADRG_TILE_WIDTH + (size_in_x % ADRG_TILE_WIDTH ? 1 : 0); ossim_int32 tiles_in_y_dir = size_in_y / ADRG_TILE_HEIGHT + (size_in_y % ADRG_TILE_HEIGHT ? 1 : 0); ossimIpt ulTilePt = tileOrigin; // Chunk loop in line direction. for (ossim_int32 y=0; y<tiles_in_y_dir; y++) { ulTilePt.x = tileOrigin.x; // Tile loop in sample direction. for (ossim_int32 x=0; x<tiles_in_x_dir; x++) { ossimIrect adrg_tile_rect(ulTilePt.x, ulTilePt.y, ulTilePt.x + ADRG_TILE_WIDTH- 1, ulTilePt.y + ADRG_TILE_HEIGHT - 1); if (adrg_tile_rect.intersects(clip_rect)) { ossimIrect tile_clip_rect = clip_rect.clipToRect(adrg_tile_rect); //--- // Some point in the chip intersect the tile so grab the // data. //--- ossim_int32 row = (ossim_int32) ulTilePt.y / ADRG_TILE_HEIGHT; ossim_int32 col = (ossim_int32) ulTilePt.x / ADRG_TILE_WIDTH; ossim_int32 tileOffset = m_AdrgHeader->tim(row, col); if(tileOffset != 0) { // Get the data. int seek_position = (tileOffset - 1) * 49152 + 2048; int band; // seek to start of chip m_FileStr.seekg(seek_position, ios::beg); for (band=0; band<3; band++) { //*** // Read the chip from the ccf file into the chunk buffer. // This will get all the bands. Bands are interleaved by // chip. //*** if (!m_FileStr.read((char*)m_TileBuffer, ADRG_TILE_SIZE)) { theErrorStatus = ossimErrorCodes::OSSIM_ERROR; return false; } tile->loadBand(m_TileBuffer, adrg_tile_rect, tile_clip_rect, band); } // End of band loop. } // End of if (tileOffset != 0) } // End of if (adrg_tile_rect.intersects(clip_rect)) ulTilePt.x += ADRG_TILE_WIDTH; } // End of tile loop in the sample direction. ulTilePt.y += ADRG_TILE_HEIGHT; } // End of tile loop in the line direction. return true; }
ossimRefPtr<ossimImageData> ossimCFARFilter::getTile(const ossimIrect& tileRect, ossim_uint32 resLevel) { if(!theInputConnection) { return theTile; } if(!isSourceEnabled()) { return theInputConnection->getTile(tileRect, resLevel); } //--- // We have a 5x5 matrix so stretch the rect out to cover // the required pixels. We only need 2 pixels to the left // and right of the center pixel. //--- ossimIrect newRect(ossimIpt(tileRect.ul().x - 2, tileRect.ul().y - 2), ossimIpt(tileRect.lr().x + 2, tileRect.lr().y + 2)); ossimRefPtr<ossimImageData> data = theInputConnection->getTile(newRect, resLevel); if(!data.valid() || !data->getBuf()) { return data; } // First time through or after an initialize()... if (!theTile.valid()) { allocate(); if (!theTile.valid()) // Should never happen! { return data; } } // First time through, after an initialize() or a setKernel()... if (!theNullPixValue.size()) { computeNullMinMax(); if (!theNullPixValue.size()) // Should never happen! { return data; } } theTile->setImageRectangle(tileRect); theTile->makeBlank(); switch(data->getScalarType()) { case OSSIM_UCHAR: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<ossim_uint8>(0), data, theTile); } else { convolvePartial(static_cast<ossim_uint8>(0), data, theTile); } break; } case OSSIM_FLOAT: case OSSIM_NORMALIZED_FLOAT: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<float>(0), data, theTile); } else { convolvePartial(static_cast<float>(0), data, theTile); } break; } case OSSIM_USHORT16: case OSSIM_USHORT11: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<ossim_uint16>(0), data, theTile); } else { convolvePartial(static_cast<ossim_uint16>(0), data, theTile); } break; } case OSSIM_SSHORT16: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<ossim_sint16>(0), data, theTile); } else { convolvePartial(static_cast<ossim_sint16>(0), data, theTile); } break; } case OSSIM_DOUBLE: case OSSIM_NORMALIZED_DOUBLE: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<double>(0), data, theTile); } else { convolvePartial(static_cast<double>(0), data, theTile); } break; } default: { ossimNotify(ossimNotifyLevel_WARN) << "ossimCFARFilter::getTile WARNING:\n" << "Scalar type = " << theTile->getScalarType() << " Not supported by ossimCFARFilter" << endl; break; } } 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::getValidBoundingRect( H5::DataSet& dataset, const std::string& name, ossimIrect& rect ) { bool result = false; H5::DataSpace imageDataspace = dataset.getSpace(); const ossim_int32 IN_DIM_COUNT = imageDataspace.getSimpleExtentNdims(); if ( IN_DIM_COUNT == 2 ) { // Get the extents. Assuming dimensions are same for lat lon dataset. std::vector<hsize_t> dimsOut(IN_DIM_COUNT); imageDataspace.getSimpleExtentDims( &dimsOut.front(), 0 ); if ( dimsOut[0] && dimsOut[1] ) { //--- // Capture the rectangle: // dimsOut[0] is height, dimsOut[1] is width: //--- rect = ossimIrect( 0, 0, static_cast<ossim_int32>( dimsOut[1]-1 ), static_cast<ossim_int32>( dimsOut[0]-1 ) ); const ossim_int32 WIDTH = rect.width(); std::vector<hsize_t> inputCount(IN_DIM_COUNT); std::vector<hsize_t> inputOffset(IN_DIM_COUNT); inputOffset[0] = 0; inputOffset[1] = 0; inputCount[0] = 1; inputCount[1] = WIDTH; // 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] = WIDTH; // whole line // 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. //--- const ossim_float32 NULL_VALUE = -999.0; //--- // VIIRS Radiance data has a -1.5e-9 in the first column. // Treat this as a null. //--- const ossim_float32 NULL_VALUE2 = ( name == "/All_Data/VIIRS-DNB-SDR_All/Radiance" ) ? -1.5e-9 : NULL_VALUE; const ossim_float32 TOLERANCE = 0.1e-9; // For ossim::almostEqual() // Hold one line: std::vector<ossim_float32> values( WIDTH ); // Find the ul pixel: ossimIpt ulIpt = rect.ul(); bool found = false; // Line loop to find upper left pixel: while ( ulIpt.y <= rect.lr().y ) { inputOffset[0] = static_cast<hsize_t>(ulIpt.y); imageDataspace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); // Read data from file into the buffer. dataset.read( (void*)&values.front(), datatype, bufferDataSpace, imageDataspace ); if ( endian ) { // If the endian pointer is initialized(not zero) swap the bytes. endian->swap( scalar, (void*)&values.front(), WIDTH ); } // Sample loop: ulIpt.x = rect.ul().x; ossim_int32 index = 0; while ( ulIpt.x <= rect.lr().x ) { if ( !ossim::almostEqual(values[index], NULL_VALUE2, TOLERANCE) && ( values[index] > NULL_VALUE ) ) { found = true; // Found valid pixel. break; } ++ulIpt.x; ++index; } // End: sample loop if ( found ) { break; } ++ulIpt.y; } // End line loop to find ul pixel: // Find the lower right pixel: ossimIpt lrIpt = rect.lr(); found = false; // Line loop to find last pixel: while ( lrIpt.y >= rect.ul().y ) { inputOffset[0] = static_cast<hsize_t>(lrIpt.y); imageDataspace.selectHyperslab( H5S_SELECT_SET, &inputCount.front(), &inputOffset.front() ); // Read data from file into the buffer. dataset.read( (void*)&values.front(), datatype, bufferDataSpace, imageDataspace ); if ( endian ) { // If the endian pointer is initialized(not zero) swap the bytes. endian->swap( scalar, (void*)&values.front(), WIDTH ); } // Sample loop: lrIpt.x = rect.lr().x; ossim_int32 index = WIDTH-1; while ( lrIpt.x >= rect.ul().x ) { if ( !ossim::almostEqual(values[index], NULL_VALUE2, TOLERANCE) && ( values[index] > NULL_VALUE ) ) { found = true; // Found valid pixel. break; } --lrIpt.x; --index; } // End: sample loop if ( found ) { break; } --lrIpt.y; } // End line loop to find lower right pixel. rect = ossimIrect( ulIpt, lrIpt ); // Cleanup: if ( endian ) { delete endian; endian = 0; } result = true; } else // Matches: if ( scalar == OSSIM_FLOAT32 ){...} { ossimNotify(ossimNotifyLevel_WARN) << "ossim_hdf5::getBoundingRect WARNING!" << "\nUnhandled scalar type: " << ossimScalarTypeLut::instance()->getEntryString( scalar ) << std::endl; } } // Matches: if ( dimsOut... } // Matches: if ( IN_DIM_COUNT == 2 ) imageDataspace.close(); return result; } // End: ossim_hdf5::getBoundingRect(...)
ossimRefPtr<ossimProjection> ossim_hdf5::getBilinearProjection( H5::DataSet& latDataSet, H5::DataSet& lonDataSet, const ossimIrect& validRect ) { ossimRefPtr<ossimProjection> proj = 0; // Get dataspace of the dataset. H5::DataSpace latDataSpace = latDataSet.getSpace(); H5::DataSpace lonDataSpace = lonDataSet.getSpace(); // Number of dimensions of the input dataspace: const ossim_int32 DIM_COUNT = latDataSpace.getSimpleExtentNdims(); if ( DIM_COUNT == 2 ) { // Get the extents. Assuming dimensions are same for lat lon dataset. std::vector<hsize_t> dimsOut(DIM_COUNT); latDataSpace.getSimpleExtentDims( &dimsOut.front(), 0 ); if ( dimsOut[0] && dimsOut[1] ) { std::vector<hsize_t> inputCount(DIM_COUNT); std::vector<hsize_t> inputOffset(DIM_COUNT); inputOffset[0] = 0; inputOffset[1] = 0; inputCount[0] = 1; inputCount[1] = 1; // 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] = 1; // 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( &latDataSet ); if ( scalar == OSSIM_FLOAT32 ) { // 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(); std::vector<ossimDpt> ipts; std::vector<ossimGpt> gpts; ossimGpt gpt(0.0, 0.0, 0.0); // Assuming WGS84... ossim_float32 latValue = 0.0; ossim_float32 lonValue = 0.0; // Only grab every 256th value.: const ossim_int32 GRID_SIZE = 256; // Output dataspace always the same one pixel. 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. //--- const ossim_float32 NULL_VALUE = -999.0; //--- // Get the tie points within the valid rect: //--- ossimDpt ipt = validRect.ul(); while ( ipt.y <= validRect.lr().y ) { inputOffset[0] = static_cast<hsize_t>(ipt.y); // Sample loop: ipt.x = validRect.ul().x; while ( ipt.x <= validRect.lr().x ) { inputOffset[1] = static_cast<hsize_t>(ipt.x); 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, latDataType, bufferDataSpace, latDataSpace ); lonDataSet.read( &lonValue, lonDataType, bufferDataSpace, lonDataSpace ); if ( endian ) { // If the endian pointer is initialized(not zero) swap the bytes. endian->swap( latValue ); endian->swap( lonValue ); } if ( ( latValue > NULL_VALUE ) && ( lonValue > NULL_VALUE ) ) { gpt.lat = latValue; gpt.lon = lonValue; gpts.push_back( gpt ); // Add the image point subtracting the image offset. ossimIpt shiftedIpt = ipt - validRect.ul(); ipts.push_back( shiftedIpt ); } // Go to next point: if ( ipt.x < validRect.lr().x ) { ipt.x += GRID_SIZE; if ( ipt.x > validRect.lr().x ) { ipt.x = validRect.lr().x; // Clamp to last sample. } } else { break; // At the end: } } // End sample loop. if ( ipt.y < validRect.lr().y ) { ipt.y += GRID_SIZE; if ( ipt.y > validRect.lr().y ) { ipt.y = validRect.lr().y; // Clamp to last line. } } else { break; // At the end: } } // End line loop. if ( ipts.size() ) { // Create the projection: ossimRefPtr<ossimBilinearProjection> bp = new ossimBilinearProjection(); // Add the tie points: bp->setTiePoints( ipts, gpts ); // Assign to output projection: proj = bp.get(); } // Cleanup: if ( endian ) { delete endian; endian = 0; } } else // Matches: if ( scalar == OSSIM_FLOAT32 ){...} { ossimNotify(ossimNotifyLevel_WARN) << "ossim_hdf5::getBilinearProjection WARNING!" << "\nUnhandled scalar type: " << ossimScalarTypeLut::instance()->getEntryString( scalar ) << std::endl; } } // Matches: if ( dimsOut... } // Matches: if ( IN_DIM_COUNT == 2 ) latDataSpace.close(); lonDataSpace.close(); return proj; } // End: ossim_hdf5::getBilinearProjection()