QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
21 #include <QLinearGradient>
50 , mIsEditable( layer->isEditable() )
51 , mFeedback( new QgsMeshLayerRendererFeedback )
52 , mRendererSettings( layer->rendererSettings() )
53 , mLayerOpacity( layer->opacity() )
72 copyTriangularMeshes( layer, context );
75 copyScalarDatasetValues( layer );
76 copyVectorDatasetValues( layer );
78 calculateOutputSize();
91 mIsMeshSimplificationActive =
true;
104 void QgsMeshLayerRenderer::calculateOutputSize()
110 const QgsRectangle screenBBox = QgsMeshLayerUtils::boundingBoxToScreenRectangle( mapToPixel, extent );
111 const int width = int( screenBBox.
width() );
112 const int height = int( screenBBox.
height() );
116 void QgsMeshLayerRenderer::copyScalarDatasetValues(
QgsMeshLayer *layer )
128 if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
129 ( cache->mActiveScalarDatasetIndex == datasetIndex ) &&
130 ( cache->mDataInterpolationMethod == method ) &&
175 if (
mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnFaces )
177 mScalarDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnVertices;
186 else if (
mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnVertices )
205 cache->mDatasetGroupsCount = datasetGroupCount;
206 cache->mActiveScalarDatasetIndex = datasetIndex;
207 cache->mDataInterpolationMethod = method;
217 void QgsMeshLayerRenderer::copyVectorDatasetValues(
QgsMeshLayer *layer )
228 if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
229 ( cache->mActiveVectorDatasetIndex == datasetIndex ) &&
248 const bool isScalar = metadata.
isScalar();
251 QgsDebugMsg( QStringLiteral(
"Dataset has no vector values" ) );
279 cache->mDatasetGroupsCount = datasetGroupCount;
280 cache->mActiveVectorDatasetIndex = datasetIndex;
297 bool needsPainterClipPath =
false;
299 if ( needsPainterClipPath )
303 renderScalarDataset();
306 renderVectorDataset();
316 void QgsMeshLayerRenderer::renderMesh()
343 nativeFacesInExtent.values() );
357 QPainter *painter = context.
painter();
362 QPen pen = painter->pen();
363 pen.setCapStyle( Qt::FlatCap );
364 pen.setJoinStyle( Qt::MiterJoin );
367 pen.setWidthF( penWidth );
368 pen.setColor( settings.
color() );
369 painter->setPen( pen );
381 QPainter *painter = _painterForMeshFrame( context, settings );
386 for (
const int i : edgesInExtent )
391 if ( i >= edges.size() )
395 const int startVertexIndex = edge.first;
396 const int endVertexIndex = edge.second;
398 if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
401 const QgsMeshVertex &startVertex = vertices[startVertexIndex];
410 void QgsMeshLayerRenderer::renderFaceMesh(
412 const QVector<QgsMeshFace> &faces,
413 const QList<int> &facesInExtent )
415 Q_ASSERT( settings.
isEnabled() || mIsEditable );
421 QPainter *painter = _painterForMeshFrame( context, settings );
424 QSet<QPair<int, int>> drawnEdges;
426 for (
const int i : facesInExtent )
431 if ( i < 0 || i >= faces.count() )
435 if ( face.size() < 2 )
438 for (
int j = 0; j < face.size(); ++j )
440 const int startVertexId = face[j];
441 const int endVertexId = face[( j + 1 ) % face.size()];
442 const QPair<int, int> thisEdge( startVertexId, endVertexId );
443 const QPair<int, int> thisEdgeReversed( endVertexId, startVertexId );
444 if ( drawnEdges.contains( thisEdge ) || drawnEdges.contains( thisEdgeReversed ) )
446 drawnEdges.insert( thisEdge );
447 drawnEdges.insert( thisEdgeReversed );
460 void QgsMeshLayerRenderer::renderScalarDataset()
469 if ( groupIndex < 0 )
475 (
mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnEdges ) )
477 renderScalarDatasetOnFaces( scalarSettings );
481 (
mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnFaces ) )
483 renderScalarDatasetOnEdges( scalarSettings );
499 for (
const int i : egdesInExtent )
504 if ( i >= edges.size() )
508 const int startVertexIndex = edge.first;
509 const int endVertexIndex = edge.second;
511 if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
514 const QgsMeshVertex &startVertex = vertices[startVertexIndex];
517 if (
mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnEdges )
531 if ( shader->
shade( val, &r, &g, &b, &a ) )
533 return QColor( r, g, b, a );
540 const QgsPointXY pt( p1.
x() + fraction * ( p2.
x() - p1.
x() ),
541 p1.
y() + fraction * ( p2.
y() - p1.
y() ) );
558 interpolator.setSpatialIndexActive( mIsMeshSimplificationActive );
562 renderer.setOpacity( scalarSettings.
opacity() );
565 const QImage img = bl->image();
567 context.
painter()->drawImage( 0, 0, img );
570 void QgsMeshLayerRenderer::renderVectorDataset()
573 if ( groupIndex < 0 )
585 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
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 the current map units per pixel.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
void setInterpolatedColor(const QgsInterpolatedLineColor &strokeColoring)
Sets the stroke color used to render.
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
QgsUnitTypes::RenderUnit lineWidthUnit() const
Returns units of the width of the mesh frame.
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 testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
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.
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
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 render.
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 > 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.
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.
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
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. wind speed) and a dataset in thi...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
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 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. The color can vary depending on the dataset value.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering or calling to updateMesh)
@ 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.
void render(double value1, double value2, const QgsPointXY &point1, const QgsPointXY &point2, QgsRenderContext &context) const
Renders a line in the context between point1 and point2 with color and width that vary depending on v...
QgsMeshRendererMeshSettings triangularMeshSettings() const
Returns triangular mesh renderer settings.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Represents an overview renderer settings.
double mVectorDatasetGroupMagMaximum
A class to represent a 2D point.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
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.
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.
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 simple line renderer with width and color varying depending on values.
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.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
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
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMeshDatasetIndex activeScalarDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active scalar group depending on the time range.
double mVectorDatasetMagMinimum
void setWidthUnit(QgsUnitTypes::RenderUnit strokeWidthUnit)
Sets the unit of the stroke width.
bool isValid() const
Whether the block is valid.
int meshResolution() const
Returns the mesh resolution i.e., the minimum size (average) of triangles in pixels.