36using namespace Qt::StringLiterals;
41 : mRenderContext( context )
51 return mPointsRendered;
56 mPointsRendered += count;
62 mPointRecordSize = mAttributes.pointRecordSize();
77 mLabelTextFormat = std::move( textFormat );
78 mElevationShadingRenderer.setActiveEyeDomeLighting(
false );
79 mElevationShadingRenderer.setActiveHillshading(
false );
84 if ( element.isNull() )
88 const QString rendererType = element.attribute( u
"type"_s );
94 std::unique_ptr< QgsPointCloudRenderer > r( m->
createRenderer( element, context ) );
101 if ( mDataDefinedProperties.hasActiveProperties() )
103 res = mDataDefinedProperties.referencedVariables();
118 mThread = QThread::currentThread();
122 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsPointCloudRenderer::startRender",
"startRender called in a different thread - use a cloned renderer instead" );
128 switch ( mPointSymbol )
141 if ( mDataDefinedProperties.hasActiveProperties() )
143 mExpressionContextScope = std::make_unique<QgsExpressionContextScope>();
151 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsPointCloudRenderer::stopRender",
"stopRender called in a different thread - use a cloned renderer instead" );
154 if ( mExpressionContextScope )
157 mExpressionContextScope.reset();
171 return mMaximumScreenError;
176 mMaximumScreenError = error;
181 mOverviewSwitchingScale = scale;
186 return mMaximumScreenErrorUnit;
191 mMaximumScreenErrorUnit = unit;
196 return QList<QgsLayerTreeModelLegendNode *>();
201 return QStringList();
211 const QPointF originalXY( x, y );
216 switch ( mPointSymbol )
219 elevationPainter->fillRect( QRectF( x - width * 0.5, y - width * 0.5, width, width ), brush );
223 elevationPainter->setBrush( brush );
224 elevationPainter->setPen( Qt::NoPen );
225 elevationPainter->drawEllipse( QRectF( x - width * 0.5, y - width * 0.5, width, width ) );
255 mPointSize = element.attribute( u
"pointSize"_s, u
"1"_s ).toDouble();
259 mMaximumScreenError = element.attribute( u
"maximumScreenError"_s, u
"0.3"_s ).toDouble();
261 mPointSymbol =
static_cast< Qgis::PointCloudSymbol >( element.attribute( u
"pointSymbol"_s, u
"0"_s ).toInt() );
264 mRenderAsTriangles = element.attribute( u
"renderAsTriangles"_s, u
"0"_s ).toInt();
265 mHorizontalTriangleFilter = element.attribute( u
"horizontalTriangleFilter"_s, u
"0"_s ).toInt();
266 mHorizontalTriangleFilterThreshold = element.attribute( u
"horizontalTriangleFilterThreshold"_s, u
"5"_s ).toDouble();
269 mShowLabels = element.attribute( u
"showLabels"_s, u
"0"_s ).toInt();
270 if ( !element.firstChildElement( u
"text-style"_s ).isNull() )
273 mLabelTextFormat.readXml( element.firstChildElement( u
"text-style"_s ), context );
276 mOverviewSwitchingScale = element.attribute( u
"overviewSwitchingScale"_s, u
"1.0"_s ).toDouble();
278 const QDomNode elevationShadingNode = element.namedItem( u
"elevation-shading-renderer"_s );
279 if ( !elevationShadingNode.isNull() )
281 mElevationShadingRenderer.readXml( elevationShadingNode.toElement(), context );
283 const QDomElement ddElem = element.firstChildElement( u
"dataDefinedProperties"_s );
284 if ( !ddElem.isNull() )
294 element.setAttribute( u
"maximumScreenError"_s,
qgsDoubleToString( mMaximumScreenError ) );
296 element.setAttribute( u
"pointSymbol"_s, QString::number(
static_cast< int >( mPointSymbol ) ) );
297 element.setAttribute( u
"drawOrder2d"_s, QString::number(
static_cast< int >( mDrawOrder2d ) ) );
299 element.setAttribute( u
"renderAsTriangles"_s, QString::number(
static_cast< int >( mRenderAsTriangles ) ) );
300 element.setAttribute( u
"horizontalTriangleFilter"_s, QString::number(
static_cast< int >( mHorizontalTriangleFilter ) ) );
301 element.setAttribute( u
"horizontalTriangleFilterThreshold"_s,
qgsDoubleToString( mHorizontalTriangleFilterThreshold ) );
302 element.setAttribute( u
"horizontalTriangleFilterUnit"_s,
QgsUnitTypes::encodeUnit( mHorizontalTriangleFilterUnit ) );
305 element.setAttribute( u
"showLabels"_s, u
"1"_s );
306 if ( mLabelTextFormat.isValid() )
308 QDomDocument doc = element.ownerDocument();
309 element.appendChild( mLabelTextFormat.writeXml( doc, context ) );
313 element.setAttribute( u
"zoomOutBehavior"_s,
qgsEnumValueToKey( mZoomOutBehavior ) );
315 if ( mOverviewSwitchingScale != 1.0 )
317 element.setAttribute( u
"overviewSwitchingScale"_s,
qgsDoubleToString( mOverviewSwitchingScale ) );
320 QDomDocument doc = element.ownerDocument();
321 QDomElement elevationShadingNode = doc.createElement( u
"elevation-shading-renderer"_s );
322 mElevationShadingRenderer.writeXml( elevationShadingNode, context );
323 element.appendChild( elevationShadingNode );
325 QDomElement ddElem = doc.createElement( u
"dataDefinedProperties"_s );
327 element.appendChild( ddElem );
337 mPointSymbol = symbol;
347 mDrawOrder2d = order;
350void QgsPointCloudRenderer::initPropertyDefinitions()
352 if ( !sPropertyDefinitions.isEmpty() )
355 sPropertyDefinitions = {
362 QgsPointCloudRenderer::initPropertyDefinitions();
363 return sPropertyDefinitions;
368 QVector<QVariantMap> selectedPoints;
373 QgsRectangle layerExtentMapCoords = layerExtentLayerCoords;
384 QgsDebugError( u
"Could not transform node extent to map CRS"_s );
389 if ( ( mapUnitsPerPixel < 0.0 ) || ( maxErrorPixels < 0.0 ) )
392 return selectedPoints;
395 const double maxErrorInMapCoordinates = maxErrorPixels * mapUnitsPerPixel;
396 const double maxErrorInLayerCoordinates = maxErrorInMapCoordinates * layerExtentLayerCoords.
width() / layerExtentMapCoords.
width();
401 const double x = geometry.
asPoint().
x();
402 const double y = geometry.
asPoint().
y();
404 const double pointSizePixels = renderContext.
convertToPainterUnits( mPointSize, mPointSizeUnit, mPointSizeMapUnitScale );
410 const QgsPointXY point1( deviceCoords.
x() - std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.
y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
411 const QgsPointXY point2( deviceCoords.
x() + std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.
y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
414 const QgsRectangle pointRect( point1MapCoords, point2MapCoords );
420 const QgsPoint centerMapCoords( x, y );
422 const QgsPoint point1( deviceCoords.
x(), deviceCoords.
y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
423 const QgsPoint point2( deviceCoords.
x(), deviceCoords.
y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
427 std::unique_ptr<QgsPolygon> polygon( circle.
toPolygon( 6 ) );
428 const QgsGeometry circleGeometry( std::move( polygon ) );
429 selectionGeometry = circleGeometry;
442 QgsDebugError( u
"Could not transform geometry to layer CRS"_s );
443 return selectedPoints;
448 selectedPoints.erase( std::remove_if( selectedPoints.begin(), selectedPoints.end(), [
this](
const QMap<QString, QVariant> &point ) { return !this->willRenderPoint( point ); } ), selectedPoints.end() );
450 return selectedPoints;
455 return mElevationShadingRenderer;
460 const char *ptr = block->
data();
463 const char *pointData = ptr + pointIndex * recordSize;
471 context.
getAttribute( pointData, offset, att.type(), value );
472 mExpressionContextScope->setVariable( att.name(), value,
false );
473 offset += att.size();
478 return mDataDefinedProperties.valueAsColor(
Property::Color, ctx, rendererColor );
PointCloudSymbol
Rendering symbols for point cloud points.
@ Circle
Renders points as circles.
@ Square
Renders points as squares.
PointCloudDrawOrder
Pointcloud rendering order for 2d views.
@ RenderExtents
Render only point cloud extents when zoomed out.
RenderUnit
Rendering size units.
@ Reverse
Reverse/inverse transform (from destination to source).
static QgsPointCloudRendererRegistry * pointCloudRendererRegistry()
Returns the application's point cloud renderer registry, used for managing point cloud layer 2D rende...
static QgsCircle from2Points(const QgsPoint &pt1, const QgsPoint &pt2)
Constructs a circle by 2 points on the circle.
Custom exception class for Coordinate Reference System related exceptions.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
static QRgb encodeElevation(float z)
Converts elevation value to an actual color.
QPainter * painter() const
Returns painter to the underlying QImage with elevations.
Renders elevation shading on an image with different methods (eye dome lighting, hillshading,...
virtual QgsPolygon * toPolygon(unsigned int segments=36) const
Returns a segmented polygon.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
Layer tree node points to a map layer.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
A collection of point cloud attributes.
int pointRecordSize() const
Returns total size of record.
Attribute for point cloud data pair of name and size in bytes.
Base class for storing raw data from point cloud nodes.
const char * data() const
Returns raw pointer to data.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes that are stored in the data block, along with their size.
QVector< QVariantMap > identify(double maxError, const QgsGeometry &extentGeometry, const QgsDoubleRange &extentZRange=QgsDoubleRange(), int pointsLimit=1000)
Returns the list of points of the point cloud according to a zoom level defined by maxError (in layer...
Represents a map layer supporting display of point clouds.
QgsPointCloudDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Encapsulates the render context for a 2D point cloud rendering operation.
double zValueFixedOffset() const
Returns any constant offset which must be applied to z values taken from the point cloud index.
QgsVector3D offset() const
Returns the offset of the layer's int32 coordinates compared to CRS coords.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
void incrementPointsRendered(long count)
Increments the count of points rendered by the specified amount.
long pointsRendered() const
Returns the total number of points rendered.
static void getAttribute(const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value)
Retrieves the attribute value from data at the specified offset, where type indicates the original da...
double zValueScale() const
Returns any constant scaling factor which must be applied to z values taken from the point cloud inde...
QgsVector3D scale() const
Returns the scale of the layer's int32 coordinates compared to CRS coords.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the rendered block.
QgsPointCloudRenderContext(QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset, double zValueScale, double zValueFixedOffset, QgsFeedback *feedback=nullptr)
Constructor for QgsPointCloudRenderContext.
QgsFeedback * feedback() const
Returns the feedback object used to cancel rendering.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets the attributes associated with the rendered block.
QgsPointCloudRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
virtual void checkLegendItem(const QString &key, bool state=true)
Called when the check state of the legend item with the specified key is changed.
void setMaximumScreenError(double error)
Sets the maximum screen error allowed when rendering the point cloud.
void drawPointToElevationMap(double x, double y, double z, QgsPointCloudRenderContext &context) const
Draws a point at the elevation z using at the specified x and y (in map coordinates) on the elevation...
void restoreCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Restores common renderer properties (such as point size and screen error) from the specified DOM elem...
void setMaximumScreenErrorUnit(Qgis::RenderUnit unit)
Sets the unit for the maximum screen error allowed when rendering the point cloud.
void saveCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Saves common renderer properties (such as point size and screen error) to the specified DOM element.
const QgsMapUnitScale & pointSizeMapUnitScale() const
Returns the map unit scale used for the point size.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the renderer's property collection, used for data defined overrides.
virtual std::unique_ptr< QgsPreparedPointCloudRendererData > prepare()
Returns prepared data container for bulk point color retrieval.
QColor colorFromExpression(const QgsPointCloudBlock *block, int pointIndex, const QColor &rendererColor, QgsPointCloudRenderContext &context)
Computes color from the expression set, uses expression referenced variables and renderer base color.
void setPointSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the point size.
virtual QSet< QString > usedAttributes(const QgsPointCloudRenderContext &context) const
Returns a list of attributes required by this renderer.
virtual bool legendItemChecked(const QString &key)
Returns true if the legend item with the specified key is checked.
void setPointSize(double size)
Sets the point size.
void setHorizontalTriangleFilterThreshold(double threshold)
Sets threshold for filtering of triangles.
static QgsPointCloudRenderer * load(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer from an XML element.
void setHorizontalTriangleFilterUnit(Qgis::RenderUnit unit)
Sets units of the threshold for filtering of triangles.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the property definitions for data defined properties used by the renderer.
Qgis::RenderUnit maximumScreenErrorUnit() const
Returns the unit for the maximum screen error allowed when rendering the point cloud.
void setDrawOrder2d(Qgis::PointCloudDrawOrder order)
Sets the drawing order used by the renderer for drawing points.
virtual QStringList legendRuleKeys() const
Returns a list of all rule keys for legend nodes created by the renderer.
QVector< QVariantMap > identify(QgsPointCloudLayer *layer, const QgsRenderContext &context, const QgsGeometry &geometry, double toleranceForPointIdentification=0)
Returns the list of visible points of the point cloud layer layer and an extent defined by a geometry...
void setPointSizeUnit(const Qgis::RenderUnit units)
Sets the units used for the point size.
QgsElevationShadingRenderer elevationShadingRenderer() const
Returns the shading renderer used to render shading on the layer.
void setRenderAsTriangles(bool asTriangles)
Sets whether points are triangulated to render solid surface.
void copyCommonProperties(QgsPointCloudRenderer *destination) const
Copies common point cloud properties (such as point size and screen error) to the destination rendere...
void setPointSymbol(Qgis::PointCloudSymbol symbol)
Sets the symbol used by the renderer for drawing points.
void setLabelTextFormat(const QgsTextFormat &textFormat)
Sets the text format renderers should use for rendering labels.
double maximumScreenError() const
Returns the maximum screen error allowed when rendering the point cloud.
void setShowLabels(const bool show)
Set whether the renderer should also render file labels inside extent.
Qgis::RenderUnit pointSizeUnit() const
Returns the units used for the point size.
Qgis::PointCloudSymbol pointSymbol() const
Returns the symbol used by the renderer for drawing points.
virtual void startRender(QgsPointCloudRenderContext &context)
Must be called when a new render cycle is started.
virtual void stopRender(QgsPointCloudRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Qgis::PointCloudDrawOrder drawOrder2d() const
Returns the drawing order used by the renderer for drawing points.
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer)
Creates a set of legend nodes representing the renderer.
void setHorizontalTriangleFilter(bool enabled)
Sets whether large triangles will get rendered.
double pointSize() const
Returns the point size.
void setZoomOutBehavior(const Qgis::PointCloudZoomOutRenderBehavior behavior)
Sets the renderer behavior when zoomed out.
void setOverviewSwitchingScale(const double value)
Sets the overview switching scale.
void setElevationShadingRenderer(const QgsElevationShadingRenderer &renderer)
Sets the shading renderer used to render shading on the layer.
Point geometry type, with support for z-dimension and m-values.
virtual ~QgsPreparedPointCloudRendererData()
Definition for a property.
@ ColorWithAlpha
Color with alpha channel.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsElevationMap * elevationMap() const
Returns the destination elevation map for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
QgsTextFormat defaultTextFormat(QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling) const
Returns the default text format to use for new text based objects in the specified context.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
Container for settings relating to a text buffer.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setSize(double size)
Sets the size of the buffer.
Container for all settings relating to text rendering.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
#define QgsDebugError(str)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.