QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgstriangularmesh.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstriangularmesh.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 QGSTRIANGULARMESH_H
19 #define QGSTRIANGULARMESH_H
20 
21 
22 #define SIP_NO_FILE
23 
24 #include <QVector>
25 #include <memory>
26 #include "qgis_core.h"
27 #include "qgsmeshdataprovider.h"
28 #include "qgsgeometry.h"
29 #include "qgsmeshspatialindex.h"
30 
31 class QgsRenderContext;
33 class QgsRectangle;
34 
46 class CORE_EXPORT QgsTriangularMesh
47 {
48  public:
53 
59  void update( QgsMesh *nativeMesh, QgsRenderContext *context );
60 
67  const QVector<QgsMeshVertex> &vertices() const ;
69  const QVector<QgsMeshFace> &triangles() const ;
70 
72  const QVector<QgsMeshVertex> &centroids() const ;
73 
75  const QVector<int> &trianglesToNativeFaces() const ;
76 
86  int faceIndexForPoint( const QgsPointXY &point ) const ;
87 
97  QList<int> faceIndexesForRectangle( const QgsRectangle &rectangle ) const ;
98 
99  private:
100 
111  void triangulate( const QgsMeshFace &face, int nativeIndex );
112 
113  // vertices: map CRS; 0-N ... native vertices, N+1 - len ... extra vertices
114  // faces are derived triangles
115  QgsMesh mTriangularMesh;
116  QVector<int> mTrianglesToNativeFaces; //len(mTrianglesToNativeFaces) == len(mTriangles). Mapping derived -> native
117 
118  // centroids of the native faces in map CRS
119  QVector<QgsMeshVertex> mNativeMeshFaceCentroids;
120 
121  QgsMeshSpatialIndex mSpatialIndex;
122  QgsCoordinateTransform mCoordinateTransform; //coordinate transform used to convert native mesh vertices to map vertices
123 
124  friend class TestQgsTriangularMesh;
125 };
126 
127 namespace QgsMeshUtils
128 {
130  CORE_EXPORT QgsGeometry toGeometry( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
131 
133  CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
134 
139  CORE_EXPORT QList<int> nativeFacesFromTriangles( const QList<int> &triangleIndexes, const QVector<int> &trianglesToNativeFaces );
140 };
141 
142 #endif // QGSTRIANGULARMESH_H
CORE_EXPORT QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Triangular/Derived Mesh is mesh with vertices in map coordinates.
A class to represent a 2D point.
Definition: qgspointxy.h:43
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
CORE_EXPORT QList< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
A spatial index for QgsMeshFace objects.
Contains information about the context of a rendering operation.
Mesh - vertices and faces.
QVector< int > QgsMeshFace
List of vertex indexes.
Class for doing transforms between two map coordinate systems.