41 , mFeedback( new QgsMeshLayerRendererFeedback )
43 , mRendererSettings( layer->rendererSettings() )
54 copyScalarDatasetValues( layer );
55 copyVectorDatasetValues( layer );
57 calculateOutputSize();
65 void QgsMeshLayerRenderer::calculateOutputSize()
72 int width = int( bottomright.
x() - topleft.
x() );
73 int height = int( bottomright.
y() - topleft.
y() );
77 void QgsMeshLayerRenderer::copyScalarDatasetValues(
QgsMeshLayer *layer )
84 if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
85 ( cache->mActiveScalarDatasetIndex == datasetIndex ) )
122 cache->mDatasetGroupsCount = datasetGroupCount;
123 cache->mActiveScalarDatasetIndex = datasetIndex;
131 void QgsMeshLayerRenderer::copyVectorDatasetValues(
QgsMeshLayer *layer )
138 if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
139 ( cache->mActiveVectorDatasetIndex == datasetIndex ) )
157 bool isScalar = metadata.
isScalar();
160 QgsDebugMsg( QStringLiteral(
"Dataset has no vector values" ) );
189 cache->mDatasetGroupsCount = datasetGroupCount;
190 cache->mActiveVectorDatasetIndex = datasetIndex;
202 renderScalarDataset();
204 renderVectorDataset();
208 void QgsMeshLayerRenderer::renderMesh()
230 nativeFacesInExtent );
234 void QgsMeshLayerRenderer::renderMesh(
const QgsMeshRendererMeshSettings &settings,
const QVector<QgsMeshFace> &faces,
const QList<int> facesInExtent )
242 painter->setRenderHint( QPainter::Antialiasing,
true );
244 QPen pen = painter->pen();
245 pen.setCapStyle( Qt::FlatCap );
246 pen.setJoinStyle( Qt::MiterJoin );
249 QgsUnitTypes::RenderUnit::RenderMillimeters );
250 pen.setWidthF( penWidth );
251 pen.setColor( settings.
color() );
252 painter->setPen( pen );
255 QSet<QPair<int, int>> drawnEdges;
257 for (
const int i : facesInExtent )
263 if ( face.size() < 2 )
266 for (
int j = 0; j < face.size(); ++j )
268 const int startVertexId = face[j];
269 const int endVertexId = face[( j + 1 ) % face.size()];
270 const QPair<int, int> thisEdge( startVertexId, endVertexId );
271 const QPair<int, int> thisEdgeReversed( endVertexId, startVertexId );
272 if ( drawnEdges.contains( thisEdge ) || drawnEdges.contains( thisEdgeReversed ) )
274 drawnEdges.insert( thisEdge );
275 drawnEdges.insert( thisEdgeReversed );
288 void QgsMeshLayerRenderer::renderScalarDataset()
303 sh->setRasterShaderFunction( fcn );
316 QImage img = bl->image();
321 void QgsMeshLayerRenderer::renderVectorDataset()
A rectangle specified with double values.
Interface for all raster shaders.
Use antialiasing while drawing.
QgsMeshRendererSettings mRendererSettings
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Represents a mesh renderer settings for mesh object.
A class to represent a 2D point.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e...
Represents a mesh renderer settings for scalar datasets.
bool isEnabled() const
Returns whether mesh structure rendering is enabled.
bool renderingStopped() const
Flags flags() const
Returns combination of flags used for rendering.
double mVectorDatasetGroupMagMinimum
QVector< double > mScalarDatasetValues
bool mScalarDataOnVertices
double mVectorDatasetMagMinimum
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
int group() const
Returns a group index.
void setClassificationMax(double max)
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering)
bool mVectorDataOnVertices
QgsMeshDataBlock mVectorDatasetValues
QVector< double > mVectorDatasetValuesMag
QVector< QgsMeshVertex > vertices
vertices
QgsTriangularMesh mTriangularMesh
double opacity() const
Returns opacity.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Perform transforms between map coordinates and device coordinates.
double lineWidth() const
Returns line width used for rendering (in millimeters)
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be null)
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
bool render() override
Do the rendering (based on data stored in the class)
QgsMeshDatasetIndex activeVectorDataset() const
Returns active vector dataset.
QPointF toQPointF() const
Converts a point to a QPointF.
double mScalarDatasetMaximum
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
Raster renderer pipe for single band pseudocolor.
virtual QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const =0
Returns N vector/scalar values from the index from the dataset.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be null.
Point geometry type, with support for z-dimension and m-values.
std::unique_ptr< QgsMeshLayerRendererFeedback > mFeedback
feedback class for cancelation
CORE_EXPORT QList< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
QgsRenderContext & mContext
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QgsMeshRendererVectorSettings vectorSettings(int groupIndex) const
Returns renderer settings.
virtual QgsMeshDatasetMetadata datasetMetadata(QgsMeshDatasetIndex index) const =0
Returns dataset metadata.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
void setClassificationMin(double min)
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
double mVectorDatasetGroupMagMaximum
QgsMeshLayerRenderer(QgsMeshLayer *layer, QgsRenderContext &context)
Ctor.
QgsMeshRendererMeshSettings nativeMeshSettings() const
Returns renderer settings.
bool isValid() const
Whether the block is valid.
QColor color() const
Returns color used for rendering.
QVector< int > QgsMeshFace
List of vertex indexes.
double mVectorDatasetMagMaximum
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshRendererMeshSettings triangularMeshSettings() const
Returns renderer settings.
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering)
double xMinimum() const
Returns the x minimum value (left side of rectangle).
bool isValid() const
Returns whether index is valid, ie at least groups is set.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QVector< QgsMeshFace > faces
faces
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
double mScalarDatasetMinimum
QgsMeshDataBlock mScalarActiveFaceFlagValues
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
double classificationMaximum() const
Returns max value used for creation of the color ramp shader.
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
double classificationMinimum() const
Returns min value used for creation of the color ramp shader.
virtual QgsMeshDataBlock areFacesActive(QgsMeshDatasetIndex index, int faceIndex, int count) const =0
Returns whether the faces are active for particular dataset.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
QgsMeshDatasetIndex activeScalarDataset() const
Returns active scalar dataset.