/
qgsmeshmemorydataprovider.h
192 lines (168 loc) · 7.35 KB
/
qgsmeshmemorydataprovider.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/***************************************************************************
qgsmeshmemorydataprovider.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 QGSMESHMEMORYDATAPROVIDER_H
#define QGSMESHMEMORYDATAPROVIDER_H
#define SIP_NO_FILE
///@cond PRIVATE
#include <QString>
#include <memory>
#include "qgis_core.h"
#include "qgis.h"
#include "qgsmeshdataprovider.h"
#include "qgsrectangle.h"
/**
* \ingroup core
* Provides data stored in-memory for QgsMeshLayer. Useful for plugins or tests.
* \since QGIS 3.2
*/
class CORE_EXPORT QgsMeshMemoryDataProvider final: public QgsMeshDataProvider
{
Q_OBJECT
public:
/**
* Construct a mesh in-memory data provider from data string
*
* Data string contains simple definition of vertices and faces or edges
*
* Each entry is separated by "\n" sign and section deliminer "---"
* First section defines vertices (x and y coordinate separated by comma)
* Second section defines face list (vertex indexes, numbered from 0. A face has 3 or move vertices)
* or defines edge list (vertex indexes, numbered from 0. An edge has 2 vertices)
*
* It is not possible to define mesh with both faces and edges
*
* For example (mesh with faces and vertices):
*
* \code
* QString uri(
* "1.0, 2.0 \n" \
* "2.0, 2.0 \n" \
* "3.0, 2.0 \n" \
* "2.0, 3.0 \n" \
* "1.0, 3.0 \n" \
* "--- \n"
* "0, 1, 3, 4 \n" \
* "1, 2, 3 \n"
* );
* \endcode
*
* For example (mesh with edges and vertices):
*
* \code
* QString uri(
* "1.0, 2.0 \n" \
* "2.0, 2.0 \n" \
* "3.0, 2.0 \n" \
* "2.0, 3.0 \n" \
* "1.0, 3.0 \n" \
* "---\n"
* "0, 1 \n" \
* "1, 2 \n"
* );
* \endcode
*/
QgsMeshMemoryDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions,
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
bool isValid() const override;
QString name() const override;
QString description() const override;
QgsCoordinateReferenceSystem crs() const override;
int vertexCount() const override;
int faceCount() const override;
int edgeCount() const override;
void populateMesh( QgsMesh *mesh ) const override;
QgsRectangle extent() const override;
/**
* Adds dataset to a mesh in-memory data provider from data string
*
* Data string contains simple definition of datasets
* Each entry is separated by "\n" sign and section deliminer "---"
* First section defines the dataset group: Vertex/Edge/Face Vector/Scalar Name
* Second section defines the group metadata: key: value pairs
* Third section defines the datasets (timesteps). First line is time,
* other lines are values (one value on line). For vectors separated by comma
*
* For example:
*
* \code
* QString uri(
* "Vertex Vector MyVertexVectorDataset\n" \
* "---"
* "description: My great dataset \n" \
* "reference_time: Midnight \n" \
* "---"
* "0 \n"
* "3, 2 \n" \
* "1, -2 \n"
* "---"
* "1 \n"
* "2, 2 \n" \
* "2, -2 \n"
* );
* \endcode
*/
bool addDataset( const QString &uri ) override;
QStringList extraDatasets() const override;
int datasetGroupCount() const override;
int datasetCount( int groupIndex ) const override;
QgsMeshDatasetGroupMetadata datasetGroupMetadata( int groupIndex ) const override;
QgsMeshDatasetMetadata datasetMetadata( QgsMeshDatasetIndex index ) const override;
QgsMeshDatasetValue datasetValue( QgsMeshDatasetIndex index, int valueIndex ) const override;
QgsMeshDataBlock datasetValues( QgsMeshDatasetIndex index, int valueIndex, int count ) const override;
QgsMesh3dDataBlock dataset3dValues( QgsMeshDatasetIndex index, int faceIndex, int count ) const override;
bool isFaceActive( QgsMeshDatasetIndex index, int faceIndex ) const override;
QgsMeshDataBlock areFacesActive( QgsMeshDatasetIndex index, int faceIndex, int count ) const override;
bool persistDatasetGroup( const QString &outputFilePath,
const QString &outputDriver,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> ×
) override;
virtual bool persistDatasetGroup( const QString &outputFilePath,
const QString &outputDriver,
QgsMeshDatasetSourceInterface *source,
int datasetGroupIndex
) override;
//! Returns the memory provider key
static QString providerKey();
//! Returns the memory provider description
static QString providerDescription();
//! Provider factory
static QgsMeshMemoryDataProvider *createProvider( const QString &uri,
const QgsDataProvider::ProviderOptions &providerOptions,
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
private:
QgsRectangle calculateExtent( ) const;
bool splitMeshSections( const QString &uri );
bool addMeshVertices( const QString &def );
bool addMeshFacesOrEdges( const QString &def );
bool splitDatasetSections( const QString &uri, QgsMeshMemoryDatasetGroup &datasetGroup );
bool setDatasetGroupType( const QString &uri, QgsMeshMemoryDatasetGroup &datasetGroup );
bool addDatasetGroupMetadata( const QString &def, QgsMeshMemoryDatasetGroup &datasetGroup );
bool addDatasetValues( const QString &def, std::shared_ptr<QgsMeshMemoryDataset> &dataset, bool isScalar );
bool checkDatasetValidity( std::shared_ptr<QgsMeshMemoryDataset> &dataset, QgsMeshDatasetGroupMetadata::DataType dataType );
bool checkVertexId( int vertex_id );
void addGroupToTemporalCapabilities( int groupIndex, const QgsMeshMemoryDatasetGroup &group );
QVector<QgsMeshVertex> mVertices;
QVector<QgsMeshFace> mFaces;
QVector<QgsMeshEdge> mEdges;
QVector<QgsMeshMemoryDatasetGroup> mDatasetGroups;
bool mIsValid = false;
QStringList mExtraDatasetUris;
};
///@endcond
#endif // QGSMESHMEMORYDATAPROVIDER_H