Skip to content

Commit

Permalink
When a point cloud is first added to a project, default to setting
Browse files Browse the repository at this point in the history
a 3d renderer on it to match its 2d renderer

It just makes sense!
  • Loading branch information
nyalldawson committed Dec 9, 2020
1 parent 56169d3 commit 3930790
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 41 deletions.
24 changes: 12 additions & 12 deletions python/3d/auto_generated/symbols/qgspointcloud3dsymbol.sip.in
Expand Up @@ -158,18 +158,18 @@ Constructor for QgsColorRampPointCloud3DSymbol
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );


QString renderingParameter() const;
QString attribute() const;
%Docstring
Returns the parameter used to select the color of the point cloud
Returns the attribute used to select the color of the point cloud.

.. seealso:: :py:func:`setRenderingParameter`
.. seealso:: :py:func:`setAttribute`
%End

void setRenderingParameter( const QString &parameter );
void setAttribute( const QString &attribute );
%Docstring
Sets the parameter used to select the color of the point cloud
Sets the ``attribute`` used to select the color of the point cloud.

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

QgsColorRampShader colorRampShader() const;
Expand Down Expand Up @@ -424,18 +424,18 @@ Constructor for QgsClassificationPointCloud3DSymbol
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );


QString renderingParameter() const;
QString attribute() const;
%Docstring
Returns the parameter used to select the color of the point cloud
Returns the attribute used to select the color of the point cloud.

.. seealso:: :py:func:`setRenderingParameter`
.. seealso:: :py:func:`setAttribute`
%End

void setRenderingParameter( const QString &parameter );
void setAttribute( const QString &attribute );
%Docstring
Sets the parameter used to select the color of the point cloud
Sets the ``attribute`` used to select the color of the point cloud.

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

QgsPointCloudCategoryList categoriesList() const;
Expand Down
10 changes: 5 additions & 5 deletions src/3d/symbols/qgspointcloud3dsymbol.cpp
Expand Up @@ -139,12 +139,12 @@ void QgsColorRampPointCloud3DSymbol::readXml( const QDomElement &elem, const Qgs
mColorRampShader.readXml( elem );
}

QString QgsColorRampPointCloud3DSymbol::renderingParameter() const
QString QgsColorRampPointCloud3DSymbol::attribute() const
{
return mRenderingParameter;
}

void QgsColorRampPointCloud3DSymbol::setRenderingParameter( const QString &parameter )
void QgsColorRampPointCloud3DSymbol::setAttribute( const QString &parameter )
{
mRenderingParameter = parameter;
}
Expand Down Expand Up @@ -440,14 +440,14 @@ void QgsClassificationPointCloud3DSymbol::readXml( const QDomElement &elem, cons
}
}

QString QgsClassificationPointCloud3DSymbol::renderingParameter() const
QString QgsClassificationPointCloud3DSymbol::attribute() const
{
return mRenderingParameter;
}

void QgsClassificationPointCloud3DSymbol::setRenderingParameter( const QString &parameter )
void QgsClassificationPointCloud3DSymbol::setAttribute( const QString &attribute )
{
mRenderingParameter = parameter;
mRenderingParameter = attribute;
}

void QgsClassificationPointCloud3DSymbol::setCategoriesList( const QgsPointCloudCategoryList &categories )
Expand Down
24 changes: 12 additions & 12 deletions src/3d/symbols/qgspointcloud3dsymbol.h
Expand Up @@ -150,16 +150,16 @@ class _3D_EXPORT QgsColorRampPointCloud3DSymbol : public QgsPointCloud3DSymbol
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;

/**
* Returns the parameter used to select the color of the point cloud
* \see setRenderingParameter( const QString &parameter )
* Returns the attribute used to select the color of the point cloud.
* \see setAttribute()
*/
QString renderingParameter() const;
QString attribute() const;

/**
* Sets the parameter used to select the color of the point cloud
* \see renderingParameter()
* Sets the \a attribute used to select the color of the point cloud.
* \see attribute()
*/
void setRenderingParameter( const QString &parameter );
void setAttribute( const QString &attribute );

/**
* Returns the color ramp shader used to render the color
Expand Down Expand Up @@ -383,16 +383,16 @@ class _3D_EXPORT QgsClassificationPointCloud3DSymbol : public QgsPointCloud3DSym
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;

/**
* Returns the parameter used to select the color of the point cloud
* \see setRenderingParameter( const QString &parameter )
* Returns the attribute used to select the color of the point cloud.
* \see setAttribute()
*/
QString renderingParameter() const;
QString attribute() const;

/**
* Sets the parameter used to select the color of the point cloud
* \see renderingParameter()
* Sets the \a attribute used to select the color of the point cloud.
* \see attribute()
*/
void setRenderingParameter( const QString &parameter );
void setAttribute( const QString &attribute );

