Skip to content

Commit

Permalink
Move setting for maximum screen error to QgsPointCloudRenderer, expos…
Browse files Browse the repository at this point in the history
…e in GUI
  • Loading branch information
nyalldawson committed Nov 16, 2020
1 parent 28c2788 commit 0d3ccf7
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 9 deletions.
44 changes: 44 additions & 0 deletions python/core/auto_generated/pointcloud/qgspointcloudrenderer.sip.in
Expand Up @@ -200,6 +200,50 @@ 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

double maximumScreenError() const;
%Docstring
Returns the maximum screen error allowed when rendering the point cloud.

Larger values result in a faster render with less points rendered.

Units are retrieved via :py:func:`~QgsPointCloudRenderer.maximumScreenErrorUnit`.

.. seealso:: :py:func:`setMaximumScreenError`

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

void setMaximumScreenError( double error );
%Docstring
Sets the maximum screen ``error`` allowed when rendering the point cloud.

Larger values result in a faster render with less points rendered.

Units are set via :py:func:`~QgsPointCloudRenderer.setMaximumScreenErrorUnit`.

.. seealso:: :py:func:`maximumScreenError`

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

QgsUnitTypes::RenderUnit maximumScreenErrorUnit() const;
%Docstring
Returns the unit for the maximum screen error allowed when rendering the point cloud.

.. seealso:: :py:func:`maximumScreenError`

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

void setMaximumScreenErrorUnit( QgsUnitTypes::RenderUnit unit );
%Docstring
Sets the ``unit`` for the maximum screen error allowed when rendering the point cloud.

.. seealso:: :py:func:`setMaximumScreenError`

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

protected:
Expand Down
3 changes: 1 addition & 2 deletions src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Expand Up @@ -89,8 +89,7 @@ bool QgsPointCloudLayerRenderer::render()

const IndexedPointCloudNode root = pc->root();

// TODO -- move to renderer
float maximumError = 5; // mConfig.maximumScreenError(); // in pixels
const float maximumError = context.renderContext().convertToPainterUnits( mRenderer->maximumScreenError(), mRenderer->maximumScreenErrorUnit() );// in pixels

float rootError = pc->nodeError( root ); // in map coords
double mapUnitsPerPixel = context.renderContext().mapToPixel().mapUnitsPerPixel();
Expand Down
20 changes: 20 additions & 0 deletions src/core/pointcloud/qgspointcloudrenderer.cpp
Expand Up @@ -89,6 +89,26 @@ void QgsPointCloudRenderer::stopRender( QgsPointCloudRenderContext & )
#endif
}

double QgsPointCloudRenderer::maximumScreenError() const
{
return mMaximumScreenError;
}

void QgsPointCloudRenderer::setMaximumScreenError( double error )
{
mMaximumScreenError = error;
}

QgsUnitTypes::RenderUnit QgsPointCloudRenderer::maximumScreenErrorUnit() const
{
return mMaximumScreenErrorUnit;
}

void QgsPointCloudRenderer::setMaximumScreenErrorUnit( QgsUnitTypes::RenderUnit unit )
{
mMaximumScreenErrorUnit = unit;
}



///@cond PRIVATE
Expand Down
43 changes: 43 additions & 0 deletions src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -235,6 +235,46 @@ class CORE_EXPORT QgsPointCloudRenderer
*/
virtual void stopRender( QgsPointCloudRenderContext &context );

/**
* Returns the maximum screen error allowed when rendering the point cloud.
*
* Larger values result in a faster render with less points rendered.
*
* Units are retrieved via maximumScreenErrorUnit().
*
* \see setMaximumScreenError()
* \see maximumScreenErrorUnit()
*/
double maximumScreenError() const;

/**
* Sets the maximum screen \a error allowed when rendering the point cloud.
*
* Larger values result in a faster render with less points rendered.
*
* Units are set via setMaximumScreenErrorUnit().
*
* \see maximumScreenError()
* \see setMaximumScreenErrorUnit()
*/
void setMaximumScreenError( double error );

/**
* Returns the unit for the maximum screen error allowed when rendering the point cloud.
*
* \see maximumScreenError()
* \see setMaximumScreenErrorUnit()
*/
QgsUnitTypes::RenderUnit maximumScreenErrorUnit() const;

/**
* Sets the \a unit for the maximum screen error allowed when rendering the point cloud.
*
* \see setMaximumScreenError()
* \see maximumScreenErrorUnit()
*/
void setMaximumScreenErrorUnit( QgsUnitTypes::RenderUnit unit );

protected:

