24 QgsColorRampTextureGenerator::QgsColorRampTextureGenerator(
const QgsColorRampShader &colorRampShader,
double verticalScale )
25 : mColorRampShader( colorRampShader )
26 , mVerticalScale( verticalScale )
30 Qt3DRender::QTextureImageDataPtr QgsColorRampTextureGenerator::operator()()
32 Qt3DRender::QTextureImageDataPtr dataPtr = Qt3DRender::QTextureImageDataPtr::create();
33 dataPtr->setFormat( QOpenGLTexture::RGBA32F );
34 dataPtr->setTarget( QOpenGLTexture::Target1D );
35 dataPtr->setPixelFormat( QOpenGLTexture::RGBA );
36 dataPtr->setPixelType( QOpenGLTexture::Float32 );
39 QList<QgsColorRampShader::ColorRampItem> colorItemList = mColorRampShader.colorRampItemList();
40 int size = colorItemList.count() ;
42 dataPtr->setWidth( size );
43 dataPtr->setHeight( 1 );
44 dataPtr->setDepth( 1 );
45 dataPtr->setFaces( 1 );
46 dataPtr->setLayers( 1 );
47 dataPtr->setMipLevels( 1 );
49 for (
int i = 0; i < colorItemList.count(); ++i )
51 float mag = float( colorItemList.at( i ).value * mVerticalScale );
53 QColor color = colorItemList.at( i ).color;
54 if ( color.alphaF() == 0.0f )
56 float rf = float( color.redF() );
57 float gf = float( color.greenF() );
58 float bf = float( color.blueF() );
60 data.append(
reinterpret_cast<const char *
>( &mag ),
sizeof(
float ) );
61 data.append(
reinterpret_cast<const char *
>( &rf ),
sizeof(
float ) );
62 data.append(
reinterpret_cast<const char *
>( &gf ),
sizeof(
float ) );
63 data.append(
reinterpret_cast<const char *
>( &bf ),
sizeof(
float ) );
66 dataPtr->setData( data,
sizeof(
float ) );
73 const QgsColorRampTextureGenerator *otherFunctor = functor_cast<QgsColorRampTextureGenerator>( &other );
77 return mColorRampShader == otherFunctor->mColorRampShader;
82 QgsColorRampTexture::QgsColorRampTexture(
const QgsColorRampShader &colorRampShader,
double verticalScale, Qt3DCore::QNode *parent )
84 mColorRampShader( colorRampShader ),
85 mVerticalScale( verticalScale )
90 Qt3DRender::QTextureImageDataGeneratorPtr QgsColorRampTexture::dataGenerator()
const
92 return Qt3DRender::QTextureImageDataGeneratorPtr(
new QgsColorRampTextureGenerator( mColorRampShader, mVerticalScale ) );
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)