Skip to content

Commit

Permalink
Split QgsPointCloud3DSymbol into different classes
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Dec 3, 2020
1 parent ae749de commit 3979b47
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 156 deletions.
126 changes: 95 additions & 31 deletions python/3d/auto_generated/symbols/qgspointcloud3dsymbol.sip.in
Expand Up @@ -35,27 +35,18 @@ class QgsPointCloud3DSymbol : QgsAbstract3DSymbol
ColorRamp,
};

enum RenderingParameter
{
Height,
ClassID
};

QgsPointCloud3DSymbol();
QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle style );
%Docstring
Constructor for QgsPointCloud3DSymbol
%End
~QgsPointCloud3DSymbol();

virtual QString type() const;
virtual QgsAbstract3DSymbol *clone() const /Factory/;


virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;


virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );

virtual QString type() const;

bool isEnabled() const;
%Docstring
Expand All @@ -71,6 +62,43 @@ Sets whether rendering for this symbol is enabled
.. seealso:: :py:func:`isEnabled`
%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;
%Docstring
Returns the point size of the point cloud
Expand All @@ -85,46 +113,82 @@ Sets the point size
.. seealso:: :py:func:`pointSize`
%End

QgsPointCloud3DSymbol::RenderingStyle renderingStyle() const;
QColor singleColor() const;
%Docstring
Returns the rendering style
Returns the color used by the renderer when using SingleColor rendering mode

.. seealso:: :py:func:`setRenderingStyle`
.. seealso:: :py:func:`setSingleColor`
%End

void setRenderingStyle( QgsPointCloud3DSymbol::RenderingStyle style );
void setSingleColor( QColor color );
%Docstring
Sets the rendering style
Sets the color used by the renderer when using SingleColor rendering mode

.. seealso:: :py:func:`renderingStyle`
.. seealso:: :py:func:`singleColor`
%End

QgsPointCloud3DSymbol::RenderingParameter renderingParameter() const;
};

class QgsColorRampPointCloud3DSymbol : QgsPointCloud3DSymbol
{
%Docstring
Returns the parameter used to select the color of the point cloud when using color ramp coloring
3D symbol that draws point cloud geometries as 3D objects.using color ramp shader

.. seealso:: :py:func:`setRenderingParameter`
.. 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;

void setRenderingParameter( QgsPointCloud3DSymbol::RenderingParameter parameter );
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );


float pointSize() const;
%Docstring
Sets the parameter used to select the color of the point cloud when using color ramp coloring
Returns the point size of the point cloud

.. seealso:: :py:func:`renderingParameter`
.. seealso:: :py:func:`setPointSize`
%End

QColor singleColor() const;
void setPointSize( float size );
%Docstring
Returns the color used by the renderer when using SingleColor rendering mode
Sets the point size

.. seealso:: :py:func:`setSingleColor`
.. seealso:: :py:func:`pointSize`
%End

void setSingleColor( QColor color );
QgsColorRampPointCloud3DSymbol::RenderingParameter renderingParameter() const;
%Docstring
Sets the color used by the renderer when using SingleColor rendering mode
Returns the parameter used to select the color of the point cloud when using color ramp coloring

.. seealso:: :py:func:`singleColor`
.. 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

QgsColorRampShader colorRampShader() const;
Expand All @@ -134,7 +198,7 @@ Returns the color ramp shader used to render the color

void setColorRampShader( const QgsColorRampShader &colorRampShader );
%Docstring
Sets the color ramp shader used to render the color
Sets the color ramp shader used to render the point cloud
%End

double colorRampShaderMin() const;
Expand All @@ -155,7 +219,7 @@ Returns the maximum value used when classifying colors in the color ramp shader
%Docstring
Sets the minimum and maximum values used when classifying colors in the color ramp shader

.. seealso:: :py:func:`setColorRampShaderMinMax`
.. seealso:: :py:func:`colorRampShaderMin`
%End

};
Expand Down
13 changes: 11 additions & 2 deletions src/3d/qgspointcloudlayer3drenderer.cpp
Expand Up @@ -110,8 +110,17 @@ void QgsPointCloudLayer3DRenderer::readXml( const QDomElement &elem, const QgsRe
mLayerRef = QgsMapLayerRef( elem.attribute( QStringLiteral( "layer" ) ) );

QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
if ( !mSymbol )
mSymbol = qgis::make_unique< QgsPointCloud3DSymbol >();
int renderingStyleInt = elemSymbol.attribute( QStringLiteral( "rendering-style" ), QStringLiteral( "0" ) ).toInt();
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 );
}

