void TextPainter::Process() { for (auto it = texts_.begin(); it != texts_.end(); ++it) { if (it->second->CanUpdate()) it->second->Update(); auto image = it->second->content_image_; if (image == nullptr) continue; int x_ul = it->second->x_ul_, y_ul = it->second->y_ul_; int x_dr = it->second->x_dr_, y_dr = it->second->y_dr_; if (x_dr == -1) x_dr = x_ul + image->GetXSize(); if (y_dr == -1) y_dr = y_ul + image->GetYSize(); GetScreen().Draw(image, x_ul, y_ul, x_dr, y_dr); } }
TemporaryRef<DataSourceSurface> YCbCrImageDataDeserializer::ToDataSourceSurface() { RefPtr<DataSourceSurface> result = Factory::CreateDataSourceSurface(GetYSize(), gfx::SurfaceFormat::B8G8R8X8); DataSourceSurface::MappedSurface map; result->Map(DataSourceSurface::MapType::WRITE, &map); gfx::ConvertYCbCrToRGB32(GetYData(), GetCbData(), GetCrData(), map.mData, 0, 0, //pic x and y GetYSize().width, GetYSize().height, GetYStride(), GetCbCrStride(), map.mStride, gfx::YV12); result->Unmap(); return result.forget(); }
void Paint(ItemID pitemArg, Surface* psurface, bool bSelected, bool bFocus) { StringListItem* pitem = (StringListItem*)pitemArg; if (bSelected) { psurface->FillRect( WinRect(0, 0, GetXSize(), GetYSize()), m_colorSelected ); } psurface->DrawString(m_pfont, m_color, WinPoint(0, 0), pitem->GetString()); }
CPLErr VRTSourcedRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage ) { int nPixelSize = GDALGetDataTypeSize(eDataType)/8; int nReadXSize, nReadYSize; if( (nBlockXOff+1) * nBlockXSize > GetXSize() ) nReadXSize = GetXSize() - nBlockXOff * nBlockXSize; else nReadXSize = nBlockXSize; if( (nBlockYOff+1) * nBlockYSize > GetYSize() ) nReadYSize = GetYSize() - nBlockYOff * nBlockYSize; else nReadYSize = nBlockYSize; return IRasterIO( GF_Read, nBlockXOff * nBlockXSize, nBlockYOff * nBlockYSize, nReadXSize, nReadYSize, pImage, nReadXSize, nReadYSize, eDataType, nPixelSize, nPixelSize * nBlockXSize ); }
int SDTSRasterReader::GetMinMax( double * pdfMin, double * pdfMax, double dfNoData ) { void *pBuffer; int bFirst = TRUE; int b32Bit = GetRasterType() == SDTS_RT_FLOAT32; CPLAssert( GetBlockXSize() == GetXSize() && GetBlockYSize() == 1 ); pBuffer = CPLMalloc(sizeof(float) * GetXSize()); for( int iLine = 0; iLine < GetYSize(); iLine++ ) { if( !GetBlock( 0, iLine, pBuffer ) ) { CPLFree( pBuffer ); return FALSE; } for( int iPixel = 0; iPixel < GetXSize(); iPixel++ ) { double dfValue; if( b32Bit ) dfValue = ((float *) pBuffer)[iPixel]; else dfValue = ((short *) pBuffer)[iPixel]; if( dfValue != dfNoData ) { if( bFirst ) { *pdfMin = *pdfMax = dfValue; bFirst = FALSE; } else { *pdfMin = MIN(*pdfMin,dfValue); *pdfMax = MAX(*pdfMax,dfValue); } } } } CPLFree( pBuffer ); return !bFirst; }
already_AddRefed<DataSourceSurface> YCbCrImageDataDeserializer::ToDataSourceSurface() { RefPtr<DataSourceSurface> result = Factory::CreateDataSourceSurface(GetYSize(), gfx::SurfaceFormat::B8G8R8X8); if (NS_WARN_IF(!result)) { return nullptr; } DataSourceSurface::MappedSurface map; if (NS_WARN_IF(!result->Map(DataSourceSurface::MapType::WRITE, &map))) { return nullptr; } gfx::ConvertYCbCrToRGB32(GetYData(), GetCbData(), GetCrData(), map.mData, 0, 0, //pic x and y GetYSize().width, GetYSize().height, GetYStride(), GetCbCrStride(), map.mStride, gfx::YV12); result->Unmap(); return result.forget(); }
int SDTSRasterReader::GetMinMax( double * pdfMin, double * pdfMax, double dfNoData ) { CPLAssert( GetBlockXSize() == GetXSize() && GetBlockYSize() == 1 ); bool bFirst = true; const bool b32Bit = GetRasterType() == SDTS_RT_FLOAT32; void *pBuffer = CPLMalloc(sizeof(float) * GetXSize()); for( int iLine = 0; iLine < GetYSize(); iLine++ ) { if( !GetBlock( 0, iLine, pBuffer ) ) { CPLFree( pBuffer ); return FALSE; } for( int iPixel = 0; iPixel < GetXSize(); iPixel++ ) { double dfValue; if( b32Bit ) dfValue = reinterpret_cast<float *>( pBuffer )[iPixel]; else dfValue = reinterpret_cast<short *>( pBuffer )[iPixel]; if( dfValue != dfNoData ) { if( bFirst ) { *pdfMin = dfValue; *pdfMax = dfValue; bFirst = false; } else { *pdfMin = std::min( *pdfMin, dfValue ); *pdfMax = std::max( *pdfMax, dfValue ); } } } } CPLFree( pBuffer ); return !bFirst; }
double VRTSourcedRasterBand::GetMaximum(int *pbSuccess ) { const char *pszValue = NULL; if( (pszValue = GetMetadataItem("STATISTICS_MAXIMUM")) != NULL ) { if( pbSuccess != NULL ) *pbSuccess = TRUE; return CPLAtofM(pszValue); } if ( bAntiRecursionFlag ) { CPLError( CE_Failure, CPLE_AppDefined, "VRTSourcedRasterBand::GetMaximum() called recursively on the same band. " "It looks like the VRT is referencing itself." ); if( pbSuccess != NULL ) *pbSuccess = FALSE; return 0.0; } bAntiRecursionFlag = TRUE; double dfMax = 0; for( int iSource = 0; iSource < nSources; iSource++ ) { int bSuccess = FALSE; double dfSourceMax = papoSources[iSource]->GetMaximum(GetXSize(), GetYSize(), &bSuccess); if (!bSuccess) { dfMax = GDALRasterBand::GetMaximum(pbSuccess); bAntiRecursionFlag = FALSE; return dfMax; } if (iSource == 0 || dfSourceMax > dfMax) dfMax = dfSourceMax; } bAntiRecursionFlag = FALSE; if( pbSuccess != NULL ) *pbSuccess = TRUE; return dfMax; }
bool YCbCrImageDataSerializer::CopyData(const uint8_t* aYData, const uint8_t* aCbData, const uint8_t* aCrData, gfxIntSize aYSize, uint32_t aYStride, gfxIntSize aCbCrSize, uint32_t aCbCrStride, uint32_t aYSkip, uint32_t aCbCrSkip) { if (!IsValid() || GetYSize() != aYSize || GetCbCrSize() != aCbCrSize) { return false; } for (int i = 0; i < aYSize.height; ++i) { if (aYSkip == 0) { // fast path memcpy(GetYData() + i * GetYStride(), aYData + i * aYStride, aYSize.width); } else { // slower path CopyLineWithSkip(aYData + i * aYStride, GetYData() + i * GetYStride(), aYSize.width, aYSkip); } } for (int i = 0; i < aCbCrSize.height; ++i) { if (aCbCrSkip == 0) { // fast path memcpy(GetCbData() + i * GetCbCrStride(), aCbData + i * aCbCrStride, aCbCrSize.width); memcpy(GetCrData() + i * GetCbCrStride(), aCrData + i * aCbCrStride, aCbCrSize.width); } else { // slower path CopyLineWithSkip(aCbData + i * aCbCrStride, GetCbData() + i * GetCbCrStride(), aCbCrSize.width, aCbCrSkip); CopyLineWithSkip(aCrData + i * aCbCrStride, GetCrData() + i * GetCbCrStride(), aCbCrSize.width, aCbCrSkip); } } return true; }
CPLErr VRTRawRasterBand::SetRawLink( const char *pszFilename, const char *pszVRTPath, int bRelativeToVRTIn, vsi_l_offset nImageOffset, int nPixelOffset, int nLineOffset, const char *pszByteOrder ) { ClearRawLink(); reinterpret_cast<VRTDataset *>( poDS )->SetNeedsFlush(); /* -------------------------------------------------------------------- */ /* Prepare filename. */ /* -------------------------------------------------------------------- */ if( pszFilename == NULL ) { CPLError( CE_Warning, CPLE_AppDefined, "Missing <SourceFilename> element in VRTRasterBand." ); return CE_Failure; } char *pszExpandedFilename = NULL; if( pszVRTPath != NULL && bRelativeToVRTIn ) { pszExpandedFilename = CPLStrdup( CPLProjectRelativeFilename( pszVRTPath, pszFilename ) ); } else { pszExpandedFilename = CPLStrdup( pszFilename ); } /* -------------------------------------------------------------------- */ /* Try and open the file. We always use the large file API. */ /* -------------------------------------------------------------------- */ FILE *fp = CPLOpenShared( pszExpandedFilename, "rb+", TRUE ); if( fp == NULL ) fp = CPLOpenShared( pszExpandedFilename, "rb", TRUE ); if( fp == NULL && reinterpret_cast<VRTDataset *>( poDS )->GetAccess() == GA_Update ) { fp = CPLOpenShared( pszExpandedFilename, "wb+", TRUE ); } if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to open %s.%s", pszExpandedFilename, VSIStrerror( errno ) ); CPLFree( pszExpandedFilename ); return CE_Failure; } CPLFree( pszExpandedFilename ); m_pszSourceFilename = CPLStrdup(pszFilename); m_bRelativeToVRT = bRelativeToVRTIn; /* -------------------------------------------------------------------- */ /* Work out if we are in native mode or not. */ /* -------------------------------------------------------------------- */ bool bNative = true; if( pszByteOrder != NULL ) { if( EQUAL(pszByteOrder,"LSB") ) bNative = CPL_TO_BOOL(CPL_IS_LSB); else if( EQUAL(pszByteOrder,"MSB") ) bNative = !CPL_IS_LSB; else { CPLError( CE_Failure, CPLE_AppDefined, "Illegal ByteOrder value '%s', should be LSB or MSB.", pszByteOrder ); return CE_Failure; } } /* -------------------------------------------------------------------- */ /* Create a corresponding RawRasterBand. */ /* -------------------------------------------------------------------- */ m_poRawRaster = new RawRasterBand( fp, nImageOffset, nPixelOffset, nLineOffset, GetRasterDataType(), bNative, GetXSize(), GetYSize(), TRUE ); /* -------------------------------------------------------------------- */ /* Reset block size to match the raw raster. */ /* -------------------------------------------------------------------- */ m_poRawRaster->GetBlockSize( &nBlockXSize, &nBlockYSize ); return CE_None; }
CPLErr USGSDEMRasterBand::IReadBlock( CPL_UNUSED int nBlockXOff, CPL_UNUSED int nBlockYOff, void * pImage ) { /* int bad = FALSE; */ USGSDEMDataset *poGDS = reinterpret_cast<USGSDEMDataset *>( poDS ); /* -------------------------------------------------------------------- */ /* Initialize image buffer to nodata value. */ /* -------------------------------------------------------------------- */ for( int k = GetXSize() * GetYSize() - 1; k >= 0; k-- ) { if( GetRasterDataType() == GDT_Int16 ) reinterpret_cast<GInt16 *>( pImage )[k] = USGSDEM_NODATA; else reinterpret_cast<float *>( pImage )[k] = USGSDEM_NODATA; } /* -------------------------------------------------------------------- */ /* Seek to data. */ /* -------------------------------------------------------------------- */ CPL_IGNORE_RET_VAL(VSIFSeekL(poGDS->fp, poGDS->nDataStartOffset, 0)); double dfYMin = poGDS->adfGeoTransform[3] + (GetYSize()-0.5) * poGDS->adfGeoTransform[5]; /* -------------------------------------------------------------------- */ /* Read all the profiles into the image buffer. */ /* -------------------------------------------------------------------- */ Buffer sBuffer; sBuffer.max_size = 32768; sBuffer.buffer = reinterpret_cast<char *>( CPLMalloc( sBuffer.max_size + 1 ) ); sBuffer.fp = poGDS->fp; sBuffer.buffer_size = 0; sBuffer.cur_index = 0; for( int i = 0; i < GetXSize(); i++) { int bSuccess; const int nRowNumber = USGSDEMReadIntFromBuffer(&sBuffer, &bSuccess); if( nRowNumber != 1 ) CPLDebug("USGSDEM", "i = %d, nRowNumber = %d", i, nRowNumber); if( bSuccess ) { const int nColNumber = USGSDEMReadIntFromBuffer(&sBuffer, &bSuccess); if( nColNumber != i + 1 ) { CPLDebug("USGSDEM", "i = %d, nColNumber = %d", i, nColNumber); } } const int nCPoints = (bSuccess) ? USGSDEMReadIntFromBuffer(&sBuffer, &bSuccess) : 0; #ifdef DEBUG_VERBOSE CPLDebug("USGSDEM", "i = %d, nCPoints = %d", i, nCPoints); #endif if( bSuccess ) { const int nNumberOfCols = USGSDEMReadIntFromBuffer(&sBuffer, &bSuccess); if( nNumberOfCols != 1 ) { CPLDebug("USGSDEM", "i = %d, nNumberOfCols = %d", i, nNumberOfCols); } } // x-start if( bSuccess ) /* dxStart = */ USGSDEMReadDoubleFromBuffer(&sBuffer, 24, &bSuccess); double dyStart = (bSuccess) ? USGSDEMReadDoubleFromBuffer(&sBuffer, 24, &bSuccess) : 0; const double dfElevOffset = (bSuccess) ? USGSDEMReadDoubleFromBuffer(&sBuffer, 24, &bSuccess) : 0; // min z value if( bSuccess ) /* djunk = */ USGSDEMReadDoubleFromBuffer(&sBuffer, 24, &bSuccess); // max z value if( bSuccess ) /* djunk = */ USGSDEMReadDoubleFromBuffer(&sBuffer, 24, &bSuccess); if( !bSuccess ) { CPLFree(sBuffer.buffer); return CE_Failure; } if( STARTS_WITH_CI(poGDS->pszProjection, "GEOGCS") ) dyStart = dyStart / 3600.0; double dygap = (dfYMin - dyStart)/poGDS->adfGeoTransform[5]+ 0.5; if( dygap <= INT_MIN || dygap >= INT_MAX || !CPLIsFinite(dygap) ) { CPLFree(sBuffer.buffer); return CE_Failure; } int lygap = static_cast<int>(dygap); if( nCPoints <= 0 ) continue; if( lygap > INT_MAX - nCPoints ) lygap = INT_MAX - nCPoints; for (int j=lygap; j < (nCPoints + lygap); j++) { const int iY = GetYSize() - j - 1; const int nElev = USGSDEMReadIntFromBuffer(&sBuffer, &bSuccess); #ifdef DEBUG_VERBOSE CPLDebug("USGSDEM", " j - lygap = %d, nElev = %d", j - lygap, nElev); #endif if( !bSuccess ) { CPLFree(sBuffer.buffer); return CE_Failure; } if (iY < 0 || iY >= GetYSize() ) { /* bad = TRUE; */ } else if( nElev == USGSDEM_NODATA ) /* leave in output buffer as nodata */; else { const float fComputedElev = static_cast<float>(nElev * poGDS->fVRes + dfElevOffset); if( GetRasterDataType() == GDT_Int16 ) { GUInt16 nVal = ( fComputedElev < -32768 ) ? -32768 : ( fComputedElev > 32767 ) ? 32767 : static_cast<GInt16>( fComputedElev ); reinterpret_cast<GInt16 *>( pImage )[i + iY*GetXSize()] = nVal; } else { reinterpret_cast<float *>( pImage )[i + iY*GetXSize()] = fComputedElev; } } } if( poGDS->nDataStartOffset == 1024 ) { // Seek to the next 1024 byte boundary. // Some files have 'junk' profile values after the valid/declared ones vsi_l_offset nCurPos = USGSDEMGetCurrentFilePos(&sBuffer); vsi_l_offset nNewPos = (nCurPos + 1023) / 1024 * 1024; if( nNewPos > nCurPos ) { USGSDEMSetCurrentFilePos(&sBuffer, nNewPos); } } } CPLFree(sBuffer.buffer); return CE_None; }
CPLErr BAGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage ) { herr_t status; hsize_t count[3]; H5OFFSET_TYPE offset[3]; int nSizeOfData; hid_t memspace; hsize_t col_dims[3]; hsize_t rank; rank=2; offset[0] = MAX(0,nRasterYSize - (nBlockYOff+1)*nBlockYSize); offset[1] = nBlockXOff*nBlockXSize; count[0] = nBlockYSize; count[1] = nBlockXSize; nSizeOfData = H5Tget_size( native ); memset( pImage,0,nBlockXSize*nBlockYSize*nSizeOfData ); /* blocksize may not be a multiple of imagesize */ count[0] = MIN( size_t(nBlockYSize), GetYSize() - offset[0]); count[1] = MIN( size_t(nBlockXSize), GetXSize() - offset[1]); if( nRasterYSize - (nBlockYOff+1)*nBlockYSize < 0 ) { count[0] += (nRasterYSize - (nBlockYOff+1)*nBlockYSize); } /* -------------------------------------------------------------------- */ /* Select block from file space */ /* -------------------------------------------------------------------- */ status = H5Sselect_hyperslab( dataspace, H5S_SELECT_SET, offset, NULL, count, NULL ); /* -------------------------------------------------------------------- */ /* Create memory space to receive the data */ /* -------------------------------------------------------------------- */ col_dims[0]=nBlockYSize; col_dims[1]=nBlockXSize; memspace = H5Screate_simple( (int) rank, col_dims, NULL ); H5OFFSET_TYPE mem_offset[3] = {0, 0, 0}; status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, mem_offset, NULL, count, NULL); status = H5Dread ( hDatasetID, native, memspace, dataspace, H5P_DEFAULT, pImage ); H5Sclose( memspace ); /* -------------------------------------------------------------------- */ /* Y flip the data. */ /* -------------------------------------------------------------------- */ int nLinesToFlip = count[0]; int nLineSize = nSizeOfData * nBlockXSize; GByte *pabyTemp = (GByte *) CPLMalloc(nLineSize); for( int iY = 0; iY < nLinesToFlip/2; iY++ ) { memcpy( pabyTemp, ((GByte *)pImage) + iY * nLineSize, nLineSize ); memcpy( ((GByte *)pImage) + iY * nLineSize, ((GByte *)pImage) + (nLinesToFlip-iY-1) * nLineSize, nLineSize ); memcpy( ((GByte *)pImage) + (nLinesToFlip-iY-1) * nLineSize, pabyTemp, nLineSize ); } CPLFree( pabyTemp ); /* -------------------------------------------------------------------- */ /* Return success or failure. */ /* -------------------------------------------------------------------- */ if( status < 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "H5Dread() failed for block." ); return CE_Failure; } else return CE_None; }
CPLErr USGSDEMRasterBand::IReadBlock( CPL_UNUSED int nBlockXOff, CPL_UNUSED int nBlockYOff, void * pImage ) { double dfYMin; /* int bad = FALSE; */ USGSDEMDataset *poGDS = (USGSDEMDataset *) poDS; /* -------------------------------------------------------------------- */ /* Initialize image buffer to nodata value. */ /* -------------------------------------------------------------------- */ for( int k = GetXSize() * GetYSize() - 1; k >= 0; k-- ) { if( GetRasterDataType() == GDT_Int16 ) ((GInt16 *) pImage)[k] = USGSDEM_NODATA; else ((float *) pImage)[k] = USGSDEM_NODATA; } /* -------------------------------------------------------------------- */ /* Seek to data. */ /* -------------------------------------------------------------------- */ VSIFSeekL(poGDS->fp, poGDS->nDataStartOffset, 0); dfYMin = poGDS->adfGeoTransform[3] + (GetYSize()-0.5) * poGDS->adfGeoTransform[5]; /* -------------------------------------------------------------------- */ /* Read all the profiles into the image buffer. */ /* -------------------------------------------------------------------- */ Buffer sBuffer; sBuffer.max_size = 32768; sBuffer.buffer = (char*) CPLMalloc(sBuffer.max_size + 1); sBuffer.fp = poGDS->fp; sBuffer.buffer_size = 0; sBuffer.cur_index = 0; for( int i = 0; i < GetXSize(); i++) { int /* njunk, */ nCPoints, lygap; double /* djunk, dxStart, */ dyStart, dfElevOffset; /* njunk = */ USGSDEMReadIntFromBuffer(&sBuffer); /* njunk = */ USGSDEMReadIntFromBuffer(&sBuffer); nCPoints = USGSDEMReadIntFromBuffer(&sBuffer); /* njunk = */ USGSDEMReadIntFromBuffer(&sBuffer); /* dxStart = */ USGSDEMReadDoubleFromBuffer(&sBuffer, 24); dyStart = USGSDEMReadDoubleFromBuffer(&sBuffer, 24); dfElevOffset = USGSDEMReadDoubleFromBuffer(&sBuffer, 24); /* djunk = */ USGSDEMReadDoubleFromBuffer(&sBuffer, 24); /* djunk = */ USGSDEMReadDoubleFromBuffer(&sBuffer, 24); if( EQUALN(poGDS->pszProjection,"GEOGCS",6) ) dyStart = dyStart / 3600.0; lygap = (int)((dfYMin - dyStart)/poGDS->adfGeoTransform[5]+ 0.5); for (int j=lygap; j < (nCPoints+(int)lygap); j++) { int iY = GetYSize() - j - 1; int nElev; int bSuccess; nElev = USGSDEMReadIntFromBuffer(&sBuffer, &bSuccess); if( !bSuccess ) { CPLFree(sBuffer.buffer); return CE_Failure; } if (iY < 0 || iY >= GetYSize() ) { /* bad = TRUE; */ } else if( nElev == USGSDEM_NODATA ) /* leave in output buffer as nodata */; else { float fComputedElev = (float)(nElev * poGDS->fVRes + dfElevOffset); if( GetRasterDataType() == GDT_Int16 ) { ((GInt16 *) pImage)[i + iY*GetXSize()] = (GInt16) fComputedElev; } else { ((float *) pImage)[i + iY*GetXSize()] = fComputedElev; } } } } CPLFree(sBuffer.buffer); return CE_None; }
CPLErr VRTSourcedRasterBand::GetHistogram( double dfMin, double dfMax, int nBuckets, int *panHistogram, int bIncludeOutOfRange, int bApproxOK, GDALProgressFunc pfnProgress, void *pProgressData ) { if( nSources != 1 ) return GDALRasterBand::GetHistogram( dfMin, dfMax, nBuckets, panHistogram, bIncludeOutOfRange, bApproxOK, pfnProgress, pProgressData ); if( pfnProgress == NULL ) pfnProgress = GDALDummyProgress; /* -------------------------------------------------------------------- */ /* If we have overviews, use them for the histogram. */ /* -------------------------------------------------------------------- */ if( bApproxOK && GetOverviewCount() > 0 && !HasArbitraryOverviews() ) { // FIXME: should we use the most reduced overview here or use some // minimum number of samples like GDALRasterBand::ComputeStatistics() // does? GDALRasterBand *poBestOverview = GetRasterSampleOverview( 0 ); if( poBestOverview != this ) { return poBestOverview->GetHistogram( dfMin, dfMax, nBuckets, panHistogram, bIncludeOutOfRange, bApproxOK, pfnProgress, pProgressData ); } } /* -------------------------------------------------------------------- */ /* Try with source bands. */ /* -------------------------------------------------------------------- */ if ( bAntiRecursionFlag ) { CPLError( CE_Failure, CPLE_AppDefined, "VRTSourcedRasterBand::GetHistogram() called recursively on the same band. " "It looks like the VRT is referencing itself." ); return CE_Failure; } bAntiRecursionFlag = TRUE; CPLErr eErr = papoSources[0]->GetHistogram(GetXSize(), GetYSize(), dfMin, dfMax, nBuckets, panHistogram, bIncludeOutOfRange, bApproxOK, pfnProgress, pProgressData); if (eErr != CE_None) { eErr = GDALRasterBand::GetHistogram( dfMin, dfMax, nBuckets, panHistogram, bIncludeOutOfRange, bApproxOK, pfnProgress, pProgressData ); bAntiRecursionFlag = FALSE; return eErr; } bAntiRecursionFlag = FALSE; return CE_None; }
CPLErr VRTSourcedRasterBand::ComputeStatistics( int bApproxOK, double *pdfMin, double *pdfMax, double *pdfMean, double *pdfStdDev, GDALProgressFunc pfnProgress, void *pProgressData ) { if( nSources != 1 ) return GDALRasterBand::ComputeStatistics( bApproxOK, pdfMin, pdfMax, pdfMean, pdfStdDev, pfnProgress, pProgressData ); if( pfnProgress == NULL ) pfnProgress = GDALDummyProgress; /* -------------------------------------------------------------------- */ /* If we have overview bands, use them for statistics. */ /* -------------------------------------------------------------------- */ if( bApproxOK && GetOverviewCount() > 0 && !HasArbitraryOverviews() ) { GDALRasterBand *poBand; poBand = GetRasterSampleOverview( GDALSTAT_APPROX_NUMSAMPLES ); if( poBand != this ) return poBand->ComputeStatistics( FALSE, pdfMin, pdfMax, pdfMean, pdfStdDev, pfnProgress, pProgressData ); } /* -------------------------------------------------------------------- */ /* Try with source bands. */ /* -------------------------------------------------------------------- */ if ( bAntiRecursionFlag ) { CPLError( CE_Failure, CPLE_AppDefined, "VRTSourcedRasterBand::ComputeStatistics() called recursively on the same band. " "It looks like the VRT is referencing itself." ); return CE_Failure; } bAntiRecursionFlag = TRUE; double dfMin = 0.0, dfMax = 0.0, dfMean = 0.0, dfStdDev = 0.0; CPLErr eErr = papoSources[0]->ComputeStatistics(GetXSize(), GetYSize(), bApproxOK, &dfMin, &dfMax, &dfMean, &dfStdDev, pfnProgress, pProgressData); if (eErr != CE_None) { eErr = GDALRasterBand::ComputeStatistics(bApproxOK, pdfMin, pdfMax, pdfMean, pdfStdDev, pfnProgress, pProgressData); bAntiRecursionFlag = FALSE; return eErr; } bAntiRecursionFlag = FALSE; SetStatistics( dfMin, dfMax, dfMean, dfStdDev ); /* -------------------------------------------------------------------- */ /* Record results. */ /* -------------------------------------------------------------------- */ if( pdfMin != NULL ) *pdfMin = dfMin; if( pdfMax != NULL ) *pdfMax = dfMax; if( pdfMean != NULL ) *pdfMean = dfMean; if( pdfStdDev != NULL ) *pdfStdDev = dfStdDev; return CE_None; }
CPLErr VRTSourcedRasterBand::ComputeRasterMinMax( int bApproxOK, double* adfMinMax ) { double dfMin = 0.0; double dfMax = 0.0; /* -------------------------------------------------------------------- */ /* Does the driver already know the min/max? */ /* -------------------------------------------------------------------- */ if( bApproxOK ) { int bSuccessMin, bSuccessMax; dfMin = GetMinimum( &bSuccessMin ); dfMax = GetMaximum( &bSuccessMax ); if( bSuccessMin && bSuccessMax ) { adfMinMax[0] = dfMin; adfMinMax[1] = dfMax; return CE_None; } } /* -------------------------------------------------------------------- */ /* If we have overview bands, use them for min/max. */ /* -------------------------------------------------------------------- */ if ( bApproxOK && GetOverviewCount() > 0 && !HasArbitraryOverviews() ) { GDALRasterBand *poBand; poBand = GetRasterSampleOverview( GDALSTAT_APPROX_NUMSAMPLES ); if ( poBand != this ) return poBand->ComputeRasterMinMax( FALSE, adfMinMax ); } /* -------------------------------------------------------------------- */ /* Try with source bands. */ /* -------------------------------------------------------------------- */ if ( bAntiRecursionFlag ) { CPLError( CE_Failure, CPLE_AppDefined, "VRTSourcedRasterBand::ComputeRasterMinMax() called recursively on the same band. " "It looks like the VRT is referencing itself." ); return CE_Failure; } bAntiRecursionFlag = TRUE; adfMinMax[0] = 0.0; adfMinMax[1] = 0.0; for( int iSource = 0; iSource < nSources; iSource++ ) { double adfSourceMinMax[2]; CPLErr eErr = papoSources[iSource]->ComputeRasterMinMax(GetXSize(), GetYSize(), bApproxOK, adfSourceMinMax); if (eErr != CE_None) { eErr = GDALRasterBand::ComputeRasterMinMax(bApproxOK, adfMinMax); bAntiRecursionFlag = FALSE; return eErr; } if (iSource == 0 || adfSourceMinMax[0] < adfMinMax[0]) adfMinMax[0] = adfSourceMinMax[0]; if (iSource == 0 || adfSourceMinMax[1] > adfMinMax[1]) adfMinMax[1] = adfSourceMinMax[1]; } bAntiRecursionFlag = FALSE; return CE_None; }
void test_estimate_distance( const std::function<void( const visualization_msgs::MarkerArray&)>& display_fn) { const double res = 1.0; const double size = 10.0; const Eigen::Isometry3d origin_transform = Eigen::Translation3d(0.0, 0.0, 0.0) * Eigen::Quaterniond( Eigen::AngleAxisd(M_PI_4, Eigen::Vector3d::UnitZ())); auto map = sdf_tools::CollisionMapGrid(origin_transform, "world", res, size, size, 1.0, sdf_tools::COLLISION_CELL(0.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(5.0, 5.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(5.0, 6.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(6.0, 5.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(6.0, 6.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(7.0, 7.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(2.0, 2.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(3.0, 2.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(4.0, 2.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(2.0, 3.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(2.0, 4.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); map.SetValue4d(origin_transform * Eigen::Vector4d(2.0, 7.0, 0.0, 1.0), sdf_tools::COLLISION_CELL(1.0)); const std_msgs::ColorRGBA collision_color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA>::MakeFromFloatColors(1.0, 0.0, 0.0, 0.5); const std_msgs::ColorRGBA free_color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA>::MakeFromFloatColors(0.0, 0.0, 0.0, 0.0); const std_msgs::ColorRGBA unknown_color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA>::MakeFromFloatColors(0.0, 0.0, 0.0, 0.0); const auto map_marker = map.ExportForDisplay(collision_color, free_color, unknown_color); const auto sdf = map.ExtractSignedDistanceField(1e6, true, false).first; const auto sdf_marker = sdf.ExportForDisplay(0.05f); // Assemble a visualization_markers::Marker representation of the SDF to display in RViz visualization_msgs::Marker distance_rep; // Populate the header distance_rep.header.frame_id = "world"; // Populate the options distance_rep.ns = "estimated_distance_display"; distance_rep.id = 1; distance_rep.type = visualization_msgs::Marker::CUBE_LIST; distance_rep.action = visualization_msgs::Marker::ADD; distance_rep.lifetime = ros::Duration(0.0); distance_rep.frame_locked = false; distance_rep.pose = EigenHelpersConversions::EigenIsometry3dToGeometryPose(sdf.GetOriginTransform()); const double step = sdf.GetResolution() * 0.125 * 0.25; distance_rep.scale.x = sdf.GetResolution() * step;// * 0.125; distance_rep.scale.y = sdf.GetResolution() * step;// * 0.125; distance_rep.scale.z = sdf.GetResolution() * 0.95;// * 0.125;// * 0.125; // Add all the cells of the SDF to the message double min_distance = 0.0; double max_distance = 0.0; // Add colors for all the cells of the SDF to the message for (double x = 0; x < sdf.GetXSize(); x += step) { for (double y = 0; y < sdf.GetYSize(); y += step) { double z = 0.5; //for (double z = 0; z <= sdf.GetZSize(); z += step) { const Eigen::Vector4d point(x, y, z, 1.0); const Eigen::Vector4d point_in_grid_frame = origin_transform * point; // Update minimum/maximum distance variables const double distance = sdf.EstimateDistance4d(point_in_grid_frame).first; if (distance > max_distance) { max_distance = distance; } if (distance < min_distance) { min_distance = distance; } } } } std::cout << "Min dist " << min_distance << " Max dist " << max_distance << std::endl; for (double x = 0; x < sdf.GetXSize(); x += step) { for (double y = 0; y < sdf.GetYSize(); y += step) { double z = 0.5; //for (double z = 0; z <= sdf.GetZSize(); z += step) { const Eigen::Vector4d point(x, y, z, 1.0); const Eigen::Vector4d point_in_grid_frame = origin_transform * point; const double distance = sdf.EstimateDistance4d(point_in_grid_frame).first; if (distance >= 0.0) { const std_msgs::ColorRGBA new_color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA> ::InterpolateHotToCold(distance, 0.0, max_distance); distance_rep.colors.push_back(new_color); } else { const std_msgs::ColorRGBA new_color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA>::MakeFromFloatColors(1.0, 0.0, 1.0, 1.0); distance_rep.colors.push_back(new_color); } geometry_msgs::Point new_point; new_point.x = x; new_point.y = y; new_point.z = z; distance_rep.points.push_back(new_point); } } } visualization_msgs::MarkerArray markers; markers.markers = {map_marker, sdf_marker, distance_rep}; // Make gradient markers for (int64_t x_idx = 0; x_idx < sdf.GetNumXCells(); x_idx++) { for (int64_t y_idx = 0; y_idx < sdf.GetNumYCells(); y_idx++) { for (int64_t z_idx = 0; z_idx < sdf.GetNumZCells(); z_idx++) { const Eigen::Vector4d location = sdf.GridIndexToLocation(x_idx, y_idx, z_idx); const std::vector<double> discrete_gradient = sdf.GetGradient4d(location, true); std::cout << "Discrete gradient " << PrettyPrint::PrettyPrint(discrete_gradient) << std::endl; const std::vector<double> smooth_gradient = sdf.GetSmoothGradient4d(location, sdf.GetResolution() * 0.125); std::cout << "Smooth gradient " << PrettyPrint::PrettyPrint(smooth_gradient) << std::endl; const std::vector<double> autodiff_gradient = sdf.GetAutoDiffGradient4d(location); std::cout << "Autodiff gradient " << PrettyPrint::PrettyPrint(autodiff_gradient) << std::endl; if (discrete_gradient.size() == 3) { const Eigen::Vector4d gradient_vector(discrete_gradient[0], discrete_gradient[1], discrete_gradient[2], 0.0); visualization_msgs::Marker gradient_rep; // Populate the header gradient_rep.header.frame_id = "world"; // Populate the options gradient_rep.ns = "discrete_gradient"; gradient_rep.id = (int32_t)sdf.HashDataIndex(x_idx, y_idx, z_idx); gradient_rep.type = visualization_msgs::Marker::ARROW; gradient_rep.action = visualization_msgs::Marker::ADD; gradient_rep.lifetime = ros::Duration(0.0); gradient_rep.frame_locked = false; gradient_rep.pose = EigenHelpersConversions::EigenIsometry3dToGeometryPose(Eigen::Isometry3d::Identity()); gradient_rep.points.push_back(EigenHelpersConversions::EigenVector4dToGeometryPoint(location)); gradient_rep.points.push_back(EigenHelpersConversions::EigenVector4dToGeometryPoint(location + gradient_vector)); gradient_rep.scale.x = sdf.GetResolution() * 0.06125; gradient_rep.scale.y = sdf.GetResolution() * 0.125; gradient_rep.scale.z = 0.0; gradient_rep.color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA>::MakeFromFloatColors(1.0, 0.5, 0.0, 1.0); markers.markers.push_back(gradient_rep); } if (smooth_gradient.size() == 3) { const Eigen::Vector4d gradient_vector(smooth_gradient[0], smooth_gradient[1], smooth_gradient[2], 0.0); visualization_msgs::Marker gradient_rep; // Populate the header gradient_rep.header.frame_id = "world"; // Populate the options gradient_rep.ns = "smooth_gradient"; gradient_rep.id = (int32_t)sdf.HashDataIndex(x_idx, y_idx, z_idx); gradient_rep.type = visualization_msgs::Marker::ARROW; gradient_rep.action = visualization_msgs::Marker::ADD; gradient_rep.lifetime = ros::Duration(0.0); gradient_rep.frame_locked = false; gradient_rep.pose = EigenHelpersConversions::EigenIsometry3dToGeometryPose(Eigen::Isometry3d::Identity()); gradient_rep.points.push_back(EigenHelpersConversions::EigenVector4dToGeometryPoint(location)); gradient_rep.points.push_back(EigenHelpersConversions::EigenVector4dToGeometryPoint(location + gradient_vector)); gradient_rep.scale.x = sdf.GetResolution() * 0.06125; gradient_rep.scale.y = sdf.GetResolution() * 0.125; gradient_rep.scale.z = 0.0; gradient_rep.color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA>::MakeFromFloatColors(0.0, 0.5, 1.0, 1.0); markers.markers.push_back(gradient_rep); } if (autodiff_gradient.size() == 3) { const Eigen::Vector4d gradient_vector(autodiff_gradient[0], autodiff_gradient[1], autodiff_gradient[2], 0.0); visualization_msgs::Marker gradient_rep; // Populate the header gradient_rep.header.frame_id = "world"; // Populate the options gradient_rep.ns = "autodiff_gradient"; gradient_rep.id = (int32_t)sdf.HashDataIndex(x_idx, y_idx, z_idx); gradient_rep.type = visualization_msgs::Marker::ARROW; gradient_rep.action = visualization_msgs::Marker::ADD; gradient_rep.lifetime = ros::Duration(0.0); gradient_rep.frame_locked = false; gradient_rep.pose = EigenHelpersConversions::EigenIsometry3dToGeometryPose(Eigen::Isometry3d::Identity()); gradient_rep.points.push_back(EigenHelpersConversions::EigenVector4dToGeometryPoint(location)); gradient_rep.points.push_back(EigenHelpersConversions::EigenVector4dToGeometryPoint(location + gradient_vector)); gradient_rep.scale.x = sdf.GetResolution() * 0.06125; gradient_rep.scale.y = sdf.GetResolution() * 0.125; gradient_rep.scale.z = 0.0; gradient_rep.color = arc_helpers::RGBAColorBuilder<std_msgs::ColorRGBA>::MakeFromFloatColors(0.5, 0.0, 1.0, 1.0); markers.markers.push_back(gradient_rep); } } } } display_fn(markers); }
void Paint(ItemID pitemArg, Surface* psurface, bool bSelected, bool bFocus) { ImodelIGC* pDestination = (ImodelIGC*)pitemArg; IshipIGC* pship = NULL; IstationIGC* pstation = NULL; if (pDestination == NULL || trekClient.MyMission() == NULL) return; if (pDestination->GetObjectType() == OT_ship) { CastTo(pship, pDestination); } else { assert(pDestination->GetObjectType() == OT_station); CastTo(pstation, pDestination); } // draw the selection bar if (bSelected) { psurface->FillRect( WinRect(0, 0, GetXSize(), GetYSize()), Color::Red() ); } TRef<IEngineFont> pfont; // show the place we currently are in bold if (pship && pship == trekClient.GetShip()->GetParentShip() || pstation && pstation == trekClient.GetShip()->GetStation()) { pfont = TrekResources::SmallBoldFont(); } else { pfont = TrekResources::SmallFont(); } Color color; if (CanKeepCurrentShip(pDestination)) { color = Color::White(); } else { color = 0.75f * Color::White(); } // draw the name psurface->DrawString( pfont, color, WinPoint(0, 0), pship ? pship->GetName() : pstation->GetName() ); // draw the ship type (if any) if (pship) { psurface->DrawString( pfont, color, WinPoint(m_viColumns[0], 0), HullName(pDestination) ); } // draw the cluster psurface->DrawString( pfont, color, WinPoint(m_viColumns[1] + 2, 0), SectorName(pDestination) ); // draw the total number of turrets (if appropriate) if (pship && NumTurrets(pship)) { int nNumTurrets = NumTurrets(pship); if (nNumTurrets != 0) { psurface->DrawString( pfont, color, WinPoint(m_viColumns[2] + 2, 0), ZString((int)MannedTurrets(pship)) + ZString("/") + ZString(nNumTurrets) ); } } }
const char *GDALWMSRasterBand::GetMetadataItem( const char * pszName, const char * pszDomain ) { /* ==================================================================== */ /* LocationInfo handling. */ /* ==================================================================== */ if( pszDomain != NULL && EQUAL(pszDomain,"LocationInfo") && (STARTS_WITH_CI(pszName, "Pixel_") || STARTS_WITH_CI(pszName, "GeoPixel_")) ) { int iPixel, iLine; /* -------------------------------------------------------------------- */ /* What pixel are we aiming at? */ /* -------------------------------------------------------------------- */ if( STARTS_WITH_CI(pszName, "Pixel_") ) { if( sscanf( pszName+6, "%d_%d", &iPixel, &iLine ) != 2 ) return NULL; } else if( STARTS_WITH_CI(pszName, "GeoPixel_") ) { double adfGeoTransform[6]; double adfInvGeoTransform[6]; double dfGeoX, dfGeoY; { dfGeoX = CPLAtof(pszName + 9); const char* pszUnderscore = strchr(pszName + 9, '_'); if( !pszUnderscore ) return NULL; dfGeoY = CPLAtof(pszUnderscore+1); } if( m_parent_dataset->GetGeoTransform( adfGeoTransform ) != CE_None ) return NULL; if( !GDALInvGeoTransform( adfGeoTransform, adfInvGeoTransform ) ) return NULL; iPixel = (int) floor( adfInvGeoTransform[0] + adfInvGeoTransform[1] * dfGeoX + adfInvGeoTransform[2] * dfGeoY ); iLine = (int) floor( adfInvGeoTransform[3] + adfInvGeoTransform[4] * dfGeoX + adfInvGeoTransform[5] * dfGeoY ); /* The GetDataset() for the WMS driver is always the main overview level, so rescale */ /* the values if we are an overview */ if (m_overview >= 0) { iPixel = (int) (1.0 * iPixel * GetXSize() / m_parent_dataset->GetRasterBand(1)->GetXSize()); iLine = (int) (1.0 * iLine * GetYSize() / m_parent_dataset->GetRasterBand(1)->GetYSize()); } } else return NULL; if( iPixel < 0 || iLine < 0 || iPixel >= GetXSize() || iLine >= GetYSize() ) return NULL; if (nBand != 1) { GDALRasterBand* poFirstBand = m_parent_dataset->GetRasterBand(1); if (m_overview >= 0) poFirstBand = poFirstBand->GetOverview(m_overview); if (poFirstBand) return poFirstBand->GetMetadataItem(pszName, pszDomain); } GDALWMSImageRequestInfo iri; GDALWMSTiledImageRequestInfo tiri; int nBlockXOff = iPixel / nBlockXSize; int nBlockYOff = iLine / nBlockYSize; ComputeRequestInfo(iri, tiri, nBlockXOff, nBlockYOff); CPLString url; m_parent_dataset->m_mini_driver->GetTiledImageInfo(&url, iri, tiri, iPixel % nBlockXSize, iLine % nBlockXSize); char* pszRes = NULL; if (url.size() != 0) { if (url == osMetadataItemURL) { return osMetadataItem.size() != 0 ? osMetadataItem.c_str() : NULL; } osMetadataItemURL = url; char **http_request_opts = BuildHTTPRequestOpts(); CPLHTTPResult* psResult = CPLHTTPFetch( url.c_str(), http_request_opts); if( psResult && psResult->pabyData ) pszRes = CPLStrdup((const char*) psResult->pabyData); CPLHTTPDestroyResult(psResult); CSLDestroy(http_request_opts); } if (pszRes) { osMetadataItem = "<LocationInfo>"; CPLPushErrorHandler(CPLQuietErrorHandler); CPLXMLNode* psXML = CPLParseXMLString(pszRes); CPLPopErrorHandler(); if (psXML != NULL && psXML->eType == CXT_Element) { if (strcmp(psXML->pszValue, "?xml") == 0) { if (psXML->psNext) { char* pszXML = CPLSerializeXMLTree(psXML->psNext); osMetadataItem += pszXML; CPLFree(pszXML); } } else { osMetadataItem += pszRes; } } else { char* pszEscapedXML = CPLEscapeString(pszRes, -1, CPLES_XML_BUT_QUOTES); osMetadataItem += pszEscapedXML; CPLFree(pszEscapedXML); } if (psXML != NULL) CPLDestroyXMLNode(psXML); osMetadataItem += "</LocationInfo>"; CPLFree(pszRes); return osMetadataItem.c_str(); } else { osMetadataItem = ""; return NULL; } } return GDALPamRasterBand::GetMetadataItem(pszName, pszDomain); }
CPLErr BAGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage ) { const int nXOff = nBlockXOff * nBlockXSize; H5OFFSET_TYPE offset[3] = { static_cast<H5OFFSET_TYPE>( std::max(0, nRasterYSize - (nBlockYOff + 1) * nBlockYSize)), static_cast<H5OFFSET_TYPE>(nXOff), static_cast<H5OFFSET_TYPE>(0) }; const int nSizeOfData = static_cast<int>(H5Tget_size(native)); memset(pImage, 0, nBlockXSize * nBlockYSize * nSizeOfData); // Blocksize may not be a multiple of imagesize. hsize_t count[3] = { std::min(static_cast<hsize_t>(nBlockYSize), GetYSize() - offset[0]), std::min(static_cast<hsize_t>(nBlockXSize), GetXSize() - offset[1]), static_cast<hsize_t>(0) }; if( nRasterYSize - (nBlockYOff + 1) * nBlockYSize < 0 ) { count[0] += (nRasterYSize - (nBlockYOff + 1) * nBlockYSize); } // Select block from file space. { const herr_t status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, nullptr, count, nullptr); if( status < 0 ) return CE_Failure; } // Create memory space to receive the data. hsize_t col_dims[3] = { static_cast<hsize_t>(nBlockYSize), static_cast<hsize_t>(nBlockXSize), static_cast<hsize_t>(0) }; const int rank = 2; const hid_t memspace = H5Screate_simple(rank, col_dims, nullptr); H5OFFSET_TYPE mem_offset[3] = { 0, 0, 0 }; const herr_t status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, mem_offset, nullptr, count, nullptr); if( status < 0 ) return CE_Failure; const herr_t status_read = H5Dread(hDatasetID, native, memspace, dataspace, H5P_DEFAULT, pImage); H5Sclose(memspace); // Y flip the data. const int nLinesToFlip = static_cast<int>(count[0]); const int nLineSize = nSizeOfData * nBlockXSize; GByte * const pabyTemp = static_cast<GByte *>(CPLMalloc(nLineSize)); GByte * const pbyImage = static_cast<GByte *>(pImage); for( int iY = 0; iY < nLinesToFlip / 2; iY++ ) { memcpy(pabyTemp, pbyImage + iY * nLineSize, nLineSize); memcpy(pbyImage + iY * nLineSize, pbyImage + (nLinesToFlip - iY - 1) * nLineSize, nLineSize); memcpy(pbyImage + (nLinesToFlip - iY - 1) * nLineSize, pabyTemp, nLineSize); } CPLFree(pabyTemp); // Return success or failure. if( status_read < 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "H5Dread() failed for block."); return CE_Failure; } return CE_None; }
CPLErr USGSDEMRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage ) { double dfYMin; int bad = FALSE; USGSDEMDataset *poGDS = (USGSDEMDataset *) poDS; /* -------------------------------------------------------------------- */ /* Initialize image buffer to nodata value. */ /* -------------------------------------------------------------------- */ for( int k = GetXSize() * GetYSize() - 1; k >= 0; k-- ) { if( GetRasterDataType() == GDT_Int16 ) ((GInt16 *) pImage)[k] = USGSDEM_NODATA; else ((float *) pImage)[k] = USGSDEM_NODATA; } /* -------------------------------------------------------------------- */ /* Seek to data. */ /* -------------------------------------------------------------------- */ VSIFSeek(poGDS->fp, poGDS->nDataStartOffset, 0); dfYMin = poGDS->adfGeoTransform[3] + (GetYSize()-0.5) * poGDS->adfGeoTransform[5]; /* -------------------------------------------------------------------- */ /* Read all the profiles into the image buffer. */ /* -------------------------------------------------------------------- */ for( int i = 0; i < GetXSize(); i++) { int njunk, nCPoints, lygap; double djunk, dxStart, dyStart, dfElevOffset; fscanf(poGDS->fp, "%d", &njunk); fscanf(poGDS->fp, "%d", &njunk); fscanf(poGDS->fp, "%d", &nCPoints); fscanf(poGDS->fp, "%d", &njunk); dxStart = DConvert(poGDS->fp, 24); dyStart = DConvert(poGDS->fp, 24); dfElevOffset = DConvert(poGDS->fp, 24); djunk = DConvert(poGDS->fp, 24); djunk = DConvert(poGDS->fp, 24); if( EQUALN(poGDS->pszProjection,"GEOGCS",6) ) dyStart = dyStart / 3600.0; lygap = (int)((dfYMin - dyStart)/poGDS->adfGeoTransform[5]+ 0.5); for (int j=lygap; j < (nCPoints+(int)lygap); j++) { int iY = GetYSize() - j - 1; int nElev; fscanf(poGDS->fp, "%d", &nElev); if (iY < 0 || iY >= GetYSize() ) bad = TRUE; else if( nElev == USGSDEM_NODATA ) /* leave in output buffer as nodata */; else { float fComputedElev = (float)(nElev * poGDS->fVRes + dfElevOffset); if( GetRasterDataType() == GDT_Int16 ) { ((GInt16 *) pImage)[i + iY*GetXSize()] = (GInt16) fComputedElev; } else { ((float *) pImage)[i + iY*GetXSize()] = fComputedElev; } } } } return CE_None; }
const char *VRTSourcedRasterBand::GetMetadataItem( const char * pszName, const char * pszDomain ) { /* ==================================================================== */ /* LocationInfo handling. */ /* ==================================================================== */ if( pszDomain != NULL && EQUAL(pszDomain,"LocationInfo") && (EQUALN(pszName,"Pixel_",6) || EQUALN(pszName,"GeoPixel_",9)) ) { int iPixel, iLine; /* -------------------------------------------------------------------- */ /* What pixel are we aiming at? */ /* -------------------------------------------------------------------- */ if( EQUALN(pszName,"Pixel_",6) ) { if( sscanf( pszName+6, "%d_%d", &iPixel, &iLine ) != 2 ) return NULL; } else if( EQUALN(pszName,"GeoPixel_",9) ) { double adfGeoTransform[6]; double adfInvGeoTransform[6]; double dfGeoX, dfGeoY; if( sscanf( pszName+9, "%lf_%lf", &dfGeoX, &dfGeoY ) != 2 ) return NULL; if( GetDataset() == NULL ) return NULL; if( GetDataset()->GetGeoTransform( adfGeoTransform ) != CE_None ) return NULL; if( !GDALInvGeoTransform( adfGeoTransform, adfInvGeoTransform ) ) return NULL; iPixel = (int) floor( adfInvGeoTransform[0] + adfInvGeoTransform[1] * dfGeoX + adfInvGeoTransform[2] * dfGeoY ); iLine = (int) floor( adfInvGeoTransform[3] + adfInvGeoTransform[4] * dfGeoX + adfInvGeoTransform[5] * dfGeoY ); } else return NULL; if( iPixel < 0 || iLine < 0 || iPixel >= GetXSize() || iLine >= GetYSize() ) return NULL; /* -------------------------------------------------------------------- */ /* Find the file(s) at this location. */ /* -------------------------------------------------------------------- */ char **papszFileList = NULL; int nListMaxSize = 0, nListSize = 0; CPLHashSet* hSetFiles = CPLHashSetNew(CPLHashSetHashStr, CPLHashSetEqualStr, NULL); for( int iSource = 0; iSource < nSources; iSource++ ) { int nReqXOff, nReqYOff, nReqXSize, nReqYSize; int nOutXOff, nOutYOff, nOutXSize, nOutYSize; if (!papoSources[iSource]->IsSimpleSource()) continue; VRTSimpleSource *poSrc = (VRTSimpleSource *) papoSources[iSource]; if( !poSrc->GetSrcDstWindow( iPixel, iLine, 1, 1, 1, 1, &nReqXOff, &nReqYOff, &nReqXSize, &nReqYSize, &nOutXOff, &nOutYOff, &nOutXSize, &nOutYSize ) ) continue; poSrc->GetFileList( &papszFileList, &nListSize, &nListMaxSize, hSetFiles ); } /* -------------------------------------------------------------------- */ /* Format into XML. */ /* -------------------------------------------------------------------- */ int i; osLastLocationInfo = "<LocationInfo>"; for( i = 0; i < nListSize; i++ ) { osLastLocationInfo += "<File>"; char* pszXMLEscaped = CPLEscapeString(papszFileList[i], -1, CPLES_XML); osLastLocationInfo += pszXMLEscaped; CPLFree(pszXMLEscaped); osLastLocationInfo += "</File>"; } osLastLocationInfo += "</LocationInfo>"; CSLDestroy( papszFileList ); CPLHashSetDestroy( hSetFiles ); return osLastLocationInfo.c_str(); } /* ==================================================================== */ /* Other domains. */ /* ==================================================================== */ else return GDALRasterBand::GetMetadataItem( pszName, pszDomain ); }
void GDALTerrain::init() { dataset = (GDALDataset*) GDALOpen(gdalFile.c_str(), GA_ReadOnly); if(dataset == nullptr) { std::cerr << "Unable to open GDAL File: " << gdalFile << std::endl; exit(1); } auto raster = dataset->GetRasterBand(1); width = raster->GetXSize(); height = raster->GetYSize(); int gotMin, gotMax; float min = (float) raster->GetMinimum(&gotMin); float max = (float) raster->GetMaximum(&gotMax); double minMax[2] = {min, max}; if(!(gotMin && gotMax)) { GDALComputeRasterMinMax((GDALRasterBandH) raster, TRUE, minMax); min = (float) minMax[0]; max = (float) minMax[1]; } if(Engine::getEngine()->getOptions().verbose) { std::cout << "terrain: " << gdalFile << " x: " << width << " y: " << height << " min: " << min << " max: " << max << std::endl; } Vertex vert; vert.normal[0] = 0; vert.normal[1] = 1; vert.normal[2] = 0; float scale = Engine::getEngine()->getOptions().map_scalar; heightScale = 100.0f; gdal_data = std::vector<std::vector<float>>(height, std::vector<float>(width, 0.0f)); float *lineData1 = new float[width]; float *lineData2 = new float[width]; float range = max - min; for(int z = 0; z < height-1; z++) { raster->RasterIO(GF_Read, 0, z, width, 1, lineData1, width, 1, GDT_Float32, 0, 0); raster->RasterIO(GF_Read, 0, z+1, width, 1, lineData2, width, 1, GDT_Float32, 0, 0); gdal_data[z].assign(lineData1, lineData1+width); gdal_data[z+1].assign(lineData2, lineData2+width); for(int x = 0; x < width-1; x++) { vert.pos[0] = x * scale; vert.pos[1] = heightScale * (lineData1[x]-min)/range; vert.pos[2] = z * scale; vert.texture[0] = x;// / float(width); vert.texture[1] = z;// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = (x+1) * scale; vert.pos[1] = heightScale * (lineData1[x+1]-min)/range; vert.pos[2] = z * scale; vert.texture[0] = (x+1);// / float(width); vert.texture[1] = z;// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = x * scale; vert.pos[1] = heightScale * (lineData2[x]-min)/range; vert.pos[2] = (z+1) * scale; vert.texture[0] = x;// / float(width); vert.texture[1] = (z+1);// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = x * scale; vert.pos[1] = heightScale * (lineData2[x]-min)/range; vert.pos[2] = (z+1) * scale; vert.texture[0] = x;// / float(width); vert.texture[1] = (z+1);// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = (x+1) * scale; vert.pos[1] = heightScale * (lineData2[x+1]-min)/range; vert.pos[2] = (z+1) * scale; vert.texture[0] = (x+1);// / float(width); vert.texture[1] = (z+1);// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); vert.pos[0] = (x+1) * scale; vert.pos[1] = heightScale * (lineData1[x+1]-min)/range; vert.pos[2] = z * scale; vert.texture[0] = (x+1);// / float(width); vert.texture[1] = z;// / float(height); calcNormal(x, z, vert, min, range); geometry.push_back(vert); } } // for(int i = 0; i < geometry.size(); i++) { // if(i % 6 == 0) // std::cout << i << ": " << geometry[i].pos[1] << std::endl; //} std::cout << "size: " << geometry.size() << std::endl; delete[] lineData1; delete[] lineData2; Vertex *geo = geometry.data(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * geometry.size(), geo, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(program->getLocation("vs_pos"), 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,pos)); glEnableVertexAttribArray(1); glVertexAttribPointer(program->getLocation("vs_norm"), 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,normal)); glEnableVertexAttribArray(2); glVertexAttribPointer(program->getLocation("vs_uv"), 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,texture)); texture = new Texture("../assets/desert.jpg", GL_TEXTURE_2D); //model = glm::translate(model, glm::vec3(width/2, 0, height/2)); }