/**
* Returns the list of categories of the classification
Expand Down
16 changes: 8 additions & 8 deletions src/3d/symbols/qgspointcloud3dsymbol_p.cpp
Expand Up @@ -320,21 +320,21 @@ void QgsColorRampPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc,
int offset = 0;
QgsPointCloudAttributeCollection collection = context.attributes();

if ( symbol->renderingParameter() == QLatin1String( "X" ) )
if ( symbol->attribute() == QLatin1String( "X" ) )
{
attrIsX = true;
}
else if ( symbol->renderingParameter() == QLatin1String( "Y" ) )
else if ( symbol->attribute() == QLatin1String( "Y" ) )
{
attrIsY = true;
}
else if ( symbol->renderingParameter() == QLatin1String( "Z" ) )
else if ( symbol->attribute() == QLatin1String( "Z" ) )
{
attrIsZ = true;
}
else
{
const QgsPointCloudAttribute *attr = collection.find( symbol->renderingParameter(), offset );
const QgsPointCloudAttribute *attr = collection.find( symbol->attribute(), offset );
if ( attr )
{
attributeType = attr->type();
Expand Down Expand Up @@ -555,21 +555,21 @@ void QgsClassificationPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex
int offset = 0;
QgsPointCloudAttributeCollection collection = context.attributes();

if ( symbol->renderingParameter() == QLatin1String( "X" ) )
if ( symbol->attribute() == QLatin1String( "X" ) )
{
attrIsX = true;
}
else if ( symbol->renderingParameter() == QLatin1String( "Y" ) )
else if ( symbol->attribute() == QLatin1String( "Y" ) )
{
attrIsY = true;
}
else if ( symbol->renderingParameter() == QLatin1String( "Z" ) )
else if ( symbol->attribute() == QLatin1String( "Z" ) )
{
attrIsZ = true;
}
else
{
const QgsPointCloudAttribute *attr = collection.find( symbol->renderingParameter(), offset );
const QgsPointCloudAttribute *attr = collection.find( symbol->attribute(), offset );
if ( attr )
{
attributeType = attr->type();
Expand Down
53 changes: 53 additions & 0 deletions src/app/3d/qgs3dapputils.cpp
Expand Up @@ -27,6 +27,12 @@
#include "qgssimplelinematerialwidget.h"
#include "qgsnullmaterialwidget.h"
#include "qgs3dicongenerator.h"
#include "qgspointcloudrenderer.h"
#include "qgspointcloud3dsymbol.h"
#include "qgspointcloudlayer3drenderer.h"
#include "qgspointcloudrgbrenderer.h"
#include "qgspointcloudattributebyramprenderer.h"
#include "qgspointcloudclassifiedrenderer.h"

void Qgs3DAppUtils::initialize()
{
Expand All @@ -42,3 +48,50 @@ void Qgs3DAppUtils::initialize()

QgsStyleModel::setIconGenerator( new Qgs3DIconGenerator( QgsApplication::defaultStyleModel() ) );
}

std::unique_ptr<QgsPointCloudLayer3DRenderer> Qgs3DAppUtils::convert2dPointCloudRendererTo3d( QgsPointCloudRenderer *renderer )
{
if ( !renderer )
return nullptr;

std::unique_ptr< QgsPointCloud3DSymbol > symbol3D;
if ( renderer->type() == QLatin1String( "ramp" ) )
{
const QgsPointCloudAttributeByRampRenderer *renderer2d = dynamic_cast< const QgsPointCloudAttributeByRampRenderer * >( renderer );
symbol3D = qgis::make_unique< QgsColorRampPointCloud3DSymbol >();
QgsColorRampPointCloud3DSymbol *symbol = static_cast< QgsColorRampPointCloud3DSymbol * >( symbol3D.get() );
symbol->setAttribute( renderer2d->attribute() );
symbol->setColorRampShaderMinMax( renderer2d->minimum(), renderer2d->maximum() );
symbol->setColorRampShader( renderer2d->colorRampShader() );
}
else if ( renderer->type() == QLatin1String( "rgb" ) )
{
const QgsPointCloudRgbRenderer *renderer2d = dynamic_cast< const QgsPointCloudRgbRenderer * >( renderer );
symbol3D = qgis::make_unique< QgsRgbPointCloud3DSymbol >();
QgsRgbPointCloud3DSymbol *symbol = static_cast< QgsRgbPointCloud3DSymbol * >( symbol3D.get() );
symbol->setRedAttribute( renderer2d->redAttribute() );
symbol->setGreenAttribute( renderer2d->greenAttribute() );
symbol->setBlueAttribute( renderer2d->blueAttribute() );

symbol->setRedContrastEnhancement( renderer2d->redContrastEnhancement() ? new QgsContrastEnhancement( *renderer2d->redContrastEnhancement() ) : nullptr );
symbol->setGreenContrastEnhancement( renderer2d->greenContrastEnhancement() ? new QgsContrastEnhancement( *renderer2d->greenContrastEnhancement() ) : nullptr );
symbol->setBlueContrastEnhancement( renderer2d->blueContrastEnhancement() ? new QgsContrastEnhancement( *renderer2d->blueContrastEnhancement() ) : nullptr );
}
else if ( renderer->type() == QLatin1String( "classification" ) )
{

const QgsPointCloudClassifiedRenderer *renderer2d = dynamic_cast< const QgsPointCloudClassifiedRenderer * >( renderer );
symbol3D = qgis::make_unique< QgsClassificationPointCloud3DSymbol >();
QgsClassificationPointCloud3DSymbol *symbol = static_cast< QgsClassificationPointCloud3DSymbol * >( symbol3D.get() );
symbol->setAttribute( renderer2d->attribute() );
symbol->setCategoriesList( renderer2d->categories() );
}

if ( symbol3D )
{
std::unique_ptr< QgsPointCloudLayer3DRenderer > renderer3D = qgis::make_unique< QgsPointCloudLayer3DRenderer >();
renderer3D->setSymbol( symbol3D.release() );
return renderer3D;
}
return nullptr;
}
7 changes: 7 additions & 0 deletions src/app/3d/qgs3dapputils.h
Expand Up @@ -16,6 +16,11 @@
#ifndef QGS3DAPPUTILS_H
#define QGS3DAPPUTILS_H

#include <memory>

class QgsPointCloudLayer3DRenderer;
class QgsPointCloudRenderer;

class Qgs3DAppUtils
{
public:
Expand All @@ -25,6 +30,8 @@ class Qgs3DAppUtils
*/
static void initialize();

