diff --git a/python/3d/auto_generated/symbols/qgspointcloud3dsymbol.sip.in b/python/3d/auto_generated/symbols/qgspointcloud3dsymbol.sip.in index 35c624d0de7..5874aac13c1 100644 --- a/python/3d/auto_generated/symbols/qgspointcloud3dsymbol.sip.in +++ b/python/3d/auto_generated/symbols/qgspointcloud3dsymbol.sip.in @@ -37,7 +37,7 @@ class QgsPointCloud3DSymbol : QgsAbstract3DSymbol ColorRamp, }; - QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle style ); + QgsPointCloud3DSymbol( QgsPointCloudLayer *layer, QgsPointCloud3DSymbol::RenderingStyle style ); %Docstring Constructor for QgsPointCloud3DSymbol %End @@ -50,6 +50,18 @@ Constructor for QgsPointCloud3DSymbol virtual QString type() const; + QgsPointCloudLayer *layer(); +%Docstring +Returns the point cloud layer object used by the symbol +see setLayer( :py:class:`QgsPointCloudLayer` *layer ) +%End + + void setLayer( QgsPointCloudLayer *layer ); +%Docstring +Sets the point cloud layer object used by the symbol +see :py:func:`~QgsPointCloud3DSymbol.layer` +%End + QgsPointCloud3DSymbol::RenderingStyle renderingStyle() const; %Docstring Returns the rendering style used to render the point cloud @@ -75,7 +87,7 @@ class QgsNoRenderingPointCloud3DSymbol : QgsPointCloud3DSymbol #include "qgspointcloud3dsymbol.h" %End public: - QgsNoRenderingPointCloud3DSymbol(); + QgsNoRenderingPointCloud3DSymbol( QgsPointCloudLayer *layer ); virtual QgsAbstract3DSymbol *clone() const /Factory/; @@ -103,7 +115,7 @@ class QgsSingleColorPointCloud3DSymbol : QgsPointCloud3DSymbol #include "qgspointcloud3dsymbol.h" %End public: - QgsSingleColorPointCloud3DSymbol(); + QgsSingleColorPointCloud3DSymbol( QgsPointCloudLayer *layer ); virtual QgsAbstract3DSymbol *clone() const /Factory/; @@ -160,14 +172,7 @@ class QgsColorRampPointCloud3DSymbol : QgsPointCloud3DSymbol #include "qgspointcloud3dsymbol.h" %End public: - - enum RenderingParameter - { - Height, - ClassID - }; - - QgsColorRampPointCloud3DSymbol(); + QgsColorRampPointCloud3DSymbol( QgsPointCloudLayer *layer ); virtual QgsAbstract3DSymbol *clone() const /Factory/; @@ -191,14 +196,14 @@ Sets the point size .. seealso:: :py:func:`pointSize` %End - QgsColorRampPointCloud3DSymbol::RenderingParameter renderingParameter() const; + QString renderingParameter() const; %Docstring Returns the parameter used to select the color of the point cloud .. seealso:: :py:func:`setRenderingParameter` %End - void setRenderingParameter( QgsColorRampPointCloud3DSymbol::RenderingParameter parameter ); + void setRenderingParameter( const QString ¶meter ); %Docstring Sets the parameter used to select the color of the point cloud @@ -208,11 +213,15 @@ Sets the parameter used to select the color of the point cloud QgsColorRampShader colorRampShader() const; %Docstring Returns the color ramp shader used to render the color + +.. seealso:: :py:func:`setColorRampShader` %End void setColorRampShader( const QgsColorRampShader &colorRampShader ); %Docstring Sets the color ramp shader used to render the point cloud + +.. seealso:: :py:func:`colorRampShader` %End double colorRampShaderMin() const; diff --git a/src/3d/qgspointcloudlayer3drenderer.cpp b/src/3d/qgspointcloudlayer3drenderer.cpp index 18fecf23a85..cfb63ffe48c 100644 --- a/src/3d/qgspointcloudlayer3drenderer.cpp +++ b/src/3d/qgspointcloudlayer3drenderer.cpp @@ -51,6 +51,8 @@ QgsPointCloudLayer3DRenderer::QgsPointCloudLayer3DRenderer( ) void QgsPointCloudLayer3DRenderer::setLayer( QgsPointCloudLayer *layer ) { mLayerRef = QgsMapLayerRef( layer ); + if ( mSymbol ) + mSymbol->setLayer( layer ); } QgsPointCloudLayer *QgsPointCloudLayer3DRenderer::layer() const @@ -117,13 +119,13 @@ void QgsPointCloudLayer3DRenderer::readXml( const QDomElement &elem, const QgsRe switch ( renderingStyle ) { case QgsPointCloud3DSymbol::RenderingStyle::NoRendering: - mSymbol.reset( new QgsSingleColorPointCloud3DSymbol ); + mSymbol.reset( new QgsNoRenderingPointCloud3DSymbol( layer() ) ); break; case QgsPointCloud3DSymbol::RenderingStyle::SingleColor: - mSymbol.reset( new QgsSingleColorPointCloud3DSymbol ); + mSymbol.reset( new QgsSingleColorPointCloud3DSymbol( layer() ) ); break; case QgsPointCloud3DSymbol::RenderingStyle::ColorRamp: - mSymbol.reset( new QgsColorRampPointCloud3DSymbol ); + mSymbol.reset( new QgsColorRampPointCloud3DSymbol( layer() ) ); break; } mSymbol->readXml( elemSymbol, context ); @@ -132,4 +134,5 @@ void QgsPointCloudLayer3DRenderer::readXml( const QDomElement &elem, const QgsRe void QgsPointCloudLayer3DRenderer::resolveReferences( const QgsProject &project ) { mLayerRef.setLayer( project.mapLayer( mLayerRef.layerId ) ); + mSymbol->setLayer( layer() ); } diff --git a/src/3d/qgspointcloudlayerchunkloader_p.cpp b/src/3d/qgspointcloudlayerchunkloader_p.cpp index a5f5c52eba2..c7705a1406a 100644 --- a/src/3d/qgspointcloudlayerchunkloader_p.cpp +++ b/src/3d/qgspointcloudlayerchunkloader_p.cpp @@ -48,7 +48,7 @@ QgsPointCloud3DGeometry::QgsPointCloud3DGeometry( Qt3DCore::QNode *parent, const QgsPointCloud3DSymbolHandler::PointData &data ) : Qt3DRender::QGeometry( parent ) , mPositionAttribute( new Qt3DRender::QAttribute( this ) ) - , mClassAttribute( new Qt3DRender::QAttribute( this ) ) + , mParameterAttribute( new Qt3DRender::QAttribute( this ) ) #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) , mVertexBuffer( new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, this ) ) #else @@ -63,17 +63,16 @@ QgsPointCloud3DGeometry::QgsPointCloud3DGeometry( Qt3DCore::QNode *parent, const mPositionAttribute->setByteOffset( 0 ); mPositionAttribute->setByteStride( 16 ); - mClassAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute ); - mClassAttribute->setBuffer( mVertexBuffer ); - mClassAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float ); - mClassAttribute->setVertexSize( 1 ); - mClassAttribute->setName( "cls" ); - mClassAttribute->setByteOffset( 12 ); - mClassAttribute->setByteStride( 16 ); + mParameterAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute ); + mParameterAttribute->setBuffer( mVertexBuffer ); + mParameterAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float ); + mParameterAttribute->setVertexSize( 1 ); + mParameterAttribute->setName( "vertexParameter" ); + mParameterAttribute->setByteOffset( 12 ); + mParameterAttribute->setByteStride( 16 ); addAttribute( mPositionAttribute ); - addAttribute( mClassAttribute ); - + addAttribute( mParameterAttribute ); makeVertexBuffer( data ); } @@ -84,13 +83,13 @@ void QgsPointCloud3DGeometry::makeVertexBuffer( const QgsPointCloud3DSymbolHandl vertexBufferData.resize( data.positions.size() * 4 * sizeof( float ) ); float *rawVertexArray = reinterpret_cast( vertexBufferData.data() ); int idx = 0; - Q_ASSERT( data.positions.count() == data.classes.count() ); + Q_ASSERT( data.positions.count() == data.parameter.count() ); for ( int i = 0; i < data.positions.size(); ++i ) { rawVertexArray[idx++] = data.positions.at( i ).x(); rawVertexArray[idx++] = data.positions.at( i ).y(); rawVertexArray[idx++] = data.positions.at( i ).z(); - rawVertexArray[idx++] = data.classes.at( i ); + rawVertexArray[idx++] = data.parameter.at( i ); } mVertexCount = data.positions.size(); @@ -115,7 +114,26 @@ void QgsPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const In attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) ); attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Y" ), QgsPointCloudAttribute::Int32 ) ); attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Z" ), QgsPointCloudAttribute::Int32 ) ); - attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Classification" ), QgsPointCloudAttribute::Char ) ); + + std::unique_ptr< QgsPointCloudAttribute > parameterAttribute; + if ( mSymbol.get()->renderingStyle() == QgsPointCloud3DSymbol::ColorRamp ) + { + QgsColorRampPointCloud3DSymbol *symbol = dynamic_cast( mSymbol.get() ); + QgsPointCloudLayer *layer = symbol->layer(); + if ( symbol && layer ) + { + int offset = 0; + const QgsPointCloudAttribute *attr = layer->attributes().find( symbol->renderingParameter(), offset ); + if ( attr ) + { + parameterAttribute.reset( new QgsPointCloudAttribute( attr->name(), attr->type() ) ); + attributes.push_back( *parameterAttribute.get() ); + } + } + } + + +// attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Classification" ), QgsPointCloudAttribute::Char ) ); QgsPointCloudRequest request; request.setAttributes( attributes ); std::unique_ptr block( pc->nodeData( n, request ) ); @@ -134,7 +152,28 @@ void QgsPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const In qint32 ix = *( qint32 * )( ptr + i * recordSize + 0 ); qint32 iy = *( qint32 * )( ptr + i * recordSize + 4 ); qint32 iz = *( qint32 * )( ptr + i * recordSize + 8 ); - char cls = *( char * )( ptr + i * recordSize + 12 ); + float iParam = 0.0f; + if ( parameterAttribute ) + { + switch ( parameterAttribute->type() ) + { + case QgsPointCloudAttribute::DataType::Char: + iParam = *( char * )( ptr + i * recordSize + 12 ); + break; + case QgsPointCloudAttribute::DataType::Float: + iParam = *( float * )( ptr + i * recordSize + 12 ); + break; + case QgsPointCloudAttribute::DataType::Int32: + iParam = *( qint32 * )( ptr + i * recordSize + 12 ); + break; + case QgsPointCloudAttribute::DataType::Short: + iParam = *( short * )( ptr + i * recordSize + 12 ); + break; + case QgsPointCloudAttribute::DataType::Double: + iParam = *( double * )( ptr + i * recordSize + 12 ); + break; + } + } double x = offset.x() + scale.x() * ix; double y = offset.y() + scale.y() * iy; @@ -142,8 +181,11 @@ void QgsPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const In QVector3D point( x, y, z ); QgsVector3D p = context.map().mapToWorldCoordinates( point ); outNormal.positions.push_back( QVector3D( p.x(), p.y(), p.z() ) ); - outNormal.classes.push_back( cls ); + outNormal.parameter.push_back( iParam ); } + qDebug() << "outNormal.positions.size() " << outNormal.positions.size(); + qDebug() << "outNormal.parameter.size() " << outNormal.parameter.size(); + qDebug() << "--------------------------------------------------"; } void QgsPointCloud3DSymbolHandler::finalize( Qt3DCore::QEntity *parent, const Qgs3DRenderContext &context ) @@ -263,8 +305,8 @@ Qt3DRender::QMaterial *QgsPointCloud3DSymbolHandler::constructMaterial( QgsColor mat->addParameter( renderingStyle ); Qt3DRender::QParameter *pointSizeParameter = new Qt3DRender::QParameter( "u_pointSize", QVariant::fromValue( symbol->pointSize() ) ); mat->addParameter( pointSizeParameter ); - Qt3DRender::QParameter *renderingParameter = new Qt3DRender::QParameter( "u_renderingParameter", symbol->renderingParameter() ); - mat->addParameter( renderingParameter ); +// Qt3DRender::QParameter *renderingParameter = new Qt3DRender::QParameter( "u_renderingParameter", symbol->renderingParameter() ); +// mat->addParameter( renderingParameter ); QgsColorRampShader colorRampShader = symbol->colorRampShader(); // Create the texture to pass the color ramp Qt3DRender::QTexture1D *colorRampTexture = nullptr; diff --git a/src/3d/qgspointcloudlayerchunkloader_p.h b/src/3d/qgspointcloudlayerchunkloader_p.h index 250bb494864..810416a1894 100644 --- a/src/3d/qgspointcloudlayerchunkloader_p.h +++ b/src/3d/qgspointcloudlayerchunkloader_p.h @@ -64,7 +64,7 @@ class QgsPointCloud3DSymbolHandler // : public QgsFeature3DHandler struct PointData { QVector positions; // contains triplets of float x,y,z for each point - QVector classes; + QVector parameter; }; protected: @@ -105,7 +105,7 @@ class QgsPointCloud3DGeometry: public Qt3DRender::QGeometry void makeVertexBuffer( const QgsPointCloud3DSymbolHandler::PointData &data ); Qt3DRender::QAttribute *mPositionAttribute = nullptr; - Qt3DRender::QAttribute *mClassAttribute = nullptr; + Qt3DRender::QAttribute *mParameterAttribute = nullptr; Qt3DRender::QBuffer *mVertexBuffer = nullptr; int mVertexCount = 0; }; diff --git a/src/3d/shaders/pointcloud.frag b/src/3d/shaders/pointcloud.frag index 35ff1756f33..2e739b47350 100644 --- a/src/3d/shaders/pointcloud.frag +++ b/src/3d/shaders/pointcloud.frag @@ -1,7 +1,6 @@ #version 150 -in float magnitude; -in float clsid; +in float parameter; out vec4 color; @@ -16,29 +15,29 @@ uniform sampler1D u_colorRampTexture; // // Sets the color ramp value count, used to check the if not void uniform int u_colorRampCount; // -vec4 clsidBasedRendering() -{ - vec4 color; - if ( abs(clsid-2) < 0.1 ) // ground - color = vec4(1,1,0,1); - else if ( abs( clsid - 3 ) < 0.1 ) // low vegetation - color = vec4(0,0.4,0,1); - else if ( abs( clsid - 4 ) < 0.1 ) // medium vegetation - color = vec4(0,0.6,0,1); - else if ( abs( clsid - 5 ) < 0.1 ) // high vegetation - color = vec4(0,1,0,1); - else if ( abs( clsid - 12 ) < 0.1 ) // overlaps - { - color = vec4(1,0,0,1); - discard; // skip overlaps - } - else - { - color = vec4(0,1,1,1); - //discard; - } - return color; -} +//vec4 clsidBasedRendering() +//{ +// vec4 color; +// if ( abs(clsid-2) < 0.1 ) // ground +// color = vec4(1,1,0,1); +// else if ( abs( clsid - 3 ) < 0.1 ) // low vegetation +// color = vec4(0,0.4,0,1); +// else if ( abs( clsid - 4 ) < 0.1 ) // medium vegetation +// color = vec4(0,0.6,0,1); +// else if ( abs( clsid - 5 ) < 0.1 ) // high vegetation +// color = vec4(0,1,0,1); +// else if ( abs( clsid - 12 ) < 0.1 ) // overlaps +// { +// color = vec4(1,0,0,1); +// discard; // skip overlaps +// } +// else +// { +// color = vec4(0,1,1,1); +// //discard; +// } +// return color; +//} vec3 linearColorRamp() { @@ -62,12 +61,12 @@ vec3 linearColorRamp() float value1=colorRampLine1.x; float value2=colorRampLine2.x; - if (magnitude<=value1 ) + if (parameter <= value1 ) return color1; - if (magnitude>value1 && magnitude<=value2) + if (parameter > value1 && parameter <= value2) { - float mixValue=(magnitude-value1)/(value2-value1); + float mixValue=(parameter - value1)/(value2-value1); return mix(color1,color2,mixValue); } } @@ -89,7 +88,7 @@ vec3 discreteColorRamp() vec4 colorRampLine=texelFetch(u_colorRampTexture,i,0); color=colorRampLine.yzw; float value=colorRampLine.x; - if ( isinf(value) || magnitudemRenderingStyle = mRenderingStyle; copyBaseSettings( result ); return result; @@ -54,15 +60,15 @@ void QgsNoRenderingPointCloud3DSymbol::readXml( const QDomElement &elem, const Q // QgsSingleColorPointCloud3DSymbol -QgsSingleColorPointCloud3DSymbol::QgsSingleColorPointCloud3DSymbol() - : QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle::SingleColor ) +QgsSingleColorPointCloud3DSymbol::QgsSingleColorPointCloud3DSymbol( QgsPointCloudLayer *layer ) + : QgsPointCloud3DSymbol( layer, QgsPointCloud3DSymbol::RenderingStyle::SingleColor ) { } QgsAbstract3DSymbol *QgsSingleColorPointCloud3DSymbol::clone() const { - QgsSingleColorPointCloud3DSymbol *result = new QgsSingleColorPointCloud3DSymbol; + QgsSingleColorPointCloud3DSymbol *result = new QgsSingleColorPointCloud3DSymbol( mLayer ); result->mPointSize = mPointSize; result->mRenderingStyle = mRenderingStyle; result->mSingleColor = mSingleColor; @@ -104,15 +110,15 @@ void QgsSingleColorPointCloud3DSymbol::setSingleColor( QColor color ) // QgsColorRampPointCloud3DSymbol -QgsColorRampPointCloud3DSymbol::QgsColorRampPointCloud3DSymbol() - : QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle::ColorRamp ) +QgsColorRampPointCloud3DSymbol::QgsColorRampPointCloud3DSymbol( QgsPointCloudLayer *layer ) + : QgsPointCloud3DSymbol( layer, QgsPointCloud3DSymbol::RenderingStyle::ColorRamp ) { } QgsAbstract3DSymbol *QgsColorRampPointCloud3DSymbol::clone() const { - QgsColorRampPointCloud3DSymbol *result = new QgsColorRampPointCloud3DSymbol; + QgsColorRampPointCloud3DSymbol *result = new QgsColorRampPointCloud3DSymbol( mLayer ); result->mPointSize = mPointSize; result->mRenderingStyle = mRenderingStyle; result->mRenderingParameter = mRenderingParameter; @@ -143,18 +149,18 @@ void QgsColorRampPointCloud3DSymbol::readXml( const QDomElement &elem, const Qgs 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() ); + mRenderingParameter = elem.attribute( "rendering-parameter", QStringLiteral( "0" ) ); mColorRampShaderMin = elem.attribute( QStringLiteral( "color-ramp-shader-min" ), QStringLiteral( "0.0" ) ).toDouble(); mColorRampShaderMax = elem.attribute( QStringLiteral( "color-ramp-shader-max" ), QStringLiteral( "1.0" ) ).toDouble(); mColorRampShader.readXml( elem ); } -QgsColorRampPointCloud3DSymbol::RenderingParameter QgsColorRampPointCloud3DSymbol::renderingParameter() const +QString QgsColorRampPointCloud3DSymbol::renderingParameter() const { return mRenderingParameter; } -void QgsColorRampPointCloud3DSymbol::setRenderingParameter( QgsColorRampPointCloud3DSymbol::RenderingParameter parameter ) +void QgsColorRampPointCloud3DSymbol::setRenderingParameter( const QString ¶meter ) { mRenderingParameter = parameter; } diff --git a/src/3d/symbols/qgspointcloud3dsymbol.h b/src/3d/symbols/qgspointcloud3dsymbol.h index 533300a2671..a44bd86cbe6 100644 --- a/src/3d/symbols/qgspointcloud3dsymbol.h +++ b/src/3d/symbols/qgspointcloud3dsymbol.h @@ -20,6 +20,7 @@ #include "qgsabstract3dsymbol.h" #include "qgscolorrampshader.h" +#include "qgspointcloudlayer.h" /** * \ingroup 3d @@ -48,7 +49,7 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol }; //! Constructor for QgsPointCloud3DSymbol - QgsPointCloud3DSymbol( QgsPointCloud3DSymbol::RenderingStyle style ); + QgsPointCloud3DSymbol( QgsPointCloudLayer *layer, QgsPointCloud3DSymbol::RenderingStyle style ); //! Destructor for QgsPointCloud3DSymbol ~QgsPointCloud3DSymbol() override; @@ -59,11 +60,24 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol QString type() const override { return "pointcloud"; } + /** + * Returns the point cloud layer object used by the symbol + * see setLayer( QgsPointCloudLayer *layer ) + */ + QgsPointCloudLayer *layer() { return mLayer; } + + /** + * Sets the point cloud layer object used by the symbol + * see layer() + */ + void setLayer( QgsPointCloudLayer *layer ); + //! Returns the rendering style used to render the point cloud QgsPointCloud3DSymbol::RenderingStyle renderingStyle() const { return mRenderingStyle; } protected: QgsPointCloud3DSymbol::RenderingStyle mRenderingStyle = QgsPointCloud3DSymbol::NoRendering; + QgsPointCloudLayer *mLayer = nullptr; }; /** @@ -78,7 +92,7 @@ class _3D_EXPORT QgsPointCloud3DSymbol : public QgsAbstract3DSymbol class _3D_EXPORT QgsNoRenderingPointCloud3DSymbol : public QgsPointCloud3DSymbol { public: - QgsNoRenderingPointCloud3DSymbol(); + QgsNoRenderingPointCloud3DSymbol( QgsPointCloudLayer *layer ); QgsAbstract3DSymbol *clone() const override SIP_FACTORY; @@ -98,7 +112,7 @@ class _3D_EXPORT QgsNoRenderingPointCloud3DSymbol : public QgsPointCloud3DSymbol class _3D_EXPORT QgsSingleColorPointCloud3DSymbol : public QgsPointCloud3DSymbol { public: - QgsSingleColorPointCloud3DSymbol(); + QgsSingleColorPointCloud3DSymbol( QgsPointCloudLayer *layer ); QgsAbstract3DSymbol *clone() const override SIP_FACTORY; @@ -146,17 +160,7 @@ class _3D_EXPORT QgsSingleColorPointCloud3DSymbol : public QgsPointCloud3DSymbol class _3D_EXPORT QgsColorRampPointCloud3DSymbol : public QgsPointCloud3DSymbol { public: - - /** - * The value used to select colors from the color ramp - */ - enum RenderingParameter - { - Height = 0, - ClassID - }; - - QgsColorRampPointCloud3DSymbol(); + QgsColorRampPointCloud3DSymbol( QgsPointCloudLayer *layer ); QgsAbstract3DSymbol *clone() const override SIP_FACTORY; @@ -179,21 +183,23 @@ class _3D_EXPORT QgsColorRampPointCloud3DSymbol : public QgsPointCloud3DSymbol * Returns the parameter used to select the color of the point cloud * \see setRenderingParameter( QgsColorRampPointCloud3DSymbol::RenderingParameter parameter ) */ - QgsColorRampPointCloud3DSymbol::RenderingParameter renderingParameter() const; + QString renderingParameter() const; /** * Sets the parameter used to select the color of the point cloud * \see renderingParameter() */ - void setRenderingParameter( QgsColorRampPointCloud3DSymbol::RenderingParameter parameter ); + void setRenderingParameter( const QString ¶meter ); /** * Returns the color ramp shader used to render the color + * \see setColorRampShader( const QgsColorRampShader &colorRampShader ) */ QgsColorRampShader colorRampShader() const; /** * Sets the color ramp shader used to render the point cloud + * \see colorRampShader() */ void setColorRampShader( const QgsColorRampShader &colorRampShader ); @@ -217,7 +223,7 @@ class _3D_EXPORT QgsColorRampPointCloud3DSymbol : public QgsPointCloud3DSymbol private: float mPointSize = 2.0f; - QgsColorRampPointCloud3DSymbol::RenderingParameter mRenderingParameter = QgsColorRampPointCloud3DSymbol::RenderingParameter::Height; + QString mRenderingParameter; QgsColorRampShader mColorRampShader; double mColorRampShaderMin = 0.0; double mColorRampShaderMax = 1.0; diff --git a/src/app/3d/qgspointcloud3dsymbolwidget.cpp b/src/app/3d/qgspointcloud3dsymbolwidget.cpp index e40be3d09fc..d9f81a06bbd 100644 --- a/src/app/3d/qgspointcloud3dsymbolwidget.cpp +++ b/src/app/3d/qgspointcloud3dsymbolwidget.cpp @@ -19,13 +19,19 @@ #include "qgspointcloud3dsymbol.h" #include "qgspointcloudlayer3drenderer.h" -QgsPointCloud3DSymbolWidget::QgsPointCloud3DSymbolWidget( QgsPointCloud3DSymbol *symbol, QWidget *parent ) +QgsPointCloud3DSymbolWidget::QgsPointCloud3DSymbolWidget( QgsPointCloudLayer *layer, QgsPointCloud3DSymbol *symbol, QWidget *parent ) : QWidget( parent ) + , mLayer( layer ) { setupUi( this ); mPointSizeSpinBox->setClearValue( 2.0 ); + for ( QgsPointCloudAttribute attr : layer->attributes().attributes() ) + { + mRenderingParameterComboBox->addItem( attr.name() ); + } + if ( symbol ) setSymbol( symbol ); @@ -53,7 +59,7 @@ void QgsPointCloud3DSymbolWidget::setSymbol( QgsPointCloud3DSymbol *symbol ) { QgsColorRampPointCloud3DSymbol *symb = static_cast( symbol ); mPointSizeSpinBox->setValue( symb->pointSize() ); - mRenderingParameterComboBox->setCurrentIndex( symb->renderingParameter() ); + mRenderingParameterComboBox->setCurrentText( symb->renderingParameter() ); QgsColorRampShader shader = symb->colorRampShader(); setColorRampMinMax( symb->colorRampShaderMin(), symb->colorRampShaderMax() ); mColorRampShaderWidget->setFromShader( symb->colorRampShader() ); @@ -74,12 +80,12 @@ QgsPointCloud3DSymbol *QgsPointCloud3DSymbolWidget::symbol() const { case QgsPointCloud3DSymbol::RenderingStyle::NoRendering: { - ret_symb = new QgsNoRenderingPointCloud3DSymbol; + ret_symb = new QgsNoRenderingPointCloud3DSymbol( mLayer ); break; } case QgsPointCloud3DSymbol::RenderingStyle::SingleColor: { - QgsSingleColorPointCloud3DSymbol *symb = new QgsSingleColorPointCloud3DSymbol; + QgsSingleColorPointCloud3DSymbol *symb = new QgsSingleColorPointCloud3DSymbol( mLayer ); symb->setPointSize( mPointSizeSpinBox->value() ); symb->setSingleColor( mSingleColorBtn->color() ); ret_symb = symb; @@ -87,8 +93,8 @@ QgsPointCloud3DSymbol *QgsPointCloud3DSymbolWidget::symbol() const } case QgsPointCloud3DSymbol::RenderingStyle::ColorRamp: { - QgsColorRampPointCloud3DSymbol *symb = new QgsColorRampPointCloud3DSymbol; - symb->setRenderingParameter( static_cast< QgsColorRampPointCloud3DSymbol::RenderingParameter >( mRenderingParameterComboBox->currentIndex() ) ); + QgsColorRampPointCloud3DSymbol *symb = new QgsColorRampPointCloud3DSymbol( mLayer ); + symb->setRenderingParameter( mRenderingParameterComboBox->currentText() ); symb->setPointSize( mPointSizeSpinBox->value() ); symb->setColorRampShader( mColorRampShaderWidget->shader() ); symb->setColorRampShaderMinMax( mColorRampShaderMinEdit->value(), mColorRampShaderMaxEdit->value() ); diff --git a/src/app/3d/qgspointcloud3dsymbolwidget.h b/src/app/3d/qgspointcloud3dsymbolwidget.h index 3066e432c83..c4516e3dac4 100644 --- a/src/app/3d/qgspointcloud3dsymbolwidget.h +++ b/src/app/3d/qgspointcloud3dsymbolwidget.h @@ -26,7 +26,7 @@ class QgsPointCloud3DSymbolWidget : public QWidget, private Ui::QgsPointCloud3DS Q_OBJECT public: - explicit QgsPointCloud3DSymbolWidget( QgsPointCloud3DSymbol *symbol, QWidget *parent = nullptr ); + explicit QgsPointCloud3DSymbolWidget( QgsPointCloudLayer *layer, QgsPointCloud3DSymbol *symbol, QWidget *parent = nullptr ); void setSymbol( QgsPointCloud3DSymbol *symbol ); @@ -41,6 +41,10 @@ class QgsPointCloud3DSymbolWidget : public QWidget, private Ui::QgsPointCloud3DS private: void setColorRampMinMax( double min, double max ); + + private: + QgsPointCloudLayer *mLayer = nullptr; + }; #endif // QGSPOINTCLOUD3DSYMBOLWIDGET_H diff --git a/src/app/3d/qgspointcloudlayer3drendererwidget.cpp b/src/app/3d/qgspointcloudlayer3drendererwidget.cpp index 177a8491608..96cc4f9097b 100644 --- a/src/app/3d/qgspointcloudlayer3drendererwidget.cpp +++ b/src/app/3d/qgspointcloudlayer3drendererwidget.cpp @@ -32,7 +32,7 @@ QgsPointCloudLayer3DRendererWidget::QgsPointCloudLayer3DRendererWidget( QgsPoint QVBoxLayout *layout = new QVBoxLayout( this ); layout->setContentsMargins( 0, 0, 0, 0 ); - mWidgetPointCloudSymbol = new QgsPointCloud3DSymbolWidget( nullptr, this ); + mWidgetPointCloudSymbol = new QgsPointCloud3DSymbolWidget( layer, nullptr, this ); layout->addWidget( mWidgetPointCloudSymbol ); connect( mWidgetPointCloudSymbol, &QgsPointCloud3DSymbolWidget::changed, this, &QgsPointCloudLayer3DRendererWidget::widgetChanged ); diff --git a/src/ui/3d/qgspointcloud3dsymbolwidget.ui b/src/ui/3d/qgspointcloud3dsymbolwidget.ui index 432a39d0d5f..435bc6cae77 100644 --- a/src/ui/3d/qgspointcloud3dsymbolwidget.ui +++ b/src/ui/3d/qgspointcloud3dsymbolwidget.ui @@ -7,7 +7,7 @@ 0 0 400 - 300 + 310 @@ -175,18 +175,7 @@ - - - - Height - - - - - ClassID - - - +