Split QgsPointCloud3DSymbol into different classes

This commit is contained in:
NEDJIMAbelgacem 2020-11-24 05:35:42 +01:00 committed by Martin Dobias
parent ae749de439
commit 3979b47ed1
7 changed files with 400 additions and 177 deletions

View File

@ -35,27 +35,18 @@ class QgsPointCloud3DSymbol : QgsAbstract3DSymbol
ColorRamp, ColorRamp,
}; };
enum RenderingParameter QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle style );
{
Height,
ClassID
};
QgsPointCloud3DSymbol();
%Docstring %Docstring
Constructor for QgsPointCloud3DSymbol Constructor for QgsPointCloud3DSymbol
%End %End
~QgsPointCloud3DSymbol(); ~QgsPointCloud3DSymbol();
virtual QString type() const;
virtual QgsAbstract3DSymbol *clone() const /Factory/; virtual QgsAbstract3DSymbol *clone() const /Factory/;
virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const; virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context ); virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
virtual QString type() const;
bool isEnabled() const; bool isEnabled() const;
%Docstring %Docstring
@ -71,6 +62,43 @@ Sets whether rendering for this symbol is enabled
.. seealso:: :py:func:`isEnabled` .. seealso:: :py:func:`isEnabled`
%End %End
QgsPointCloud3DSymbol::RenderingStyle renderingStyle() const;
%Docstring
Returns the rendering style
.. seealso:: :py:func:`setRenderingStyle`
%End
protected:
};
class QgsSingleColorPointCloud3DSymbol : QgsPointCloud3DSymbol
{
%Docstring
3D symbol that draws point cloud geometries as 3D objects.using one color
.. warning::
This is not considered stable API, and may change in future QGIS releases. It is
exposed to the Python bindings as a tech preview only.
.. versionadded:: 3.18
%End
%TypeHeaderCode
#include "qgspointcloud3dsymbol.h"
%End
public:
QgsSingleColorPointCloud3DSymbol();
virtual QgsAbstract3DSymbol *clone() const /Factory/;
virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
float pointSize() const; float pointSize() const;
%Docstring %Docstring
Returns the point size of the point cloud Returns the point size of the point cloud
@ -83,34 +111,6 @@ Returns the point size of the point cloud
Sets the point size Sets the point size
.. seealso:: :py:func:`pointSize` .. seealso:: :py:func:`pointSize`
%End
QgsPointCloud3DSymbol::RenderingStyle renderingStyle() const;
%Docstring
Returns the rendering style
.. seealso:: :py:func:`setRenderingStyle`
%End
void setRenderingStyle( QgsPointCloud3DSymbol::RenderingStyle style );
%Docstring
Sets the rendering style
.. seealso:: :py:func:`renderingStyle`
%End
QgsPointCloud3DSymbol::RenderingParameter renderingParameter() const;
%Docstring
Returns the parameter used to select the color of the point cloud when using color ramp coloring
.. seealso:: :py:func:`setRenderingParameter`
%End
void setRenderingParameter( QgsPointCloud3DSymbol::RenderingParameter parameter );
%Docstring
Sets the parameter used to select the color of the point cloud when using color ramp coloring
.. seealso:: :py:func:`renderingParameter`
%End %End
QColor singleColor() const; QColor singleColor() const;
@ -125,6 +125,70 @@ Returns the color used by the renderer when using SingleColor rendering mode
Sets the color used by the renderer when using SingleColor rendering mode Sets the color used by the renderer when using SingleColor rendering mode
.. seealso:: :py:func:`singleColor` .. seealso:: :py:func:`singleColor`
%End
};
class QgsColorRampPointCloud3DSymbol : QgsPointCloud3DSymbol
{
%Docstring
3D symbol that draws point cloud geometries as 3D objects.using color ramp shader
.. warning::
This is not considered stable API, and may change in future QGIS releases. It is
exposed to the Python bindings as a tech preview only.
.. versionadded:: 3.18
%End
%TypeHeaderCode
#include "qgspointcloud3dsymbol.h"
%End
public:
enum RenderingParameter
{
Height,
ClassID
};
QgsColorRampPointCloud3DSymbol();
virtual QgsAbstract3DSymbol *clone() const /Factory/;
virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
float pointSize() const;
%Docstring
Returns the point size of the point cloud
.. seealso:: :py:func:`setPointSize`
%End
void setPointSize( float size );
%Docstring
Sets the point size
.. seealso:: :py:func:`pointSize`
%End
QgsColorRampPointCloud3DSymbol::RenderingParameter renderingParameter() const;
%Docstring
Returns the parameter used to select the color of the point cloud when using color ramp coloring
.. seealso:: :py:func:`setRenderingParameter`
%End
void setRenderingParameter( QgsColorRampPointCloud3DSymbol::RenderingParameter parameter );
%Docstring
Sets the parameter used to select the color of the point cloud when using color ramp coloring
.. seealso:: :py:func:`renderingParameter`
%End %End
QgsColorRampShader colorRampShader() const; QgsColorRampShader colorRampShader() const;
@ -134,7 +198,7 @@ Returns the color ramp shader used to render the color
void setColorRampShader( const QgsColorRampShader &colorRampShader ); void setColorRampShader( const QgsColorRampShader &colorRampShader );
%Docstring %Docstring
Sets the color ramp shader used to render the color Sets the color ramp shader used to render the point cloud
%End %End
double colorRampShaderMin() const; double colorRampShaderMin() const;
@ -155,7 +219,7 @@ Returns the maximum value used when classifying colors in the color ramp shader
%Docstring %Docstring
Sets the minimum and maximum values used when classifying colors in the color ramp shader Sets the minimum and maximum values used when classifying colors in the color ramp shader
.. seealso:: :py:func:`setColorRampShaderMinMax` .. seealso:: :py:func:`colorRampShaderMin`
%End %End
}; };

