36QgsMeshLayerInterpolator::QgsMeshLayerInterpolator(
38 const QVector<double> &datasetValues,
43 : mTriangularMesh( m ),
44 mDatasetValues( datasetValues ),
45 mActiveFaceFlagValues( activeFaceFlagValues ),
47 mDataType( dataType ),
52QgsMeshLayerInterpolator::~QgsMeshLayerInterpolator() =
default;
65int QgsMeshLayerInterpolator::bandCount()
const
73 const double noDataValue = std::numeric_limits<double>::quiet_NaN();
74 outputBlock->setNoDataValue( noDataValue );
75 outputBlock->setIsNoData();
76 double *data =
reinterpret_cast<double *
>( outputBlock->bits() );
78 QList<int> spatialIndexTriangles;
80 if ( mSpatialIndexActive )
82 spatialIndexTriangles = mTriangularMesh.faceIndexesForRectangle( extent );
83 indexCount = spatialIndexTriangles.count();
87 indexCount = mTriangularMesh.triangles().count();
92 return outputBlock.release();
95 const QVector<QgsMeshVertex> &vertices = mTriangularMesh.vertices();
99 Q_ASSERT( mDatasetValues.count() == mTriangularMesh.vertices().count() );
101 double pixelRatio = mContext.devicePixelRatio();
103 for (
int i = 0; i < indexCount; ++i )
108 if ( mContext.renderingStopped() )
112 if ( mSpatialIndexActive )
113 triangleIndex = spatialIndexTriangles[i];
117 const QgsMeshFace &face = mTriangularMesh.triangles()[triangleIndex];
119 if ( face.isEmpty() )
122 const int v1 = face[0], v2 = face[1], v3 = face[2];
123 const QgsPointXY &p1 = vertices[v1], &p2 = vertices[v2], &p3 = vertices[v3];
125 const int nativeFaceIndex = mTriangularMesh.trianglesToNativeFaces()[triangleIndex];
126 const bool isActive = mActiveFaceFlagValues.active( nativeFaceIndex );
130 const QgsRectangle bbox = QgsMeshLayerUtils::triangleBoundingBox( p1, p2, p3 );
135 int topLim, bottomLim, leftLim, rightLim;
136 QgsMeshLayerUtils::boundingBoxToScreenRectangle( mContext.mapToPixel(), mOutputSize, bbox, leftLim, rightLim, topLim, bottomLim, pixelRatio );
138 double value( 0 ), value1( 0 ), value2( 0 ), value3( 0 );
139 const int faceIdx = mTriangularMesh.trianglesToNativeFaces()[triangleIndex];
143 value1 = mDatasetValues[v1];
144 value2 = mDatasetValues[v2];
145 value3 = mDatasetValues[v3];
148 value = mDatasetValues[faceIdx];
151 for (
int j = topLim; j <= bottomLim; j++ )
153 double *line = data + ( j * width );
154 for (
int k = leftLim; k <= rightLim; k++ )
157 const QgsPointXY p = mContext.mapToPixel().toMapCoordinates( k / pixelRatio, j / pixelRatio );
159 val = QgsMeshLayerUtils::interpolateFromVerticesData(
169 val = QgsMeshLayerUtils::interpolateFromFacesData(
177 if ( !std::isnan( val ) )
180 outputBlock->setIsData( j, k );
186 if ( mRenderElevation )
189 if ( elevationMap && elevationMap->
isValid() )
190 elevationMap->
fillWithRasterBlock( outputBlock.get(), 0, 0, mElevationScale, mElevationOffset );
193 return outputBlock.release();
196void QgsMeshLayerInterpolator::setSpatialIndexActive(
bool active )
198 mSpatialIndexActive = active;
201void QgsMeshLayerInterpolator::setElevationMapSettings(
bool renderElevationMap,
double elevationScale,
double elevationOffset )
203 mRenderElevation = renderElevationMap;
204 mElevationScale = elevationScale;
205 mElevationOffset = elevationOffset;
DataType
Raster data types.
@ Float64
Sixty four bit floating point (double)
Stores a digital elevation model in a raster image which may get updated as a part of the map layer r...
bool isValid() const
Returns whether the elevation map is valid.
void fillWithRasterBlock(QgsRasterBlock *block, int top, int left, double zScale=1.0, double offset=0.0)
Fills the elevation map with values contains in a raster block starting from position defined by top ...
bool isCanceled() const
Tells whether the operation has been canceled already.
A block of integers/doubles from a mesh dataset.
Feedback object tailored for raster block reading.
Base class for processing filters like renderers, reprojector, resampler etc.
A rectangle specified with double values.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
Contains information about the context of a rendering operation.
A triangular/derived mesh with vertices in map coordinates.
QVector< int > QgsMeshFace
List of vertex indexes.