/**
Expand All @@ -258,6 +298,9 @@ class CORE_EXPORT QgsPointCloudRenderer
//! Pointer to thread in which startRender was first called
QThread *mThread = nullptr;
#endif

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

#ifndef SIP_RUN
Expand Down
8 changes: 8 additions & 0 deletions src/core/pointcloud/qgspointcloudrgbrenderer.cpp
Expand Up @@ -50,6 +50,9 @@ QgsPointCloudRenderer *QgsPointCloudRgbRenderer::clone() const
res->setBlueContrastEnhancement( new QgsContrastEnhancement( *mBlueContrastEnhancement ) );
}

res->setMaximumScreenError( maximumScreenError() );
res->setMaximumScreenErrorUnit( maximumScreenErrorUnit() );

return res.release();
}

Expand Down Expand Up @@ -213,6 +216,8 @@ QgsPointCloudRenderer *QgsPointCloudRgbRenderer::create( QDomElement &element, c
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" ) ) ) );

//contrast enhancements
QgsContrastEnhancement *redContrastEnhancement = nullptr;
Expand Down Expand Up @@ -256,6 +261,9 @@ QDomElement QgsPointCloudRgbRenderer::save( QDomDocument &doc, const QgsReadWrit
rendererElem.setAttribute( QStringLiteral( "green" ), mGreenAttribute );
rendererElem.setAttribute( QStringLiteral( "blue" ), mBlueAttribute );

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

//contrast enhancement
if ( mRedContrastEnhancement )
{
Expand Down
15 changes: 15 additions & 0 deletions src/gui/pointcloud/qgspointcloudrendererpropertieswidget.cpp
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/
#include "qgspointcloudrendererpropertieswidget.h"

#include "qgis.h"
#include "qgspointcloudrendererregistry.h"
#include "qgsapplication.h"
#include "qgssymbolwidgetcontext.h"
Expand All @@ -22,6 +23,8 @@
#include "qgspointcloudrenderer.h"
#include "qgspointcloudrgbrendererwidget.h"

#include "qgspointcloudrgbrenderer.h"

static bool _initRenderer( const QString &name, QgsPointCloudRendererWidgetFunc f, const QString &iconName = QString() )
{
QgsPointCloudRendererRegistry *reg = QgsApplication::pointCloudRendererRegistry();
Expand Down Expand Up @@ -82,6 +85,12 @@ QgsPointCloudRendererPropertiesWidget::QgsPointCloudRendererPropertiesWidget( Qg
connect( mBlendModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );

mMaxErrorUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMetersInMapUnits << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );

connect( mMaxErrorSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ), this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );
connect( mMaxErrorUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointCloudRendererPropertiesWidget::emitWidgetChanged );

syncToLayer( layer );
}

Expand Down Expand Up @@ -113,6 +122,9 @@ void QgsPointCloudRendererPropertiesWidget::syncToLayer( QgsMapLayer *layer )

// no renderer found... this mustn't happen
Q_ASSERT( rendererIdx != -1 && "there must be a renderer!" );

mMaxErrorSpinBox->setValue( mLayer->renderer()->maximumScreenError() );
mMaxErrorUnitWidget->setUnit( mLayer->renderer()->maximumScreenErrorUnit() );
}

mBlockChangedSignal = false;
Expand All @@ -130,6 +142,9 @@ void QgsPointCloudRendererPropertiesWidget::apply()
QDomElement elem;
mLayer->setRenderer( QgsApplication::pointCloudRendererRegistry()->rendererMetadata( cboRenderers->currentData().toString() )->createRenderer( elem, QgsReadWriteContext() ) );
}

mLayer->renderer()->setMaximumScreenError( mMaxErrorSpinBox->value() );
mLayer->renderer()->setMaximumScreenErrorUnit( mMaxErrorUnitWidget->unit() );
}

void QgsPointCloudRendererPropertiesWidget::rendererChanged()
Expand Down
55 changes: 48 additions & 7 deletions src/ui/pointcloud/qgspointcloudrendererpropsdialogbase.ui
Expand Up @@ -114,28 +114,58 @@
<property name="rightMargin">
<number>3</number>
</property>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="lblTransparency">
<property name="text">
<string>Opacity</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblBlend">
<property name="text">
<string>Blending mode</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QgsOpacityWidget" name="mOpacityWidget" native="true">
<widget class="QgsDoubleSpinBox" name="mMaxErrorSpinBox">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>99999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblTransparency_2">
<property name="text">
<string>Maximum error</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QgsUnitSelectionWidget" name="mMaxErrorUnitWidget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblBlend">
<property name="text">
<string>Blending mode</string>
<item row="1" column="1" colspan="3">
<widget class="QgsOpacityWidget" name="mOpacityWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<item row="2" column="1" colspan="3">
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
Expand Down Expand Up @@ -180,6 +210,17 @@
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsunitselectionwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cboRenderers</tabstop>
Expand Down

0 comments on commit 0d3ccf7

Please sign in to comment.