-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsmeshtriangulation.h
158 lines (133 loc) · 6 KB
/
qgsmeshtriangulation.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***************************************************************************
qgsmeshtriangulation.h
-----------------
begin : August 9th, 2020
copyright : (C) 2020 by Vincent Cloarec
email : vcloarec 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 QGSMESHTRIANGULATION_H
#define QGSMESHTRIANGULATION_H
#include "qgscoordinatereferencesystem.h"
#include "qgsmeshdataprovider.h"
#include "qgis_analysis.h"
class QgsVectorLayer;
class QgsCoordinateTransformContext;
class QgsFeature;
class QgsFeatureIterator;
class QgsTriangulation;
class QgsFeedback;
/**
* \ingroup analysis
* \class QgsMeshTriangulation
*
* Class that handles mesh creation with Delaunay constrained triangulation
*
* \since QGIS 3.16
*/
class ANALYSIS_EXPORT QgsMeshTriangulation : public QObject
{
Q_OBJECT
public:
//! Constructor
QgsMeshTriangulation();
//! Destructor
~QgsMeshTriangulation();
/**
* Adds vertices to the triangulation from a feature iterator, return TRUE if successful.
*
* \param vertexFeatureIterator the feature iterator of vertices to insert
* \param valueAttribute the index of the attribute that represents the value of vertices, if -1 uses Z coordinate of vertices
* \param transform the coordinates transform used to transform coordinates
* \param feedback feedback argument may be specified to allow cancellation and progress reports
* \param featureCount the count of feature to allow progress report of the feedback
*/
bool addVertices( QgsFeatureIterator &vertexFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transform, QgsFeedback *feedback = nullptr, long featureCount = 1 );
/**
* Adds break lines from a vector layer, return TRUE if successful.
* \param lineFeatureIterator the feature iterator of break lines to insert
* \param valueAttribute the index of the attribute that represents the value of vertices, if -1 uses Z coordinate of vertices
* \param transform the coordinates transform used to transform coordinates
* \param feedback feedback argument may be specified to allow cancellation and progress reports
* \param featureCount the count of feature to allow progress report of the feedback
*
* \warning if the feature iterator contains only point geometries, the vertices will be added only without treating them as breaklines
*/
bool addBreakLines( QgsFeatureIterator &lineFeatureIterator, int valueAttribute, const QgsCoordinateTransform &transformContext, QgsFeedback *feedback = nullptr, long featureCount = 1 );
//! Returns the triangulated mesh
QgsMesh triangulatedMesh() const;
//! Sets the coordinate reference system used for the triangulation
void setCrs( const QgsCoordinateReferenceSystem &crs );
private:
#ifdef SIP_RUN
QgsMeshTriangulation( const QgsMeshTriangulation &rhs );
#endif
QgsCoordinateReferenceSystem mCrs;
std::unique_ptr<QgsTriangulation> mTriangulation;
void addVerticesFromFeature( const QgsFeature &feature, int valueAttribute, const QgsCoordinateTransform &transform, QgsFeedback *feedback = nullptr );
void addBreakLinesFromFeature( const QgsFeature &feature, int valueAttribute, const QgsCoordinateTransform &transform, QgsFeedback *feedback = nullptr );
};
#ifndef SIP_RUN
/**
* \ingroup analysis
* \class QgsMeshZValueDataset
*
* Convenient class that can be used to obtain a dataset that represents the Z values of mesh vertices
*
* \since QGIS 3.16
*/
class QgsMeshZValueDataset: public QgsMeshDataset
{
public:
//! Constructor with the mesh
QgsMeshZValueDataset( const QgsMesh &mesh );
QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
bool isActive( int faceIndex ) const override;
QgsMeshDatasetMetadata metadata() const override;
int valuesCount() const override;
private:
QgsMesh mMesh;
double mZMinimum = std::numeric_limits<double>::max();
double mZMaximum = -std::numeric_limits<double>::max();
};
#endif //SIP_RUN
/**
* \ingroup analysis
* \class QgsMeshZValueDatasetGroup
*
* Convenient class that can be used to obtain a datasetgroup on vertices that represents the Z value of the mesh vertices
*
* \since QGIS 3.16
*/
class ANALYSIS_EXPORT QgsMeshZValueDatasetGroup: public QgsMeshDatasetGroup
{
public:
/**
* Constructor
*
* \param datasetGroupName the name of the dataset group
* \param mesh the mesh used to create the Z value dataset
*/
QgsMeshZValueDatasetGroup( const QString &datasetGroupName, const QgsMesh &mesh );
void initialize() override;
QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
int datasetCount() const override;
QgsMeshDataset *dataset( int index ) const override;
QgsMeshDatasetGroup::Type type() const override {return QgsMeshDatasetGroup::Virtual;}
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
private:
#ifdef SIP_RUN
QgsMeshZValueDatasetGroup( const QgsMeshZValueDatasetGroup &rhs );
#endif
std::unique_ptr<QgsMeshZValueDataset> mDataset;
};
#endif // QGSMESHTRIANGULATION_H