QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmeshlayerrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshlayerrenderer.cpp
3  ------------------------
4  begin : April 2018
5  copyright : (C) 2018 by Peter Petrik
6  email : zilolv at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include <memory>
19 #include <QSet>
20 #include <QPair>
21 #include <QLinearGradient>
22 #include <QBrush>
23 #include <algorithm>
24 
25 #include "qgsmeshlayerrenderer.h"
26 
27 #include "qgsfield.h"
28 #include "qgslogger.h"
29 #include "qgsmeshlayer.h"
30 #include "qgspointxy.h"
31 #include "qgsrenderer.h"
33 #include "qgsrastershader.h"
35 #include "qgsmeshlayerutils.h"
36 #include "qgsmeshvectorrenderer.h"
37 #include "qgsmeshtracerenderer.h"
38 #include "qgsfillsymbollayer.h"
39 #include "qgssettings.h"
40 #include "qgsstyle.h"
42 #include "qgsmapclippingutils.h"
43 
45  QgsMeshLayer *layer,
46  QgsRenderContext &context )
47  : QgsMapLayerRenderer( layer->id(), &context )
48  , mFeedback( new QgsMeshLayerRendererFeedback )
49  , mRendererSettings( layer->rendererSettings() )
50 {
51  // make copies for mesh data
52  // cppcheck-suppress assertWithSideEffect
53  Q_ASSERT( layer->nativeMesh() );
54  // cppcheck-suppress assertWithSideEffect
55  Q_ASSERT( layer->triangularMesh() );
56  // cppcheck-suppress assertWithSideEffect
57  Q_ASSERT( layer->rendererCache() );
58  // cppcheck-suppress assertWithSideEffect
59  Q_ASSERT( layer->dataProvider() );
60 
61  // copy native mesh
62  mNativeMesh = *( layer->nativeMesh() );
63  mLayerExtent = layer->extent();
64 
65  // copy triangular mesh
66  copyTriangularMeshes( layer, context );
67 
68  // copy datasets
69  copyScalarDatasetValues( layer );
70  copyVectorDatasetValues( layer );
71 
72  calculateOutputSize();
73 
75 }
76 
77 void QgsMeshLayerRenderer::copyTriangularMeshes( QgsMeshLayer *layer, QgsRenderContext &context )
78 {
79  // handle level of details of mesh
80  QgsMeshSimplificationSettings simplificationSettings = layer->meshSimplificationSettings();
81  if ( simplificationSettings.isEnabled() )
82  {
83  double triangleSize = simplificationSettings.meshResolution() * context.mapToPixel().mapUnitsPerPixel();
84  mTriangularMesh = *( layer->triangularMesh( triangleSize ) );
85  mIsMeshSimplificationActive = true;
86  }
87  else
88  {
89  mTriangularMesh = *( layer->triangularMesh() );
90  }
91 }
92 
94 {
95  return mFeedback.get();
96 }
97 
98 void QgsMeshLayerRenderer::calculateOutputSize()
99 {
100  // figure out image size
101  QgsRenderContext &context = *renderContext();
102  const QgsRectangle extent = context.mapExtent();
103  const QgsMapToPixel mapToPixel = context.mapToPixel();
104  const QgsRectangle screenBBox = QgsMeshLayerUtils::boundingBoxToScreenRectangle( mapToPixel, extent );
105  int width = int( screenBBox.width() );
106  int height = int( screenBBox.height() );
107  mOutputSize = QSize( width, height );
108 }
109 
110 void QgsMeshLayerRenderer::copyScalarDatasetValues( QgsMeshLayer *layer )
111 {
112  QgsMeshDatasetIndex datasetIndex;
113  if ( renderContext()->isTemporal() )
114  datasetIndex = layer->activeScalarDatasetAtTime( renderContext()->temporalRange() );
115  else
116  datasetIndex = layer->staticScalarDatasetIndex();
117 
118  // Find out if we can use cache up to date. If yes, use it and return
119  const int datasetGroupCount = layer->datasetGroupCount();
121  QgsMeshLayerRendererCache *cache = layer->rendererCache();
122  if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
123  ( cache->mActiveScalarDatasetIndex == datasetIndex ) &&
124  ( cache->mDataInterpolationMethod == method ) &&
125  ( QgsMesh3dAveragingMethod::equals( cache->mScalarAveragingMethod.get(), mRendererSettings.averagingMethod() ) )
126  )
127  {
128  mScalarDatasetValues = cache->mScalarDatasetValues;
129  mScalarActiveFaceFlagValues = cache->mScalarActiveFaceFlagValues;
130  mScalarDataType = cache->mScalarDataType;
131  mScalarDatasetMinimum = cache->mScalarDatasetMinimum;
132  mScalarDatasetMaximum = cache->mScalarDatasetMaximum;
133  return;
134  }
135 
136  // Cache is not up-to-date, gather data
137  if ( datasetIndex.isValid() )
138  {
139  const QgsMeshDatasetGroupMetadata metadata = layer->datasetGroupMetadata( datasetIndex.group() );
140  mScalarDataType = QgsMeshLayerUtils::datasetValuesType( metadata.dataType() );
141 
142  // populate scalar values
143  const int count = QgsMeshLayerUtils::datasetValuesCount( &mNativeMesh, mScalarDataType );
144  QgsMeshDataBlock vals = QgsMeshLayerUtils::datasetValues(
145  layer,
146  datasetIndex,
147  0,
148  count );
149 
150  if ( vals.isValid() )
151  {
152  // vals could be scalar or vectors, for contour rendering we want always magnitude
153  mScalarDatasetValues = QgsMeshLayerUtils::calculateMagnitudes( vals );
154  }
155  else
156  {
157  mScalarDatasetValues = QVector<double>( count, std::numeric_limits<double>::quiet_NaN() );
158  }
159 
160  // populate face active flag, always defined on faces
162  datasetIndex,
163  0,
164  mNativeMesh.faces.count() );
165 
166  // for data on faces, there could be request to interpolate the data to vertices
167  if ( method != QgsMeshRendererScalarSettings::None )
168  {
169  if ( mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnFaces )
170  {
171  mScalarDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnVertices;
172  mScalarDatasetValues = QgsMeshLayerUtils::interpolateFromFacesData(
174  &mNativeMesh,
177  method
178  );
179  }
180  else if ( mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnVertices )
181  {
182  mScalarDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnFaces;
183  mScalarDatasetValues = QgsMeshLayerUtils::resampleFromVerticesToFaces(
185  &mNativeMesh,
188  method
189  );
190  }
191 
192  }
193 
194  const QgsMeshDatasetMetadata datasetMetadata = layer->datasetMetadata( datasetIndex );
195  mScalarDatasetMinimum = datasetMetadata.minimum();
196  mScalarDatasetMaximum = datasetMetadata.maximum();
197  }
198 
199  // update cache
200  cache->mDatasetGroupsCount = datasetGroupCount;
201  cache->mActiveScalarDatasetIndex = datasetIndex;
202  cache->mDataInterpolationMethod = method;
203  cache->mScalarDatasetValues = mScalarDatasetValues;
204  cache->mScalarActiveFaceFlagValues = mScalarActiveFaceFlagValues;
205  cache->mScalarDataType = mScalarDataType;
206  cache->mScalarDatasetMinimum = mScalarDatasetMinimum;
207  cache->mScalarDatasetMaximum = mScalarDatasetMaximum;
208  cache->mScalarAveragingMethod.reset( mRendererSettings.averagingMethod() ? mRendererSettings.averagingMethod()->clone() : nullptr );
209 }
210 
211 
212 void QgsMeshLayerRenderer::copyVectorDatasetValues( QgsMeshLayer *layer )
213 {
214  QgsMeshDatasetIndex datasetIndex;
215  if ( renderContext()->isTemporal() )
216  datasetIndex = layer->activeVectorDatasetAtTime( renderContext()->temporalRange() );
217  else
218  datasetIndex = layer->staticVectorDatasetIndex();
219 
220  // Find out if we can use cache up to date. If yes, use it and return
221  const int datasetGroupCount = layer->datasetGroupCount();
222  QgsMeshLayerRendererCache *cache = layer->rendererCache();
223  if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
224  ( cache->mActiveVectorDatasetIndex == datasetIndex ) &&
225  ( QgsMesh3dAveragingMethod::equals( cache->mVectorAveragingMethod.get(), mRendererSettings.averagingMethod() ) )
226  )
227  {
228  mVectorDatasetValues = cache->mVectorDatasetValues;
229  mVectorDatasetValuesMag = cache->mVectorDatasetValuesMag;
230  mVectorDatasetMagMinimum = cache->mVectorDatasetMagMinimum;
231  mVectorDatasetMagMaximum = cache->mVectorDatasetMagMaximum;
232  mVectorDatasetGroupMagMinimum = cache->mVectorDatasetMagMinimum;
233  mVectorDatasetGroupMagMaximum = cache->mVectorDatasetMagMaximum;
234  mVectorDataType = cache->mVectorDataType;
235  return;
236  }
237 
238  // Cache is not up-to-date, gather data
239  if ( datasetIndex.isValid() )
240  {
241  const QgsMeshDatasetGroupMetadata metadata = layer->datasetGroupMetadata( datasetIndex );
242 
243  bool isScalar = metadata.isScalar();
244  if ( isScalar )
245  {
246  QgsDebugMsg( QStringLiteral( "Dataset has no vector values" ) );
247  }
248  else
249  {
250  mVectorDataType = QgsMeshLayerUtils::datasetValuesType( metadata.dataType() );
251 
254 
255  int count = QgsMeshLayerUtils::datasetValuesCount( &mNativeMesh, mVectorDataType );
256  mVectorDatasetValues = QgsMeshLayerUtils::datasetValues(
257  layer,
258  datasetIndex,
259  0,
260  count );
261 
263  mVectorDatasetValuesMag = QgsMeshLayerUtils::calculateMagnitudes( mVectorDatasetValues );
264  else
265  mVectorDatasetValuesMag = QVector<double>( count, std::numeric_limits<double>::quiet_NaN() );
266 
267  const QgsMeshDatasetMetadata datasetMetadata = layer->datasetMetadata( datasetIndex );
268  mVectorDatasetMagMinimum = datasetMetadata.minimum();
269  mVectorDatasetMagMaximum = datasetMetadata.maximum();
270  }
271  }
272 
273  // update cache
274  cache->mDatasetGroupsCount = datasetGroupCount;
275  cache->mActiveVectorDatasetIndex = datasetIndex;
276  cache->mVectorDatasetValues = mVectorDatasetValues;
277  cache->mVectorDatasetValuesMag = mVectorDatasetValuesMag;
278  cache->mVectorDatasetMagMinimum = mVectorDatasetMagMinimum;
279  cache->mVectorDatasetMagMaximum = mVectorDatasetMagMaximum;
280  cache->mVectorDatasetGroupMagMinimum = mVectorDatasetMagMinimum;
281  cache->mVectorDatasetGroupMagMaximum = mVectorDatasetMagMaximum;
282  cache->mVectorDataType = mVectorDataType;
283  cache->mVectorAveragingMethod.reset( mRendererSettings.averagingMethod() ? mRendererSettings.averagingMethod()->clone() : nullptr );
284 }
285 
287 {
288  QgsScopedQPainterState painterState( renderContext()->painter() );
289  if ( !mClippingRegions.empty() )
290  {
291  bool needsPainterClipPath = false;
293  if ( needsPainterClipPath )
294  renderContext()->painter()->setClipPath( path, Qt::IntersectClip );
295  }
296 
297  renderScalarDataset();
298  renderMesh();
299  renderVectorDataset();
300 
301  return true;
302 }
303 
304 void QgsMeshLayerRenderer::renderMesh()
305 {
309  return;
310 
311  // triangular mesh
312  const QList<int> trianglesInExtent = mTriangularMesh.faceIndexesForRectangle( renderContext()->mapExtent() );
314  {
315  renderFaceMesh(
318  trianglesInExtent );
319  }
320 
321  // native mesh
323  {
324  const QSet<int> nativeFacesInExtent = QgsMeshUtils::nativeFacesFromTriangles( trianglesInExtent,
326 
327  renderFaceMesh(
330  nativeFacesInExtent.values() );
331  }
332 
333  // edge mesh
335  {
336  const QList<int> edgesInExtent = mTriangularMesh.edgeIndexesForRectangle( renderContext()->mapExtent() );
337  renderEdgeMesh( mRendererSettings.edgeMeshSettings(), edgesInExtent );
338  }
339 }
340 
341 static QPainter *_painterForMeshFrame( QgsRenderContext &context, const QgsMeshRendererMeshSettings &settings )
342 {
343  // Set up the render configuration options
344  QPainter *painter = context.painter();
345 
346  painter->save();
347  context.setPainterFlagsUsingContext( painter );
348 
349  QPen pen = painter->pen();
350  pen.setCapStyle( Qt::FlatCap );
351  pen.setJoinStyle( Qt::MiterJoin );
352 
353  double penWidth = context.convertToPainterUnits( settings.lineWidth(),
354  QgsUnitTypes::RenderUnit::RenderMillimeters );
355  pen.setWidthF( penWidth );
356  pen.setColor( settings.color() );
357  painter->setPen( pen );
358  return painter;
359 }
360 
361 void QgsMeshLayerRenderer::renderEdgeMesh( const QgsMeshRendererMeshSettings &settings, const QList<int> &edgesInExtent )
362 {
363  Q_ASSERT( settings.isEnabled() );
364 
365  if ( !mTriangularMesh.contains( QgsMesh::ElementType::Edge ) )
366  return;
367 
368  QgsRenderContext &context = *renderContext();
369  QPainter *painter = _painterForMeshFrame( context, settings );
370 
371  const QVector<QgsMeshEdge> edges = mTriangularMesh.edges();
372  const QVector<QgsMeshVertex> vertices = mTriangularMesh.vertices();
373 
374  for ( const int i : edgesInExtent )
375  {
376  if ( context.renderingStopped() )
377  break;
378 
379  if ( i >= edges.size() )
380  continue;
381 
382  const QgsMeshEdge &edge = edges[i];
383  const int startVertexIndex = edge.first;
384  const int endVertexIndex = edge.second;
385 
386  if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
387  continue;
388 
389  const QgsMeshVertex &startVertex = vertices[startVertexIndex];
390  const QgsMeshVertex &endVertex = vertices[endVertexIndex];
391  const QgsPointXY lineStart = context.mapToPixel().transform( startVertex.x(), startVertex.y() );
392  const QgsPointXY lineEnd = context.mapToPixel().transform( endVertex.x(), endVertex.y() );
393  painter->drawLine( lineStart.toQPointF(), lineEnd.toQPointF() );
394  }
395  painter->restore();
396 };
397 
398 void QgsMeshLayerRenderer::renderFaceMesh(
399  const QgsMeshRendererMeshSettings &settings,
400  const QVector<QgsMeshFace> &faces,
401  const QList<int> &facesInExtent )
402 {
403  Q_ASSERT( settings.isEnabled() );
404 
406  return;
407 
408  QgsRenderContext &context = *renderContext();
409  QPainter *painter = _painterForMeshFrame( context, settings );
410 
411  const QVector<QgsMeshVertex> &vertices = mTriangularMesh.vertices(); //Triangular mesh vertices contains also native mesh vertices
412  QSet<QPair<int, int>> drawnEdges;
413 
414  for ( const int i : facesInExtent )
415  {
416  if ( context.renderingStopped() )
417  break;
418 
419  const QgsMeshFace &face = faces[i];
420  if ( face.size() < 2 )
421  continue;
422 
423  for ( int j = 0; j < face.size(); ++j )
424  {
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 ) )
430  continue;
431  drawnEdges.insert( thisEdge );
432  drawnEdges.insert( thisEdgeReversed );
433 
434  const QgsMeshVertex &startVertex = vertices[startVertexId];
435  const QgsMeshVertex &endVertex = vertices[endVertexId];
436  const QgsPointXY lineStart = context.mapToPixel().transform( startVertex.x(), startVertex.y() );
437  const QgsPointXY lineEnd = context.mapToPixel().transform( endVertex.x(), endVertex.y() );
438  painter->drawLine( lineStart.toQPointF(), lineEnd.toQPointF() );
439  }
440  }
441 
442  painter->restore();
443 }
444 
445 void QgsMeshLayerRenderer::renderScalarDataset()
446 {
447  if ( mScalarDatasetValues.isEmpty() )
448  return; // activeScalarDataset == NO_ACTIVE_MESH_DATASET
449 
450  if ( std::isnan( mScalarDatasetMinimum ) || std::isnan( mScalarDatasetMaximum ) )
451  return; // only NODATA values
452 
453  int groupIndex = mRendererSettings.activeScalarDatasetGroup();
454  if ( groupIndex < 0 )
455  return; // no shader
456 
457  const QgsMeshRendererScalarSettings scalarSettings = mRendererSettings.scalarSettings( groupIndex );
458 
460  ( mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnEdges ) )
461  {
462  renderScalarDatasetOnFaces( scalarSettings );
463  }
464 
465  if ( ( mTriangularMesh.contains( QgsMesh::ElementType::Edge ) ) &&
466  ( mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnFaces ) )
467  {
468  renderScalarDatasetOnEdges( scalarSettings );
469  }
470 }
471 
472 void QgsMeshLayerRenderer::renderScalarDatasetOnEdges( const QgsMeshRendererScalarSettings &scalarSettings )
473 {
474  QgsRenderContext &context = *renderContext();
475  const QVector<QgsMeshEdge> edges = mTriangularMesh.edges();
476  const QVector<QgsMeshVertex> vertices = mTriangularMesh.vertices();
477  const QList<int> egdesInExtent = mTriangularMesh.edgeIndexesForRectangle( context.mapExtent() );
478  const QSet<int> nativeEdgesInExtent = QgsMeshUtils::nativeEdgesFromEdges( egdesInExtent,
480 
481  QgsInterpolatedLineRenderer edgePlotter;
482  edgePlotter.setInterpolatedColor( QgsInterpolatedLineColor( scalarSettings.colorRampShader() ) );
483  edgePlotter.setInterpolatedWidth( QgsInterpolatedLineWidth( scalarSettings.edgeStrokeWidth() ) );
484  edgePlotter.setWidthUnit( scalarSettings.edgeStrokeWidthUnit() );
485 
486  for ( const int i : egdesInExtent )
487  {
488  if ( context.renderingStopped() )
489  break;
490 
491  if ( i >= edges.size() )
492  continue;
493 
494  const QgsMeshEdge &edge = edges[i];
495  const int startVertexIndex = edge.first;
496  const int endVertexIndex = edge.second;
497 
498  if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
499  continue;
500 
501  const QgsMeshVertex &startVertex = vertices[startVertexIndex];
502  const QgsMeshVertex &endVertex = vertices[endVertexIndex];
503 
504  if ( mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnEdges )
505  {
506  edgePlotter.render( mScalarDatasetValues[i], mScalarDatasetValues[i], startVertex, endVertex, context );
507  }
508  else
509  {
510  edgePlotter.render( mScalarDatasetValues[startVertexIndex], mScalarDatasetValues[endVertexIndex], startVertex, endVertex, context );
511  }
512  }
513 }
514 
515 QColor QgsMeshLayerRenderer::colorAt( QgsColorRampShader *shader, double val ) const
516 {
517  int r, g, b, a;
518  if ( shader->shade( val, &r, &g, &b, &a ) )
519  {
520  return QColor( r, g, b, a );
521  }
522  return QColor();
523 }
524 
525 QgsPointXY QgsMeshLayerRenderer::fractionPoint( const QgsPointXY &p1, const QgsPointXY &p2, double fraction ) const
526 {
527  const QgsPointXY pt( p1.x() + fraction * ( p2.x() - p1.x() ),
528  p1.y() + fraction * ( p2.y() - p1.y() ) );
529  return pt;
530 }
531 
532 void QgsMeshLayerRenderer::renderScalarDatasetOnFaces( const QgsMeshRendererScalarSettings &scalarSettings )
533 {
534  QgsRenderContext &context = *renderContext();
535 
536  QgsColorRampShader *fcn = new QgsColorRampShader( scalarSettings.colorRampShader() );
537  QgsRasterShader *sh = new QgsRasterShader();
538  sh->setRasterShaderFunction( fcn ); // takes ownership of fcn
539  QgsMeshLayerInterpolator interpolator( mTriangularMesh,
543  context,
544  mOutputSize );
545  interpolator.setSpatialIndexActive( mIsMeshSimplificationActive );
546  QgsSingleBandPseudoColorRenderer renderer( &interpolator, 0, sh ); // takes ownership of sh
547  renderer.setClassificationMin( scalarSettings.classificationMinimum() );
548  renderer.setClassificationMax( scalarSettings.classificationMaximum() );
549  renderer.setOpacity( scalarSettings.opacity() );
550 
551  std::unique_ptr<QgsRasterBlock> bl( renderer.block( 0, context.mapExtent(), mOutputSize.width(), mOutputSize.height(), mFeedback.get() ) );
552  QImage img = bl->image();
553 
554  context.painter()->drawImage( 0, 0, img );
555 }
556 
557 void QgsMeshLayerRenderer::renderVectorDataset()
558 {
559  int groupIndex = mRendererSettings.activeVectorDatasetGroup();
560  if ( groupIndex < 0 )
561  return;
562 
563  if ( !mVectorDatasetValues.isValid() )
564  return; // no data at all
565 
566  if ( std::isnan( mVectorDatasetMagMinimum ) || std::isnan( mVectorDatasetMagMaximum ) )
567  return; // only NODATA values
568 
569  if ( !( mVectorDatasetMagMaximum > 0 ) )
570  return; //all vector are null vector
571 
572  std::unique_ptr<QgsMeshVectorRenderer> renderer( QgsMeshVectorRenderer::makeVectorRenderer(
580  mRendererSettings.vectorSettings( groupIndex ),
581  *renderContext(),
582  mLayerExtent,
583  mOutputSize ) );
584 
585  if ( renderer )
586  renderer->draw();
587 }
588 
QgsMeshDatasetGroupMetadata::minimum
double minimum() const
Returns minimum scalar value/vector magnitude present for whole dataset group.
Definition: qgsmeshdataset.cpp:176
QgsMapClippingUtils::collectClippingRegionsForLayer
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.
Definition: qgsmapclippingutils.cpp:23
qgsmeshlayerutils.h
QgsMeshLayerRenderer::mScalarDataType
QgsMeshDatasetGroupMetadata::DataType mScalarDataType
Definition: qgsmeshlayerrenderer.h:134
QgsMeshDatasetMetadata::minimum
double minimum() const
Returns minimum scalar value/vector magnitude present for the dataset.
Definition: qgsmeshdataset.cpp:225
QgsMeshLayerRenderer::mTriangularMesh
QgsTriangularMesh mTriangularMesh
Definition: qgsmeshlayerrenderer.h:126
QgsMeshLayerRenderer::mScalarDatasetValues
QVector< double > mScalarDatasetValues
Definition: qgsmeshlayerrenderer.h:132
QgsRectangle::height
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsMeshLayerRenderer::mRendererSettings
QgsMeshRendererSettings mRendererSettings
Definition: qgsmeshlayerrenderer.h:148
QgsPointXY::y
double y
Definition: qgspointxy.h:48
QgsRenderContext::convertToPainterUnits
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
Definition: qgsrendercontext.cpp:318
QgsRenderContext::setPainterFlagsUsingContext
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
Definition: qgsrendercontext.cpp:143
QgsRenderContext::mapToPixel
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Definition: qgsrendercontext.h:325
QgsMeshRendererScalarSettings::dataResamplingMethod
DataResamplingMethod dataResamplingMethod() const
Returns the type of interpolation to use to convert face defined datasets to values on vertices.
Definition: qgsmeshrenderersettings.cpp:105
QgsMeshLayerRenderer::mVectorDatasetGroupMagMinimum
double mVectorDatasetGroupMagMinimum
Definition: qgsmeshlayerrenderer.h:143
Face
struct Face_t Face
QgsTriangularMesh::vertices
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
Definition: qgstriangularmesh.cpp:287
QgsMapToPixel::mapUnitsPerPixel
double mapUnitsPerPixel() const
Returns current map units per pixel.
Definition: qgsmaptopixel.cpp:128
QgsMapLayerType::MeshLayer
@ MeshLayer
Added in 3.2.
QgsInterpolatedLineRenderer::setInterpolatedColor
void setInterpolatedColor(const QgsInterpolatedLineColor &strokeColoring)
Sets the stroke color used to plot.
Definition: qgsinterpolatedlinerenderer.cpp:26
QgsMeshLayerRenderer::mScalarDatasetMaximum
double mScalarDatasetMaximum
Definition: qgsmeshlayerrenderer.h:136
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsMeshRendererMeshSettings
Represents a mesh renderer settings for mesh object.
Definition: qgsmeshrenderersettings.h:42
QgsMeshRendererMeshSettings::color
QColor color() const
Returns color used for rendering.
Definition: qgsmeshrenderersettings.cpp:42
QgsMeshRendererScalarSettings::classificationMinimum
double classificationMinimum() const
Returns min value used for creation of the color ramp shader.
Definition: qgsmeshrenderersettings.cpp:91
QgsMeshLayerRenderer::mVectorDataType
QgsMeshDatasetGroupMetadata::DataType mVectorDataType
Definition: qgsmeshlayerrenderer.h:145
QgsPointXY::x
Q_GADGET double x
Definition: qgspointxy.h:47
QgsMeshRendererMeshSettings::lineWidth
double lineWidth() const
Returns line width used for rendering (in millimeters)
Definition: qgsmeshrenderersettings.cpp:32
QgsMeshLayerRenderer::feedback
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
Definition: qgsmeshlayerrenderer.cpp:93
QgsMeshLayer::rendererCache
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering)
Definition: qgsmeshlayer.cpp:282
QgsMeshLayer::meshSimplificationSettings
QgsMeshSimplificationSettings meshSimplificationSettings() const
Returns mesh simplification settings.
Definition: qgsmeshlayer.cpp:936
QgsMeshLayerRenderer::mLayerExtent
QgsRectangle mLayerExtent
Definition: qgsmeshlayerrenderer.h:129
QgsMeshLayerRenderer::render
bool render() override
Do the rendering (based on data stored in the class)
Definition: qgsmeshlayerrenderer.cpp:286
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsMapLayerRenderer::renderContext
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
Definition: qgsmaplayerrenderer.h:84
QgsPointXY::toQPointF
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspointxy.h:154
QgsTriangularMesh::triangles
const QVector< QgsMeshFace > & triangles() const
Returns triangles.
Definition: qgstriangularmesh.cpp:292
QgsMeshLayerRenderer::mNativeMesh
QgsMesh mNativeMesh
Definition: qgsmeshlayerrenderer.h:123
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsTriangularMesh::edgeIndexesForRectangle
QList< int > edgeIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of edges intersecting given bounding box It uses spatial indexing.
Definition: qgstriangularmesh.cpp:358
QgsColorRampShader
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Definition: qgscolorrampshader.h:40
qgssinglebandpseudocolorrenderer.h
QgsMeshLayer::triangularMesh
QgsTriangularMesh * triangularMesh(double minimumTriangleSize=0) const
Returns triangular mesh (nullptr before rendering or calling to updateMesh).
Definition: qgsmeshlayer.cpp:248
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsMeshDatasetMetadata
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
Definition: qgsmeshdataset.h:476
QgsInterpolatedLineRenderer::setInterpolatedWidth
void setInterpolatedWidth(const QgsInterpolatedLineWidth &strokeWidth)
Sets the stroke width used to plot.
Definition: qgsinterpolatedlinerenderer.cpp:21
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:51
QgsMeshLayer::datasetMetadata
QgsMeshDatasetMetadata datasetMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset metadata.
Definition: qgsmeshlayer.cpp:352
QgsTriangularMesh::levelOfDetail
int levelOfDetail() const
Returns the corresponding index of level of detail on which this mesh is associated.
Definition: qgstriangularmesh.cpp:267
QgsMeshUtils::nativeEdgesFromEdges
CORE_EXPORT QSet< int > nativeEdgesFromEdges(const QList< int > &edgesIndexes, const QVector< int > &edgesToNativeEdges)
Returns unique native faces indexes from list of triangle indexes.
Definition: qgstriangularmesh.cpp:545
QgsMeshUtils::nativeFacesFromTriangles
CORE_EXPORT QSet< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
Definition: qgstriangularmesh.cpp:540
QgsRenderContext::renderingStopped
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
Definition: qgsrendercontext.h:341
QgsPoint::y
double y
Definition: qgspoint.h:42
QgsMeshLayer::staticVectorDatasetIndex
QgsMeshDatasetIndex staticVectorDatasetIndex() const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
Definition: qgsmeshlayer.cpp:709
QgsMeshLayer::dataProvider
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Definition: qgsmeshlayer.cpp:156
QgsMeshLayerRenderer::mVectorDatasetValuesMag
QVector< double > mVectorDatasetValuesMag
Definition: qgsmeshlayerrenderer.h:140
QgsMeshRendererScalarSettings::opacity
double opacity() const
Returns opacity.
Definition: qgsmeshrenderersettings.cpp:101
QgsMeshRendererSettings::activeScalarDatasetGroup
int activeScalarDatasetGroup() const
Returns the active scalar dataset group.
Definition: qgsmeshrenderersettings.cpp:509
QgsMeshLayerRenderer::mFeedback
std::unique_ptr< QgsMeshLayerRendererFeedback > mFeedback
feedback class for cancellation
Definition: qgsmeshlayerrenderer.h:120
QgsMeshDatasetIndex::group
int group() const
Returns a group index.
Definition: qgsmeshdataset.cpp:26
qgsmeshlayerinterpolator.h
QgsMeshRendererSettings::scalarSettings
QgsMeshRendererScalarSettings scalarSettings(int groupIndex) const
Returns renderer settings.
Definition: qgsmeshrenderersettings.h:624
QgsMeshSimplificationSettings::isEnabled
bool isEnabled() const
Returns if the overview is active.
Definition: qgsmeshsimplificationsettings.cpp:20
QgsMesh::faces
QVector< QgsMeshFace > faces
Definition: qgsmeshdataprovider.h:113
QgsInterpolatedLineWidth
Represents a width than can vary depending on values.
Definition: qgsinterpolatedlinerenderer.h:111
QgsMeshRendererScalarSettings::colorRampShader
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
Definition: qgsmeshrenderersettings.cpp:81
QgsMapClippingUtils::calculatePainterClipRegion
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > &regions, const QgsRenderContext &context, QgsMapLayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
Definition: qgsmapclippingutils.cpp:126
QgsMesh3dAveragingMethod::equals
static bool equals(const QgsMesh3dAveragingMethod *a, const QgsMesh3dAveragingMethod *b)
Returns whether two methods equal.
Definition: qgsmesh3daveraging.cpp:214
QgsMeshDatasetIndex
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Definition: qgsmeshdataset.h:47
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsMeshRendererSettings::activeVectorDatasetGroup
int activeVectorDatasetGroup() const
Returns the active vector dataset group.
Definition: qgsmeshrenderersettings.cpp:519
QgsTriangularMesh::contains
bool contains(const QgsMesh::ElementType &type) const
Returns whether the mesh contains at mesh elements of given type.
Definition: qgstriangularmesh.cpp:272
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
QgsTriangularMesh::edges
const QVector< QgsMeshEdge > & edges() const
Returns edges.
Definition: qgstriangularmesh.cpp:297
QgsMeshDatasetIndex::isValid
bool isValid() const
Returns whether index is valid, ie at least groups is set.
Definition: qgsmeshdataset.cpp:36
QgsMeshLayerRenderer::QgsMeshLayerRenderer
QgsMeshLayerRenderer(QgsMeshLayer *layer, QgsRenderContext &context)
Ctor.
Definition: qgsmeshlayerrenderer.cpp:44
QgsMeshLayerRenderer::mVectorDatasetValues
QgsMeshDataBlock mVectorDatasetValues
Definition: qgsmeshlayerrenderer.h:139
QgsInterpolatedLineColor
Class defining color to render mesh datasets.
Definition: qgsinterpolatedlinerenderer.h:35
QgsPoint::x
Q_GADGET double x
Definition: qgspoint.h:41
QgsMeshRendererScalarSettings::None
@ None
Does not use resampling.
Definition: qgsmeshrenderersettings.h:111
QgsMeshLayerRenderer::mVectorDatasetMagMaximum
double mVectorDatasetMagMaximum
Definition: qgsmeshlayerrenderer.h:142
QgsMeshRendererScalarSettings::DataResamplingMethod
DataResamplingMethod
Resampling of value from dataset.
Definition: qgsmeshrenderersettings.h:106
QgsMeshLayer::activeVectorDatasetAtTime
QgsMeshDatasetIndex activeVectorDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active vector group depending on the time range If the temporal properties...
Definition: qgsmeshlayer.cpp:638
qgsrenderer.h
QgsScopedQPainterState
Scoped object for saving and restoring a QPainter object's state.
Definition: qgsrendercontext.h:1120
qgsfillsymbollayer.h
QgsMeshRendererSettings::nativeMeshSettings
QgsMeshRendererMeshSettings nativeMeshSettings() const
Returns native mesh renderer settings.
Definition: qgsmeshrenderersettings.h:602
QgsMeshFace
QVector< int > QgsMeshFace
List of vertex indexes.
Definition: qgsmeshdataprovider.h:41
QgsMeshRendererSettings::triangularMeshSettings
QgsMeshRendererMeshSettings triangularMeshSettings() const
Returns triangular mesh renderer settings.
Definition: qgsmeshrenderersettings.h:607
QgsMapToPixel::transform
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
Definition: qgsmaptopixel.cpp:217
QgsMeshSimplificationSettings
Represents a overview renderer settings.
Definition: qgsmeshsimplificationsettings.h:40
qgsstyle.h
QgsMeshLayerRenderer::mVectorDatasetGroupMagMaximum
double mVectorDatasetGroupMagMaximum
Definition: qgsmeshlayerrenderer.h:144
qgsmeshlayer.h
qgsrastershader.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsMeshRendererScalarSettings::edgeStrokeWidthUnit
QgsUnitTypes::RenderUnit edgeStrokeWidthUnit() const
Returns the stroke width unit used to render edges scalar dataset.
Definition: qgsmeshrenderersettings.cpp:181
QgsMeshDatasetGroupMetadata::dataType
DataType dataType() const
Returns whether dataset group data is defined on vertices or faces or volumes.
Definition: qgsmeshdataset.cpp:171
QgsMeshRendererScalarSettings
Represents a mesh renderer settings for scalar datasets.
Definition: qgsmeshrenderersettings.h:95
QgsMeshRendererSettings::vectorSettings
QgsMeshRendererVectorSettings vectorSettings(int groupIndex) const
Returns renderer settings.
Definition: qgsmeshrenderersettings.h:629
QgsTriangularMesh::faceIndexesForRectangle
QList< int > faceIndexesForRectangle(const QgsRectangle &rectangle) const
Finds indexes of triangles intersecting given bounding box It uses spatial indexing.
Definition: qgstriangularmesh.cpp:353
QgsMeshDatasetGroupMetadata
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
Definition: qgsmeshdataset.h:350
qgsmeshtracerenderer.h
qgsmeshlayerrenderer.h
QgsRenderContext::mapExtent
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
Definition: qgsrendercontext.h:318
QgsMeshDatasetGroupMetadata::isScalar
bool isScalar() const
Returns whether dataset group has scalar data.
Definition: qgsmeshdataset.cpp:156
QgsMeshLayerRenderer::mScalarActiveFaceFlagValues
QgsMeshDataBlock mScalarActiveFaceFlagValues
Definition: qgsmeshlayerrenderer.h:133
QgsMeshEdge
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
Definition: qgsmeshdataprovider.h:48
QgsMeshRendererSettings::edgeMeshSettings
QgsMeshRendererMeshSettings edgeMeshSettings() const
Returns edge mesh renderer settings.
Definition: qgsmeshrenderersettings.h:615
QgsMeshRendererMeshSettings::isEnabled
bool isEnabled() const
Returns whether mesh structure rendering is enabled.
Definition: qgsmeshrenderersettings.cpp:22
QgsInterpolatedLineRenderer::setWidthUnit
void setWidthUnit(const QgsUnitTypes::RenderUnit &strokeWidthUnit)
Sets the unit of the stroke width.
Definition: qgsinterpolatedlinerenderer.cpp:31
QgsMeshDatasetGroupMetadata::maximum
double maximum() const
Returns maximum scalar value/vector magnitude present for whole dataset group.
Definition: qgsmeshdataset.cpp:181
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
qgsmeshvectorrenderer.h
QgsColorRampShader::shade
bool shade(double value, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) const override
Generates and new RGB value based on one input value.
Definition: qgscolorrampshader.cpp:321
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsTriangularMesh::trianglesToNativeFaces
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
Definition: qgstriangularmesh.cpp:317
qgsfield.h
qgssettings.h
qgsmapclippingutils.h
QgsMeshLayer::staticScalarDatasetIndex
QgsMeshDatasetIndex staticScalarDatasetIndex() const
Returns the static scalar dataset index that is rendered if the temporal properties is not active.
Definition: qgsmeshlayer.cpp:909
qgsmeshdataprovidertemporalcapabilities.h
QgsMeshRendererSettings::averagingMethod
QgsMesh3dAveragingMethod * averagingMethod() const
Returns averaging method for conversion of 3d stacked mesh data to 2d data.
Definition: qgsmeshrenderersettings.cpp:396
QgsMeshLayerRenderer::mClippingRegions
QList< QgsMapClippingRegion > mClippingRegions
Definition: qgsmeshlayerrenderer.h:150
QgsMeshDataBlock
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
Definition: qgsmeshdataset.h:136
QgsMeshLayer::datasetGroupMetadata
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
Definition: qgsmeshlayer.cpp:342
QgsMeshDatasetMetadata::maximum
double maximum() const
Returns maximum scalar value/vector magnitude present for the dataset.
Definition: qgsmeshdataset.cpp:230
QgsMeshLayer::nativeMesh
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering or calling to updateMesh)
Definition: qgsmeshlayer.cpp:238
QgsSingleBandPseudoColorRenderer
Raster renderer pipe for single band pseudocolor.
Definition: qgssinglebandpseudocolorrenderer.h:36
QgsMeshLayer::extent
QgsRectangle extent() const override
Returns the extent of the layer.
Definition: qgsmeshlayer.cpp:178
QgsRasterShader::setRasterShaderFunction
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
Definition: qgsrastershader.cpp:56
QgsInterpolatedLineRenderer
Represents a line with width and color varying depending on values.
Definition: qgsinterpolatedlinerenderer.h:185
qgslogger.h
QgsTriangularMesh::edgesToNativeEdges
const QVector< int > & edgesToNativeEdges() const
Returns mapping between edges and original edges.
Definition: qgstriangularmesh.cpp:322
QgsMeshRendererScalarSettings::edgeStrokeWidth
QgsInterpolatedLineWidth edgeStrokeWidth() const
Returns the stroke width used to render edges scalar dataset.
Definition: qgsmeshrenderersettings.cpp:171
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:179
QgsMeshRendererScalarSettings::classificationMaximum
double classificationMaximum() const
Returns max value used for creation of the color ramp shader.
Definition: qgsmeshrenderersettings.cpp:93
QgsRasterShader
Interface for all raster shaders.
Definition: qgsrastershader.h:35
QgsMeshLayer::datasetGroupCount
int datasetGroupCount() const
Returns the dataset groups count handle by the layer.
Definition: qgsmeshlayer.cpp:327
QgsMesh3dAveragingMethod::clone
virtual QgsMesh3dAveragingMethod * clone() const =0
Clone the instance.
QgsMeshLayer::areFacesActive
QgsMeshDataBlock areFacesActive(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns whether the faces are active for particular dataset.
Definition: qgsmeshlayer.cpp:372
QgsMeshLayerRenderer::mScalarDatasetMinimum
double mScalarDatasetMinimum
Definition: qgsmeshlayerrenderer.h:135
QgsMeshLayer::activeScalarDatasetAtTime
QgsMeshDatasetIndex activeScalarDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active scalar group depending on the time range.
Definition: qgsmeshlayer.cpp:630
qgspointxy.h
QgsMeshLayerRenderer::mVectorDatasetMagMinimum
double mVectorDatasetMagMinimum
Definition: qgsmeshlayerrenderer.h:141
QgsMeshLayerRenderer::mOutputSize
QSize mOutputSize
Definition: qgsmeshlayerrenderer.h:153
QgsMeshDataBlock::isValid
bool isValid() const
Whether the block is valid.
Definition: qgsmeshdataset.cpp:261
QgsInterpolatedLineRenderer::render
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...
Definition: qgsinterpolatedlinerenderer.cpp:36
QgsMeshSimplificationSettings::meshResolution
int meshResolution() const
Returns the mesh resolution e.i., the minimum size (average) of triangles in pixels.
Definition: qgsmeshsimplificationsettings.cpp:58