QGIS API Documentation  3.6.0-Noosa (5873452)
qgsmeshdataprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshdataprovider.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 QGSMESHDATAPROVIDER_H
19 #define QGSMESHDATAPROVIDER_H
20 
21 #include <QVector>
22 #include <QString>
23 #include <QMap>
24 #include <limits>
25 
26 #include "qgis_core.h"
27 #include "qgspoint.h"
28 #include "qgsdataprovider.h"
29 
30 class QgsRectangle;
31 
42 class CORE_EXPORT QgsMeshDatasetIndex
43 {
44  public:
46  QgsMeshDatasetIndex( int group = -1, int dataset = -1 );
48  int group() const;
50  int dataset() const;
52  bool isValid() const;
54  bool operator == ( const QgsMeshDatasetIndex &other ) const;
56  bool operator != ( const QgsMeshDatasetIndex &other ) const;
57  private:
58  int mGroupIndex = -1;
59  int mDatasetIndex = -1;
60 };
61 
64 
66 typedef QVector<int> QgsMeshFace;
67 
75 struct CORE_EXPORT QgsMesh
76 {
78  int vertexCount() const;
80  int faceCount() const;
81 
83  QgsMeshVertex vertex( int index ) const;
85  QgsMeshFace face( int index ) const;
86 
88  QVector<QgsMeshVertex> vertices SIP_SKIP;
90  QVector<QgsMeshFace> faces SIP_SKIP;
91 };
92 
104 class CORE_EXPORT QgsMeshDatasetValue
105 {
106  public:
108  QgsMeshDatasetValue( double x,
109  double y );
110 
112  QgsMeshDatasetValue( double scalar );
113 
115  QgsMeshDatasetValue() = default;
116 
118  ~QgsMeshDatasetValue() = default;
119 
121  void set( double scalar );
122 
124  void setX( double x );
125 
127  void setY( double y ) ;
128 
130  double scalar() const;
131 
133  double x() const;
134 
136  double y() const;
137 
138  bool operator==( const QgsMeshDatasetValue &other ) const;
139 
140  private:
141  double mX = std::numeric_limits<double>::quiet_NaN();
142  double mY = std::numeric_limits<double>::quiet_NaN();
143 };
144 
162 class CORE_EXPORT QgsMeshDataBlock
163 {
164  public:
166  enum DataType
167  {
171  };
172 
175 
177  QgsMeshDataBlock( DataType type, int count );
178 
180  DataType type() const;
181 
183  int count() const;
184 
186  bool isValid() const;
187 
192  QgsMeshDatasetValue value( int index ) const;
193 
198  bool active( int index ) const;
199 
211  void *buffer() SIP_SKIP;
212 
222  const void *constBuffer() const SIP_SKIP;
223 
224  private:
225  QVector<double> mDoubleBuffer;
226  QVector<int> mIntegerBuffer;
227  DataType mType;
228 };
229 
241 {
242  public:
243 
245  enum DataType
246  {
248  DataOnVertices
249  };
250 
252  QgsMeshDatasetGroupMetadata() = default;
253 
264  QgsMeshDatasetGroupMetadata( const QString &name,
265  bool isScalar,
266  bool isOnVertices,
267  double minimum,
268  double maximum,
269  const QMap<QString, QString> &extraOptions );
270 
274  QString name() const;
275 
279  QMap<QString, QString> extraOptions() const;
280 
284  bool isVector() const;
285 
289  bool isScalar() const;
290 
294  DataType dataType() const;
295 
299  double minimum() const;
300 
304  double maximum() const;
305 
306  private:
307  QString mName;
308  bool mIsScalar = false;
309  bool mIsOnVertices = false;
310  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
311  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
312  QMap<QString, QString> mExtraOptions;
313 };
314 
325 class CORE_EXPORT QgsMeshDatasetMetadata
326 {
327  public:
329  QgsMeshDatasetMetadata() = default;
330 
339  QgsMeshDatasetMetadata( double time,
340  bool isValid,
341  double minimum,
342  double maximum
343  );
344 
348  double time() const;
349 
353  bool isValid() const;
354 
358  double minimum() const;
359 
363  double maximum() const;
364 
365  private:
366  double mTime = std::numeric_limits<double>::quiet_NaN();
367  bool mIsValid = false;
368  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
369  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
370 };
371 
389 {
390  public:
392  virtual ~QgsMeshDataSourceInterface() = default;
393 
398  virtual int vertexCount() const = 0;
399 
404  virtual int faceCount() const = 0;
405 
410  virtual void populateMesh( QgsMesh *mesh ) const = 0;
411 };
412 
429 {
430  public:
432  virtual ~QgsMeshDatasetSourceInterface() = default;
433 
439  virtual bool addDataset( const QString &uri ) = 0;
440 
444  virtual QStringList extraDatasets() const = 0;
445 
449  virtual int datasetGroupCount( ) const = 0;
450 
454  virtual int datasetCount( int groupIndex ) const = 0;
455 
459  int datasetCount( QgsMeshDatasetIndex index ) const;
460 
464  virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata( int groupIndex ) const = 0;
465 
469  QgsMeshDatasetGroupMetadata datasetGroupMetadata( QgsMeshDatasetIndex index ) const;
470 
474  virtual QgsMeshDatasetMetadata datasetMetadata( QgsMeshDatasetIndex index ) const = 0;
475 
483  virtual QgsMeshDatasetValue datasetValue( QgsMeshDatasetIndex index, int valueIndex ) const = 0;
484 
492  virtual QgsMeshDataBlock datasetValues( QgsMeshDatasetIndex index, int valueIndex, int count ) const = 0;
493 
504  virtual bool isFaceActive( QgsMeshDatasetIndex index, int faceIndex ) const = 0;
505 
511  virtual QgsMeshDataBlock areFacesActive( QgsMeshDatasetIndex index, int faceIndex, int count ) const = 0;
512 
529  virtual bool persistDatasetGroup( const QString &path,
530  const QgsMeshDatasetGroupMetadata &meta,
531  const QVector<QgsMeshDataBlock> &datasetValues,
532  const QVector<QgsMeshDataBlock> &datasetActive,
533  const QVector<double> &times
534  ) = 0;
535 };
536 
537 
549 {
550  Q_OBJECT
551 
552  public:
554  QgsMeshDataProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options );
555 
556  signals:
558  void datasetGroupsAdded( int count );
559 };
560 
561 #endif // QGSMESHDATAPROVIDER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Vector double pairs (x1, y1, x2, y2, ... )
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e...
Abstract base class for spatial data provider implementations.
#define SIP_ABSTRACT
Definition: qgis_sip.h:187
DataType
Location of where data is specified for datasets in the dataset group.
#define SIP_SKIP
Definition: qgis_sip.h:119
Integer boolean flag whether face is active.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
DataType
Type of data stored in the block.
Base class for providing data for QgsMeshLayer.
Setting options for creating vector data providers.
Mesh - vertices and faces.
Interface for mesh datasets and dataset groups.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
QVector< int > QgsMeshFace
List of vertex indexes.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshDatasetValue represents single dataset value.
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
Interface for mesh data sources.
QgsPoint QgsMeshVertex
xyz coords of vertex