QGIS API Documentation  3.12.1-București (121cc00ff0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <memory>
27 #include "qgis_core.h"
28 #include "qgsmeshdataprovider.h"
29 #include "qgsgeometry.h"
30 #include "qgsmeshspatialindex.h"
31 
32 class QgsRenderContext;
34 class QgsRectangle;
35 
47 class CORE_EXPORT QgsTriangularMesh
48 {
49  public:
54 
60  void update( QgsMesh *nativeMesh, QgsRenderContext *context );
61 
68  const QVector<QgsMeshVertex> &vertices() const ;
70  const QVector<QgsMeshFace> &triangles() const ;
71 
73  const QVector<QgsMeshVertex> &centroids() const ;
74 
76  const QVector<int> &trianglesToNativeFaces() const ;
77 
87  int faceIndexForPoint( const QgsPointXY &point ) const ;
88 
98  int faceIndexForPoint_v2( const QgsPointXY &point ) const;
99 
109  QList<int> faceIndexesForRectangle( const QgsRectangle &rectangle ) const ;
110 
119  QVector<QVector3D> vertexNormals( float vertScale ) const;
120 
121  private:
122 
133  void triangulate( const QgsMeshFace &face, int nativeIndex );
134 
135  // check and, if needed set the indexes of the face counter clock-wise
136  void setTrianglesCounterClockWise( QgsMeshFace &face );
137 
138  // vertices: map CRS; 0-N ... native vertices, N+1 - len ... extra vertices
139  // faces are derived triangles
140  QgsMesh mTriangularMesh;
141  QVector<int> mTrianglesToNativeFaces; //len(mTrianglesToNativeFaces) == len(mTriangles). Mapping derived -> native
142 
143  // centroids of the native faces in map CRS
144  QVector<QgsMeshVertex> mNativeMeshFaceCentroids;
145 
146  QgsMeshSpatialIndex mSpatialIndex;
147  QgsCoordinateTransform mCoordinateTransform; //coordinate transform used to convert native mesh vertices to map vertices
148 
149  friend class TestQgsTriangularMesh;
150 };
151 
152 namespace QgsMeshUtils
153 {
155  CORE_EXPORT QgsGeometry toGeometry( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
156 
158  CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
159 
164  CORE_EXPORT QList<int> nativeFacesFromTriangles( const QList<int> &triangleIndexes, const QVector<int> &trianglesToNativeFaces );
165 
170  bool isInTriangleFace( const QgsPointXY point, const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
171 
172 };
173 
174 #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:122
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 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.