38 const QVector<double> &datasetValues,
const QgsMeshDataBlock &activeFaceFlagValues,
39 bool dataIsOnVertices,
42 : mTriangularMesh( m ),
43 mDatasetValues( datasetValues ),
44 mActiveFaceFlagValues( activeFaceFlagValues ),
46 mDataOnVertices( dataIsOnVertices ),
51 QgsMeshLayerInterpolator::~QgsMeshLayerInterpolator() =
default;
64 int QgsMeshLayerInterpolator::bandCount()
const 72 const double noDataValue = std::numeric_limits<double>::min();
73 outputBlock->setNoDataValue( noDataValue );
74 outputBlock->setIsNoData();
75 double *data =
reinterpret_cast<double *
>( outputBlock->bits() );
77 const QVector<QgsMeshFace> &triangles = mTriangularMesh.triangles();
78 const QVector<QgsMeshVertex> &vertices = mTriangularMesh.vertices();
81 if ( mDataOnVertices )
82 Q_ASSERT( mDatasetValues.count() == mTriangularMesh.vertices().count() );
84 for (
int i = 0; i < triangles.size(); ++i )
89 if ( mContext.renderingStopped() )
94 const int v1 = face[0], v2 = face[1], v3 = face[2];
95 const QgsPoint p1 = vertices[v1], p2 = vertices[v2], p3 = vertices[v3];
97 const int nativeFaceIndex = mTriangularMesh.trianglesToNativeFaces()[i];
98 const bool isActive = mActiveFaceFlagValues.active( nativeFaceIndex );
102 QgsRectangle bbox = QgsMeshLayerUtils::triangleBoundingBox( p1, p2, p3 );
107 int topLim, bottomLim, leftLim, rightLim;
108 QgsMeshLayerUtils::boundingBoxToScreenRectangle( mContext.mapToPixel(), mOutputSize, bbox, leftLim, rightLim, topLim, bottomLim );
111 for (
int j = topLim; j <= bottomLim; j++ )
113 double *line = data + ( j * width );
114 for (
int k = leftLim; k <= rightLim; k++ )
117 const QgsPointXY p = mContext.mapToPixel().toMapCoordinates( k, j );
118 if ( mDataOnVertices )
119 val = QgsMeshLayerUtils::interpolateFromVerticesData(
129 int face = mTriangularMesh.trianglesToNativeFaces()[i];
130 val = QgsMeshLayerUtils::interpolateFromFacesData(
134 mDatasetValues[face],
139 if ( !std::isnan( val ) )
142 outputBlock->setIsData( j, k );
149 return outputBlock.release();;
159 double mapUnitsPerPixel,
169 int widthPixel =
static_cast<int>( extent.
width() / mapUnitsPerPixel );
170 int heightPixel =
static_cast<int>( extent.
height() / mapUnitsPerPixel );
183 renderContext.setMapToPixel( mapToPixel );
184 renderContext.setExtent( extent );
186 std::unique_ptr<QgsMesh>
nativeMesh = qgis::make_unique<QgsMesh>();
188 std::unique_ptr<QgsTriangularMesh>
triangularMesh = qgis::make_unique<QgsTriangularMesh>();
189 triangularMesh->
update( nativeMesh.get(), &renderContext );
197 scalarDataOnVertices ? nativeMesh->vertices.count() : nativeMesh->faces.count() );
199 QVector<double> datasetValues = QgsMeshLayerUtils::calculateMagnitudes( vals );
203 nativeMesh->faces.count() );
205 QgsMeshLayerInterpolator iterpolator(
206 *( triangularMesh.get() ),
208 activeFaceFlagValues,
209 scalarDataOnVertices,
211 QSize( widthPixel, heightPixel )
214 return iterpolator.block( 0, extent, widthPixel, heightPixel, feedback );
A rectangle specified with double values.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
A class to represent a 2D point.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e...
DataType
Raster data types.
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
CORE_EXPORT QgsRasterBlock * exportRasterBlock(const QgsMeshLayer &layer, const QgsMeshDatasetIndex &datasetIndex, const QgsCoordinateReferenceSystem &destinationCrs, const QgsCoordinateTransformContext &transformContext, double mapUnitsPerPixel, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback=nullptr)
Exports mesh layer's dataset values as raster block.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering)
Sixty four bit floating point (double)
Perform transforms between map coordinates and device coordinates.
QgsRectangle extent() const override
Returns the extent of the layer.
double width() const
Returns the width of the rectangle.
virtual QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const =0
Returns N vector/scalar values from the index from the dataset.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be null.
Contains information about the context in which a coordinate transform is executed.
Base class for processing filters like renderers, reprojector, resampler etc.
Point geometry type, with support for z-dimension and m-values.
virtual void populateMesh(QgsMesh *mesh) const =0
Populates the mesh vertices and faces.
void update(QgsMesh *nativeMesh, QgsRenderContext *context)
Constructs triangular mesh from layer's native mesh and context.
Contains information about the context of a rendering operation.
bool isCanceled() const
Tells whether the operation has been canceled already.
QVector< int > QgsMeshFace
List of vertex indexes.
This class represents a coordinate reference system (CRS).
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QgsPointXY center() const
Returns the center point of the rectangle.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
Feedback object tailored for raster block reading.
QgsTriangularMesh * triangularMesh()
Returns triangular mesh (nullptr before rendering)
QgsCoordinateReferenceSystem crs
double height() const
Returns the height of the rectangle.
virtual QgsMeshDataBlock areFacesActive(QgsMeshDatasetIndex index, int faceIndex, int count) const =0
Returns whether the faces are active for particular dataset.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.