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 ) )
107 for (
int i = 0; i < count; ++i )
125 cache->mDatasetGroupsCount = datasetGroupCount;
126 cache->mActiveScalarDatasetIndex = datasetIndex;
134 void QgsMeshLayerRenderer::copyVectorDatasetValues(
QgsMeshLayer *layer )
141 if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
142 ( cache->mActiveVectorDatasetIndex == datasetIndex ) )
159 bool isScalar = metadata.
isScalar();
162 QgsDebugMsg( QStringLiteral(
"Dataset has no vector values" ) );
176 for (
int i = 0; i < count; ++i )
193 cache->mDatasetGroupsCount = datasetGroupCount;
194 cache->mActiveVectorDatasetIndex = datasetIndex;
205 renderScalarDataset();
207 renderVectorDataset();
211 void QgsMeshLayerRenderer::renderMesh()
233 nativeFacesInExtent );
237 void QgsMeshLayerRenderer::renderMesh(
const QgsMeshRendererMeshSettings &settings,
const QVector<QgsMeshFace> &faces,
const QList<int> facesInExtent )
245 painter->setRenderHint( QPainter::Antialiasing,
true );
247 QPen pen = painter->pen();
248 pen.setCapStyle( Qt::FlatCap );
249 pen.setJoinStyle( Qt::MiterJoin );
252 QgsUnitTypes::RenderUnit::RenderMillimeters );
253 pen.setWidthF( penWidth );
254 pen.setColor( settings.
color() );
255 painter->setPen( pen );
258 QSet<QPair<int, int>> drawnEdges;
260 for (
const int i : facesInExtent )
266 if ( face.size() < 2 )
269 for (
int j = 0; j < face.size(); ++j )
271 const int startVertexId = face[j];
272 const int endVertexId = face[( j + 1 ) % face.size()];
273 const QPair<int, int> thisEdge( startVertexId, endVertexId );
274 const QPair<int, int> thisEdgeReversed( endVertexId, startVertexId );
275 if ( drawnEdges.contains( thisEdge ) || drawnEdges.contains( thisEdgeReversed ) )
277 drawnEdges.insert( thisEdge );
278 drawnEdges.insert( thisEdgeReversed );
291 void QgsMeshLayerRenderer::renderScalarDataset()
306 sh->setRasterShaderFunction( fcn );
315 QImage img = bl->image();
320 void QgsMeshLayerRenderer::renderVectorDataset()
QPointF toQPointF() const
Converts a point to a QPointF.
QVector< bool > mScalarActiveFaceFlagValues
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
A rectangle specified with double values.
Interface for all raster shaders.
QVector< double > mVectorDatasetValuesX
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
Use antialiasing while drawing.
QgsMeshRendererSettings mRendererSettings
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
QgsMeshRendererMeshSettings triangularMeshSettings() const
Returns renderer settings.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
Represents a mesh renderer settings for mesh object.
A class to represent a 2D point.
Represents a mesh renderer settings for scalar datasets.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QVector< double > mScalarDatasetValues
bool mScalarDataOnVertices
double classificationMinimum() const
Returns min value used for creation of the color ramp shader.
double mVectorDatasetMagMinimum
void setClassificationMax(double max)
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering)
bool mVectorDataOnVertices
QVector< double > mVectorDatasetValuesMag
QVector< QgsMeshVertex > vertices
vertices
QgsTriangularMesh mTriangularMesh
Base class for feedback objects to be used for cancellation of something running in a worker thread...
bool isEnabled() const
Returns whether mesh structure rendering is enabled.
Perform transforms between map coordinates and device coordinates.
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be null)
bool render() override
Do the rendering (based on data stored in the class)
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double mScalarDatasetMaximum
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool renderingStopped() const
Returns TRUE if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
QColor color() const
Returns color used for rendering.
Raster renderer pipe for single band pseudocolor.
double y() const
Returns y value.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider.
QVector< double > mVectorDatasetValuesY
Point geometry type, with support for z-dimension and m-values.
std::unique_ptr< QgsMeshLayerRendererFeedback > mFeedback
feedback class for cancellation
double scalar() const
Returns magnitude of vector for vector data or scalar value for scalar data.
QList< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
QgsRenderContext & mContext
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
Contains information about the context of a rendering operation.
void setClassificationMin(double min)
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsMeshLayerRenderer(QgsMeshLayer *layer, QgsRenderContext &context)
Ctor.
virtual bool isFaceActive(QgsMeshDatasetIndex index, int faceIndex) const =0
Returns whether the face is active for particular dataset.
double classificationMaximum() const
Returns max value used for creation of the color ramp shader.
QVector< int > QgsMeshFace
List of vertex indexes.
double mVectorDatasetMagMaximum
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Flags flags() const
Returns combination of flags used for rendering.
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering)
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Base class for utility classes that encapsulate information necessary for rendering of map layers...
QgsMeshDatasetIndex activeVectorDataset() const
Returns active vector dataset.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QVector< QgsMeshFace > faces
faces
int group() const
Returns a group index.
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original 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
double x() const
Returns x value.
virtual QgsMeshDatasetValue datasetValue(QgsMeshDatasetIndex index, int valueIndex) const =0
Returns vector/scalar value associated with the index from the dataset.
QgsMeshDatasetIndex activeScalarDataset() const
Returns active scalar dataset.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
double opacity() const
Returns opacity.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
QgsMeshRendererVectorSettings vectorSettings(int groupIndex) const
Returns renderer settings.
QgsMeshRendererMeshSettings nativeMeshSettings() const
Returns renderer settings.
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
double lineWidth() const
Returns line width used for rendering (in millimeters)