static std::unique_ptr< QgsPointCloudLayer3DRenderer > convert2dPointCloudRendererTo3d( QgsPointCloudRenderer *renderer );

};

#endif // QGS3DAPPUTILS_H
8 changes: 4 additions & 4 deletions src/app/3d/qgspointcloud3dsymbolwidget.cpp
Expand Up @@ -138,7 +138,7 @@ void QgsPointCloud3DSymbolWidget::setSymbol( QgsPointCloud3DSymbol *symbol )
mStackedWidget->setCurrentIndex( 2 );
QgsColorRampPointCloud3DSymbol *symb = dynamic_cast<QgsColorRampPointCloud3DSymbol *>( symbol );

mRenderingParameterComboBox->setAttribute( symb->renderingParameter() );
mRenderingParameterComboBox->setAttribute( symb->attribute() );

mColorRampShaderMinEdit->setValue( symb->colorRampShaderMin() );
mColorRampShaderMaxEdit->setValue( symb->colorRampShaderMax() );
Expand All @@ -165,7 +165,7 @@ void QgsPointCloud3DSymbolWidget::setSymbol( QgsPointCloud3DSymbol *symbol )
{
mStackedWidget->setCurrentIndex( 4 );
QgsClassificationPointCloud3DSymbol *symb = dynamic_cast<QgsClassificationPointCloud3DSymbol *>( symbol );
mClassifiedRendererWidget->setFromCategories( symb->categoriesList(), symb->renderingParameter() );
mClassifiedRendererWidget->setFromCategories( symb->categoriesList(), symb->attribute() );
}
else
{
Expand Down Expand Up @@ -196,7 +196,7 @@ QgsPointCloud3DSymbol *QgsPointCloud3DSymbolWidget::symbol() const
else if ( symbolType == QLatin1String( "color-ramp" ) )
{
QgsColorRampPointCloud3DSymbol *symb = new QgsColorRampPointCloud3DSymbol;
symb->setRenderingParameter( mRenderingParameterComboBox->currentText() );
symb->setAttribute( mRenderingParameterComboBox->currentText() );
symb->setPointSize( mPointSizeSpinBox->value() );
symb->setColorRampShader( mColorRampShaderWidget->shader() );
symb->setColorRampShaderMinMax( mColorRampShaderMinEdit->value(), mColorRampShaderMaxEdit->value() );
Expand All @@ -219,7 +219,7 @@ QgsPointCloud3DSymbol *QgsPointCloud3DSymbolWidget::symbol() const
QgsClassificationPointCloud3DSymbol *symb = new QgsClassificationPointCloud3DSymbol;
symb->setPointSize( mPointSizeSpinBox->value() );

symb->setRenderingParameter( mClassifiedRendererWidget->attribute() );
symb->setAttribute( mClassifiedRendererWidget->attribute() );
symb->setCategoriesList( mClassifiedRendererWidget->categoriesList() );
retSymb = symb;
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -5819,6 +5819,14 @@ QgsPointCloudLayer *QgisApp::addPointCloudLayerPrivate( const QString &uri, cons
layer->loadDefaultStyle( ok );
layer->loadDefaultMetadata( ok );

if ( !layer->renderer3D() )
{
// for point clouds we default to a 3d renderer. it just makes sense :)
std::unique_ptr< QgsPointCloudLayer3DRenderer > renderer3D = Qgs3DAppUtils::convert2dPointCloudRendererTo3d( layer->renderer() );
if ( renderer3D )
layer->setRenderer3D( renderer3D.release() );
}

QgsProject::instance()->addMapLayer( layer.get() );
activateDeactivateLayerRelatedActions( activeLayer() );

Expand Down

0 comments on commit 3930790

Please sign in to comment.