Skip to content
Permalink
Browse files

[pointclouds] Expose option to set point size for 2d point cloud renders

  • Loading branch information
nyalldawson authored and PeterPetrik committed Nov 19, 2020
1 parent 2c1468a commit acbeebe32a08e01dd524296640a6e5ca0091e36e
@@ -203,6 +203,74 @@ Calls to :py:func:`~QgsPointCloudRenderer.stopRender` must always be preceded by
the renderer should instead be cloned and :py:func:`~QgsPointCloudRenderer.startRender`/:py:func:`~QgsPointCloudRenderer.stopRender` called on the clone.

.. seealso:: :py:func:`startRender`
%End

void setPointSize( double size );
%Docstring
Sets the point ``size``. Point size units are specified via :py:func:`~QgsPointCloudRenderer.setPointSizeUnit`.

.. seealso:: :py:func:`pointSize`

.. seealso:: :py:func:`setPointSizeUnit`

.. seealso:: :py:func:`setPointSizeMapUnitScale`
%End

double pointSize() const;
%Docstring
Returns the point size.

The point size units are retrieved by calling :py:func:`~QgsPointCloudRenderer.pointSizeUnit`.

.. seealso:: :py:func:`setPointSize`

.. seealso:: :py:func:`pointSizeUnit`

.. seealso:: :py:func:`pointSizeMapUnitScale`
%End

void setPointSizeUnit( const QgsUnitTypes::RenderUnit units );
%Docstring
Sets the ``units`` used for the point size.

.. seealso:: :py:func:`setPointSize`

.. seealso:: :py:func:`pointSizeUnit`

.. seealso:: :py:func:`setPointSizeMapUnitScale`
%End

QgsUnitTypes::RenderUnit pointSizeUnit() const;
%Docstring
Returns the units used for the point size.

.. seealso:: :py:func:`setPointSizeUnit`

.. seealso:: :py:func:`pointSize`

.. seealso:: :py:func:`pointSizeMapUnitScale`
%End

void setPointSizeMapUnitScale( const QgsMapUnitScale &scale );
%Docstring
Sets the map unit ``scale`` used for the point size.

.. seealso:: :py:func:`pointSizeMapUnitScale`

.. seealso:: :py:func:`setPointSize`

.. seealso:: :py:func:`setPointSizeUnit`
%End

const QgsMapUnitScale &pointSizeMapUnitScale() const;
%Docstring
Returns the map unit scale used for the point size.

.. seealso:: :py:func:`setPointSizeMapUnitScale`

.. seealso:: :py:func:`pointSizeUnit`

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

double maximumScreenError() const;
@@ -254,6 +322,27 @@ Sets the ``unit`` for the maximum screen error allowed when rendering the point
static void pointXY( QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y );
%Docstring
Retrieves the x and y coordinate for the point at index ``i``.
%End

void copyCommonProperties( QgsPointCloudRenderer *destination ) const;
%Docstring
Copies common point cloud properties (such as point size and screen error) to the ``destination`` renderer.
%End

void restoreCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );
%Docstring
Restores common renderer properties (such as point size and screen error) from the
specified DOM ``element``.

.. seealso:: :py:func:`saveCommonProperties`
%End

void saveCommonProperties( QDomElement &element, const QgsReadWriteContext &context ) const;
%Docstring
Saves common renderer properties (such as point size and screen error) to the
specified DOM ``element``.

.. seealso:: :py:func:`restoreCommonProperties`
%End

private:
@@ -46,16 +46,6 @@ Constructor for QgsPointCloudRgbRenderer.
static QgsPointCloudRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) /Factory/;
%Docstring
Creates an RGB renderer from an XML ``element``.
%End

int penWidth() const;
%Docstring
Returns pen width
%End

void setPenWidth( int value );
%Docstring
Sets pen width
%End

QString redAttribute() const;
@@ -18,6 +18,7 @@
#include "qgspointcloudrenderer.h"
#include "qgspointcloudrendererregistry.h"
#include "qgsapplication.h"
#include "qgssymbollayerutils.h"

QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset )
: mRenderContext( context )
@@ -109,6 +110,34 @@ void QgsPointCloudRenderer::setMaximumScreenErrorUnit( QgsUnitTypes::RenderUnit
mMaximumScreenErrorUnit = unit;
}

void QgsPointCloudRenderer::copyCommonProperties( QgsPointCloudRenderer *destination ) const
{
destination->setPointSize( mPointSize );
destination->setPointSizeUnit( mPointSizeUnit );
destination->setPointSizeMapUnitScale( mPointSizeMapUnitScale );
destination->setMaximumScreenError( mMaximumScreenError );
destination->setMaximumScreenErrorUnit( mMaximumScreenErrorUnit );
}

void QgsPointCloudRenderer::restoreCommonProperties( const QDomElement &element, const QgsReadWriteContext & )
{
mPointSize = element.attribute( QStringLiteral( "pointSize" ), QStringLiteral( "1" ) ).toDouble();
mPointSizeUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( QStringLiteral( "pointSizeUnit" ), QStringLiteral( "MM" ) ) );
mPointSizeMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( element.attribute( QStringLiteral( "pointSizeMapUnitScale" ), QString() ) );

