QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmeshlayerrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshlayerrenderer.h
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 #ifndef QGSMESHLAYERRENDERER_H
19 #define QGSMESHLAYERRENDERER_H
20 
21 class QgsMeshLayer;
22 
23 #define SIP_NO_FILE
24 
25 #include <memory>
26 #include <limits>
27 
28 #include "qgis.h"
29 
30 #include "qgsmaplayerrenderer.h"
31 #include "qgsrasterinterface.h"
32 #include "qgstriangularmesh.h"
33 #include "qgsmeshlayer.h"
34 #include "qgssymbol.h"
35 #include "qgsmeshdataprovider.h"
36 #include "qgsmeshtracerenderer.h"
37 #include "qgsmapclippingregion.h"
38 
39 class QgsRenderContext;
40 
42 
47 class QgsMeshLayerRendererFeedback : public QgsRasterBlockFeedback
48 {
49  Q_OBJECT
50 };
51 
52 
56 struct CORE_NO_EXPORT QgsMeshLayerRendererCache
57 {
58  int mDatasetGroupsCount = 0;
59 
60  // scalar dataset
61  QgsMeshDatasetIndex mActiveScalarDatasetIndex;
62  QVector<double> mScalarDatasetValues;
63  QgsMeshDataBlock mScalarActiveFaceFlagValues;
64  QgsMeshDatasetGroupMetadata::DataType mScalarDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnVertices;
65  double mScalarDatasetMinimum = std::numeric_limits<double>::quiet_NaN();
66  double mScalarDatasetMaximum = std::numeric_limits<double>::quiet_NaN();
68  std::unique_ptr<QgsMesh3dAveragingMethod> mScalarAveragingMethod;
69 
70  // vector dataset
71  QgsMeshDatasetIndex mActiveVectorDatasetIndex;
72  QgsMeshDataBlock mVectorDatasetValues;
73  QVector<double> mVectorDatasetValuesMag;
74  double mVectorDatasetMagMinimum = std::numeric_limits<double>::quiet_NaN();
75  double mVectorDatasetMagMaximum = std::numeric_limits<double>::quiet_NaN();
76  double mVectorDatasetGroupMagMinimum = std::numeric_limits<double>::quiet_NaN();
77  double mVectorDatasetGroupMagMaximum = std::numeric_limits<double>::quiet_NaN();
78  QgsMeshDatasetGroupMetadata::DataType mVectorDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnVertices;
79  std::unique_ptr<QgsMesh3dAveragingMethod> mVectorAveragingMethod;
80 };
81 
82 
84 
93 {
94  public:
97  ~QgsMeshLayerRenderer() override = default;
98  QgsFeedback *feedback() const override;
99  bool render() override;
100 
101  private:
102  void renderMesh();
103  void renderEdgeMesh( const QgsMeshRendererMeshSettings &settings, const QList<int> &edgesInExtent );
104  void renderFaceMesh( const QgsMeshRendererMeshSettings &settings, const QVector<QgsMeshFace> &faces, const QList<int> &facesInExtent );
105  void renderScalarDataset();
106  void renderScalarDatasetOnEdges( const QgsMeshRendererScalarSettings &scalarSettings );
107  void renderScalarDatasetOnFaces( const QgsMeshRendererScalarSettings &scalarSettings );
108 
109  void renderVectorDataset();
110  void copyTriangularMeshes( QgsMeshLayer *layer, QgsRenderContext &context );
111  void copyScalarDatasetValues( QgsMeshLayer *layer );
112  void copyVectorDatasetValues( QgsMeshLayer *layer );
113  void calculateOutputSize();
114  QgsPointXY fractionPoint( const QgsPointXY &p1, const QgsPointXY &p2, double fraction ) const;
115  bool mIsMeshSimplificationActive = false;
116  QColor colorAt( QgsColorRampShader *shader, double val ) const;
117 
118  protected:
120  std::unique_ptr<QgsMeshLayerRendererFeedback> mFeedback;
121 
122  // copy from mesh layer
124 
125  // copy from mesh layer
127 
128  // copy from mesh layer
130 
131  // copy of the scalar dataset
132  QVector<double> mScalarDatasetValues;
135  double mScalarDatasetMinimum = std::numeric_limits<double>::quiet_NaN();
136  double mScalarDatasetMaximum = std::numeric_limits<double>::quiet_NaN();
137 
138  // copy of the vector dataset
140  QVector<double> mVectorDatasetValuesMag;
141  double mVectorDatasetMagMinimum = std::numeric_limits<double>::quiet_NaN();
142  double mVectorDatasetMagMaximum = std::numeric_limits<double>::quiet_NaN();
143  double mVectorDatasetGroupMagMinimum = std::numeric_limits<double>::quiet_NaN();
144  double mVectorDatasetGroupMagMaximum = std::numeric_limits<double>::quiet_NaN();
146 
147  // copy of rendering settings
149 
150  QList< QgsMapClippingRegion > mClippingRegions;
151 
152  // output screen size
153  QSize mOutputSize;
154 };
155 
156 
157 #endif // QGSMESHLAYERRENDERER_H
QgsMeshLayerRenderer::mScalarDataType
QgsMeshDatasetGroupMetadata::DataType mScalarDataType
Definition: qgsmeshlayerrenderer.h:134
QgsMeshLayerRenderer::mTriangularMesh
QgsTriangularMesh mTriangularMesh
Definition: qgsmeshlayerrenderer.h:126
QgsMeshLayerRenderer::mScalarDatasetValues
QVector< double > mScalarDatasetValues
Definition: qgsmeshlayerrenderer.h:132
QgsMeshLayerRenderer::mRendererSettings
QgsMeshRendererSettings mRendererSettings
Definition: qgsmeshlayerrenderer.h:148
QgsMeshLayerRenderer::mVectorDatasetGroupMagMinimum
double mVectorDatasetGroupMagMinimum
Definition: qgsmeshlayerrenderer.h:143
QgsMeshRendererSettings
Represents all mesh renderer settings.
Definition: qgsmeshrenderersettings.h:591
QgsMeshLayerRenderer::mScalarDatasetMaximum
double mScalarDatasetMaximum
Definition: qgsmeshlayerrenderer.h:136
QgsMeshRendererMeshSettings
Represents a mesh renderer settings for mesh object.
Definition: qgsmeshrenderersettings.h:42
QgsMeshLayerRenderer::mVectorDataType
QgsMeshDatasetGroupMetadata::DataType mVectorDataType
Definition: qgsmeshlayerrenderer.h:145
QgsMeshLayerRenderer::feedback
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
Definition: qgsmeshlayerrenderer.cpp:93
QgsMeshLayerRenderer::mLayerExtent
QgsRectangle mLayerExtent
Definition: qgsmeshlayerrenderer.h:129
QgsMeshLayerRenderer::~QgsMeshLayerRenderer
~QgsMeshLayerRenderer() override=default
QgsMeshLayerRenderer::render
bool render() override
Do the rendering (based on data stored in the class)
Definition: qgsmeshlayerrenderer.cpp:286
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsMesh
Mesh - vertices, edges and faces.
Definition: qgsmeshdataprovider.h:58
QgsMeshLayerRenderer::mNativeMesh
QgsMesh mNativeMesh
Definition: qgsmeshlayerrenderer.h:123
QgsColorRampShader
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Definition: qgscolorrampshader.h:40
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:51
qgstriangularmesh.h
QgsMeshDatasetGroupMetadata::DataOnVertices
@ DataOnVertices
Data is defined on vertices.
Definition: qgsmeshdataset.h:357
qgsrasterinterface.h
QgsMeshLayerRenderer::mVectorDatasetValuesMag
QVector< double > mVectorDatasetValuesMag
Definition: qgsmeshlayerrenderer.h:140
QgsMeshLayerRenderer::mFeedback
std::unique_ptr< QgsMeshLayerRendererFeedback > mFeedback
feedback class for cancellation
Definition: qgsmeshlayerrenderer.h:120
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
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
QgsMeshLayerRenderer::QgsMeshLayerRenderer
QgsMeshLayerRenderer(QgsMeshLayer *layer, QgsRenderContext &context)
Ctor.
Definition: qgsmeshlayerrenderer.cpp:44
QgsMeshLayerRenderer::mVectorDatasetValues
QgsMeshDataBlock mVectorDatasetValues
Definition: qgsmeshlayerrenderer.h:139
qgsmaplayerrenderer.h
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
QgsMeshLayerRenderer::mVectorDatasetGroupMagMaximum
double mVectorDatasetGroupMagMaximum
Definition: qgsmeshlayerrenderer.h:144
qgsmeshlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsMeshRendererScalarSettings
Represents a mesh renderer settings for scalar datasets.
Definition: qgsmeshrenderersettings.h:95
qgsmeshtracerenderer.h
QgsMeshLayerRenderer::mScalarActiveFaceFlagValues
QgsMeshDataBlock mScalarActiveFaceFlagValues
Definition: qgsmeshlayerrenderer.h:133
QgsMeshDatasetGroupMetadata::DataType
DataType
Location of where data is specified for datasets in the dataset group.
Definition: qgsmeshdataset.h:355
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsMeshLayerRenderer
Implementation of threaded rendering for mesh layers.
Definition: qgsmeshlayerrenderer.h:93
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
QgsTriangularMesh
Triangular/Derived Mesh is mesh with vertices in map coordinates.
Definition: qgstriangularmesh.h:50
qgssymbol.h
QgsMeshLayerRenderer::mScalarDatasetMinimum
double mScalarDatasetMinimum
Definition: qgsmeshlayerrenderer.h:135
qgsmeshdataprovider.h
qgsmapclippingregion.h
QgsMeshLayerRenderer::mVectorDatasetMagMinimum
double mVectorDatasetMagMinimum
Definition: qgsmeshlayerrenderer.h:141
QgsMeshLayerRenderer::mOutputSize
QSize mOutputSize
Definition: qgsmeshlayerrenderer.h:153