-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgstriangularmesh.h
109 lines (91 loc) · 3.5 KB
/
qgstriangularmesh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/***************************************************************************
qgstriangularmesh.h
-------------------
begin : April 2018
copyright : (C) 2018 by Peter Petrik
email : zilolv at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSTRIANGULARMESH_H
#define QGSTRIANGULARMESH_H
#define SIP_NO_FILE
#include <QVector>
#include "qgis_core.h"
#include "qgsmeshdataprovider.h"
#include "qgsgeometry.h"
#include "qgsspatialindex.h"
class QgsRenderContext;
//! Mesh - vertices and faces
struct CORE_EXPORT QgsMesh
{
//! vertices
QVector<QgsMeshVertex> vertices;
//! faces
QVector<QgsMeshFace> faces;
};
/**
* \ingroup core
*
* Triangular/Derived Mesh is mesh with vertices in map coordinates. It creates
* spatial index for identification of a triangle that contains a particular point
* on the map.
*
* \note The API is considered EXPERIMENTAL and can be changed without a notice
*
* \since QGIS 3.2
*/
class CORE_EXPORT QgsTriangularMesh
{
public:
//! Ctor
QgsTriangularMesh() = default;
//! Dtor
~QgsTriangularMesh() = default;
/**
* Constructs triangular mesh from layer's native mesh and context. Populates spatial index.
* \param nativeMesh QgsMesh to access native vertices and faces
* \param context Rendering context to estimate number of triagles to create for an face
*/
void update( QgsMesh *nativeMesh, QgsRenderContext *context );
/**
* Returns vertices in map CRS
*
* The list of consist of vertices from native mesh (0-N) and
* extra vertices needed to create triangles (N+1 - len)
*/
const QVector<QgsMeshVertex> &vertices() const ;
//! Returns triangles
const QVector<QgsMeshFace> &triangles() const ;
//! Returns centroids of the native faces in map CRS
const QVector<QgsMeshVertex> ¢roids() const ;
//! Returns mapping between triangles and original faces
const QVector<int> &trianglesToNativeFaces() const ;
/**
* Returns triangle index that contains the given point, -1 if no such triangle exists
* It uses spatial indexing
*
* \since QGIS 3.4
*/
int faceIndexForPoint( const QgsPointXY &point ) const ;
private:
// vertices: map CRS; 0-N ... native vertices, N+1 - len ... extra vertices
// faces are derived triangles
QgsMesh mTriangularMesh;
QVector<int> mTrianglesToNativeFaces; //len(mTrianglesToNativeFaces) == len(mTriangles). Mapping derived -> native
// centroids of the native faces in map CRS
QVector<QgsMeshVertex> mNativeMeshFaceCentroids;
QgsSpatialIndex mSpatialIndex;
};
namespace QgsMeshUtils
{
//! Returns face as polygon geometry
QgsGeometry toGeometry( const QgsMeshFace &face, const QVector<QgsMeshVertex> &vertices );
};
#endif // QGSTRIANGULARMESH_H