37 double mapUnitsPerPixel,
48 const int widthPixel =
static_cast<int>( extent.
width() / mapUnitsPerPixel );
49 const int heightPixel =
static_cast<int>( extent.
height() / mapUnitsPerPixel );
52 const QgsMapToPixel mapToPixel( mapUnitsPerPixel, center.
x(), center.
y(), widthPixel, heightPixel, 0 );
60 auto nativeMesh = std::make_unique<QgsMesh>();
62 auto triangularMesh = std::make_unique<QgsTriangularMesh>();
63 triangularMesh->update( nativeMesh.get(), transform );
67 const int count = QgsMeshLayerUtils::datasetValuesCount( nativeMesh.get(), scalarDataType );
68 const QgsMeshDataBlock vals = QgsMeshLayerUtils::datasetValues( &layer, datasetIndex, 0, count );
72 const QVector<double> datasetValues = QgsMeshLayerUtils::calculateMagnitudes( vals );
75 QgsMeshLayerInterpolator interpolator( *( triangularMesh.get() ), datasetValues, activeFaceFlagValues, scalarDataType, renderContext, QSize( widthPixel, heightPixel ) );
77 return interpolator.block( 0, extent, widthPixel, heightPixel, feedback );
86 double mapUnitsPerPixel,
91 const int widthPixel =
static_cast<int>( extent.
width() / mapUnitsPerPixel );
92 const int heightPixel =
static_cast<int>( extent.
height() / mapUnitsPerPixel );
95 const QgsMapToPixel mapToPixel( mapUnitsPerPixel, center.
x(), center.
y(), widthPixel, heightPixel, 0 );
102 const QVector<double> magnitudes = QgsMeshLayerUtils::calculateMagnitudes( datasetValues );
104 QgsMeshLayerInterpolator interpolator( triangularMesh, magnitudes, activeFlags, dataType, renderContext, QSize( widthPixel, heightPixel ) );
106 return interpolator.block( 0, extent, widthPixel, heightPixel, feedback );
111 QVector<QgsPoint> ring;
112 for (
int j = 0; j < face.size(); ++j )
114 int vertexId = face[j];
115 Q_ASSERT( vertexId < vertices.size() );
116 const QgsPoint &vertex = vertices[vertexId];
117 ring.append( vertex );
119 auto polygon = std::make_unique< QgsPolygon >();
129static QSet<int> nativeElementsFromElements(
const QList<int> &indexes,
const QVector<int> &elementToNativeElements )
131 QSet<int> nativeElements;
132 for (
const int index : indexes )
134 if ( index < elementToNativeElements.count() )
136 const int nativeIndex = elementToNativeElements[index];
137 nativeElements.insert( nativeIndex );
140 return nativeElements;
145 return nativeElementsFromElements( triangleIndexes, trianglesToNativeFaces );
150 return nativeElementsFromElements( edgesIndexes, edgesToNativeEdges );
155 return ( p2.
x() - p1.
x() ) * ( p.
y() - p1.
y() ) - ( p.
x() - p1.
x() ) * ( p2.
y() - p1.
y() );
158static bool isInTriangle2D(
const QgsPoint &p,
const QVector<QgsMeshVertex> &triangle )
161 ( isLeft2D( triangle[2], triangle[0], p ) * isLeft2D( triangle[2], triangle[0], triangle[1] ) >= 0 )
162 && ( isLeft2D( triangle[0], triangle[1], p ) * isLeft2D( triangle[0], triangle[1], triangle[2] ) >= 0 )
163 && ( isLeft2D( triangle[2], triangle[1], p ) * isLeft2D( triangle[2], triangle[1], triangle[0] ) >= 0 )
169 if ( face.count() != 3 )
172 QVector<QgsMeshVertex> triangle( 3 );
173 for (
int i = 0; i < 3; ++i )
175 if ( face[i] >= vertices.count() )
177 triangle[i] = vertices[face[i]];
182 return isInTriangle2D( p, triangle );
187 QSet<int> uniqueVertices;
188 for (
int triangleIndex : triangleIndexes )
190 const QgsMeshFace triangle = triangles[triangleIndex];
191 for (
int i : triangle )
193 uniqueVertices.insert( i );
196 return uniqueVertices;
201 QSet<int> uniqueVertices;
202 for (
int edgeIndex : edgesIndexes )
205 uniqueVertices.insert( edge.first );
206 uniqueVertices.insert( edge.second );
208 return uniqueVertices;
211static void ENP_centroid_step(
const QPolygonF &pX,
double &cx,
double &cy,
double &signedArea,
int i,
int i1 )
223 a = x0 * y1 - x1 * y0;
225 cx += ( x0 + x1 ) * a;
226 cy += ( y0 + y1 ) * a;
229static void ENP_centroid(
const QPolygonF &pX,
double &cx,
double &cy )
238 double signedArea = 0.0;
240 const QPointF &pt0 = pX.first();
241 QPolygonF localPolygon( pX.count() );
242 for (
int i = 0; i < pX.count(); ++i )
243 localPolygon[i] = pX.at( i ) - pt0;
247 for ( ; i < localPolygon.size() - 1; ++i )
249 ENP_centroid_step( localPolygon, cx, cy, signedArea, i, i + 1 );
253 ENP_centroid_step( localPolygon, cx, cy, signedArea, i, 0 );
256 cx /= ( 6.0 * signedArea );
257 cy /= ( 6.0 * signedArea );
265 QVector<QPointF> points( face.size() );
266 for (
int j = 0; j < face.size(); ++j )
268 int index = face.at( j );
272 QPolygonF poly( points );
274 ENP_centroid( poly, cx, cy );
282 double ux = v1.
x() - v0.
x();
283 double uy = v1.
y() - v0.
y();
284 double vx = v2.
x() - v0.
x();
285 double vy = v2.
y() - v0.
y();
287 double crossProduct = ux * vy - uy * vx;
288 if ( crossProduct < 0 )
290 std::swap( triangle[1], triangle[2] );
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
A geometry is the spatial representation of a feature.
Line string geometry type, with support for z-dimension and m-values.
QgsCoordinateReferenceSystem crs
Perform transforms between map coordinates and device coordinates.
A block of integers/doubles from a mesh dataset.
bool isValid() const
Whether the block is valid.
virtual void populateMesh(QgsMesh *mesh) const =0
Populates the mesh vertices, edges and faces.
An 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.
QgsMeshDataBlock areFacesActive(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns whether the faces are active for particular dataset.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
static bool isInTriangleFace(const QgsPointXY point, const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Tests if point p is on the face defined with vertices.
static QSet< int > nativeEdgesFromEdges(const QList< int > &edgesIndexes, const QVector< int > &edgesToNativeEdges)
Returns unique native faces indexes from list of triangle indexes.
static std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
static QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
static void setCounterClockwise(QgsMeshFace &triangle, const QgsMeshVertex &v0, const QgsMeshVertex &v1, const QgsMeshVertex &v2)
Checks if the triangle is counter clockwise, if not sets it counter clockwise.
static QSet< int > nativeVerticesFromEdges(const QList< int > &edgesIndexes, const QVector< QgsMeshEdge > &edges)
Returns unique native faces indexes from list of vertices of triangles.
static QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
static QSet< int > nativeVerticesFromTriangles(const QList< int > &triangleIndexes, const QVector< QgsMeshFace > &triangles)
Returns unique native vertex indexes from list of vertices of triangles.
static QSet< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
static 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.
Point geometry type, with support for z-dimension and m-values.
QPointF toQPointF() const
Returns the point as a QPointF.
Feedback object tailored for raster block reading.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
A triangular/derived mesh with vertices in map coordinates.
QVector< int > QgsMeshFace
List of vertex indexes.
QPair< int, int > QgsMeshEdge
Edge is a straight line seqment between 2 points.
QgsPoint QgsMeshVertex
xyz coords of vertex