QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
44  QgsMeshLayer *layer,
45  QgsRenderContext &context )
46  : QgsMapLayerRenderer( layer->id(), &context )
47  , mFeedback( new QgsMeshLayerRendererFeedback )
48  , mRendererSettings( layer->rendererSettings() )
49 {
50  // make copies for mesh data
51  // cppcheck-suppress assertWithSideEffect
52  Q_ASSERT( layer->nativeMesh() );
53  // cppcheck-suppress assertWithSideEffect
54  Q_ASSERT( layer->triangularMesh() );
55  // cppcheck-suppress assertWithSideEffect
56  Q_ASSERT( layer->rendererCache() );
57  // cppcheck-suppress assertWithSideEffect
58  Q_ASSERT( layer->dataProvider() );
59 
60  // copy native mesh
61  mNativeMesh = *( layer->nativeMesh() );
62  mLayerExtent = layer->extent();
63 
64  // copy triangular mesh
65  copyTriangularMeshes( layer, context );
66 
67  // copy datasets
68  copyScalarDatasetValues( layer );
69  copyVectorDatasetValues( layer );
70 
71  calculateOutputSize();
72 }
73 
74 void QgsMeshLayerRenderer::copyTriangularMeshes( QgsMeshLayer *layer, QgsRenderContext &context )
75 {
76  // handle level of details of mesh
77  QgsMeshSimplificationSettings simplificationSettings = layer->meshSimplificationSettings();
78  if ( simplificationSettings.isEnabled() )
79  {
80  double triangleSize = simplificationSettings.meshResolution() * context.mapToPixel().mapUnitsPerPixel();
81  mTriangularMesh = *( layer->triangularMesh( triangleSize ) );
82  mIsMeshSimplificationActive = true;
83  }
84  else
85  {
86  mTriangularMesh = *( layer->triangularMesh() );
87  }
88 }
89 
91 {
92  return mFeedback.get();
93 }
94 
95 void QgsMeshLayerRenderer::calculateOutputSize()
96 {
97  // figure out image size
98  QgsRenderContext &context = *renderContext();
99  QgsRectangle extent = context.mapExtent();
100  QgsMapToPixel mapToPixel = context.mapToPixel();
101  QgsPointXY topleft = mapToPixel.transform( extent.xMinimum(), extent.yMaximum() );
102  QgsPointXY bottomright = mapToPixel.transform( extent.xMaximum(), extent.yMinimum() );
103  int width = int( bottomright.x() - topleft.x() );
104  int height = int( bottomright.y() - topleft.y() );
105  mOutputSize = QSize( width, height );
106 }
107 
108 void QgsMeshLayerRenderer::copyScalarDatasetValues( QgsMeshLayer *layer )
109 {
110  QgsMeshDatasetIndex datasetIndex;
111  if ( renderContext()->isTemporal() )
112  datasetIndex = layer->activeScalarDatasetAtTime( renderContext()->temporalRange() );
113  else
114  datasetIndex = layer->staticScalarDatasetIndex();
115 
116  // Find out if we can use cache up to date. If yes, use it and return
117  const int datasetGroupCount = layer->dataProvider()->datasetGroupCount();
119  QgsMeshLayerRendererCache *cache = layer->rendererCache();
120  if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
121  ( cache->mActiveScalarDatasetIndex == datasetIndex ) &&
122  ( cache->mDataInterpolationMethod == method ) &&
123  ( QgsMesh3dAveragingMethod::equals( cache->mScalarAveragingMethod.get(), mRendererSettings.averagingMethod() ) )
124  )
125  {
126  mScalarDatasetValues = cache->mScalarDatasetValues;
127  mScalarActiveFaceFlagValues = cache->mScalarActiveFaceFlagValues;
128  mScalarDataType = cache->mScalarDataType;
129  mScalarDatasetMinimum = cache->mScalarDatasetMinimum;
130  mScalarDatasetMaximum = cache->mScalarDatasetMaximum;
131  return;
132  }
133 
134  // Cache is not up-to-date, gather data
135  if ( datasetIndex.isValid() )
136  {
137  const QgsMeshDatasetGroupMetadata metadata = layer->dataProvider()->datasetGroupMetadata( datasetIndex.group() );
138  mScalarDataType = QgsMeshLayerUtils::datasetValuesType( metadata.dataType() );
139 
140  // populate scalar values
141  const int count = QgsMeshLayerUtils::datasetValuesCount( &mNativeMesh, mScalarDataType );
142  QgsMeshDataBlock vals = QgsMeshLayerUtils::datasetValues(
143  layer,
144  datasetIndex,
145  0,
146  count );
147 
148  if ( vals.isValid() )
149  {
150  // vals could be scalar or vectors, for contour rendering we want always magnitude
151  mScalarDatasetValues = QgsMeshLayerUtils::calculateMagnitudes( vals );
152  }
153  else
154  {
155  mScalarDatasetValues = QVector<double>( count, std::numeric_limits<double>::quiet_NaN() );
156  }
157 
158  // populate face active flag, always defined on faces
160  datasetIndex,
161  0,
162  mNativeMesh.faces.count() );
163 
164  // for data on faces, there could be request to interpolate the data to vertices
165  if ( method != QgsMeshRendererScalarSettings::None )
166  {
167  if ( mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnFaces )
168  {
169  mScalarDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnVertices;
170  mScalarDatasetValues = QgsMeshLayerUtils::interpolateFromFacesData(
172  &mNativeMesh,
175  method
176  );
177  }
178  else if ( mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnVertices )
179  {
180  mScalarDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnFaces;
181  mScalarDatasetValues = QgsMeshLayerUtils::resampleFromVerticesToFaces(
183  &mNativeMesh,
186  method
187  );
188  }
189 
190  }
191 
192  const QgsMeshDatasetMetadata datasetMetadata = layer->dataProvider()->datasetMetadata( datasetIndex );
193  mScalarDatasetMinimum = datasetMetadata.minimum();
194  mScalarDatasetMaximum = datasetMetadata.maximum();
195  }
196 
197  // update cache
198  cache->mDatasetGroupsCount = datasetGroupCount;
199  cache->mActiveScalarDatasetIndex = datasetIndex;
200  cache->mDataInterpolationMethod = method;
201  cache->mScalarDatasetValues = mScalarDatasetValues;
202  cache->mScalarActiveFaceFlagValues = mScalarActiveFaceFlagValues;
203  cache->mScalarDataType = mScalarDataType;
204  cache->mScalarDatasetMinimum = mScalarDatasetMinimum;
205  cache->mScalarDatasetMaximum = mScalarDatasetMaximum;
206  cache->mScalarAveragingMethod.reset( mRendererSettings.averagingMethod() ? mRendererSettings.averagingMethod()->clone() : nullptr );
207 }
208 
209 
210 void QgsMeshLayerRenderer::copyVectorDatasetValues( QgsMeshLayer *layer )
211 {
212  QgsMeshDatasetIndex datasetIndex;
213  if ( renderContext()->isTemporal() )
214  datasetIndex = layer->activeVectorDatasetAtTime( renderContext()->temporalRange() );
215  else
216  datasetIndex = layer->staticVectorDatasetIndex();
217 
218  // Find out if we can use cache up to date. If yes, use it and return
219  const int datasetGroupCount = layer->dataProvider()->datasetGroupCount();
220  QgsMeshLayerRendererCache *cache = layer->rendererCache();
221  if ( ( cache->mDatasetGroupsCount == datasetGroupCount ) &&
222  ( cache->mActiveVectorDatasetIndex == datasetIndex ) &&
223  ( QgsMesh3dAveragingMethod::equals( cache->mVectorAveragingMethod.get(), mRendererSettings.averagingMethod() ) )
224  )
225  {
226  mVectorDatasetValues = cache->mVectorDatasetValues;
227  mVectorDatasetValuesMag = cache->mVectorDatasetValuesMag;
228  mVectorDatasetMagMinimum = cache->mVectorDatasetMagMinimum;
229  mVectorDatasetMagMaximum = cache->mVectorDatasetMagMaximum;
230  mVectorDatasetGroupMagMinimum = cache->mVectorDatasetMagMinimum;
231  mVectorDatasetGroupMagMaximum = cache->mVectorDatasetMagMaximum;
232  mVectorDataType = cache->mVectorDataType;
233  return;
234  }
235 
236  // Cache is not up-to-date, gather data
237  if ( datasetIndex.isValid() )
238  {
239  const QgsMeshDatasetGroupMetadata metadata = layer->dataProvider()->datasetGroupMetadata( datasetIndex );
240 
241  bool isScalar = metadata.isScalar();
242  if ( isScalar )
243  {
244  QgsDebugMsg( QStringLiteral( "Dataset has no vector values" ) );
245  }
246  else
247  {
248  mVectorDataType = QgsMeshLayerUtils::datasetValuesType( metadata.dataType() );
249 
252 
253  int count = QgsMeshLayerUtils::datasetValuesCount( &mNativeMesh, mVectorDataType );
254  mVectorDatasetValues = QgsMeshLayerUtils::datasetValues(
255  layer,
256  datasetIndex,
257  0,
258  count );
259 
261  mVectorDatasetValuesMag = QgsMeshLayerUtils::calculateMagnitudes( mVectorDatasetValues );
262  else
263  mVectorDatasetValuesMag = QVector<double>( count, std::numeric_limits<double>::quiet_NaN() );
264 
265  const QgsMeshDatasetMetadata datasetMetadata = layer->dataProvider()->datasetMetadata( datasetIndex );
266  mVectorDatasetMagMinimum = datasetMetadata.minimum();
267  mVectorDatasetMagMaximum = datasetMetadata.maximum();
268  }
269  }
270 
271  // update cache
272  cache->mDatasetGroupsCount = datasetGroupCount;
273  cache->mActiveVectorDatasetIndex = datasetIndex;
274  cache->mVectorDatasetValues = mVectorDatasetValues;
275  cache->mVectorDatasetValuesMag = mVectorDatasetValuesMag;
276  cache->mVectorDatasetMagMinimum = mVectorDatasetMagMinimum;
277  cache->mVectorDatasetMagMaximum = mVectorDatasetMagMaximum;
278  cache->mVectorDatasetGroupMagMinimum = mVectorDatasetMagMinimum;
279  cache->mVectorDatasetGroupMagMaximum = mVectorDatasetMagMaximum;
280  cache->mVectorDataType = mVectorDataType;
281  cache->mVectorAveragingMethod.reset( mRendererSettings.averagingMethod() ? mRendererSettings.averagingMethod()->clone() : nullptr );
282 }
283 
285 {
286  renderScalarDataset();
287  renderMesh();
288  renderVectorDataset();
289  return true;
290 }
291 
292 void QgsMeshLayerRenderer::renderMesh()
293 {
297  return;
298 
299  // triangular mesh
300  const QList<int> trianglesInExtent = mTriangularMesh.faceIndexesForRectangle( renderContext()->mapExtent() );
302  {
303  renderFaceMesh(
306  trianglesInExtent );
307  }
308 
309  // native mesh
311  {
312  const QSet<int> nativeFacesInExtent = QgsMeshUtils::nativeFacesFromTriangles( trianglesInExtent,
314 
315  renderFaceMesh(
318  nativeFacesInExtent.values() );
319  }
320 
321  // edge mesh
323  {
324  const QList<int> edgesInExtent = mTriangularMesh.edgeIndexesForRectangle( renderContext()->mapExtent() );
325  renderEdgeMesh( mRendererSettings.edgeMeshSettings(), edgesInExtent );
326  }
327 }
328 
329 static QPainter *_painterForMeshFrame( QgsRenderContext &context, const QgsMeshRendererMeshSettings &settings )
330 {
331  // Set up the render configuration options
332  QPainter *painter = context.painter();
333  painter->save();
334  if ( context.flags() & QgsRenderContext::Antialiasing )
335  painter->setRenderHint( QPainter::Antialiasing, true );
336 
337  QPen pen = painter->pen();
338  pen.setCapStyle( Qt::FlatCap );
339  pen.setJoinStyle( Qt::MiterJoin );
340 
341  double penWidth = context.convertToPainterUnits( settings.lineWidth(),
342  QgsUnitTypes::RenderUnit::RenderMillimeters );
343  pen.setWidthF( penWidth );
344  pen.setColor( settings.color() );
345  painter->setPen( pen );
346  return painter;
347 }
348 
349 void QgsMeshLayerRenderer::renderEdgeMesh( const QgsMeshRendererMeshSettings &settings, const QList<int> &edgesInExtent )
350 {
351  Q_ASSERT( settings.isEnabled() );
352 
353  if ( !mTriangularMesh.contains( QgsMesh::ElementType::Edge ) )
354  return;
355 
356  QgsRenderContext &context = *renderContext();
357  QPainter *painter = _painterForMeshFrame( context, settings );
358 
359  const QVector<QgsMeshEdge> edges = mTriangularMesh.edges();
360  const QVector<QgsMeshVertex> vertices = mTriangularMesh.vertices();
361 
362  for ( const int i : edgesInExtent )
363  {
364  if ( context.renderingStopped() )
365  break;
366 
367  if ( i >= edges.size() )
368  continue;
369 
370  const QgsMeshEdge &edge = edges[i];
371  const int startVertexIndex = edge.first;
372  const int endVertexIndex = edge.second;
373 
374  if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
375  continue;
376 
377  const QgsMeshVertex &startVertex = vertices[startVertexIndex];
378  const QgsMeshVertex &endVertex = vertices[endVertexIndex];
379  const QgsPointXY lineStart = context.mapToPixel().transform( startVertex.x(), startVertex.y() );
380  const QgsPointXY lineEnd = context.mapToPixel().transform( endVertex.x(), endVertex.y() );
381  painter->drawLine( lineStart.toQPointF(), lineEnd.toQPointF() );
382  }
383  painter->restore();
384 };
385 
386 void QgsMeshLayerRenderer::renderFaceMesh(
387  const QgsMeshRendererMeshSettings &settings,
388  const QVector<QgsMeshFace> &faces,
389  const QList<int> &facesInExtent )
390 {
391  Q_ASSERT( settings.isEnabled() );
392 
394  return;
395 
396  QgsRenderContext &context = *renderContext();
397  QPainter *painter = _painterForMeshFrame( context, settings );
398 
399  const QVector<QgsMeshVertex> &vertices = mTriangularMesh.vertices(); //Triangular mesh vertices contains also native mesh vertices
400  QSet<QPair<int, int>> drawnEdges;
401 
402  for ( const int i : facesInExtent )
403  {
404  if ( context.renderingStopped() )
405  break;
406 
407  const QgsMeshFace &face = faces[i];
408  if ( face.size() < 2 )
409  continue;
410 
411  for ( int j = 0; j < face.size(); ++j )
412  {
413  const int startVertexId = face[j];
414  const int endVertexId = face[( j + 1 ) % face.size()];
415  const QPair<int, int> thisEdge( startVertexId, endVertexId );
416  const QPair<int, int> thisEdgeReversed( endVertexId, startVertexId );
417  if ( drawnEdges.contains( thisEdge ) || drawnEdges.contains( thisEdgeReversed ) )
418  continue;
419  drawnEdges.insert( thisEdge );
420  drawnEdges.insert( thisEdgeReversed );
421 
422  const QgsMeshVertex &startVertex = vertices[startVertexId];
423  const QgsMeshVertex &endVertex = vertices[endVertexId];
424  const QgsPointXY lineStart = context.mapToPixel().transform( startVertex.x(), startVertex.y() );
425  const QgsPointXY lineEnd = context.mapToPixel().transform( endVertex.x(), endVertex.y() );
426  painter->drawLine( lineStart.toQPointF(), lineEnd.toQPointF() );
427  }
428  }
429 
430  painter->restore();
431 }
432 
433 void QgsMeshLayerRenderer::renderScalarDataset()
434 {
435  if ( mScalarDatasetValues.isEmpty() )
436  return; // activeScalarDataset == NO_ACTIVE_MESH_DATASET
437 
438  if ( std::isnan( mScalarDatasetMinimum ) || std::isnan( mScalarDatasetMaximum ) )
439  return; // only NODATA values
440 
441  int groupIndex = mRendererSettings.activeScalarDatasetGroup();
442  if ( groupIndex < 0 )
443  return; // no shader
444 
445  const QgsMeshRendererScalarSettings scalarSettings = mRendererSettings.scalarSettings( groupIndex );
446 
448  ( mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnEdges ) )
449  {
450  renderScalarDatasetOnFaces( scalarSettings );
451  }
452 
453  if ( ( mTriangularMesh.contains( QgsMesh::ElementType::Edge ) ) &&
454  ( mScalarDataType != QgsMeshDatasetGroupMetadata::DataType::DataOnFaces ) )
455  {
456  renderScalarDatasetOnEdges( scalarSettings );
457  }
458 }
459 
460 void QgsMeshLayerRenderer::renderScalarDatasetOnEdges( const QgsMeshRendererScalarSettings &scalarSettings )
461 {
462  QgsRenderContext &context = *renderContext();
463  const QVector<QgsMeshEdge> edges = mTriangularMesh.edges();
464  const QVector<QgsMeshVertex> vertices = mTriangularMesh.vertices();
465  const QList<int> egdesInExtent = mTriangularMesh.edgeIndexesForRectangle( context.mapExtent() );
466  const QSet<int> nativeEdgesInExtent = QgsMeshUtils::nativeEdgesFromEdges( egdesInExtent,
468 
469  QgsInterpolatedLineRenderer edgePlotter;
470  edgePlotter.setInterpolatedColor( QgsInterpolatedLineColor( scalarSettings.colorRampShader() ) );
471  edgePlotter.setInterpolatedWidth( QgsInterpolatedLineWidth( scalarSettings.edgeStrokeWidth() ) );
472  edgePlotter.setWidthUnit( scalarSettings.edgeStrokeWidthUnit() );
473 
474  for ( const int i : egdesInExtent )
475  {
476  if ( context.renderingStopped() )
477  break;
478 
479  if ( i >= edges.size() )
480  continue;
481 
482  const QgsMeshEdge &edge = edges[i];
483  const int startVertexIndex = edge.first;
484  const int endVertexIndex = edge.second;
485 
486  if ( ( startVertexIndex >= vertices.size() ) || endVertexIndex >= vertices.size() )
487  continue;
488 
489  const QgsMeshVertex &startVertex = vertices[startVertexIndex];
490  const QgsMeshVertex &endVertex = vertices[endVertexIndex];
491 
492  if ( mScalarDataType == QgsMeshDatasetGroupMetadata::DataType::DataOnEdges )
493  {
494  edgePlotter.render( mScalarDatasetValues[i], mScalarDatasetValues[i], startVertex, endVertex, context );
495  }
496  else
497  {
498  edgePlotter.render( mScalarDatasetValues[startVertexIndex], mScalarDatasetValues[endVertexIndex], startVertex, endVertex, context );
499  }
500  }
501 }
502 
503 QColor QgsMeshLayerRenderer::colorAt( QgsColorRampShader *shader, double val ) const
504 {
505  int r, g, b, a;
506  if ( shader->shade( val, &r, &g, &b, &a ) )
507  {
508  return QColor( r, g, b, a );
509  }
510  return QColor();
511 }
512 
513 QgsPointXY QgsMeshLayerRenderer::fractionPoint( const QgsPointXY &p1, const QgsPointXY &p2, double fraction ) const
514 {
515  const QgsPointXY pt( p1.x() + fraction * ( p2.x() - p1.x() ),
516  p1.y() + fraction * ( p2.y() - p1.y() ) );
517  return pt;
518 }
519 
520 void QgsMeshLayerRenderer::renderScalarDatasetOnFaces( const QgsMeshRendererScalarSettings &scalarSettings )
521 {
522  QgsRenderContext &context = *renderContext();
523 
524  QgsColorRampShader *fcn = new QgsColorRampShader( scalarSettings.colorRampShader() );
525  QgsRasterShader *sh = new QgsRasterShader();
526  sh->setRasterShaderFunction( fcn ); // takes ownership of fcn
527  QgsMeshLayerInterpolator interpolator( mTriangularMesh,
531  context,
532  mOutputSize );
533  interpolator.setSpatialIndexActive( mIsMeshSimplificationActive );
534  QgsSingleBandPseudoColorRenderer renderer( &interpolator, 0, sh ); // takes ownership of sh
535  renderer.setClassificationMin( scalarSettings.classificationMinimum() );
536  renderer.setClassificationMax( scalarSettings.classificationMaximum() );
537  renderer.setOpacity( scalarSettings.opacity() );
538 
539  std::unique_ptr<QgsRasterBlock> bl( renderer.block( 0, context.mapExtent(), mOutputSize.width(), mOutputSize.height(), mFeedback.get() ) );
540  QImage img = bl->image();
541 
542  context.painter()->drawImage( 0, 0, img );
543 }
544 
545 void QgsMeshLayerRenderer::renderVectorDataset()
546 {
547  int groupIndex = mRendererSettings.activeVectorDatasetGroup();
548  if ( groupIndex < 0 )
549  return;
550 
551  if ( !mVectorDatasetValues.isValid() )
552  return; // no data at all
553 
554  if ( std::isnan( mVectorDatasetMagMinimum ) || std::isnan( mVectorDatasetMagMaximum ) )
555  return; // only NODATA values
556 
557  if ( !( mVectorDatasetMagMaximum > 0 ) )
558  return; //all vector are null vector
559 
560  std::unique_ptr<QgsMeshVectorRenderer> renderer( QgsMeshVectorRenderer::makeVectorRenderer(
568  mRendererSettings.vectorSettings( groupIndex ),
569  *renderContext(),
570  mLayerExtent,
571  mOutputSize ) );
572 
573  if ( renderer )
574  renderer->draw();
575 }
576 
QgsMeshDatasetGroupMetadata::minimum
double minimum() const
Returns minimum scalar value/vector magnitude present for whole dataset group.
Definition: qgsmeshdataset.cpp:174
qgsmeshlayerutils.h
QgsMeshDatasetSourceInterface::datasetGroupCount
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
QgsMeshLayerRenderer::mScalarDataType
QgsMeshDatasetGroupMetadata::DataType mScalarDataType
Definition: qgsmeshlayerrenderer.h:133
QgsMeshDatasetMetadata::minimum
double minimum() const
Returns minimum scalar value/vector magnitude present for the dataset.
Definition: qgsmeshdataset.cpp:218
QgsMeshLayerRenderer::mTriangularMesh
QgsTriangularMesh mTriangularMesh
Definition: qgsmeshlayerrenderer.h:125
QgsMeshLayerRenderer::mScalarDatasetValues
QVector< double > mScalarDatasetValues
Definition: qgsmeshlayerrenderer.h:131
QgsMeshLayerRenderer::mRendererSettings
QgsMeshRendererSettings mRendererSettings
Definition: qgsmeshlayerrenderer.h:147
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:287
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:309
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:142
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
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:135
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
QgsMeshRendererMeshSettings
Definition: qgsmeshrenderersettings.h:41
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:144
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:90
QgsRectangle::xMaximum
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
QgsMeshLayer::rendererCache
QgsMeshLayerRendererCache * rendererCache()
Returns native mesh (nullptr before rendering)
Definition: qgsmeshlayer.cpp:258
QgsMeshLayer::meshSimplificationSettings
QgsMeshSimplificationSettings meshSimplificationSettings() const
Returns mesh simplification settings.
Definition: qgsmeshlayer.cpp:852
QgsMeshLayerRenderer::mLayerExtent
QgsRectangle mLayerExtent
Definition: qgsmeshlayerrenderer.h:128
QgsMeshLayerRenderer::render
bool render() override
Do the rendering (based on data stored in the class)
Definition: qgsmeshlayerrenderer.cpp:284
QgsRenderContext
Definition: qgsrendercontext.h:57
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:122
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
Definition: qgscolorrampshader.h:39
qgssinglebandpseudocolorrenderer.h
QgsMeshLayer::triangularMesh
QgsTriangularMesh * triangularMesh(double minimumTriangleSize=0) const
Returns triangular mesh (nullptr before rendering or calling to updateMesh).
Definition: qgsmeshlayer.cpp:224
QgsRectangle
Definition: qgsrectangle.h:41
QgsMeshDatasetMetadata
Definition: qgsmeshdataset.h:467
QgsInterpolatedLineRenderer::setInterpolatedWidth
void setInterpolatedWidth(const QgsInterpolatedLineWidth &strokeWidth)
Sets the stroke width used to plot.
Definition: qgsinterpolatedlinerenderer.cpp:21
QgsMapLayerRenderer
Definition: qgsmaplayerrenderer.h:50
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:325
QgsPoint::y
double y
Definition: qgspoint.h:59
QgsMeshLayer::staticVectorDatasetIndex
QgsMeshDatasetIndex staticVectorDatasetIndex() const
Returns the static vector dataset index that is rendered if the temporal properties is not active.
Definition: qgsmeshlayer.cpp:638
QgsMeshLayerRenderer::mVectorDatasetValuesMag
QVector< double > mVectorDatasetValuesMag
Definition: qgsmeshlayerrenderer.h:139
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:119
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:107
QgsInterpolatedLineWidth
Definition: qgsinterpolatedlinerenderer.h:110
QgsMeshRendererScalarSettings::colorRampShader
QgsColorRampShader colorRampShader() const
Returns color ramp shader function.
Definition: qgsmeshrenderersettings.cpp:81
QgsMesh3dAveragingMethod::equals
static bool equals(const QgsMesh3dAveragingMethod *a, const QgsMesh3dAveragingMethod *b)
Returns whether two methods equal.
Definition: qgsmesh3daveraging.cpp:214
QgsMeshDatasetIndex
Definition: qgsmeshdataset.h:45
QgsFeedback
Definition: qgsfeedback.h:43
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
Definition: qgsmeshlayer.h:94
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:43
QgsMeshLayerRenderer::mVectorDatasetValues
QgsMeshDataBlock mVectorDatasetValues
Definition: qgsmeshlayerrenderer.h:138
QgsInterpolatedLineColor
Definition: qgsinterpolatedlinerenderer.h:34
QgsMeshLayer::nativeMesh
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering or calling to updateMesh)
Definition: qgsmeshlayer.cpp:214
QgsMeshRendererScalarSettings::None
@ None
Does not use resampling.
Definition: qgsmeshrenderersettings.h:111
QgsMeshLayerRenderer::mVectorDatasetMagMaximum
double mVectorDatasetMagMaximum
Definition: qgsmeshlayerrenderer.h:141
QgsMeshRendererScalarSettings::DataResamplingMethod
DataResamplingMethod
Resampling of value from dataset.
Definition: qgsmeshrenderersettings.h:105
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:554
qgsrenderer.h
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
QgsRectangle::yMaximum
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
QgsMeshSimplificationSettings
Definition: qgsmeshsimplificationsettings.h:39
qgsstyle.h
QgsMeshLayerRenderer::mVectorDatasetGroupMagMaximum
double mVectorDatasetGroupMagMaximum
Definition: qgsmeshlayerrenderer.h:143
QgsMeshDatasetSourceInterface::datasetMetadata
virtual QgsMeshDatasetMetadata datasetMetadata(QgsMeshDatasetIndex index) const =0
Returns dataset metadata.
qgsmeshlayer.h
qgsrastershader.h
QgsPointXY
Definition: qgspointxy.h:43
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:169
QgsMeshRendererScalarSettings
Definition: qgsmeshrenderersettings.h:94
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
Definition: qgsmeshdataset.h:348
qgsmeshtracerenderer.h
qgsmeshlayerrenderer.h
QgsRenderContext::mapExtent
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
Definition: qgsrendercontext.h:302
QgsMeshDatasetGroupMetadata::isScalar
bool isScalar() const
Returns whether dataset group has scalar data.
Definition: qgsmeshdataset.cpp:154
QgsMeshLayerRenderer::mScalarActiveFaceFlagValues
QgsMeshDataBlock mScalarActiveFaceFlagValues
Definition: qgsmeshlayerrenderer.h:132
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:179
QgsMapToPixel
Definition: qgsmaptopixel.h:37
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
QgsTriangularMesh::trianglesToNativeFaces
const QVector< int > & trianglesToNativeFaces() const
Returns mapping between triangles and original faces.
Definition: qgstriangularmesh.cpp:317
qgsfield.h
QgsPointXY::x
double x
Definition: qgspointxy.h:47
qgssettings.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:825
qgsmeshdataprovidertemporalcapabilities.h
QgsMeshRendererSettings::averagingMethod
QgsMesh3dAveragingMethod * averagingMethod() const
Returns averaging method for conversion of 3d stacked mesh data to 2d data.
Definition: qgsmeshrenderersettings.cpp:396
QgsRectangle::yMinimum
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsRenderContext::Antialiasing
@ Antialiasing
Use antialiasing while drawing.
Definition: qgsrendercontext.h:78
QgsMeshDataBlock
Definition: qgsmeshdataset.h:134
QgsMeshDatasetMetadata::maximum
double maximum() const
Returns maximum scalar value/vector magnitude present for the dataset.
Definition: qgsmeshdataset.cpp:223
QgsSingleBandPseudoColorRenderer
Definition: qgssinglebandpseudocolorrenderer.h:35
QgsMeshLayer::extent
QgsRectangle extent() const override
Returns the extent of the layer.
Definition: qgsmeshlayer.cpp:169
QgsRasterShader::setRasterShaderFunction
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
Definition: qgsrastershader.cpp:56
QgsInterpolatedLineRenderer
Definition: qgsinterpolatedlinerenderer.h:184
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:174
QgsMeshRendererScalarSettings::classificationMaximum
double classificationMaximum() const
Returns max value used for creation of the color ramp shader.
Definition: qgsmeshrenderersettings.cpp:93
QgsRasterShader
Definition: qgsrastershader.h:34
QgsMesh3dAveragingMethod::clone
virtual QgsMesh3dAveragingMethod * clone() const =0
Clone the instance.
QgsMeshLayerRenderer::mScalarDatasetMinimum
double mScalarDatasetMinimum
Definition: qgsmeshlayerrenderer.h:134
QgsMeshDatasetSourceInterface::areFacesActive
virtual QgsMeshDataBlock areFacesActive(QgsMeshDatasetIndex index, int faceIndex, int count) const =0
Returns whether the faces are active for particular dataset.
QgsMeshDatasetSourceInterface::datasetGroupMetadata
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
QgsPoint::x
double x
Definition: qgspoint.h:58
QgsMeshLayer::dataProvider
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Definition: qgsmeshlayer.cpp:147
QgsMeshLayer::activeScalarDatasetAtTime
QgsMeshDatasetIndex activeScalarDatasetAtTime(const QgsDateTimeRange &timeRange) const
Returns dataset index from active scalar group depending on the time range.
Definition: qgsmeshlayer.cpp:546
qgspointxy.h
QgsRectangle::xMinimum
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsMeshLayerRenderer::mVectorDatasetMagMinimum
double mVectorDatasetMagMinimum
Definition: qgsmeshlayerrenderer.h:140
QgsMeshLayerRenderer::mOutputSize
QSize mOutputSize
Definition: qgsmeshlayerrenderer.h:150
QgsRenderContext::flags
Flags flags() const
Returns combination of flags used for rendering.
Definition: qgsrendercontext.cpp:160
QgsMeshDataBlock::isValid
bool isValid() const
Whether the block is valid.
Definition: qgsmeshdataset.cpp:254
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