1 /*************************************************************************** 2 qgsmeshlayerinterpolator.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 QGSMESHLAYERINTERPOLATOR_H 19 #define QGSMESHLAYERINTERPOLATOR_H 20 21 class QgsMeshLayer; 22 class QgsSymbol; 23 class QgsCoordinateReferenceSystem; 24 class QgsCoordinateTransformContext; 25 class QgsMeshDatasetIndex; 26 27 #include "qgis.h" 28 #include "qgis_sip.h" 29 30 #include <QSize> 31 #include "qgsmaplayerrenderer.h" 32 #include "qgstriangularmesh.h" 33 #include "qgsrasterinterface.h" 34 #include "qgssinglebandpseudocolorrenderer.h" 35 #include "qgsrastershader.h" 36 37 class QgsRenderContext; 38 39 #ifdef SIP_RUN 40 % ModuleHeaderCode 41 #include "qgsmeshlayerinterpolator.h" 42 % End 43 #endif 44 45 ///@cond PRIVATE 46 47 /** 48 * \ingroup core 49 * \brief Interpolate mesh scalar dataset to raster block 50 * 51 * \note not available in Python bindings 52 * \since QGIS 3.2 53 */ 54 class QgsMeshLayerInterpolator : public QgsRasterInterface SIP_SKIP 55 { 56 public: 57 //! Ctor 58 QgsMeshLayerInterpolator( const QgsTriangularMesh &m, 59 const QVector<double> &datasetValues, 60 const QgsMeshDataBlock &activeFaceFlagValues, 61 QgsMeshDatasetGroupMetadata::DataType dataType, 62 const QgsRenderContext &context, 63 const QSize &size ); 64 ~QgsMeshLayerInterpolator() override; 65 66 QgsRasterInterface *clone() const override; 67 Qgis::DataType dataType( int ) const override; 68 int bandCount() const override; 69 QgsRasterBlock *block( int, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override; 70 71 void setSpatialIndexActive( bool active ); 72 73 private: 74 const QgsTriangularMesh &mTriangularMesh; 75 const QVector<double> &mDatasetValues; 76 const QgsMeshDataBlock &mActiveFaceFlagValues; 77 const QgsRenderContext &mContext; 78 QgsMeshDatasetGroupMetadata::DataType mDataType = QgsMeshDatasetGroupMetadata::DataType::DataOnVertices; 79 QSize mOutputSize; 80 bool mSpatialIndexActive = false; 81 }; 82 83 ///@endcond 84 85 namespace QgsMeshUtils 86 { 87 88 /** 89 * Exports mesh layer's dataset values as raster block 90 * 91 * The function always fetches native mesh and dataset data 92 * from data provider and calculates triangular mesh 93 * 94 * \param layer mesh layer 95 * \param datasetIndex index from layer defining group and dataset (time) to export 96 * \param destinationCrs destination/map CRS. Used to create triangular mesh from native mesh 97 * \param transformContext Transform context to transform layer CRS to destination CRS 98 * \param mapUnitsPerPixel map units per pixel for block 99 * \param extent extent of block in destination CRS 100 * \param feedback optional raster feedback object for cancellation/preview 101 * \returns raster block with Float::64 values. NULLPTR on error 102 * 103 * \since QGIS 3.6 104 */ 105 CORE_EXPORT QgsRasterBlock *exportRasterBlock( 106 const QgsMeshLayer &layer, 107 const QgsMeshDatasetIndex &datasetIndex, 108 const QgsCoordinateReferenceSystem &destinationCrs, 109 const QgsCoordinateTransformContext &transformContext, 110 double mapUnitsPerPixel, 111 const QgsRectangle &extent, 112 QgsRasterBlockFeedback *feedback = nullptr 113 ) SIP_FACTORY; 114 115 116 /** 117 * Exports mesh layer's dataset values as raster block 118 * 119 * \param triangularMesh the triangular mesh of the mesh layer 120 * \param datasetValues dataset values used to build the raster block 121 * \param activeFlags active flag values 122 * \param dataType the data type iof the dataset values 123 * \param transform the coordinate transform used to export the raster block 124 * \param mapUnitsPerPixel map units per pixel for block 125 * \param extent extent of block in destination CRS 126 * \param feedback optional raster feedback object for cancellation/preview 127 * \returns raster block with Float::64 values. NULLPTR on error 128 * 129 * \since QGIS 3.18 130 */ 131 CORE_EXPORT QgsRasterBlock *exportRasterBlock( 132 const QgsTriangularMesh &triangularMesh, 133 const QgsMeshDataBlock &datasetValues, 134 const QgsMeshDataBlock &activeFlags, 135 const QgsMeshDatasetGroupMetadata::DataType dataType, 136 const QgsCoordinateTransform &transform, 137 double mapUnitsPerPixel, 138 const QgsRectangle &extent, 139 QgsRasterBlockFeedback *feedback = nullptr 140 ) SIP_SKIP; 141 }; 142 143 #endif // QGSMESHLAYERINTERPOLATOR_H 144