Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c491b9d
commit 7e25284
Showing
15 changed files
with
953 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/*************************************************************************** | ||
qgscolorramptexture.h | ||
------------------------- | ||
begin : january 2020 | ||
copyright : (C) 2020 by Vincent Cloarec | ||
email : vcloarec at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgscolorramptexture.h" | ||
|
||
// ColorRampTextureGenerator | ||
|
||
ColorRampTextureGenerator::ColorRampTextureGenerator( const QgsColorRampShader &colorRampShader, double verticalScale ) | ||
: mColorRampShader( colorRampShader ) | ||
, mVerticalScale( verticalScale ) | ||
{ | ||
} | ||
|
||
Qt3DRender::QTextureImageDataPtr ColorRampTextureGenerator::operator()() | ||
{ | ||
Qt3DRender::QTextureImageDataPtr dataPtr = Qt3DRender::QTextureImageDataPtr::create(); | ||
dataPtr->setFormat( QOpenGLTexture::RGBA32F ); | ||
dataPtr->setTarget( QOpenGLTexture::Target1D ); | ||
dataPtr->setPixelFormat( QOpenGLTexture::RGBA ); | ||
dataPtr->setPixelType( QOpenGLTexture::Float32 ); | ||
|
||
QByteArray data; | ||
QList<QgsColorRampShader::ColorRampItem> colorItemList = mColorRampShader.colorRampItemList(); | ||
int size = colorItemList.count() ; | ||
|
||
dataPtr->setWidth( size ); | ||
dataPtr->setHeight( 1 ); | ||
dataPtr->setDepth( 1 ); | ||
dataPtr->setFaces( 1 ); | ||
dataPtr->setLayers( 1 ); | ||
dataPtr->setMipLevels( 1 ); | ||
|
||
for ( int i = 0; i < colorItemList.count(); ++i ) | ||
{ | ||
float mag = float( colorItemList.at( i ).value * mVerticalScale ); | ||
|
||
QColor color = colorItemList.at( i ).color; | ||
float rf = float( color.redF() ); | ||
float gf = float( color.greenF() ); | ||
float bf = float( color.blueF() ); | ||
|
||
data.append( reinterpret_cast<const char *>( &mag ), sizeof( float ) ); | ||
data.append( reinterpret_cast<const char *>( &rf ), sizeof( float ) ); | ||
data.append( reinterpret_cast<const char *>( &gf ), sizeof( float ) ); | ||
data.append( reinterpret_cast<const char *>( &bf ), sizeof( float ) ); | ||
|
||
} | ||
|
||
dataPtr->setData( data, sizeof( float ) ); //size is the size of the type, here float | ||
|
||
return dataPtr; | ||
} | ||
|
||
bool ColorRampTextureGenerator::operator==( const Qt3DRender::QTextureImageDataGenerator &other ) const | ||
{ | ||
const ColorRampTextureGenerator *otherFunctor = functor_cast<ColorRampTextureGenerator>( &other ); | ||
if ( !otherFunctor ) | ||
return false; | ||
|
||
QgsColorRampShader otherColorRampShader = otherFunctor->mColorRampShader; | ||
|
||
if ( mColorRampShader.colorRampItemList().count() != otherColorRampShader.colorRampItemList().count() || | ||
mColorRampShader.classificationMode() != otherColorRampShader.classificationMode() || | ||
mColorRampShader.colorRampType() != otherColorRampShader.colorRampType() ) | ||
{ | ||
return false; | ||
} | ||
|
||
QList<QgsColorRampShader::ColorRampItem> colorItemList = mColorRampShader.colorRampItemList(); | ||
QList<QgsColorRampShader::ColorRampItem> otherColorItemList = otherColorRampShader.colorRampItemList(); | ||
for ( int i = 0; i < colorItemList.count(); ++i ) | ||
{ | ||
const QColor color = colorItemList.at( i ).color; | ||
const QColor otherColor = otherColorItemList.at( i ).color; | ||
double value = colorItemList.at( i ).value; | ||
double otherValue = otherColorItemList.at( i ).value; | ||
if ( color != otherColor || | ||
( !std::isnan( value ) && !std::isnan( otherValue ) && colorItemList.at( i ).value != otherColorItemList.at( i ).value ) || | ||
( std::isnan( value ) != std::isnan( otherValue ) ) ) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// ColorRampTexture | ||
|
||
ColorRampTexture::ColorRampTexture( const QgsColorRampShader &colorRampShader, double verticalScale, Qt3DCore::QNode *parent ) | ||
: Qt3DRender::QAbstractTextureImage( parent ), | ||
mColorRampShader( colorRampShader ), | ||
mVerticalScale( verticalScale ) | ||
{ | ||
|
||
} | ||
|
||
Qt3DRender::QTextureImageDataGeneratorPtr ColorRampTexture::dataGenerator() const | ||
{ | ||
return Qt3DRender::QTextureImageDataGeneratorPtr( new ColorRampTextureGenerator( mColorRampShader, mVerticalScale ) ); | ||
} |
Oops, something went wrong.