25static const int ELEVATION_OFFSET = 8000;
26static const int ELEVATION_SCALE = 1000;
30 : mElevationImage( size, QImage::Format_ARGB32 )
32 mElevationImage.fill( 0 );
33 mPainter.reset(
new QPainter );
34 mPainter->begin( &mElevationImage );
39 double zScaled = ( z + ELEVATION_OFFSET ) * ELEVATION_SCALE;
40 unsigned int zInt =
static_cast<unsigned int>( std::clamp( zScaled, 0., 16777215. ) );
41 return QRgb( zInt | ( 0xff << 24 ) );
46 unsigned int zScaled = colorRaw & 0xffffff;
47 return ( (
double ) zScaled ) / ELEVATION_SCALE - ELEVATION_OFFSET;
53 QRgb *dataPtr =
reinterpret_cast<QRgb *
>( elevMap->mElevationImage.bits() );
54 for (
int row = 0; row < block->
height(); ++row )
56 for (
int col = 0; col < block->
width(); ++col )
70 const int imgWidth = img.width(), imgHeight = img.height();
71 QRgb *imgPtr =
reinterpret_cast<QRgb *
>( img.bits() );
72 const QRgb *elevPtr =
reinterpret_cast<const QRgb *
>( mElevationImage.constBits() );
74 const int neighbours[] = { -1, 0, 1, 0, 0, -1, 0, 1 };
75 for (
int i = distance; i < imgWidth - distance; ++i )
77 for (
int j = distance; j < imgHeight - distance; ++j )
82 for (
int k = 0; k < 4; ++k )
84 int iNeighbour = i + distance * neighbours[2 * k];
85 int jNeighbour = j + distance * neighbours[2 * k + 1];
86 qgssize neighbourIndex = jNeighbour *
static_cast<qgssize>( imgWidth ) + iNeighbour;
88 factor += std::max<float>( 0, -( centerDepth - neighbourDepth ) );
90 float shade = exp( -factor * strength / rendererScale );
92 QRgb
c = imgPtr[ index ];
93 imgPtr[ index ] = qRgba( qRed(
c ) * shade, qGreen(
c ) * shade, qBlue(
c ) * shade, qAlpha(
c ) );
static QRgb encodeElevation(float z)
Converts elevation value to an actual color.
static std::unique_ptr< QgsElevationMap > fromRasterBlock(QgsRasterBlock *block)
Creates an elevation map based on data from the given raster block.
void applyEyeDomeLighting(QImage &img, int distance, float strength, float rendererScale)
Applies eye dome lighting effect to the given image.
QgsElevationMap(const QSize &size)
Constructs an elevation map with the given width and height.
static float decodeElevation(QRgb colorRaw)
Converts a color back to elevation value.
int width() const SIP_HOLDGIL
Returns the width (number of columns) of the raster block.
double valueAndNoData(int row, int column, bool &isNoData) const
Reads a single value from the pixel at row and column, if type of block is numeric.
int height() const SIP_HOLDGIL
Returns the height (number of rows) of the raster block.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...