QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
21 #include <QLinearGradient>
48 , mFeedback( new QgsMeshLayerRendererFeedback )
49 , mRendererSettings( layer->rendererSettings() )
66 copyTriangularMeshes( layer, context );
69 copyScalarDatasetValues( layer );
70 copyVectorDatasetValues( layer );
72 calculateOutputSize();
85 mIsMeshSimplificationActive =
true;
98 void QgsMeshLayerRenderer::calculateOutputSize()
104 const QgsRectangle screenBBox = QgsMeshLayerUtils::boundingBoxToScreenRectangle( mapToPixel, extent );
105 int width = int( screenBBox.
width() );
106 int height = int( screenBBox.
height() );
110 void QgsMeshLayerRenderer::copyScalarDatasetValues(
QgsMeshLayer *layer )
122 if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
123 ( cache->mActiveScalarDatasetIndex == datasetIndex ) &&
124 ( cache->mDataInterpolationMethod == method ) &&
169 if (
mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnFaces )
171 mScalarDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnVertices;
180 else if (
mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnVertices )
200 cache->mDatasetGroupsCount = datasetGroupCount;
201 cache->mActiveScalarDatasetIndex = datasetIndex;
202 cache->mDataInterpolationMethod = method;
212 void QgsMeshLayerRenderer::copyVectorDatasetValues(
QgsMeshLayer *layer )
223 if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
224 ( cache->mActiveVectorDatasetIndex == datasetIndex ) &&
243 bool isScalar = metadata.
isScalar();
246 QgsDebugMsg( QStringLiteral(
"Dataset has no vector values" ) );
274 cache->mDatasetGroupsCount = datasetGroupCount;
275 cache->mActiveVectorDatasetIndex = datasetIndex;
291 bool needsPainterClipPath =
false;
293 if ( needsPainterClipPath )
297 renderScalarDataset();
299 renderVectorDataset();
304 void QgsMeshLayerRenderer::renderMesh()
330 nativeFacesInExtent.values() );
344 QPainter *painter = context.
painter();
349 QPen pen = painter->pen();
350 pen.setCapStyle( Qt::FlatCap );
351 pen.setJoinStyle( Qt::MiterJoin );
354 QgsUnitTypes::RenderUnit::RenderMillimeters );
355 pen.setWidthF( penWidth );
356 pen.setColor( settings.
color() );
357 painter->setPen( pen );
369 QPainter *painter = _painterForMeshFrame( context, settings );
374 for (
const int i : edgesInExtent )
379 if ( i >= edges.size() )
383 const int startVertexIndex = edge.first;
384 const int endVertexIndex = edge.second;
386 if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
389 const QgsMeshVertex &startVertex = vertices[startVertexIndex];
398 void QgsMeshLayerRenderer::renderFaceMesh(
400 const QVector<QgsMeshFace> &faces,
401 const QList<int> &facesInExtent )
409 QPainter *painter = _painterForMeshFrame( context, settings );
412 QSet<QPair<int, int>> drawnEdges;
414 for (
const int i : facesInExtent )
420 if ( face.size() < 2 )
423 for (
int j = 0; j < face.size(); ++j )
425 const int startVertexId = face[j];
426 const int endVertexId = face[( j + 1 ) % face.size()];
427 const QPair<int, int> thisEdge( startVertexId, endVertexId );
428 const QPair<int, int> thisEdgeReversed( endVertexId, startVertexId );
429 if ( drawnEdges.contains( thisEdge ) || drawnEdges.contains( thisEdgeReversed ) )
431 drawnEdges.insert( thisEdge );
432 drawnEdges.insert( thisEdgeReversed );
445 void QgsMeshLayerRenderer::renderScalarDataset()
454 if ( groupIndex < 0 )
460 (
mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnEdges ) )
462 renderScalarDatasetOnFaces( scalarSettings );
466 (
mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnFaces ) )
468 renderScalarDatasetOnEdges( scalarSettings );
486 for (
const int i : egdesInExtent )
491 if ( i >= edges.size() )
495 const int startVertexIndex = edge.first;
496 const int endVertexIndex = edge.second;
498 if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
501 const QgsMeshVertex &startVertex = vertices[startVertexIndex];
504 if (
mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnEdges )
518 if ( shader->
shade( val, &r, &g, &b, &a ) )
520 return QColor( r, g, b, a );
527 const QgsPointXY pt( p1.
x() + fraction * ( p2.
x() - p1.
x() ),
528 p1.
y() + fraction * ( p2.
y() - p1.
y() ) );
545 interpolator.setSpatialIndexActive( mIsMeshSimplificationActive );
549 renderer.setOpacity( scalarSettings.
opacity() );
552 QImage img = bl->image();
554 context.
painter()->drawImage( 0, 0, img );
557 void QgsMeshLayerRenderer::renderVectorDataset()
560 if ( groupIndex < 0 )
572 std::unique_ptr<QgsMeshVectorRenderer> renderer( QgsMeshVectorRenderer::makeVectorRenderer(
static QList< QgsMapClippingRegion > collectClippingRegionsForLayer(const QgsRenderContext &context, const QgsMapLayer *layer)
Collects the list of map clipping regions from a context which apply to a map layer.
QgsMeshDatasetGroupMetadata::DataType mScalarDataType
QgsTriangularMesh mTriangularMesh
QVector< double > mScalarDatasetValues
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
QgsMeshRendererSettings mRendererSettings
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
DataResamplingMethod dataResamplingMethod() const
Returns the type of interpolation to use to convert face defined datasets to values on vertices.
double mVectorDatasetGroupMagMinimum
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
double mapUnitsPerPixel() const
Returns current map units per pixel.
void setInterpolatedColor(const QgsInterpolatedLineColor &strokeColoring)
Sets the stroke color used to plot.
double mScalarDatasetMaximum
Point geometry type, with support for z-dimension and m-values.
Represents a mesh renderer settings for mesh object.
QColor color() const
Returns color used for rendering.
double classificationMinimum() const
Returns min value used for creation of the color ramp shader.
QgsMeshDatasetGroupMetadata::DataType mVectorDataType
double lineWidth() const
Returns line width used for rendering (in millimeters)
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering)
QgsMeshSimplificationSettings meshSimplificationSettings() const
Returns mesh simplification settings.
QgsRectangle mLayerExtent
bool render() override
Do the rendering (based on data stored in the class)
Contains information about the context of a rendering operation.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
QPointF toQPointF() const
Converts a point to a QPointF.
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
QList< int > edgeIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of edges intersecting given bounding box It uses spatial indexing.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
QgsTriangularMesh * triangularMesh(double minimumTriangleSize=0) const
Returns triangular mesh (nullptr before rendering or calling to updateMesh).
A rectangle specified with double values.
void setInterpolatedWidth(const QgsInterpolatedLineWidth &strokeWidth)
Sets the stroke width used to plot.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
QgsMeshDatasetMetadata datasetMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset metadata.
int levelOfDetail() const
Returns the corresponding index of level of detail on which this mesh is associated.
CORE_EXPORT QSet< int > nativeEdgesFromEdges(const QList< int > &edgesIndexes, const QVector< int > &edgesToNativeEdges)
Returns unique native faces indexes from list of triangle indexes.
CORE_EXPORT QSet< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsMeshDatasetIndex staticVectorDatasetIndex() const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QVector< double > mVectorDatasetValuesMag
double opacity() const
Returns opacity.
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
std::unique_ptr< QgsMeshLayerRendererFeedback > mFeedback
feedback class for cancellation
int group() const
Returns a group index.
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
bool isEnabled() const
Returns if the overview is active.
QVector< QgsMeshFace > faces
Represents a width than can vary depending on values.
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, QgsMapLayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
static bool equals(const QgsMesh3dAveragingMethod *a, const QgsMesh3dAveragingMethod *b)
Returns whether two methods equal.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
const QVector< QgsMeshEdge > & edges() const
Returns edges.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
QgsMeshLayerRenderer(QgsMeshLayer *layer, QgsRenderContext &context)
Ctor.
QgsMeshDataBlock mVectorDatasetValues
Class defining color to render mesh datasets.
@ None
Does not use resampling.
double mVectorDatasetMagMaximum
DataResamplingMethod
Resampling of value from dataset.
QgsMeshDatasetIndex activeVectorDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active vector group depending on the time range If the temporal properties...
Scoped object for saving and restoring a QPainter object's state.
QgsMeshRendererMeshSettings nativeMeshSettings() const
Returns native mesh renderer settings.
QVector< int > QgsMeshFace
List of vertex indexes.
QgsMeshRendererMeshSettings triangularMeshSettings() const
Returns triangular mesh renderer settings.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
Represents a overview renderer settings.
double mVectorDatasetGroupMagMaximum
A class to represent a 2D point.
QgsUnitTypes::RenderUnit edgeStrokeWidthUnit() const
Returns the stroke width unit used to render edges scalar dataset.
Represents a mesh renderer settings for scalar datasets.
QgsMeshRendererVectorSettings vectorSettings(int groupIndex) const
Returns renderer settings.
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
QgsMeshDataBlock mScalarActiveFaceFlagValues
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
QgsMeshRendererMeshSettings edgeMeshSettings() const
Returns edge mesh renderer settings.
bool isEnabled() const
Returns whether mesh structure rendering is enabled.
void setWidthUnit(const QgsUnitTypes::RenderUnit &strokeWidthUnit)
Sets the unit of the stroke width.
Perform transforms between map coordinates and device coordinates.
bool shade(double value, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) const override
Generates and new RGB value based on one input value.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
QgsMeshDatasetIndex staticScalarDatasetIndex() const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
QgsMesh3dAveragingMethod * averagingMethod() const
Returns averaging method for conversion of 3d stacked mesh data to 2d data.
QList< QgsMapClippingRegion > mClippingRegions
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering or calling to updateMesh)
Raster renderer pipe for single band pseudocolor.
QgsRectangle extent() const override
Returns the extent of the layer.
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
Represents a line with width and color varying depending on values.
const QVector< int > & edgesToNativeEdges() const
Returns mapping between edges and original edges.
QgsInterpolatedLineWidth edgeStrokeWidth() const
Returns the stroke width used to render edges scalar dataset.
QPainter * painter()
Returns the destination QPainter for the render operation.
double classificationMaximum() const
Returns max value used for creation of the color ramp shader.
Interface for all raster shaders.
int datasetGroupCount() const
Returns the dataset groups count handle by the layer.
virtual QgsMesh3dAveragingMethod * clone() const =0
Clone the instance.
QgsMeshDataBlock areFacesActive(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns whether the faces are active for particular dataset.
double mScalarDatasetMinimum
QgsMeshDatasetIndex activeScalarDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active scalar group depending on the time range.
double mVectorDatasetMagMinimum
bool isValid() const
Whether the block is valid.
void render(double value1, double value2, QgsPointXY point1, QgsPointXY point2, QgsRenderContext &context) const
Render a line in the context between point1 and point2 with color and width that vary depending on va...
int meshResolution() const
Returns the mesh resolution e.i., the minimum size (average) of triangles in pixels.