View File

@ -110,8 +110,17 @@ void QgsPointCloudLayer3DRenderer::readXml( const QDomElement &elem, const QgsRe
mLayerRef = QgsMapLayerRef( elem.attribute( QStringLiteral( "layer" ) ) ); mLayerRef = QgsMapLayerRef( elem.attribute( QStringLiteral( "layer" ) ) );
QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) ); QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
if ( !mSymbol ) int renderingStyleInt = elemSymbol.attribute( QStringLiteral( "rendering-style" ), QStringLiteral( "0" ) ).toInt();
mSymbol = qgis::make_unique< QgsPointCloud3DSymbol >(); QgsPointCloud3DSymbol::RenderingStyle renderingStyle = static_cast<QgsPointCloud3DSymbol::RenderingStyle>( renderingStyleInt );
switch ( renderingStyle )
{
case QgsPointCloud3DSymbol::RenderingStyle::SingleColor:
mSymbol.reset( new QgsSingleColorPointCloud3DSymbol );
break;
case QgsPointCloud3DSymbol::RenderingStyle::ColorRamp:
mSymbol.reset( new QgsColorRampPointCloud3DSymbol );
break;
}
mSymbol->readXml( elemSymbol, context ); mSymbol->readXml( elemSymbol, context );
} }

View File

