Skip to content

Commit

Permalink
[pointclouds] Expose option to set point size for 2d point cloud renders
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and PeterPetrik committed Nov 19, 2020
1 parent 2c1468a commit acbeebe
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 39 deletions.
89 changes: 89 additions & 0 deletions python/core/auto_generated/pointcloud/qgspointcloudrenderer.sip.in
Expand Up @@ -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. the renderer should instead be cloned and :py:func:`~QgsPointCloudRenderer.startRender`/:py:func:`~QgsPointCloudRenderer.stopRender` called on the clone.


.. seealso:: :py:func:`startRender` .. 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 %End


double maximumScreenError() const; double maximumScreenError() const;
Expand Down Expand Up @@ -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 ); static void pointXY( QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y );
%Docstring %Docstring
Retrieves the x and y coordinate for the point at index ``i``. 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 %End


private: private:
Expand Down
Expand Up @@ -46,16 +46,6 @@ Constructor for QgsPointCloudRgbRenderer.
static QgsPointCloudRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) /Factory/; static QgsPointCloudRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) /Factory/;
%Docstring %Docstring
Creates an RGB renderer from an XML ``element``. 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 %End


QString redAttribute() const; QString redAttribute() const;
Expand Down
29 changes: 29 additions & 0 deletions src/core/pointcloud/qgspointcloudrenderer.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgspointcloudrenderer.h" #include "qgspointcloudrenderer.h"
#include "qgspointcloudrendererregistry.h" #include "qgspointcloudrendererregistry.h"
#include "qgsapplication.h" #include "qgsapplication.h"
#include "qgssymbollayerutils.h"


QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset ) QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset )
: mRenderContext( context ) : mRenderContext( context )
Expand Down Expand Up @@ -109,6 +110,34 @@ void QgsPointCloudRenderer::setMaximumScreenErrorUnit( QgsUnitTypes::RenderUnit
mMaximumScreenErrorUnit = unit; 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 ///@cond PRIVATE
Expand Down
78 changes: 78 additions & 0 deletions src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -238,6 +238,58 @@ class CORE_EXPORT QgsPointCloudRenderer
*/ */
virtual void stopRender( QgsPointCloudRenderContext &context ); 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. * Returns the maximum screen error allowed when rendering the point cloud.
* *
Expand Down Expand Up @@ -292,6 +344,27 @@ class CORE_EXPORT QgsPointCloudRenderer
y = context.offset().y() + context.scale().y() * iy; 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: private:
#ifdef SIP_RUN #ifdef SIP_RUN
QgsPointCloudRenderer( const QgsPointCloudRenderer &other ); QgsPointCloudRenderer( const QgsPointCloudRenderer &other );
Expand All @@ -304,6 +377,11 @@ class CORE_EXPORT QgsPointCloudRenderer


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

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

}; };


#ifndef SIP_RUN #ifndef SIP_RUN
Expand Down
28 changes: 6 additions & 22 deletions src/core/pointcloud/qgspointcloudrgbrenderer.cpp
Expand Up @@ -32,7 +32,6 @@ QString QgsPointCloudRgbRenderer::type() const
QgsPointCloudRenderer *QgsPointCloudRgbRenderer::clone() const QgsPointCloudRenderer *QgsPointCloudRgbRenderer::clone() const
{ {
std::unique_ptr< QgsPointCloudRgbRenderer > res = qgis::make_unique< QgsPointCloudRgbRenderer >(); std::unique_ptr< QgsPointCloudRgbRenderer > res = qgis::make_unique< QgsPointCloudRgbRenderer >();
res->mPenWidth = penWidth();
res->mRedAttribute = mRedAttribute; res->mRedAttribute = mRedAttribute;
res->mGreenAttribute = mGreenAttribute; res->mGreenAttribute = mGreenAttribute;
res->mBlueAttribute = mBlueAttribute; res->mBlueAttribute = mBlueAttribute;
Expand All @@ -50,8 +49,7 @@ QgsPointCloudRenderer *QgsPointCloudRgbRenderer::clone() const
res->setBlueContrastEnhancement( new QgsContrastEnhancement( *mBlueContrastEnhancement ) ); res->setBlueContrastEnhancement( new QgsContrastEnhancement( *mBlueContrastEnhancement ) );
} }


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


return res.release(); return res.release();
} }
Expand Down Expand Up @@ -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 >(); 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->setRedAttribute( element.attribute( QStringLiteral( "red" ), QStringLiteral( "Red" ) ) );
r->setGreenAttribute( element.attribute( QStringLiteral( "green" ), QStringLiteral( "Green" ) ) ); r->setGreenAttribute( element.attribute( QStringLiteral( "green" ), QStringLiteral( "Green" ) ) );
r->setBlueAttribute( element.attribute( QStringLiteral( "blue" ), QStringLiteral( "Blue" ) ) ); r->setBlueAttribute( element.attribute( QStringLiteral( "blue" ), QStringLiteral( "Blue" ) ) );


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


//contrast enhancements //contrast enhancements
QgsContrastEnhancement *redContrastEnhancement = nullptr; QgsContrastEnhancement *redContrastEnhancement = nullptr;
Expand Down Expand Up @@ -250,19 +246,17 @@ QgsPointCloudRenderer *QgsPointCloudRgbRenderer::create( QDomElement &element, c
return r.release(); 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" ) ); QDomElement rendererElem = doc.createElement( QStringLiteral( "renderer" ) );


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


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


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


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


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


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


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

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

QString QgsPointCloudRgbRenderer::redAttribute() const QString QgsPointCloudRgbRenderer::redAttribute() const
{ {
return mRedAttribute; return mRedAttribute;
Expand Down
7 changes: 0 additions & 7 deletions src/core/pointcloud/qgspointcloudrgbrenderer.h
Expand Up @@ -52,12 +52,6 @@ class CORE_EXPORT QgsPointCloudRgbRenderer : public QgsPointCloudRenderer
*/ */
static QgsPointCloudRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY; 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. * Returns the attribute to use for the red channel.
* *
Expand Down Expand Up @@ -174,7 +168,6 @@ class CORE_EXPORT QgsPointCloudRgbRenderer : public QgsPointCloudRenderer


private: private:


int mPenWidth = 1;
int mPainterPenWidth = 1; int mPainterPenWidth = 1;


QString mRedAttribute = QStringLiteral( "Red" ); QString mRedAttribute = QStringLiteral( "Red" );
Expand Down

0 comments on commit acbeebe

Please sign in to comment.