QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsmeshmemorydataprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshmemorydataprovider.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 QGSMESHMEMORYDATAPROVIDER_H
19 #define QGSMESHMEMORYDATAPROVIDER_H
20 
21 #define SIP_NO_FILE
22 
24 
25 #include <QString>
26 #include <memory>
27 
28 #include "qgis_core.h"
29 #include "qgis.h"
30 #include "qgsmeshdataprovider.h"
31 #include "qgsrectangle.h"
32 
33 struct CORE_EXPORT QgsMeshMemoryDataset
34 {
35  QgsMeshMemoryDataset();
36  QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const;
37  QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const;
38 
39  QVector<QgsMeshDatasetValue> values;
40  QVector<int> active;
41  double time = -1;
42  bool valid = false;
43  double minimum = std::numeric_limits<double>::quiet_NaN();
44  double maximum = std::numeric_limits<double>::quiet_NaN();
45 };
46 
47 struct CORE_EXPORT QgsMeshMemoryDatasetGroup
48 {
49  QgsMeshMemoryDatasetGroup( const QString &nm );
50  QgsMeshMemoryDatasetGroup();
51  QgsMeshDatasetGroupMetadata groupMetadata() const;
52  int datasetCount() const;
53  void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
54  void clearDatasets();
55  std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
56 
57  QMap<QString, QString> metadata;
58  QVector<std::shared_ptr<QgsMeshMemoryDataset>> datasets;
59  QString name;
60  bool isScalar = true;
62  double minimum = std::numeric_limits<double>::quiet_NaN();
63  double maximum = std::numeric_limits<double>::quiet_NaN();
64 };
65 
71 class CORE_EXPORT QgsMeshMemoryDataProvider: public QgsMeshDataProvider
72 {
73  Q_OBJECT
74 
75  public:
76 
99  QgsMeshMemoryDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions );
100 
101  bool isValid() const override;
102  QString name() const override;
103  QString description() const override;
104  QgsCoordinateReferenceSystem crs() const override;
105 
106  int vertexCount() const override;
107  int faceCount() const override;
108  void populateMesh( QgsMesh *mesh ) const override;
109  QgsRectangle extent() const override;
110 
140  bool addDataset( const QString &uri ) override;
141  QStringList extraDatasets() const override;
142  int datasetGroupCount() const override;
143  int datasetCount( int groupIndex ) const override;
144 
145  QgsMeshDatasetGroupMetadata datasetGroupMetadata( int groupIndex ) const override;
147  QgsMeshDatasetValue datasetValue( QgsMeshDatasetIndex index, int valueIndex ) const override;
148  QgsMeshDataBlock datasetValues( QgsMeshDatasetIndex index, int valueIndex, int count ) const override;
149  bool isFaceActive( QgsMeshDatasetIndex index, int faceIndex ) const override;
150  QgsMeshDataBlock areFacesActive( QgsMeshDatasetIndex index, int faceIndex, int count ) const override;
151  bool persistDatasetGroup( const QString &path,
152  const QgsMeshDatasetGroupMetadata &meta,
153  const QVector<QgsMeshDataBlock> &datasetValues,
154  const QVector<QgsMeshDataBlock> &datasetActive,
155  const QVector<double> &times
156  ) override;
157 
159  static QString providerKey();
161  static QString providerDescription();
163  static QgsMeshMemoryDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions );
164 
165  private:
166  void calculateMinMaxForDatasetGroup( QgsMeshMemoryDatasetGroup &grp ) const;
167  void calculateMinMaxForDataset( std::shared_ptr<QgsMeshMemoryDataset> &dataset ) const;
168  QgsRectangle calculateExtent( ) const;
169 
170  bool splitMeshSections( const QString &uri );
171  bool addMeshVertices( const QString &def );
172  bool addMeshFaces( const QString &def );
173 
174  bool splitDatasetSections( const QString &uri, QgsMeshMemoryDatasetGroup &datasetGroup );
175  bool setDatasetGroupType( const QString &uri, QgsMeshMemoryDatasetGroup &datasetGroup );
176  bool addDatasetGroupMetadata( const QString &def, QgsMeshMemoryDatasetGroup &datasetGroup );
177  bool addDatasetValues( const QString &def, std::shared_ptr<QgsMeshMemoryDataset> &dataset, bool isScalar );
178  bool checkDatasetValidity( std::shared_ptr<QgsMeshMemoryDataset> &dataset, bool isOnVertices );
179 
180  QVector<QgsMeshVertex> mVertices;
181  QVector<QgsMeshFace> mFaces;
182  QVector<QgsMeshMemoryDatasetGroup> mDatasetGroups;
183 
184  bool mIsValid = false;
185  QStringList mExtraDatasetUris;
186 };
187 
189 
190 #endif // QGSMESHMEMORYDATAPROVIDER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
virtual bool persistDatasetGroup(const QString &path, const QgsMeshDatasetGroupMetadata &meta, const QVector< QgsMeshDataBlock > &datasetValues, const QVector< QgsMeshDataBlock > &datasetActive, const QVector< double > &times)=0
Creates a new dataset group from a data and persists it into a destination path.
virtual int faceCount() const =0
Returns number of faces in the native mesh.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e...
virtual bool addDataset(const QString &uri)=0
Associate dataset with the mesh.
virtual int datasetCount(int groupIndex) const =0
Returns number of datasets loaded in the group.
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
virtual QString name() const =0
Returns a provider name.
DataType
Location of where data is specified for datasets in the dataset group.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
virtual QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const =0
Returns N vector/scalar values from the index from the dataset.
virtual void populateMesh(QgsMesh *mesh) const =0
Populates the mesh vertices and faces.
Base class for providing data for QgsMeshLayer.
virtual QgsMeshDatasetMetadata datasetMetadata(QgsMeshDatasetIndex index) const =0
Returns dataset metadata.
Setting options for creating vector data providers.
Mesh - vertices and faces.
virtual bool isFaceActive(QgsMeshDatasetIndex index, int faceIndex) const =0
Returns whether the face is active for particular dataset.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
This class represents a coordinate reference system (CRS).
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
virtual QStringList extraDatasets() const =0
Returns list of additional dataset file URIs added using addDataset() calls.
virtual QString description() const =0
Returns description.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
QgsMeshDatasetValue represents single dataset value.
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
virtual QgsMeshDatasetValue datasetValue(QgsMeshDatasetIndex index, int valueIndex) const =0
Returns vector/scalar value associated with the index from the dataset To read multiple continuous va...
virtual QgsMeshDataBlock areFacesActive(QgsMeshDatasetIndex index, int faceIndex, int count) const =0
Returns whether the faces are active for particular dataset.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.