QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
49 class CORE_EXPORT QgsTriangularMesh // TODO rename to QgsRendererMesh in QGIS 4
50 {
51  public:
56 
63  bool update( QgsMesh *nativeMesh, const QgsCoordinateTransform &transform = QgsCoordinateTransform() );
64 
71  const QVector<QgsMeshVertex> &vertices() const ;
72 
74  const QVector<QgsMeshFace> &triangles() const ;
75 
77  const QVector<QgsMeshEdge> &edges() const ;
78 
84  Q_DECL_DEPRECATED const QVector<QgsMeshVertex> &centroids() const ;
85 
90  const QVector<QgsMeshVertex> &faceCentroids() const ;
91 
96  const QVector<QgsMeshVertex> &edgeCentroids() const ;
97 
99  const QVector<int> &trianglesToNativeFaces() const ;
100 
102  const QVector<int> &edgesToNativeEdges() const ;
103 
113  int faceIndexForPoint( const QgsPointXY &point ) const ;
114 
124  int faceIndexForPoint_v2( const QgsPointXY &point ) const;
125 
135  QList<int> faceIndexesForRectangle( const QgsRectangle &rectangle ) const ;
136 
144  QList<int> edgeIndexesForRectangle( const QgsRectangle &rectangle ) const ;
145 
154  QVector<QVector3D> vertexNormals( float vertScale ) const;
155 
171  QVector<QgsTriangularMesh *> simplifyMesh( double reductionFactor, int minimumTrianglesCount = 10 ) const;
172 
179  double averageTriangleSize() const;
180 
191  int levelOfDetail() const;
192 
200  QgsRectangle extent() const;
201 
206  bool contains( const QgsMesh::ElementType &type ) const;
207 
208  private:
209 
220  void triangulate( const QgsMeshFace &face, int nativeIndex );
221 
222  // check clock wise and calculate average size of triangles
223  void finalizeTriangles();
224 
225  // vertices: map CRS; 0-N ... native vertices, N+1 - len ... extra vertices
226  // faces are derived triangles
227  QgsMesh mTriangularMesh;
228  QVector<int> mTrianglesToNativeFaces; //len(mTrianglesToNativeFaces) == len(mTriangles). Mapping derived -> native
229  QVector<int> mEdgesToNativeEdges; //len(mEdgesToNativeEdges) == len(mEdges). Mapping derived -> native
230 
231  // centroids of the native faces in map CRS
232  QVector<QgsMeshVertex> mNativeMeshFaceCentroids;
233 
234  // centroids of the native edges in map CRS
235  QVector<QgsMeshVertex> mNativeMeshEdgeCentroids;
236 
237  QgsMeshSpatialIndex mSpatialFaceIndex;
238  QgsMeshSpatialIndex mSpatialEdgeIndex;
239  QgsCoordinateTransform mCoordinateTransform; //coordinate transform used to convert native mesh vertices to map vertices
240 
241  QgsRectangle mExtent;
242 
243  // average size of the triangles
244  double mAverageTriangleSize = 0;
245  int mLod = 0;
246 
247  const QgsTriangularMesh *mBaseTriangularMesh = nullptr;
248 
249  friend class TestQgsTriangularMesh;
250 };
251 
252 namespace QgsMeshUtils
253 {
255  CORE_EXPORT QgsGeometry toGeometry( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
256 
258  CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
259 
264  CORE_EXPORT QSet<int> nativeFacesFromTriangles( const QList<int> &triangleIndexes, const QVector<int> &trianglesToNativeFaces );
265 
270  CORE_EXPORT QSet<int> nativeEdgesFromEdges( const QList<int> &edgesIndexes, const QVector<int> &edgesToNativeEdges );
271 
276  CORE_EXPORT QSet<int> nativeVerticesFromTriangles( const QList<int> &triangleIndexes, const QVector<QgsMeshFace> &triangles );
277 
282  CORE_EXPORT QSet<int> nativeVerticesFromEdges( const QList<int> &edgesIndexes, const QVector<QgsMeshEdge> &edges );
283 
288  bool isInTriangleFace( const QgsPointXY point, const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
289 
290 };
291 
292 #endif // QGSTRIANGULARMESH_H
QgsMeshUtils
Definition: qgsmeshlayerinterpolator.h:86
QgsMeshUtils::nativeVerticesFromEdges
CORE_EXPORT QSet< int > nativeVerticesFromEdges(const QList< int > &edgesIndexes, const QVector< QgsMeshEdge > &edges)
Returns unique native faces indexes from list of vertices of triangles.
Definition: qgstriangularmesh.cpp:595
qgsmeshspatialindex.h
QgsMeshUtils::nativeVerticesFromTriangles
CORE_EXPORT QSet< int > nativeVerticesFromTriangles(const QList< int > &triangleIndexes, const QVector< QgsMeshFace > &triangles)
Returns unique native vertex indexes from list of vertices of triangles.
Definition: qgstriangularmesh.cpp:581
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsMesh
Mesh - vertices, edges and faces.
Definition: qgsmeshdataprovider.h:58
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsMeshUtils::isInTriangleFace
bool isInTriangleFace(const QgsPointXY point, const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Tests if point p is on the face defined with vertices.
Definition: qgstriangularmesh.cpp:563
QgsMeshUtils::nativeEdgesFromEdges
CORE_EXPORT QSet< int > nativeEdgesFromEdges(const QList< int > &edgesIndexes, const QVector< int > &edgesToNativeEdges)
Returns unique native faces indexes from list of triangle indexes.
Definition: qgstriangularmesh.cpp:545
QgsMeshUtils::nativeFacesFromTriangles
CORE_EXPORT QSet< int > nativeFacesFromTriangles(const QList< int > &triangleIndexes, const QVector< int > &trianglesToNativeFaces)
Returns unique native faces indexes from list of triangle indexes.
Definition: qgstriangularmesh.cpp:540
QgsMesh::ElementType
ElementType
Defines type of mesh elements.
Definition: qgsmeshdataprovider.h:65
QgsMeshUtils::toPolygon
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
Definition: qgstriangularmesh.cpp:509
QgsTriangularMesh::~QgsTriangularMesh
~QgsTriangularMesh()
Dtor.
QgsMeshFace
QVector< int > QgsMeshFace
List of vertex indexes.
Definition: qgsmeshdataprovider.h:41
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsMeshSpatialIndex
A spatial index for QgsMeshFace or QgsMeshEdge objects.
Definition: qgsmeshspatialindex.h:50
qgsgeometry.h
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsTriangularMesh::QgsTriangularMesh
QgsTriangularMesh()
Ctor.
QgsTriangularMesh
Triangular/Derived Mesh is mesh with vertices in map coordinates.
Definition: qgstriangularmesh.h:50
QgsMeshUtils::toGeometry
CORE_EXPORT QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
Definition: qgstriangularmesh.cpp:524
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
qgsmeshdataprovider.h