mMaximumScreenError = element.attribute( QStringLiteral( "maximumScreenError" ), QStringLiteral( "5" ) ).toDouble();
mMaximumScreenErrorUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( QStringLiteral( "maximumScreenErrorUnit" ), QStringLiteral( "MM" ) ) );
}

void QgsPointCloudRenderer::saveCommonProperties( QDomElement &element, const QgsReadWriteContext & ) const
{
element.setAttribute( QStringLiteral( "pointSize" ), qgsDoubleToString( mPointSize ) );
element.setAttribute( QStringLiteral( "pointSizeUnit" ), QgsUnitTypes::encodeUnit( mPointSizeUnit ) );
element.setAttribute( QStringLiteral( "pointSizeMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( mPointSizeMapUnitScale ) );

element.setAttribute( QStringLiteral( "maximumScreenError" ), qgsDoubleToString( mMaximumScreenError ) );
element.setAttribute( QStringLiteral( "maximumScreenErrorUnit" ), QgsUnitTypes::encodeUnit( mMaximumScreenErrorUnit ) );
}


///@cond PRIVATE
@@ -238,6 +238,58 @@ class CORE_EXPORT QgsPointCloudRenderer
*/
virtual void stopRender( QgsPointCloudRenderContext &context );

/**
* Sets the point \a size. Point size units are specified via setPointSizeUnit().
* \see pointSize()
* \see setPointSizeUnit()
* \see setPointSizeMapUnitScale()
*/
void setPointSize( double size ) { mPointSize = size; }

/**
* Returns the point size.
*
* The point size units are retrieved by calling pointSizeUnit().
*
* \see setPointSize()
* \see pointSizeUnit()
* \see pointSizeMapUnitScale()
*/
double pointSize() const { return mPointSize; }

/**
* Sets the \a units used for the point size.
*
* \see setPointSize()
* \see pointSizeUnit()
* \see setPointSizeMapUnitScale()
*/
void setPointSizeUnit( const QgsUnitTypes::RenderUnit units ) { mPointSizeUnit = units; }

/**
* Returns the units used for the point size.
* \see setPointSizeUnit()
* \see pointSize()
* \see pointSizeMapUnitScale()
*/
QgsUnitTypes::RenderUnit pointSizeUnit() const { return mPointSizeUnit; }

/**
* Sets the map unit \a scale used for the point size.
* \see pointSizeMapUnitScale()
* \see setPointSize()
* \see setPointSizeUnit()
*/
void setPointSizeMapUnitScale( const QgsMapUnitScale &scale ) { mPointSizeMapUnitScale = scale; }

/**
* Returns the map unit scale used for the point size.
* \see setPointSizeMapUnitScale()
* \see pointSizeUnit()
* \see pointSize()
*/
const QgsMapUnitScale &pointSizeMapUnitScale() const { return mPointSizeMapUnitScale; }

/**
* Returns the maximum screen error allowed when rendering the point cloud.
*
@@ -292,6 +344,27 @@ class CORE_EXPORT QgsPointCloudRenderer
y = context.offset().y() + context.scale().y() * iy;
}

/**
* Copies common point cloud properties (such as point size and screen error) to the \a destination renderer.
*/
void copyCommonProperties( QgsPointCloudRenderer *destination ) const;

/**
* Restores common renderer properties (such as point size and screen error) from the
* specified DOM \a element.
*
* \see saveCommonProperties()
*/
void restoreCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );

/**
* Saves common renderer properties (such as point size and screen error) to the
* specified DOM \a element.
*
* \see restoreCommonProperties()
*/
void saveCommonProperties( QDomElement &element, const QgsReadWriteContext &context ) const;

private:
#ifdef SIP_RUN
QgsPointCloudRenderer( const QgsPointCloudRenderer &other );
@@ -304,6 +377,11 @@ class CORE_EXPORT QgsPointCloudRenderer

double mMaximumScreenError = 5.0;
QgsUnitTypes::RenderUnit mMaximumScreenErrorUnit = QgsUnitTypes::RenderMillimeters;

double mPointSize = 1;
QgsUnitTypes::RenderUnit mPointSizeUnit = QgsUnitTypes::RenderMillimeters;
QgsMapUnitScale mPointSizeMapUnitScale;

};

#ifndef SIP_RUN
@@ -32,7 +32,6 @@ QString QgsPointCloudRgbRenderer::type() const
QgsPointCloudRenderer *QgsPointCloudRgbRenderer::clone() const
{
std::unique_ptr< QgsPointCloudRgbRenderer > res = qgis::make_unique< QgsPointCloudRgbRenderer >();
res->mPenWidth = penWidth();
res->mRedAttribute = mRedAttribute;
res->mGreenAttribute = mGreenAttribute;
res->mBlueAttribute = mBlueAttribute;
@@ -50,8 +49,7 @@ QgsPointCloudRenderer *QgsPointCloudRgbRenderer::clone() const
res->setBlueContrastEnhancement( new QgsContrastEnhancement( *mBlueContrastEnhancement ) );
}

