36  double mapUnitsPerPixel,
 
   46  const int widthPixel = 
static_cast<int>( extent.
width() / mapUnitsPerPixel );
 
   47  const int heightPixel = 
static_cast<int>( extent.
height() / mapUnitsPerPixel );
 
   63  auto nativeMesh = std::make_unique<QgsMesh>();
 
   65  auto triangularMesh = std::make_unique<QgsTriangularMesh>();
 
   66  triangularMesh->update( nativeMesh.get(), transform );
 
   70  const int count =  QgsMeshLayerUtils::datasetValuesCount( nativeMesh.get(), scalarDataType );
 
   79  const QVector<double> datasetValues = QgsMeshLayerUtils::calculateMagnitudes( vals );
 
   83        nativeMesh->faces.count() );
 
   85  QgsMeshLayerInterpolator interpolator(
 
   86    *( triangularMesh.get() ),
 
   91    QSize( widthPixel, heightPixel )
 
   94  return interpolator.block( 0, extent, widthPixel, heightPixel, feedback );
 
 
  103  double mapUnitsPerPixel,
 
  108  const int widthPixel = 
static_cast<int>( extent.
width() / mapUnitsPerPixel );
 
  109  const int heightPixel = 
static_cast<int>( extent.
height() / mapUnitsPerPixel );
 
  124  const QVector<double> magnitudes = QgsMeshLayerUtils::calculateMagnitudes( datasetValues );
 
  126  QgsMeshLayerInterpolator interpolator(
 
  132    QSize( widthPixel, heightPixel )
 
  135  return interpolator.block( 0, extent, widthPixel, heightPixel, feedback );
 
 
  140  QVector<QgsPoint> ring;
 
  141  for ( 
int j = 0; j < face.size(); ++j )
 
  143    int vertexId = face[j];
 
  144    Q_ASSERT( vertexId < vertices.size() );
 
  145    const QgsPoint &vertex = vertices[vertexId];
 
  146    ring.append( vertex );
 
  148  auto polygon = std::make_unique< QgsPolygon >();
 
 
  158static QSet<int> nativeElementsFromElements( 
const QList<int> &indexes, 
const QVector<int> &elementToNativeElements )
 
  160  QSet<int> nativeElements;
 
  161  for ( 
const int index : indexes )
 
  163    if ( index < elementToNativeElements.count() )
 
  165      const int nativeIndex = elementToNativeElements[index];
 
  166      nativeElements.insert( nativeIndex );
 
  169  return nativeElements;
 
  174  return nativeElementsFromElements( triangleIndexes, trianglesToNativeFaces );
 
 
  179  return nativeElementsFromElements( edgesIndexes, edgesToNativeEdges );
 
 
  184  return ( p2.
x() - p1.
x() ) * ( p.
y() - p1.
y() ) - ( p.
x() - p1.
x() ) * ( p2.
y() - p1.
y() );
 
  187static bool isInTriangle2D( 
const QgsPoint &p, 
const QVector<QgsMeshVertex> &triangle )
 
  189  return ( ( isLeft2D( triangle[2], triangle[0], p ) * isLeft2D( triangle[2], triangle[0], triangle[1] ) >= 0 )
 
  190           && ( isLeft2D( triangle[0], triangle[1], p ) * isLeft2D( triangle[0], triangle[1], triangle[2] ) >= 0 )
 
  191           && ( isLeft2D( triangle[2], triangle[1], p ) * isLeft2D( triangle[2], triangle[1], triangle[0] ) >= 0 ) );
 
  196  if ( face.count() != 3 )
 
  199  QVector<QgsMeshVertex> triangle( 3 );
 
  200  for ( 
int i = 0; i < 3; ++i )
 
  202    if ( face[i] >= vertices.count() )
 
  204    triangle[i] = vertices[face[i]];
 
  209  return isInTriangle2D( p, triangle );
 
 
  214  QSet<int> uniqueVertices;
 
  215  for ( 
int triangleIndex : triangleIndexes )
 
  217    const QgsMeshFace triangle = triangles[triangleIndex];
 
  218    for ( 
int i : triangle )
 
  220      uniqueVertices.insert( i );
 
  223  return uniqueVertices;
 
 
  228  QSet<int> uniqueVertices;
 
  229  for ( 
int edgeIndex : edgesIndexes )
 
  232    uniqueVertices.insert( edge.first );
 
  233    uniqueVertices.insert( edge.second );
 
  235  return uniqueVertices;
 
 
  238static void ENP_centroid_step( 
const QPolygonF &pX, 
double &cx, 
double &cy, 
double &signedArea, 
int i, 
int i1 )
 
  250  a = x0 * y1 - x1 * y0;
 
  252  cx += ( x0 + x1 ) * a;
 
  253  cy += ( y0 + y1 ) * a;
 
  256static void ENP_centroid( 
const QPolygonF &pX, 
double &cx, 
double &cy )
 
  265  double signedArea = 0.0;
 
  267  const QPointF &pt0 = pX.first();
 
  268  QPolygonF localPolygon( pX.count() );
 
  269  for ( 
int i = 0; i < pX.count(); ++i )
 
  270    localPolygon[i] = pX.at( i ) - pt0;
 
  274  for ( ; i < localPolygon.size() - 1; ++i )
 
  276    ENP_centroid_step( localPolygon, cx, cy, signedArea, i, i + 1 );
 
  280  ENP_centroid_step( localPolygon, cx, cy, signedArea, i, 0 );
 
  283  cx /= ( 6.0 * signedArea );
 
  284  cy /= ( 6.0 * signedArea );
 
  292  QVector<QPointF> points( face.size() );
 
  293  for ( 
int j = 0; j < face.size(); ++j )
 
  295    int index = face.at( j );
 
  299  QPolygonF poly( points );
 
  301  ENP_centroid( poly, cx, cy );
 
 
  309  double ux = v1.
x() - v0.
x();
 
  310  double uy = v1.
y() - v0.
y();
 
  311  double vx = v2.
x() - v0.
x();
 
  312  double vy = v2.
y() - v0.
y();
 
  314  double crossProduct = ux * vy - uy * vx;
 
  315  if ( crossProduct < 0 ) 
 
  317    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