Expand Down
81 changes: 53 additions & 28 deletions src/3d/qgspointcloudlayerchunkloader_p.cpp
Expand Up @@ -100,7 +100,7 @@ void QgsPointCloud3DGeometry::makeVertexBuffer( const QgsPointCloud3DSymbolHandl

QgsPointCloud3DSymbolHandler::QgsPointCloud3DSymbolHandler( QgsPointCloud3DSymbol *symbol )
{
mSymbol.reset( symbol );
mSymbol.reset( symbol ) ;
}

bool QgsPointCloud3DSymbolHandler::prepare( const Qgs3DRenderContext &context )
Expand Down Expand Up @@ -170,7 +170,16 @@ void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
Qt3DCore::QTransform *tr = new Qt3DCore::QTransform;

// 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 );
shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral( "qrc:/shaders/pointcloud.vert" ) ) ) );
Expand All @@ -181,7 +190,15 @@ void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const

Qt3DRender::QPointSize *pointSize = new Qt3DRender::QPointSize( renderPass );
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 );

// without this filter the default forward renderer would not render this
Expand Down Expand Up @@ -211,40 +228,48 @@ void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
// cppcheck-suppress memleak
}


Qt3DRender::QMaterial *QgsPointCloud3DSymbolHandler::constructMaterial()
Qt3DRender::QMaterial *QgsPointCloud3DSymbolHandler::constructMaterial( QgsSingleColorPointCloud3DSymbol *symbol )
{
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 );
QColor singleColor = mSymbol->singleColor();
QColor singleColor = symbol->singleColor();
Qt3DRender::QParameter *singleColorParameter = new Qt3DRender::QParameter( "u_singleColor", QVector3D( singleColor.redF(), singleColor.greenF(), singleColor.blueF() ) );
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 );
Qt3DRender::QParameter *renderingParameter = new Qt3DRender::QParameter( "u_renderingParameter", mSymbol->renderingParameter() );
Qt3DRender::QParameter *renderingParameter = new Qt3DRender::QParameter( "u_renderingParameter", symbol->renderingParameter() );
mat->addParameter( renderingParameter );
if ( mSymbol->renderingStyle() == QgsPointCloud3DSymbol::ColorRamp )
QgsColorRampShader colorRampShader = symbol->colorRampShader();
// Create the texture to pass the color ramp
Qt3DRender::QTexture1D *colorRampTexture = nullptr;
if ( colorRampShader.colorRampItemList().count() > 0 )
{
QgsColorRampShader colorRampShader = mSymbol->colorRampShader();
// Create the texture to pass the color ramp
Qt3DRender::QTexture1D *colorRampTexture = nullptr;
if ( colorRampShader.colorRampItemList().count() > 0 )
{
colorRampTexture = new Qt3DRender::QTexture1D( mat );
colorRampTexture->addTextureImage( new QgsColorRampTexture( colorRampShader, 1 ) );
colorRampTexture->setMinificationFilter( Qt3DRender::QTexture1D::Linear );
colorRampTexture->setMagnificationFilter( Qt3DRender::QTexture1D::Linear );
}
// Parameters
Qt3DRender::QParameter *colorRampTextureParameter = new Qt3DRender::QParameter( "u_colorRampTexture", colorRampTexture );
mat->addParameter( colorRampTextureParameter );
Qt3DRender::QParameter *colorRampCountParameter = new Qt3DRender::QParameter( "u_colorRampCount", colorRampShader.colorRampItemList().count() );
mat->addParameter( colorRampCountParameter );
int colorRampType = colorRampShader.colorRampType();
Qt3DRender::QParameter *colorRampTypeParameter = new Qt3DRender::QParameter( "u_colorRampType", colorRampType );
mat->addParameter( colorRampTypeParameter );
colorRampTexture = new Qt3DRender::QTexture1D( mat );
colorRampTexture->addTextureImage( new QgsColorRampTexture( colorRampShader, 1 ) );
colorRampTexture->setMinificationFilter( Qt3DRender::QTexture1D::Linear );
colorRampTexture->setMagnificationFilter( Qt3DRender::QTexture1D::Linear );
}
// Parameters
Qt3DRender::QParameter *colorRampTextureParameter = new Qt3DRender::QParameter( "u_colorRampTexture", colorRampTexture );
mat->addParameter( colorRampTextureParameter );
Qt3DRender::QParameter *colorRampCountParameter = new Qt3DRender::QParameter( "u_colorRampCount", colorRampShader.colorRampItemList().count() );
mat->addParameter( colorRampCountParameter );
int colorRampType = colorRampShader.colorRampType();
Qt3DRender::QParameter *colorRampTypeParameter = new Qt3DRender::QParameter( "u_colorRampType", colorRampType );
mat->addParameter( colorRampTypeParameter );
return mat;
}

Expand Down
3 changes: 2 additions & 1 deletion src/3d/qgspointcloudlayerchunkloader_p.h
Expand Up @@ -78,7 +78,8 @@ class QgsPointCloud3DSymbolHandler // : public QgsFeature3DHandler
//static Qt3DCore::QTransform *transform( QVector3D position, const QgsPoint3DSymbol *symbol );

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 );

Expand Down

0 comments on commit 3979b47

Please sign in to comment.