@ -100,7 +100,7 @@ void QgsPointCloud3DGeometry::makeVertexBuffer( const QgsPointCloud3DSymbolHandl
QgsPointCloud3DSymbolHandler::QgsPointCloud3DSymbolHandler( QgsPointCloud3DSymbol *symbol ) QgsPointCloud3DSymbolHandler::QgsPointCloud3DSymbolHandler( QgsPointCloud3DSymbol *symbol )
{ {
mSymbol.reset( symbol ); mSymbol.reset( symbol ) ;
} }
bool QgsPointCloud3DSymbolHandler::prepare( const Qgs3DRenderContext &context ) bool QgsPointCloud3DSymbolHandler::prepare( const Qgs3DRenderContext &context )
@ -170,7 +170,16 @@ void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
Qt3DCore::QTransform *tr = new Qt3DCore::QTransform; Qt3DCore::QTransform *tr = new Qt3DCore::QTransform;
// Material // Material
Qt3DRender::QMaterial *mat = constructMaterial(); Qt3DRender::QMaterial *mat = nullptr;
switch ( mSymbol->renderingStyle() )
{
case QgsPointCloud3DSymbol::RenderingStyle::SingleColor:
mat = constructMaterial( dynamic_cast<QgsSingleColorPointCloud3DSymbol *>( mSymbol.get() ) );
break;
case QgsPointCloud3DSymbol::RenderingStyle::ColorRamp:
mat = constructMaterial( dynamic_cast<QgsColorRampPointCloud3DSymbol *>( mSymbol.get() ) );
break;
}
Qt3DRender::QShaderProgram *shaderProgram = new Qt3DRender::QShaderProgram( mat ); Qt3DRender::QShaderProgram *shaderProgram = new Qt3DRender::QShaderProgram( mat );
shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/pointcloud.vert" ) ) ) ); shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/pointcloud.vert" ) ) ) );
@ -181,7 +190,15 @@ void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
Qt3DRender::QPointSize *pointSize = new Qt3DRender::QPointSize( renderPass ); Qt3DRender::QPointSize *pointSize = new Qt3DRender::QPointSize( renderPass );
pointSize->setSizeMode( Qt3DRender::QPointSize::Programmable ); // supported since OpenGL 3.2 pointSize->setSizeMode( Qt3DRender::QPointSize::Programmable ); // supported since OpenGL 3.2
pointSize->setValue( mSymbol->pointSize() ); switch ( mSymbol->renderingStyle() )
{
case QgsPointCloud3DSymbol::RenderingStyle::SingleColor:
pointSize->setValue( dynamic_cast<QgsSingleColorPointCloud3DSymbol *>( mSymbol.get() )->pointSize() );
break;
case QgsPointCloud3DSymbol::RenderingStyle::ColorRamp:
pointSize->setValue( dynamic_cast<QgsColorRampPointCloud3DSymbol *>( mSymbol.get() )->pointSize() );
break;
}
renderPass->addRenderState( pointSize ); renderPass->addRenderState( pointSize );
// without this filter the default forward renderer would not render this // without this filter the default forward renderer would not render this
@ -211,22 +228,31 @@ void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
// cppcheck-suppress memleak // cppcheck-suppress memleak
} }
Qt3DRender::QMaterial *QgsPointCloud3DSymbolHandler::constructMaterial( QgsSingleColorPointCloud3DSymbol *symbol )
Qt3DRender::QMaterial *QgsPointCloud3DSymbolHandler::constructMaterial()
{ {
Qt3DRender::QMaterial *mat = new Qt3DRender::QMaterial; Qt3DRender::QMaterial *mat = new Qt3DRender::QMaterial;
Qt3DRender::QParameter *pointSizeParameter = new Qt3DRender::QParameter( "u_pointSize", QVariant::fromValue( mSymbol->pointSize() ) ); Qt3DRender::QParameter *renderingStyle = new Qt3DRender::QParameter( "u_renderingStyle", symbol->renderingStyle() );
mat->addParameter( renderingStyle );
Qt3DRender::QParameter *pointSizeParameter = new Qt3DRender::QParameter( "u_pointSize", QVariant::fromValue( symbol->pointSize() ) );
mat->addParameter( pointSizeParameter ); mat->addParameter( pointSizeParameter );
QColor singleColor = mSymbol->singleColor(); QColor singleColor = symbol->singleColor();
Qt3DRender::QParameter *singleColorParameter = new Qt3DRender::QParameter( "u_singleColor", QVector3D( singleColor.redF(), singleColor.greenF(), singleColor.blueF() ) ); Qt3DRender::QParameter *singleColorParameter = new Qt3DRender::QParameter( "u_singleColor", QVector3D( singleColor.redF(), singleColor.greenF(), singleColor.blueF() ) );
mat->addParameter( singleColorParameter ); mat->addParameter( singleColorParameter );
Qt3DRender::QParameter *textureTypeParameter = new Qt3DRender::QParameter( "u_textureType", static_cast<int>( mSymbol->renderingStyle() ) ); return mat;
}
Qt3DRender::QMaterial *QgsPointCloud3DSymbolHandler::constructMaterial( QgsColorRampPointCloud3DSymbol *symbol )
{
Qt3DRender::QMaterial *mat = new Qt3DRender::QMaterial;
Qt3DRender::QParameter *renderingStyle = new Qt3DRender::QParameter( "u_renderingStyle", symbol->renderingStyle() );
mat->addParameter( renderingStyle );
Qt3DRender::QParameter *pointSizeParameter = new Qt3DRender::QParameter( "u_pointSize", QVariant::fromValue( symbol->pointSize() ) );
mat->addParameter( pointSizeParameter );
Qt3DRender::QParameter *textureTypeParameter = new Qt3DRender::QParameter( "u_textureType", static_cast<int>( symbol->renderingStyle() ) );
mat->addParameter( textureTypeParameter ); mat->addParameter( textureTypeParameter );
Qt3DRender::QParameter *renderingParameter = new Qt3DRender::QParameter( "u_renderingParameter", mSymbol->renderingParameter() ); Qt3DRender::QParameter *renderingParameter = new Qt3DRender::QParameter( "u_renderingParameter", symbol->renderingParameter() );
mat->addParameter( renderingParameter ); mat->addParameter( renderingParameter );
if ( mSymbol->renderingStyle() == QgsPointCloud3DSymbol::ColorRamp ) QgsColorRampShader colorRampShader = symbol->colorRampShader();
{
QgsColorRampShader colorRampShader = mSymbol->colorRampShader();
// Create the texture to pass the color ramp // Create the texture to pass the color ramp
Qt3DRender::QTexture1D *colorRampTexture = nullptr; Qt3DRender::QTexture1D *colorRampTexture = nullptr;
if ( colorRampShader.colorRampItemList().count() > 0 ) if ( colorRampShader.colorRampItemList().count() > 0 )
@ -244,7 +270,6 @@ Qt3DRender::QMaterial *QgsPointCloud3DSymbolHandler::constructMaterial()
int colorRampType = colorRampShader.colorRampType(); int colorRampType = colorRampShader.colorRampType();
Qt3DRender::QParameter *colorRampTypeParameter = new Qt3DRender::QParameter( "u_colorRampType", colorRampType ); Qt3DRender::QParameter *colorRampTypeParameter = new Qt3DRender::QParameter( "u_colorRampType", colorRampType );
mat->addParameter( colorRampTypeParameter ); mat->addParameter( colorRampTypeParameter );
}
return mat; return mat;
} }

