ossimRefPtr<ossimImageData> ossimKakaduJ2kReader::getTile( const ossimIrect& rect, ossim_uint32 resLevel) { // This tile source bypassed, or invalid res level, return a blank tile. if(!isSourceEnabled() || !isOpen() || !isValidRLevel(resLevel)) { return ossimRefPtr<ossimImageData>(); } if (theTile.valid()) { // Rectangle must be set prior to getOverviewTile call. theTile->setImageRectangle(rect); if (resLevel) { if ( getOverviewTile(resLevel, theTile.get() ) == false ) { theTile->makeBlank(); } } else { //--- // See if the whole tile is going to be filled, if not, start out with // a blank tile so data from a previous load gets wiped out. //--- if ( !rect.completely_within(theImageRect) ) { // Start with a blank tile. theTile->makeBlank(); } //--- // See if any point of the requested tile is in the image. //--- if ( rect.intersects(theImageRect) ) { ossimIrect clipRect = rect.clipToRect(theImageRect); ossimIrect exandedRect = clipRect; //--- // Shift the upper left corner of the "clip_rect" to the an even // j2k tile boundry. //--- exandedRect.stretchToTileBoundary(ossimIpt(theTileSizeX, theTileSizeY)); // Vertical tile loop. ossim_int32 y = exandedRect.ul().y; while (y < exandedRect.lr().y) { // Horizontal tile loop. ossim_int32 x = exandedRect.ul().x; while (x < exandedRect.lr().x) { if ( loadTileFromCache(x, y, clipRect) == false ) { if ( loadTile(x, y) ) { //--- // Note: Clip the cache tile to the image clipRect // since there are j2k tiles that go beyond the image // dimensions, i.e., edge tiles. //--- ossimIrect cr = theCacheTile->getImageRectangle(). clipToRect(clipRect); theTile->loadTile(theCacheTile->getBuf(), theCacheTile->getImageRectangle(), cr, OSSIM_BSQ); } } x += theTileSizeX; // Go to next tile. } y += theTileSizeY; // Go to next row of tiles. } // Set the tile status. theTile->validate(); } // matches: if ( rect.intersects(theImageRect) ) } // r0 block } // matches: if (theTile.valid()) return theTile; }
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> 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; }
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<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(...)
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()
void ossimOpjCompressor::initOpjCodingParams( bool jp2, const ossimIpt& tileSize, const ossimIrect& imageRect ) { static const char MODULE[] = "ossimOpjCompressor::initOpjCodingParams"; if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n"; } if ( m_params ) { delete m_params; } m_params = new opj_cparameters_t(); // Set encoding parameters to default values. opj_set_default_encoder_parameters( m_params ); // Output format: 0: J2K, 1: JP2, 2: JPT m_params->cod_format = jp2 ? 1 : 0; // std::string outfile = "test.jp2"; // strncpy(m_params->outfile, outfile.data(), outfile.size()); //--- // Shall we do an Multi-component Transformation(MCT) ? // 0:no_mct;1:rgb->ycc;2:custom mct //--- // Set the tiles size: m_params->cp_tx0 = 0; m_params->cp_ty0 = 0; m_params->cp_tdx = tileSize.x; m_params->cp_tdy = tileSize.y; m_params->tile_size_on = OPJ_TRUE; // No mct. m_params->tcp_mct = 0; //--- // Number of resolutions: // This sets m_levels if not set and // m_params->numresolution. //--- initLevels( imageRect ); // Set the block size. Note 64x64 is the current kakadu default. setCodeBlockSize( 64, 64 ); //--- // Set progression order to use. Note LRCP is the current opj default. // L=layer; R=resolution C=component; P=position // // OPJ_LRCP, OPJ_RLCP, OPJ_RPCL, PCRL, CPRL */ //--- setProgressionOrder( OPJ_LRCP ); // total pixels const ossim_float64 TP = imageRect.area(); if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << "quality type: " << getQualityTypeString() << endl; } //--- // Rate is a ratio of desired bytes / total bytes. So if you // want 4 bits per pixels it's total_pixels * 4 / 8 or // total_pixels * 4 * 0.125. //--- // Allocation by rate/distortion. m_params->cp_disto_alloc = 1; switch (m_qualityType) { case ossimOpjCompressor::OPJ_NUMERICALLY_LOSSLESS: { // cout << "ossimOpjCompressor::OPJ_NUMERICALLY_LOSSLESS..." << endl; // W5X3 Kernel setReversibleFlag(true); // Tmp drb... m_params->tcp_numlayers = 1; m_params->tcp_rates[0] = 1; #if 0 m_params->tcp_numlayers = 20; m_params->tcp_rates[0] = std::ceil( TP * 0.03125 * 0.125 ); m_params->tcp_rates[1] = std::ceil( TP * 0.0625 * 0.125 ); m_params->tcp_rates[2] = std::ceil( TP * 0.125 * 0.125 ); m_params->tcp_rates[3] = std::ceil( TP * 0.25 * 0.125 ); m_params->tcp_rates[4] = std::ceil( TP * 0.5 * 0.125 ); m_params->tcp_rates[5] = std::ceil( TP * 0.6 * 0.125 ); m_params->tcp_rates[6] = std::ceil( TP * 0.7 * 0.125 ); m_params->tcp_rates[7] = std::ceil( TP * 0.8 * 0.125 ); m_params->tcp_rates[8] = std::ceil( TP * 0.9 * 0.125 ); m_params->tcp_rates[9] = std::ceil( TP * 1.0 * 0.125 ); m_params->tcp_rates[10] = std::ceil( TP * 1.1 * 0.125 ); m_params->tcp_rates[11] = std::ceil( TP * 1.2 * 0.125 ); m_params->tcp_rates[12] = std::ceil( TP * 1.3 * 0.125 ); m_params->tcp_rates[13] = std::ceil( TP * 1.5 * 0.125 ); m_params->tcp_rates[14] = std::ceil( TP * 1.7 * 0.125 ); m_params->tcp_rates[15] = std::ceil( TP * 2.0 * 0.125 ); m_params->tcp_rates[16] = std::ceil( TP * 2.3 * 0.125 ); m_params->tcp_rates[17] = std::ceil( TP * 2.8 * 0.125 ); m_params->tcp_rates[18] = std::ceil( TP * 3.5 * 0.125 ); //--- // Indicate that the final quality layer should include all // compressed bits. //--- // m_params->tcp_rates[19] = OSSIM_DEFAULT_MAX_PIX_SINT32; // KDU_LONG_MAX; m_params->tcp_rates[19] = std::ceil( TP * 4.0 * 0.125 ); #endif break; } case ossimOpjCompressor::OPJ_VISUALLY_LOSSLESS: { // W9X7 kernel: setReversibleFlag(false); m_params->tcp_numlayers = 19; m_params->tcp_rates[0] = std::ceil( TP * 0.03125 * 0.125 ); m_params->tcp_rates[1] = std::ceil( TP * 0.0625 * 0.125 ); m_params->tcp_rates[2] = std::ceil( TP * 0.125 * 0.125 ); m_params->tcp_rates[3] = std::ceil( TP * 0.25 * 0.125 ); m_params->tcp_rates[4] = std::ceil( TP * 0.5 * 0.125 ); m_params->tcp_rates[5] = std::ceil( TP * 0.6 * 0.125 ); m_params->tcp_rates[6] = std::ceil( TP * 0.7 * 0.125 ); m_params->tcp_rates[7] = std::ceil( TP * 0.8 * 0.125 ); m_params->tcp_rates[8] = std::ceil( TP * 0.9 * 0.125 ); m_params->tcp_rates[9] = std::ceil( TP * 1.0 * 0.125 ); m_params->tcp_rates[10] = std::ceil( TP * 1.1 * 0.125 ); m_params->tcp_rates[11] = std::ceil( TP * 1.2 * 0.125 ); m_params->tcp_rates[12] = std::ceil( TP * 1.3 * 0.125 ); m_params->tcp_rates[13] = std::ceil( TP * 1.5 * 0.125 ); m_params->tcp_rates[14] = std::ceil( TP * 1.7 * 0.125 ); m_params->tcp_rates[15] = std::ceil( TP * 2.0 * 0.125 ); m_params->tcp_rates[16] = std::ceil( TP * 2.3 * 0.125 ); m_params->tcp_rates[17] = std::ceil( TP * 2.8 * 0.125 ); m_params->tcp_rates[18] = std::ceil( TP * 3.5 * 0.125 ); break; } case ossimOpjCompressor::OPJ_LOSSY: { // W9X7 kernel: setReversibleFlag(false); m_params->tcp_numlayers = 10; m_params->tcp_rates[0] = std::ceil( TP * 0.03125 * 0.125 ); m_params->tcp_rates[1] = std::ceil( TP * 0.0625 * 0.125 ); m_params->tcp_rates[2] = std::ceil( TP * 0.125 * 0.125 ); m_params->tcp_rates[3] = std::ceil( TP * 0.25 * 0.125 ); m_params->tcp_rates[4] = std::ceil( TP * 0.5 * 0.125 ); m_params->tcp_rates[5] = std::ceil( TP * 0.6 * 0.125 ); m_params->tcp_rates[6] = std::ceil( TP * 0.7 * 0.125 ); m_params->tcp_rates[7] = std::ceil( TP * 0.8 * 0.125 ); m_params->tcp_rates[8] = std::ceil( TP * 0.9 * 0.125 ); m_params->tcp_rates[9] = std::ceil( TP * 1.0 * 0.125 ); break; } default: { m_params->tcp_numlayers = 1; m_params->tcp_rates[0] = 1.0; if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "unspecified quality type\n"; } } } // matches: switch (m_qualityType) //--- // Set reversible flag, note, this controls the kernel. // W5X3(default) if reversible = true, W9X7 if reversible is false. //--- m_params->irreversible = !m_reversible; if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << "m_reversible: " << m_reversible << "\nm_levels: " << m_levels << "\n"; ossim::print( ossimNotify(ossimNotifyLevel_DEBUG), *m_params ); } if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exited...\n"; } }
ossimRefPtr<ossimImageData> ossimMaskFilter::getTile(const ossimIrect& rect, ossim_uint32 resLevel) { ossimImageSource* imageSource = PTR_CAST(ossimImageSource, getInput(0)); // we will check to see if it's a fileMaskSource // ossimImageSource* maskSource = PTR_CAST(ossimImageSource, getInput(1)); ossimRefPtr<ossimImageData> imageSourceData; ossimRefPtr<ossimImageData> maskSourceData; if(imageSource) { imageSourceData = imageSource->getTile(rect, resLevel); } if(!isSourceEnabled()) { return imageSourceData; } if(maskSource) { maskSourceData = maskSource->getTile(rect, resLevel); } if (!theTile.valid()) { allocate(); } if(!imageSourceData.valid() || !theTile.valid()) { return ossimRefPtr<ossimImageData>(); } theTile->setOrigin(rect.ul()); if(theTile->getImageRectangle() != rect) { theTile->setImageRectangle(rect); theTile->initialize(); } if(!imageSourceData.valid()) { return theTile; } if(!maskSourceData.valid()) { return imageSourceData; } if(imageSourceData->getDataObjectStatus() != OSSIM_NULL) { return executeMaskFilter(imageSourceData, maskSourceData); } return theTile; }
ossimRefPtr<ossimImageData> ossimWatermarkFilter::getTile( const ossimIrect& tile_rect, ossim_uint32 resLevel) { // Lock for the length of this method. // Check for input. if (!theInputConnection) { if (theTile.valid()) { theTile->setImageRectangle(tile_rect); theTile->makeBlank(); } return theTile; } // Fetch a tile from from the input source. ossimRefPtr<ossimImageData> inputTile = theInputConnection->getTile(tile_rect, resLevel); // Check for bypass. if (theEnableFlag == false) return inputTile; // Check for weight being 0.0. if (theWatermarkWeight == 0.0) return inputTile; //--- // Check for dirty state. // Note: This is set in initialize if something changes. //--- if (theDirtyFlag == true) { if (allocate() == false) // Something not right if false. { return inputTile; } } // We will only watermark (process) within the input bounding rectangle. if (tile_rect.intersects(theInputBoundingRect) == false) { return inputTile; } // Capture the rectangle and blank out theTile. theTile->setImageRectangle(tile_rect); if (inputTile.valid() && (inputTile->getDataObjectStatus() != OSSIM_NULL)) { // Copy the inputTile to theTile. theTile->loadTile(inputTile.get()); } else { theTile->makeBlank(); } // Write the watermarks... switch(theTile->getScalarType()) { case OSSIM_UINT8: { fill(ossim_uint8(0)); break; } case OSSIM_SINT8: { fill(ossim_sint8(0)); break; } case OSSIM_USHORT11: case OSSIM_UINT16: { fill(ossim_uint16(0)); break; } case OSSIM_SINT16: { fill(ossim_sint16(0)); break; } case OSSIM_UINT32: { fill(ossim_uint32(0)); break; } case OSSIM_SINT32: { fill(ossim_sint32(0)); break; } case OSSIM_FLOAT32: case OSSIM_NORMALIZED_FLOAT: { fill(ossim_float32(0)); break; } case OSSIM_FLOAT64: case OSSIM_NORMALIZED_DOUBLE: { fill(ossim_float32(0)); break; } case OSSIM_SCALAR_UNKNOWN: default: { ossimNotify(ossimNotifyLevel_WARN) << "Scalar type = " << theTile->getScalarType() << " Not supported by ossimWatermarkFilter" << std::endl; return inputTile; } } return theTile; }
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(); }
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> ossimMrSidReader::getTile( const ossimIrect& rect, ossim_uint32 resLevel) { LT_STATUS sts = LT_STS_Uninit; // This tile source bypassed, or invalid res level, return null tile. if(!isSourceEnabled() || !isOpen() || !isValidRLevel(resLevel)) { return ossimRefPtr<ossimImageData>(); } ossimIrect imageBound = getBoundingRect(resLevel); if(!rect.intersects(imageBound)) { return ossimRefPtr<ossimImageData>(); } // Check for overview. if( resLevel > theMinDwtLevels ) { if(theOverview.valid()) { ossimRefPtr<ossimImageData> tileData = theOverview->getTile(rect, resLevel); tileData->setScalarType(getOutputScalarType()); return tileData; } } theTile->setImageRectangle(rect); // Compute clip rectangle with respect to the image bounds. ossimIrect clipRect = rect.clipToRect(imageBound); if (rect.completely_within(clipRect) == false) { // Not filling whole tile so blank it out first. theTile->makeBlank(); } lt_uint16 anOssimBandIndex = 0; LTIPixel pixel(theReader->getColorSpace(), theNumberOfBands, theReader->getDataType()); LTISceneBuffer sceneBuffer(pixel, clipRect.width(), clipRect.height(), NULL); if (!theGeometry.valid()) { theGeometry = getImageGeometry(); } double mag = theGeometry->decimationFactor(resLevel).lat; sts = theImageNavigator->setSceneAsULWH(clipRect.ul().x, clipRect.ul().y, clipRect.lr().x - clipRect.ul().x + 1, clipRect.lr().y - clipRect.ul().y + 1, mag); LTIScene scene = theImageNavigator->getScene(); sts = theReader->read(scene, sceneBuffer); if (LT_SUCCESS(sts) == true) { for(anOssimBandIndex = 0; anOssimBandIndex < theNumberOfBands; anOssimBandIndex++) { theTile->loadBand(sceneBuffer.getTotalBandData(anOssimBandIndex), clipRect, anOssimBandIndex); } } theTile->validate(); return theTile; }
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
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, ... )
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; }