QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgsmeshdataset.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshdataset.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 QGSMESHDATASET_H
19 #define QGSMESHDATASET_H
20 
21 #include <QVector>
22 #include <QString>
23 #include <QMap>
24 #include <QPair>
25 
26 #include <limits>
27 
28 #include "qgis_core.h"
29 #include "qgspoint.h"
30 #include "qgsdataprovider.h"
31 
32 class QgsMeshLayer;
34 class QgsRectangle;
35 
46 class CORE_EXPORT QgsMeshDatasetIndex
47 {
48  public:
50  QgsMeshDatasetIndex( int group = -1, int dataset = -1 );
52  int group() const;
54  int dataset() const;
56  bool isValid() const;
58  bool operator == ( QgsMeshDatasetIndex other ) const;
60  bool operator != ( QgsMeshDatasetIndex other ) const;
61  private:
62  int mGroupIndex = -1;
63  int mDatasetIndex = -1;
64 };
65 
77 class CORE_EXPORT QgsMeshDatasetValue
78 {
79  public:
81  QgsMeshDatasetValue( double x,
82  double y );
83 
85  QgsMeshDatasetValue( double scalar );
86 
88  QgsMeshDatasetValue() = default;
89 
91  ~QgsMeshDatasetValue() = default;
92 
94  void set( double scalar );
95 
97  void setX( double x );
98 
100  void setY( double y ) ;
101 
103  double scalar() const;
104 
106  double x() const;
107 
109  double y() const;
110 
111  bool operator==( QgsMeshDatasetValue other ) const;
112 
113  private:
114  double mX = std::numeric_limits<double>::quiet_NaN();
115  double mY = std::numeric_limits<double>::quiet_NaN();
116 };
117 
135 class CORE_EXPORT QgsMeshDataBlock
136 {
137  public:
139  enum DataType
140  {
144  };
145 
148 
150  QgsMeshDataBlock( DataType type, int count );
151 
153  DataType type() const;
154 
156  int count() const;
157 
159  bool isValid() const;
160 
165  QgsMeshDatasetValue value( int index ) const;
166 
171  bool active( int index ) const;
172 
186  void setActive( const QVector<int> &vals );
187 
199  QVector<int> active() const;
200 
207  QVector<double> values() const;
208 
218  void setValues( const QVector<double> &vals );
219 
221  void setValid( bool valid );
222 
223  private:
224  QVector<double> mDoubleBuffer;
225  QVector<int> mIntegerBuffer;
226  DataType mType;
227  int mSize = 0;
228  bool mIsValid = false;
229 };
230 
244 class CORE_EXPORT QgsMesh3dDataBlock
245 {
246  public:
249 
252 
254  QgsMesh3dDataBlock( int count, bool isVector );
255 
257  void setValid( bool valid );
258 
260  bool isValid() const;
261 
263  bool isVector() const;
264 
266  int count() const;
267 
269  int firstVolumeIndex() const;
270 
272  int lastVolumeIndex() const;
273 
275  int volumesCount() const;
276 
280  QVector<int> verticalLevelsCount() const;
281 
285  void setVerticalLevelsCount( const QVector<int> &verticalLevelsCount );
286 
290  QVector<double> verticalLevels() const;
291 
295  void setVerticalLevels( const QVector<double> &verticalLevels );
296 
300  QVector<int> faceToVolumeIndex() const;
301 
305  void setFaceToVolumeIndex( const QVector<int> &faceToVolumeIndex );
306 
312  QVector<double> values() const;
313 
320  QgsMeshDatasetValue value( int volumeIndex ) const;
321 
327  void setValues( const QVector<double> &doubleBuffer );
328 
329  private:
330  int mSize = 0;
331  bool mIsValid = false;
332  bool mIsVector = false;
333  QVector<int> mVerticalLevelsCount;
334  QVector<double> mVerticalLevels;
335  QVector<int> mFaceToVolumeIndex;
336  QVector<double> mDoubleBuffer; // for scalar/vector values
337 };
338 
350 {
351  public:
352 
354  enum DataType
355  {
356  DataOnFaces = 0,
359  DataOnEdges
360  };
361 
364 
379  QgsMeshDatasetGroupMetadata( const QString &name,
380  const QString uri,
381  bool isScalar,
382  DataType dataType,
383  double minimum,
384  double maximum,
385  int maximumVerticalLevels,
386  const QDateTime &referenceTime,
387  bool isTemporal,
388  const QMap<QString, QString> &extraOptions );
389 
393  QString name() const;
394 
400  QString uri() const;
401 
405  QMap<QString, QString> extraOptions() const;
406 
410  bool isVector() const;
411 
415  bool isScalar() const;
416 
420  bool isTemporal() const;
421 
427  DataType dataType() const;
428 
432  double minimum() const;
433 
437  double maximum() const;
438 
444  int maximumVerticalLevelsCount() const;
445 
451  QDateTime referenceTime() const;
452 
453  private:
454  QString mName;
455  QString mUri;
456  bool mIsScalar = false;
457  DataType mDataType = DataType::DataOnFaces;
458  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
459  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
460  QMap<QString, QString> mExtraOptions;
461  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
462  QDateTime mReferenceTime;
463  bool mIsTemporal = false;
464 };
465 
476 class CORE_EXPORT QgsMeshDatasetMetadata
477 {
478  public:
481 
491  QgsMeshDatasetMetadata( double time,
492  bool isValid,
493  double minimum,
494  double maximum,
495  int maximumVerticalLevels
496  );
497 
501  double time() const;
502 
506  bool isValid() const;
507 
511  double minimum() const;
512 
516  double maximum() const;
517 
523  int maximumVerticalLevelsCount() const;
524 
525  private:
526  double mTime = std::numeric_limits<double>::quiet_NaN();
527  bool mIsValid = false;
528  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
529  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
530  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
531 };
532 
533 
541 class CORE_EXPORT QgsMeshDataset
542 {
543  public:
545  QgsMeshDataset() = default;
546 
548  virtual ~QgsMeshDataset() = default;
549 
551  virtual QgsMeshDatasetValue datasetValue( int valueIndex ) const = 0;
552 
554  virtual QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const = 0;
555 
557  virtual QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const = 0;
558 
560  virtual bool isActive( int faceIndex ) const = 0;
561 
563  virtual QgsMeshDatasetMetadata metadata() const = 0;
564 
566  virtual int valuesCount() const = 0;
567 };
568 
576 class CORE_EXPORT QgsMeshDatasetGroup
577 {
578  public:
579 
585  enum Type
586  {
591  };
592 
594  QgsMeshDatasetGroup() = default;
596 
598  QgsMeshDatasetGroup( const QString &name );
599 
601  QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
602 
604  virtual void initialize() = 0;
605 
607  QgsMeshDatasetGroupMetadata groupMetadata() const;
608 
610  virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const = 0 ;
611 
613  virtual int datasetCount() const = 0;
614 
616  virtual QgsMeshDataset *dataset( int index ) const = 0;
617 
619  virtual QgsMeshDatasetGroup::Type type() const = 0;
620 
622  double minimum() const;
623 
625  double maximum() const;
626 
628  void setMinimumMaximum( double min, double max );
629 
631  QString name() const;
632 
634  void setName( const QString &name );
635 
637  QgsMeshDatasetGroupMetadata::DataType dataType() const;
638 
640  void setDataType( const QgsMeshDatasetGroupMetadata::DataType &dataType );
641 
643  void addExtraMetadata( QString key, QString value );
645  QMap<QString, QString> extraMetadata() const;
646 
648  bool isScalar() const;
649 
651  void setIsScalar( bool isScalar );
652 
654  bool checkValueCountPerDataset( int count ) const;
655 
657  void calculateStatistic();
658 
660  virtual QStringList datasetGroupNamesDependentOn() const;
661 
663  virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
664 
666  virtual QString description() const;
667 
669  void setReferenceTime( const QDateTime &referenceTime );
670 
671  protected:
672  QString mName;
673 
675  QMap<QString, QString> mMetadata;
676  bool mIsScalar = true;
677 
678  private:
679  double mMinimum = std::numeric_limits<double>::quiet_NaN();
680  double mMaximum = std::numeric_limits<double>::quiet_NaN();
681 
682  QDateTime mReferenceTime;
683 };
684 
685 #ifndef SIP_RUN
686 
696 class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
697 {
698  public:
700  QgsMeshMemoryDataset() = default;
701 
702  QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
703  QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
704  QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
705  QgsMeshDatasetMetadata metadata() const override;
706  bool isActive( int faceIndex ) const override;
707  int valuesCount() const override;
708 
710  void calculateMinMax();
711 
712  QVector<QgsMeshDatasetValue> values;
713  QVector<int> active;
714  double time = -1;
715  bool valid = false;
716  double minimum = std::numeric_limits<double>::quiet_NaN();
717  double maximum = std::numeric_limits<double>::quiet_NaN();
718 };
719 
730 {
731  public:
735  QgsMeshMemoryDatasetGroup( const QString &name );
737  QgsMeshMemoryDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
738 
739  void initialize() override;
740  int datasetCount() const override;
741  QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
742  QgsMeshDataset *dataset( int index ) const override;
743  virtual QgsMeshDatasetGroup::Type type() const override {return QgsMeshDatasetGroup::Memory;}
744 
746  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
747 
749  void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
750 
752  void clearDatasets();
753 
755  std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
756 
758  QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
759 };
760 
761 #endif //SIP_RUN
762 
788 {
789  public:
790 
795 
804  QgsMeshDatasetGroupTreeItem( const QString &defaultName,
805  const QString &sourceName,
806  bool isVector,
807  int index );
808 
815  QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
816 
822 
829 
836  void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
837 
846  void removeChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
847 
853  QgsMeshDatasetGroupTreeItem *child( int row ) const;
854 
862  QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
863 
868  int childCount() const;
869 
874  int totalChildCount() const;
875 
882  QList<int> enabledDatasetGroupIndexes() const;
883 
888  QgsMeshDatasetGroupTreeItem *parentItem() const;
889 
894  int row() const;
895 
901  QString name() const;
902 
909  void setName( const QString &name );
910 
918  QString providerName() const;
919 
923  bool isVector() const;
924 
928  int datasetGroupIndex() const;
929 
933  bool isEnabled() const;
934 
939  void setIsEnabled( bool isEnabled );
940 
944  QString defaultName() const;
945 
951  QgsMeshDatasetGroup::Type datasetGroupType() const;
952 
959  QList<int> groupIndexDependencies() const;
960 
966  QString description() const;
967 
975  void setDatasetGroup( QgsMeshDatasetGroup *datasetGroup );
976 
984  void setPersistentDatasetGroup( const QString &uri );
985 
992  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
993 
994  private:
995  QgsMeshDatasetGroupTreeItem *mParent = nullptr;
996  QList< QgsMeshDatasetGroupTreeItem * > mChildren;
997  QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
998 
999  // Data
1000  QString mUserName;
1001  QString mOriginalName;
1002  QString mSourceName;
1003  QgsMeshDatasetGroup::Type mDatasetGroupType = QgsMeshDatasetGroup::None;
1004  QString mDescription;
1005 
1006  bool mIsVector = false;
1007  int mDatasetGroupIndex = -1;
1008  bool mIsEnabled = true;
1009 
1010  QList<int> mDatasetGroupDependencies;
1011  QList<int> mDatasetGroupDependentOn;
1012 
1013  QgsMeshDatasetGroupTreeItem *searchItemBySourceName( const QString &sourceName ) const;
1014  QgsMeshDatasetGroupTreeItem *rootItem() const;
1015  void freeAsDependency();
1016  void freeFromDependencies();
1017 };
1018 
1019 #endif // QGSMESHDATASET_H
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame.
QgsMesh3dDataBlock()
Constructs an invalid block.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
DataType
Type of data stored in the block.
@ ScalarDouble
Scalar double values.
@ Vector2DDouble
Vector double pairs (x1, y1, x2, y2, ... )
@ ActiveFlagInteger
Integer boolean flag whether face is active.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
QgsMeshDatasetGroupMetadata()=default
Constructs an empty metadata object.
DataType
Location of where data is specified for datasets in the dataset group.
@ DataOnVertices
Data is defined on vertices.
@ DataOnVolumes
Data is defined on volumes.
Tree item for display of the mesh dataset groups.
QgsMeshDatasetGroupTreeItem()
Constructor for an empty dataset group tree item.
Abstract class that represents a dataset group.
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns the metadata of the dataset with index datasetIndex.
QgsMeshDatasetGroup()=default
Default constructor.
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
virtual ~QgsMeshDatasetGroup()
QMap< QString, QString > mMetadata
Type
Type of the dataset group.
@ Virtual
Temporary dataset group in memory.
@ Memory
Dataset group store in a file.
@ Persistent
Generic type used for non typed dataset group.
virtual void initialize()=0
Initialize the dataset group.
virtual QgsMeshDatasetGroup::Type type() const =0
Returns the type of dataset group.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Write dataset group information in a DOM element.
virtual int datasetCount() const =0
Returns the count of datasets in the group.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
QgsMeshDatasetMetadata()=default
Constructs an empty metadata object.
QgsMeshDatasetValue represents single dataset value.
QgsMeshDatasetValue()=default
Default Ctor, initialize to NaN.
~QgsMeshDatasetValue()=default
Dtor.
Abstract class that represents a dataset.
QgsMeshDataset()=default
Constructor.
virtual QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const =0
Returns count values from valueIndex.
virtual int valuesCount() const =0
Returns the values count.
virtual ~QgsMeshDataset()=default
Destructor.
virtual QgsMeshDatasetMetadata metadata() const =0
Returns the metadata of the dataset.
virtual bool isActive(int faceIndex) const =0
Returns whether the face is active.
virtual QgsMeshDataBlock areFacesActive(int faceIndex, int count) const =0
Returns whether faces are active.
virtual QgsMeshDatasetValue datasetValue(int valueIndex) const =0
Returns the value with index valueIndex.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
Class that represents a dataset group stored in memory.
QgsMeshMemoryDatasetGroup()=default
Constructor.
virtual QgsMeshDatasetGroup::Type type() const override
Returns the type of dataset group.
QVector< std::shared_ptr< QgsMeshMemoryDataset > > memoryDatasets
Contains all the memory datasets.
Class to store memory dataset.
QgsMeshMemoryDataset()=default
Constructor.
QVector< QgsMeshDatasetValue > values
QVector< int > active
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)