View File

@ -78,7 +78,8 @@ class QgsPointCloud3DSymbolHandler // : public QgsFeature3DHandler
//static Qt3DCore::QTransform *transform( QVector3D position, const QgsPoint3DSymbol *symbol ); //static Qt3DCore::QTransform *transform( QVector3D position, const QgsPoint3DSymbol *symbol );
private: private:
Qt3DRender::QMaterial *constructMaterial(); Qt3DRender::QMaterial *constructMaterial( QgsSingleColorPointCloud3DSymbol *symbol );
Qt3DRender::QMaterial *constructMaterial( QgsColorRampPointCloud3DSymbol *symbol );
void makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected ); void makeEntity( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context, PointData &out, bool selected );

View File

@ -15,31 +15,42 @@
#include "qgspointcloud3dsymbol.h" #include "qgspointcloud3dsymbol.h"
// QgsPointCloud3DSymbol
QgsPointCloud3DSymbol::QgsPointCloud3DSymbol() QgsPointCloud3DSymbol::QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle style )
: QgsAbstract3DSymbol() : QgsAbstract3DSymbol()
, mRenderingStyle( style )
{ {
} }
QgsPointCloud3DSymbol::~QgsPointCloud3DSymbol() { } QgsPointCloud3DSymbol::~QgsPointCloud3DSymbol() { }
QgsAbstract3DSymbol *QgsPointCloud3DSymbol::clone() const void QgsPointCloud3DSymbol::setIsEnabled( bool enabled )
{ {
QgsPointCloud3DSymbol *result = new QgsPointCloud3DSymbol; mEnabled = enabled;
}
// QgsSingleColorPointCloud3DSymbol
QgsSingleColorPointCloud3DSymbol::QgsSingleColorPointCloud3DSymbol()
: QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle::SingleColor )
{
}
QgsAbstract3DSymbol *QgsSingleColorPointCloud3DSymbol::clone() const
{
QgsSingleColorPointCloud3DSymbol *result = new QgsSingleColorPointCloud3DSymbol;
result->mEnabled = mEnabled; result->mEnabled = mEnabled;
result->mPointSize = mPointSize; result->mPointSize = mPointSize;
result->mRenderingStyle = mRenderingStyle; result->mRenderingStyle = mRenderingStyle;
result->mRenderingParameter = mRenderingParameter;
result->mSingleColor = mSingleColor; result->mSingleColor = mSingleColor;
result->mColorRampShader = mColorRampShader;
result->mColorRampShaderMin = mColorRampShaderMin;
result->mColorRampShaderMax = mColorRampShaderMax;
copyBaseSettings( result ); copyBaseSettings( result );
return result; return result;
} }
void QgsPointCloud3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const void QgsSingleColorPointCloud3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
{ {
Q_UNUSED( context ) Q_UNUSED( context )
@ -49,15 +60,9 @@ void QgsPointCloud3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteConte
elem.setAttribute( QStringLiteral( "single-color-red" ), mSingleColor.redF() ); elem.setAttribute( QStringLiteral( "single-color-red" ), mSingleColor.redF() );
elem.setAttribute( QStringLiteral( "single-color-green" ), mSingleColor.greenF() ); elem.setAttribute( QStringLiteral( "single-color-green" ), mSingleColor.greenF() );
elem.setAttribute( QStringLiteral( "single-color-blue" ), mSingleColor.blueF() ); elem.setAttribute( QStringLiteral( "single-color-blue" ), mSingleColor.blueF() );
elem.setAttribute( QStringLiteral( "rendering-parameter" ), mRenderingParameter );
elem.setAttribute( QStringLiteral( "color-ramp-shader-min" ), mColorRampShaderMin );
elem.setAttribute( QStringLiteral( "color-ramp-shader-max" ), mColorRampShaderMax );
QDomDocument doc = elem.ownerDocument();
QDomElement elemColorRampShader = mColorRampShader.writeXml( doc );
elem.appendChild( elemColorRampShader );
} }
void QgsPointCloud3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context ) void QgsSingleColorPointCloud3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{ {
Q_UNUSED( context ) Q_UNUSED( context )
@ -67,58 +72,94 @@ void QgsPointCloud3DSymbol::readXml( const QDomElement &elem, const QgsReadWrite
mSingleColor.setRedF( elem.attribute( "single-color-red", QStringLiteral( "0.0" ) ).toFloat() ); mSingleColor.setRedF( elem.attribute( "single-color-red", QStringLiteral( "0.0" ) ).toFloat() );
mSingleColor.setGreenF( elem.attribute( "single-color-green", QStringLiteral( "0.0" ) ).toFloat() ); mSingleColor.setGreenF( elem.attribute( "single-color-green", QStringLiteral( "0.0" ) ).toFloat() );
mSingleColor.setBlueF( elem.attribute( "single-color-blue", QStringLiteral( "1.0" ) ).toFloat() ); mSingleColor.setBlueF( elem.attribute( "single-color-blue", QStringLiteral( "1.0" ) ).toFloat() );
mRenderingParameter = static_cast< QgsPointCloud3DSymbol::RenderingParameter >( elem.attribute( "rendering-parameter", QStringLiteral( "0" ) ).toInt() ); }
void QgsSingleColorPointCloud3DSymbol::setPointSize( float size )
{
mPointSize = size;
}
void QgsSingleColorPointCloud3DSymbol::setSingleColor( QColor color )
{
mSingleColor = color;
}
// QgsColorRampPointCloud3DSymbol
QgsColorRampPointCloud3DSymbol::QgsColorRampPointCloud3DSymbol()
: QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle::ColorRamp )
{
}
QgsAbstract3DSymbol *QgsColorRampPointCloud3DSymbol::clone() const
{
QgsColorRampPointCloud3DSymbol *result = new QgsColorRampPointCloud3DSymbol;
result->mEnabled = mEnabled;
result->mPointSize = mPointSize;
result->mRenderingStyle = mRenderingStyle;
result->mRenderingParameter = mRenderingParameter;
result->mColorRampShader = mColorRampShader;
result->mColorRampShaderMin = mColorRampShaderMin;
result->mColorRampShaderMax = mColorRampShaderMax;
copyBaseSettings( result );
return result;
}
void QgsColorRampPointCloud3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
{
Q_UNUSED( context )
elem.setAttribute( QStringLiteral( "enabled" ), mEnabled );
elem.setAttribute( QStringLiteral( "point-size" ), mPointSize );
elem.setAttribute( QStringLiteral( "rendering-style" ), mRenderingStyle );
elem.setAttribute( QStringLiteral( "rendering-parameter" ), mRenderingParameter );
elem.setAttribute( QStringLiteral( "color-ramp-shader-min" ), mColorRampShaderMin );
elem.setAttribute( QStringLiteral( "color-ramp-shader-max" ), mColorRampShaderMax );
QDomDocument doc = elem.ownerDocument();
QDomElement elemColorRampShader = mColorRampShader.writeXml( doc );
elem.appendChild( elemColorRampShader );
}
void QgsColorRampPointCloud3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
Q_UNUSED( context )
mEnabled = elem.attribute( "enabled", QStringLiteral( "0" ) ).toInt();
mPointSize = elem.attribute( "point-size", QStringLiteral( "2.0" ) ).toFloat();
mRenderingStyle = static_cast< QgsPointCloud3DSymbol::RenderingStyle >( elem.attribute( "rendering-style", QStringLiteral( "0" ) ).toInt() );
mRenderingParameter = static_cast< QgsColorRampPointCloud3DSymbol::RenderingParameter >( elem.attribute( "rendering-parameter", QStringLiteral( "0" ) ).toInt() );
mColorRampShaderMin = elem.attribute( QStringLiteral( "color-ramp-shader-min" ), QStringLiteral( "0.0" ) ).toDouble(); mColorRampShaderMin = elem.attribute( QStringLiteral( "color-ramp-shader-min" ), QStringLiteral( "0.0" ) ).toDouble();
mColorRampShaderMax = elem.attribute( QStringLiteral( "color-ramp-shader-max" ), QStringLiteral( "1.0" ) ).toDouble(); mColorRampShaderMax = elem.attribute( QStringLiteral( "color-ramp-shader-max" ), QStringLiteral( "1.0" ) ).toDouble();
mColorRampShader.readXml( elem ); mColorRampShader.readXml( elem );
} }
void QgsPointCloud3DSymbol::setIsEnabled( bool enabled ) QgsColorRampPointCloud3DSymbol::RenderingParameter QgsColorRampPointCloud3DSymbol::renderingParameter() const
{
mEnabled = enabled;
}
void QgsPointCloud3DSymbol::setRenderingStyle( QgsPointCloud3DSymbol::RenderingStyle style )
{
mRenderingStyle = style;
}
QgsPointCloud3DSymbol::RenderingStyle QgsPointCloud3DSymbol::renderingStyle() const
{
return mRenderingStyle;
}
QgsPointCloud3DSymbol::RenderingParameter QgsPointCloud3DSymbol::renderingParameter() const
{ {
return mRenderingParameter; return mRenderingParameter;
} }
void QgsPointCloud3DSymbol::setRenderingParameter( QgsPointCloud3DSymbol::RenderingParameter parameter ) void QgsColorRampPointCloud3DSymbol::setRenderingParameter( QgsColorRampPointCloud3DSymbol::RenderingParameter parameter )
{ {
mRenderingParameter = parameter; mRenderingParameter = parameter;
} }
void QgsPointCloud3DSymbol::setPointSize( float size ) void QgsColorRampPointCloud3DSymbol::setPointSize( float size )
{ {
mPointSize = size; mPointSize = size;
} }
void QgsPointCloud3DSymbol::setSingleColor( QColor color ) QgsColorRampShader QgsColorRampPointCloud3DSymbol::colorRampShader() const
{
mSingleColor = color;
}
QgsColorRampShader QgsPointCloud3DSymbol::colorRampShader() const
{ {
return mColorRampShader; return mColorRampShader;
} }
void QgsPointCloud3DSymbol::setColorRampShader( const QgsColorRampShader &colorRampShader ) void QgsColorRampPointCloud3DSymbol::setColorRampShader( const QgsColorRampShader &colorRampShader )
{ {
mColorRampShader = colorRampShader; mColorRampShader = colorRampShader;
} }
void QgsPointCloud3DSymbol::setColorRampShaderMinMax( double min, double max ) void QgsColorRampPointCloud3DSymbol::setColorRampShaderMinMax( double min, double max )
{ {
mColorRampShaderMin = min; mColorRampShaderMin = min;
mColorRampShaderMax = max; mColorRampShaderMax = max;

View File

@ -35,7 +35,7 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol
public: public:
/** /**
* How to render the color of the point cloud * How to render the point cloud
*/ */
enum RenderingStyle enum RenderingStyle
{ {
@ -45,26 +45,17 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol
ColorRamp, ColorRamp,
}; };
/**
* The value used to select colors from the color ramp
*/
enum RenderingParameter
{
Height = 0,
ClassID
};
//! Constructor for QgsPointCloud3DSymbol //! Constructor for QgsPointCloud3DSymbol
QgsPointCloud3DSymbol(); QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle style );
//! Destructor for QgsPointCloud3DSymbol //! Destructor for QgsPointCloud3DSymbol
~QgsPointCloud3DSymbol() override; ~QgsPointCloud3DSymbol() override;
QgsAbstract3DSymbol *clone() const override SIP_FACTORY { Q_ASSERT( false ); return nullptr; }
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override { Q_UNUSED( context ); Q_ASSERT( false ); }
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override { Q_UNUSED( context ); Q_ASSERT( false ); }
QString type() const override { return "pointcloud"; } QString type() const override { return "pointcloud"; }
QgsAbstract3DSymbol *clone() const override SIP_FACTORY;
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
/** /**
* Returns whether rendering for this symbol is enabled * Returns whether rendering for this symbol is enabled
@ -78,6 +69,36 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol
*/ */
void setIsEnabled( bool enabled ); void setIsEnabled( bool enabled );
/**
* Returns the rendering style
* \see setRenderingStyle( QgsPointCloud3DSymbol::RenderingStyle style )
*/
QgsPointCloud3DSymbol::RenderingStyle renderingStyle() const { return mRenderingStyle; }
protected:
bool mEnabled = true;
QgsPointCloud3DSymbol::RenderingStyle mRenderingStyle = QgsPointCloud3DSymbol::ColorRamp;
};
/**
* \ingroup 3d
* 3D symbol that draws point cloud geometries as 3D objects.using one color
*
* \warning This is not considered stable API, and may change in future QGIS releases. It is
* exposed to the Python bindings as a tech preview only.
*
* \since QGIS 3.18
*/
class _3D_EXPORT QgsSingleColorPointCloud3DSymbol : public QgsPointCloud3DSymbol
{
public:
QgsSingleColorPointCloud3DSymbol();
QgsAbstract3DSymbol *clone() const override SIP_FACTORY;
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
/** /**
* Returns the point size of the point cloud * Returns the point size of the point cloud
* \see setPointSize( float size ) * \see setPointSize( float size )
@ -90,30 +111,6 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol
*/ */
void setPointSize( float size ); void setPointSize( float size );
/**
* Returns the rendering style
* \see setRenderingStyle( QgsPointCloud3DSymbol::RenderingStyle style )
*/
QgsPointCloud3DSymbol::RenderingStyle renderingStyle() const;
/**
* Sets the rendering style
* \see renderingStyle()
*/
void setRenderingStyle( QgsPointCloud3DSymbol::RenderingStyle style );
/**
* Returns the parameter used to select the color of the point cloud when using color ramp coloring
* \see setRenderingParameter( QgsPointCloud3DSymbol::RenderingParameter parameter )
*/
QgsPointCloud3DSymbol::RenderingParameter renderingParameter() const;
/**
* Sets the parameter used to select the color of the point cloud when using color ramp coloring
* \see renderingParameter()
*/
void setRenderingParameter( QgsPointCloud3DSymbol::RenderingParameter parameter );
/** /**
* Returns the color used by the renderer when using SingleColor rendering mode * Returns the color used by the renderer when using SingleColor rendering mode
* \see setSingleColor( QColor color ) * \see setSingleColor( QColor color )
@ -126,44 +123,98 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol
*/ */
void setSingleColor( QColor color ); void setSingleColor( QColor color );
private:
float mPointSize = 2.0f;
QColor mSingleColor = Qt::blue;
};
/**
* \ingroup 3d
* 3D symbol that draws point cloud geometries as 3D objects.using color ramp shader
*
* \warning This is not considered stable API, and may change in future QGIS releases. It is
* exposed to the Python bindings as a tech preview only.
*
* \since QGIS 3.18
*/
class _3D_EXPORT QgsColorRampPointCloud3DSymbol : public QgsPointCloud3DSymbol
{
public:
/**
* The value used to select colors from the color ramp
*/
enum RenderingParameter
{
Height = 0,
ClassID
};
QgsColorRampPointCloud3DSymbol();
QgsAbstract3DSymbol *clone() const override SIP_FACTORY;
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
/**
* Returns the point size of the point cloud
* \see setPointSize( float size )
*/
float pointSize() const { return mPointSize; }
/**
* Sets the point size
* \see pointSize()
*/
void setPointSize( float size );
/**
* Returns the parameter used to select the color of the point cloud when using color ramp coloring
* \see setRenderingParameter( QgsPointCloud3DSymbol::RenderingParameter parameter )
*/
QgsColorRampPointCloud3DSymbol::RenderingParameter renderingParameter() const;
/**
* Sets the parameter used to select the color of the point cloud when using color ramp coloring
* \see renderingParameter()
*/
void setRenderingParameter( QgsColorRampPointCloud3DSymbol::RenderingParameter parameter );
/** /**
* Returns the color ramp shader used to render the color * Returns the color ramp shader used to render the color
*/ */
QgsColorRampShader colorRampShader() const; QgsColorRampShader colorRampShader() const;
/** /**
* Sets the color ramp shader used to render the color * Sets the color ramp shader used to render the point cloud
*/ */
void setColorRampShader( const QgsColorRampShader &colorRampShader ); void setColorRampShader( const QgsColorRampShader &colorRampShader );
/** /**
* Returns the minimum value used when classifying colors in the color ramp shader * Returns the minimum value used when classifying colors in the color ramp shader
* \see setColorRampShaderMinMax( double min, double max ); * \see setColorRampShaderMinMax( double min, double max )
*/ */
double colorRampShaderMin() const { return mColorRampShaderMin; } double colorRampShaderMin() const { return mColorRampShaderMin; }
/** /**
* Returns the maximum value used when classifying colors in the color ramp shader * Returns the maximum value used when classifying colors in the color ramp shader
* \see setColorRampShaderMinMax( double min, double max ); * \see setColorRampShaderMinMax( double min, double max )
*/ */
double colorRampShaderMax() const { return mColorRampShaderMax; } double colorRampShaderMax() const { return mColorRampShaderMax; }
/** /**
* Sets the minimum and maximum values used when classifying colors in the color ramp shader * Sets the minimum and maximum values used when classifying colors in the color ramp shader
* \see setColorRampShaderMinMax( double min, double max ); * \see colorRampShaderMin() colorRampShaderMax()
*/ */
void setColorRampShaderMinMax( double min, double max ); void setColorRampShaderMinMax( double min, double max );
private: private:
bool mEnabled = true;
float mPointSize = 2.0f; float mPointSize = 2.0f;
QgsColorRampPointCloud3DSymbol::RenderingParameter mRenderingParameter = QgsColorRampPointCloud3DSymbol::RenderingParameter::Height;
QgsPointCloud3DSymbol::RenderingStyle mRenderingStyle = QgsPointCloud3DSymbol::ColorRamp;
QgsPointCloud3DSymbol::RenderingParameter mRenderingParameter = QgsPointCloud3DSymbol::RenderingParameter::ClassID;
QgsColorRampShader mColorRampShader; QgsColorRampShader mColorRampShader;
double mColorRampShaderMin = 0.0; double mColorRampShaderMin = 0.0;
double mColorRampShaderMax = 1.0; double mColorRampShaderMax = 1.0;
QColor mSingleColor = Qt::blue;
}; };
#endif // QGSPOINTCLOUD3DSYMBOL_H #endif // QGSPOINTCLOUD3DSYMBOL_H