res->setMaximumScreenError( maximumScreenError() );
res->setMaximumScreenErrorUnit( maximumScreenErrorUnit() );
copyCommonProperties( res.get() );

return res.release();
}
@@ -207,17 +205,15 @@ void QgsPointCloudRgbRenderer::renderBlock( const QgsPointCloudBlock *block, Qgs
}


QgsPointCloudRenderer *QgsPointCloudRgbRenderer::create( QDomElement &element, const QgsReadWriteContext & )
QgsPointCloudRenderer *QgsPointCloudRgbRenderer::create( QDomElement &element, const QgsReadWriteContext &context )
{
std::unique_ptr< QgsPointCloudRgbRenderer > r = qgis::make_unique< QgsPointCloudRgbRenderer >();
r->setPenWidth( element.attribute( QStringLiteral( "penwidth" ), QStringLiteral( "1" ) ).toInt() );

r->setRedAttribute( element.attribute( QStringLiteral( "red" ), QStringLiteral( "Red" ) ) );
r->setGreenAttribute( element.attribute( QStringLiteral( "green" ), QStringLiteral( "Green" ) ) );
r->setBlueAttribute( element.attribute( QStringLiteral( "blue" ), QStringLiteral( "Blue" ) ) );

r->setMaximumScreenError( element.attribute( QStringLiteral( "maximumScreenError" ), QStringLiteral( "5" ) ).toDouble() );
r->setMaximumScreenErrorUnit( QgsUnitTypes::decodeRenderUnit( element.attribute( QStringLiteral( "maximumScreenErrorUnit" ), QStringLiteral( "MM" ) ) ) );
r->restoreCommonProperties( element, context );

//contrast enhancements
QgsContrastEnhancement *redContrastEnhancement = nullptr;
@@ -250,19 +246,17 @@ QgsPointCloudRenderer *QgsPointCloudRgbRenderer::create( QDomElement &element, c
return r.release();
}

QDomElement QgsPointCloudRgbRenderer::save( QDomDocument &doc, const QgsReadWriteContext & ) const
QDomElement QgsPointCloudRgbRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
{
QDomElement rendererElem = doc.createElement( QStringLiteral( "renderer" ) );

rendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "rgb" ) );
rendererElem.setAttribute( QStringLiteral( "penwidth" ), mPenWidth );

rendererElem.setAttribute( QStringLiteral( "red" ), mRedAttribute );
rendererElem.setAttribute( QStringLiteral( "green" ), mGreenAttribute );
rendererElem.setAttribute( QStringLiteral( "blue" ), mBlueAttribute );

rendererElem.setAttribute( QStringLiteral( "maximumScreenError" ), qgsDoubleToString( maximumScreenError() ) );
rendererElem.setAttribute( QStringLiteral( "maximumScreenErrorUnit" ), QgsUnitTypes::encodeUnit( maximumScreenErrorUnit() ) );
saveCommonProperties( rendererElem, context );

//contrast enhancement
if ( mRedContrastEnhancement )
@@ -291,7 +285,7 @@ void QgsPointCloudRgbRenderer::startRender( QgsPointCloudRenderContext &context
{
QgsPointCloudRenderer::startRender( context );

mPainterPenWidth = context.renderContext().convertToPainterUnits( mPenWidth, QgsUnitTypes::RenderUnit::RenderMillimeters );
mPainterPenWidth = context.renderContext().convertToPainterUnits( pointSize(), pointSizeUnit(), pointSizeMapUnitScale() );
}

void QgsPointCloudRgbRenderer::stopRender( QgsPointCloudRenderContext &context )
@@ -304,16 +298,6 @@ QSet<QString> QgsPointCloudRgbRenderer::usedAttributes( const QgsPointCloudRende
return QSet<QString>() << mRedAttribute << mGreenAttribute << mBlueAttribute;
}

int QgsPointCloudRgbRenderer::penWidth() const
{
return mPenWidth;
}

void QgsPointCloudRgbRenderer::setPenWidth( int value )
{
mPenWidth = value;
}

QString QgsPointCloudRgbRenderer::redAttribute() const
{
return mRedAttribute;
@@ -52,12 +52,6 @@ class CORE_EXPORT QgsPointCloudRgbRenderer : public QgsPointCloudRenderer
*/
static QgsPointCloudRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;

//! Returns pen width
int penWidth() const;

//! Sets pen width
void setPenWidth( int value );

/**
* Returns the attribute to use for the red channel.
*
@@ -174,7 +168,6 @@ class CORE_EXPORT QgsPointCloudRgbRenderer : public QgsPointCloudRenderer

private:

int mPenWidth = 1;
int mPainterPenWidth = 1;

QString mRedAttribute = QStringLiteral( "Red" );

0 comments on commit acbeebe

Please sign in to comment.
You can’t perform that action at this time.