QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgis_core.h"
26 #include "qgsmeshdataprovider.h"
27 #include "qgsgeometry.h"
28 #include "qgsfeatureid.h"
29 #include "qgsspatialindex.h"
30 #include "qgsfeatureiterator.h"
31 
32 class QgsRenderContext;
34 class QgsRectangle;
35 
37 struct CORE_EXPORT QgsMesh
38 {
40  QVector<QgsMeshVertex> vertices;
42  QVector<QgsMeshFace> faces;
43 };
44 
46 
50 class CORE_NO_EXPORT QgsMeshFeatureIterator : public QgsAbstractFeatureIterator
51 {
52  public:
53 
59  QgsMeshFeatureIterator( QgsMesh *mesh );
60  ~QgsMeshFeatureIterator() override;
61 
62  bool rewind() override;
63  bool close() override;
64 
65  protected:
66  bool fetchFeature( QgsFeature &f ) override;
67 
68  private:
69  QgsMesh *mMesh = nullptr;
70  int it = 0;
71 };
72 
74 
86 class CORE_EXPORT QgsTriangularMesh
87 {
88  public:
90  QgsTriangularMesh() = default;
92  ~QgsTriangularMesh() = default;
93 
99  void update( QgsMesh *nativeMesh, QgsRenderContext *context );
100 
107  const QVector<QgsMeshVertex> &vertices() const ;
109  const QVector<QgsMeshFace> &triangles() const ;
110 
112  const QVector<QgsMeshVertex> &centroids() const ;
113 
115  const QVector<int> &trianglesToNativeFaces() const ;
116 
126  int faceIndexForPoint( const QgsPointXY &point ) const ;
127 
137  QList<int> faceIndexesForRectangle( const QgsRectangle &rectangle ) const ;
138 
139  private:
140  // vertices: map CRS; 0-N ... native vertices, N+1 - len ... extra vertices
141  // faces are derived triangles
142  QgsMesh mTriangularMesh;
143  QVector<int> mTrianglesToNativeFaces; //len(mTrianglesToNativeFaces) == len(mTriangles). Mapping derived -> native
144 
145  // centroids of the native faces in map CRS
146  QVector<QgsMeshVertex> mNativeMeshFaceCentroids;
147 
148  QgsSpatialIndex mSpatialIndex;
149  QgsCoordinateTransform mCoordinateTransform; //coordinate transform used to convert native mesh vertices to map vertices
150 };
151 
152 namespace QgsMeshUtils
153 {
155  QgsGeometry toGeometry( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
156 
161  QList<int> nativeFacesFromTriangles( const QList<int> &triangleIndexes, const QVector<int> &trianglesToNativeFaces );
162 };
163 
164 #endif // QGSTRIANGULARMESH_H
QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:40
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:106
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QVector< QgsMeshVertex > vertices
vertices
Internal feature iterator to be implemented within data providers.
QList< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
Contains information about the context of a rendering operation.
Mesh - vertices and faces.
A spatial index for QgsFeature objects.
QVector< int > QgsMeshFace
List of vertex indexes.
Class for doing transforms between two map coordinate systems.
QVector< QgsMeshFace > faces
faces