QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 <QVector3D>
26 #include <QSet>
27 #include <QList>
28 #include <memory>
29 #include "qgis_core.h"
30 #include "qgsmeshdataprovider.h"
31 #include "qgsgeometry.h"
32 #include "qgsmeshspatialindex.h"
33 
34 class QgsRenderContext;
36 class QgsRectangle;
37 
50 class CORE_EXPORT QgsTriangularMesh // TODO rename to QgsRendererMesh in QGIS 4
51 {
52  public:
57 
64  bool update( QgsMesh *nativeMesh, const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
65 
72  const QVector<QgsMeshVertex> &vertices() const ;
73 
75  const QVector<QgsMeshFace> &triangles() const ;
76 
78  const QVector<QgsMeshEdge> &edges() const ;
79 
85  Q_DECL_DEPRECATED const QVector<QgsMeshVertex> &centroids() const ;
86 
91  const QVector<QgsMeshVertex> &faceCentroids() const ;
92 
97  const QVector<QgsMeshVertex> &edgeCentroids() const ;
98 
100  const QVector<int> &trianglesToNativeFaces() const ;
101 
103  const QVector<int> &edgesToNativeEdges() const ;
104 
114  int faceIndexForPoint( const QgsPointXY &point ) const ;
115 
125  int faceIndexForPoint_v2( const QgsPointXY &point ) const;
126 
136  QList<int> faceIndexesForRectangle( const QgsRectangle &rectangle ) const ;
137 
145  QList<int> edgeIndexesForRectangle( const QgsRectangle &rectangle ) const ;
146 
155  QVector<QVector3D> vertexNormals( float vertScale ) const;
156 
172  QVector<QgsTriangularMesh *> simplifyMesh( double reductionFactor, int minimumTrianglesCount = 10 ) const;
173 
180  double averageTriangleSize() const;
181 
192  int levelOfDetail() const;
193 
201  QgsRectangle extent() const;
202 
207  bool contains( const QgsMesh::ElementType &type ) const;
208 
209  private:
210 
221  void triangulate( const QgsMeshFace &face, int nativeIndex );
222 
223  // check clock wise and calculate average size of triangles
224  void finalizeTriangles();
225 
226  // vertices: map CRS; 0-N ... native vertices, N+1 - len ... extra vertices
227  // faces are derived triangles
228  QgsMesh mTriangularMesh;
229  QVector<int> mTrianglesToNativeFaces; //len(mTrianglesToNativeFaces) == len(mTriangles). Mapping derived -> native
230  QVector<int> mEdgesToNativeEdges; //len(mEdgesToNativeEdges) == len(mEdges). Mapping derived -> native
231 
232  // centroids of the native faces in map CRS
233  QVector<QgsMeshVertex> mNativeMeshFaceCentroids;
234 
235  // centroids of the native edges in map CRS
236  QVector<QgsMeshVertex> mNativeMeshEdgeCentroids;
237 
238  QgsMeshSpatialIndex mSpatialFaceIndex;
239  QgsMeshSpatialIndex mSpatialEdgeIndex;
240  QgsCoordinateTransform mCoordinateTransform; //coordinate transform used to convert native mesh vertices to map vertices
241 
242  QgsRectangle mExtent;
243 
244  // average size of the triangles
245  double mAverageTriangleSize = 0;
246  int mLod = 0;
247 
248  const QgsTriangularMesh *mBaseTriangularMesh = nullptr;
249 
250  friend class TestQgsTriangularMesh;
251 };
252 
253 namespace QgsMeshUtils
254 {
256  CORE_EXPORT QgsGeometry toGeometry( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
257 
259  CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
260 
265  CORE_EXPORT QSet<int> nativeFacesFromTriangles( const QList<int> &triangleIndexes, const QVector<int> &trianglesToNativeFaces );
266 
271  CORE_EXPORT QSet<int> nativeEdgesFromEdges( const QList<int> &edgesIndexes, const QVector<int> &edgesToNativeEdges );
272 
277  CORE_EXPORT QSet<int> nativeVerticesFromTriangles( const QList<int> &triangleIndexes, const QVector<QgsMeshFace> &triangles );
278 
283  CORE_EXPORT QSet<int> nativeVerticesFromEdges( const QList<int> &edgesIndexes, const QVector<QgsMeshEdge> &edges );
284 
289  bool isInTriangleFace( const QgsPointXY point, const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
290 
291 };
292 
293 #endif // QGSTRIANGULARMESH_H
Class for doing transforms between two map coordinate systems.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
A spatial index for QgsMeshFace or QgsMeshEdge objects.
A class to represent a 2D point.
Definition: qgspointxy.h:44
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
QgsTriangularMesh()
Ctor.
~QgsTriangularMesh()
Dtor.
bool isInTriangleFace(const QgsPointXY point, const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Tests if point p is on the face defined with vertices.
CORE_EXPORT QSet< int > nativeEdgesFromEdges(const QList< int > &edgesIndexes, const QVector< int > &edgesToNativeEdges)
Returns unique native faces indexes from list of triangle indexes.
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 QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
CORE_EXPORT QSet< int > nativeVerticesFromEdges(const QList< int > &edgesIndexes, const QVector< QgsMeshEdge > &edges)
Returns unique native faces indexes from list of vertices of triangles.
CORE_EXPORT QSet< int > nativeVerticesFromTriangles(const QList< int > &triangleIndexes, const QVector< QgsMeshFace > &triangles)
Returns unique native vertex indexes from list of vertices of triangles.
CORE_EXPORT QSet< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
QVector< int > QgsMeshFace
List of vertex indexes.
Mesh - vertices, edges and faces.
ElementType
Defines type of mesh elements.