View File

@ -37,27 +37,59 @@ QgsPointCloud3DSymbolWidget::QgsPointCloud3DSymbolWidget( QgsPointCloud3DSymbol
void QgsPointCloud3DSymbolWidget::setSymbol( QgsPointCloud3DSymbol *symbol ) void QgsPointCloud3DSymbolWidget::setSymbol( QgsPointCloud3DSymbol *symbol )
{ {
mPointSizeSpinBox->setValue( symbol->pointSize() );
mRenderingStyleComboBox->setCurrentIndex( symbol->renderingStyle() ); mRenderingStyleComboBox->setCurrentIndex( symbol->renderingStyle() );
mRenderingParameterComboBox->setCurrentIndex( symbol->renderingParameter() ); switch ( symbol->renderingStyle() )
mSingleColorBtn->setColor( symbol->singleColor() ); {
QgsColorRampShader shader = symbol->colorRampShader(); case QgsPointCloud3DSymbol::RenderingStyle::SingleColor:
setColorRampMinMax( symbol->colorRampShaderMin(), symbol->colorRampShaderMax() ); {
mColorRampShaderWidget->setFromShader( symbol->colorRampShader() ); QgsSingleColorPointCloud3DSymbol *symb = static_cast<QgsSingleColorPointCloud3DSymbol *>( symbol );
mPointSizeSpinBox->setValue( symb->pointSize() );
mSingleColorBtn->setColor( symb->singleColor() );
break;
}
case QgsPointCloud3DSymbol::RenderingStyle::ColorRamp:
{
QgsColorRampPointCloud3DSymbol *symb = static_cast<QgsColorRampPointCloud3DSymbol *>( symbol );
mPointSizeSpinBox->setValue( symb->pointSize() );
mRenderingParameterComboBox->setCurrentIndex( symb->renderingParameter() );
QgsColorRampShader shader = symb->colorRampShader();
setColorRampMinMax( symb->colorRampShaderMin(), symb->colorRampShaderMax() );
mColorRampShaderWidget->setFromShader( symb->colorRampShader() );
break;
}
}
onRenderingStyleChanged( symbol->renderingStyle() ); onRenderingStyleChanged( symbol->renderingStyle() );
} }
QgsPointCloud3DSymbol *QgsPointCloud3DSymbolWidget::symbol() const QgsPointCloud3DSymbol *QgsPointCloud3DSymbolWidget::symbol() const
{ {
QgsPointCloud3DSymbol *symb = new QgsPointCloud3DSymbol;
QgsPointCloud3DSymbol *ret_symb = nullptr;
QgsPointCloud3DSymbol::RenderingStyle renderingStyle = static_cast< QgsPointCloud3DSymbol::RenderingStyle >( mRenderingStyleComboBox->currentIndex() );
switch ( renderingStyle )
{
case QgsPointCloud3DSymbol::RenderingStyle::SingleColor:
{
QgsSingleColorPointCloud3DSymbol *symb = new QgsSingleColorPointCloud3DSymbol;
symb->setPointSize( mPointSizeSpinBox->value() ); symb->setPointSize( mPointSizeSpinBox->value() );
symb->setRenderingStyle( static_cast< QgsPointCloud3DSymbol::RenderingStyle >( mRenderingStyleComboBox->currentIndex() ) );
symb->setRenderingParameter( static_cast< QgsPointCloud3DSymbol::RenderingParameter >( mRenderingParameterComboBox->currentIndex() ) );
symb->setSingleColor( mSingleColorBtn->color() ); symb->setSingleColor( mSingleColorBtn->color() );
ret_symb = symb;
break;
}
case QgsPointCloud3DSymbol::RenderingStyle::ColorRamp:
{
QgsColorRampPointCloud3DSymbol *symb = new QgsColorRampPointCloud3DSymbol;
symb->setRenderingParameter( static_cast< QgsColorRampPointCloud3DSymbol::RenderingParameter >( mRenderingParameterComboBox->currentIndex() ) );
symb->setPointSize( mPointSizeSpinBox->value() );
symb->setColorRampShader( mColorRampShaderWidget->shader() ); symb->setColorRampShader( mColorRampShaderWidget->shader() );
symb->setColorRampShaderMinMax( mColorRampShaderMinEdit->value(), mColorRampShaderMaxEdit->value() ); symb->setColorRampShaderMinMax( mColorRampShaderMinEdit->value(), mColorRampShaderMaxEdit->value() );
return symb; ret_symb = symb;
break;
}
}
return ret_symb;
} }
void QgsPointCloud3DSymbolWidget::setColorRampMinMax( double min, double max ) void QgsPointCloud3DSymbolWidget::setColorRampMinMax( double min, double max )