QGIS API Documentation  3.17.0-Master (8af46bc54f)
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 
363  QgsMeshDatasetGroupMetadata() = default;
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:
480  QgsMeshDatasetMetadata() = default;
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;
595  virtual ~QgsMeshDatasetGroup();
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 
695 class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
696 {
697  public:
699  QgsMeshMemoryDataset() = default;
700 
701  QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
702  QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
703  QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
704  QgsMeshDatasetMetadata metadata() const override;
705  bool isActive( int faceIndex ) const override;
706  int valuesCount() const override;
707 
709  void calculateMinMax();
710 
711  QVector<QgsMeshDatasetValue> values;
712  QVector<int> active;
713  double time = -1;
714  bool valid = false;
715  double minimum = std::numeric_limits<double>::quiet_NaN();
716  double maximum = std::numeric_limits<double>::quiet_NaN();
717 };
718 
728 {
729  public:
731  QgsMeshMemoryDatasetGroup() = default;
733  QgsMeshMemoryDatasetGroup( const QString &name );
735  QgsMeshMemoryDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
736 
737  void initialize() override;
738  int datasetCount() const override;
739  QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
740  QgsMeshDataset *dataset( int index ) const override;
741  virtual QgsMeshDatasetGroup::Type type() const override {return QgsMeshDatasetGroup::Memory;}
742 
744  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
745 
747  void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
748 
750  void clearDatasets();
751 
753  std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
754 
756  QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
757 };
758 
759 #endif //SIP_RUN
760 
786 {
787  public:
788 
793 
802  QgsMeshDatasetGroupTreeItem( const QString &defaultName,
803  const QString &sourceName,
804  bool isVector,
805  int index );
806 
813  QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
814 
820 
827 
834  void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
835 
844  void removeChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
845 
851  QgsMeshDatasetGroupTreeItem *child( int row ) const;
852 
860  QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
861 
866  int childCount() const;
867 
872  int totalChildCount() const;
873 
878  QgsMeshDatasetGroupTreeItem *parentItem() const;
879 
884  int row() const;
885 
891  QString name() const;
892 
899  void setName( const QString &name );
900 
908  QString providerName() const;
909 
913  bool isVector() const;
914 
918  int datasetGroupIndex() const;
919 
923  bool isEnabled() const;
924 
929  void setIsEnabled( bool isEnabled );
930 
934  QString defaultName() const;
935 
941  QgsMeshDatasetGroup::Type datasetGroupType() const;
942 
949  QList<int> groupIndexDependencies() const;
950 
956  QString description() const;
957 
965  void setDatasetGroup( QgsMeshDatasetGroup *datasetGroup );
966 
974  void setPersistentDatasetGroup( const QString &uri );
975 
982  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
983 
984  private:
985  QgsMeshDatasetGroupTreeItem *mParent = nullptr;
986  QList< QgsMeshDatasetGroupTreeItem * > mChildren;
987  QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
988 
989  // Data
990  QString mUserName;
991  QString mOriginalName;
992  QString mSourceName;
994  QString mDescription;
995 
996  bool mIsVector = false;
997  int mDatasetGroupIndex = -1;
998  bool mIsEnabled = true;
999 
1000  QList<int> mDatasetGroupDependencies;
1001  QList<int> mDatasetGroupDependentOn;
1002 
1003  QgsMeshDatasetGroupTreeItem *searchItemBySourceName( const QString &sourceName ) const;
1004  QgsMeshDatasetGroupTreeItem *rootItem() const;
1005  void freeAsDependency();
1006  void freeFromDependencies();
1007 };
1008 
1009 #endif // QGSMESHDATASET_H
virtual QgsMeshDatasetMetadata metadata() const =0
Returns the metadata of the dataset.
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:41
virtual QgsMeshDataBlock areFacesActive(int faceIndex, int count) const =0
Returns whether faces are active.
QVector< QgsMeshDatasetValue > values
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
Vector double pairs (x1, y1, x2, y2, ... )
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QMap< QString, QString > mMetadata
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e...
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame...
QVector< int > active
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns the metadata of the dataset with index datasetIndex.
Tree item for display of the mesh dataset groups.
virtual QgsMeshDatasetValue datasetValue(int valueIndex) const =0
Returns the value with index valueIndex.
DataType
Location of where data is specified for datasets in the dataset group.
Dataset group store in a file.
virtual void initialize()=0
Initialize the dataset group.
QVector< std::shared_ptr< QgsMeshMemoryDataset > > memoryDatasets
Contains all the memory datasets.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Integer boolean flag whether face is active.
#define SIP_FACTORY
Definition: qgis_sip.h:76
virtual QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const =0
Returns count values from valueIndex.
Type
Type of the dataset group.
DataType
Type of data stored in the block.
Temporary dataset group in memory.
virtual int datasetCount() const =0
Returns the count of datasets in the group.
Generic type used for non typed dataset group.
virtual QgsMeshDatasetGroup::Type type() const override
Returns the type of dataset group.
Abstract class that represents a dataset.
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
Scalar double values.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Class to store memory dataset The QgsMeshDatasetValue objects and whether the faces are active are st...
virtual bool isActive(int faceIndex) const =0
Returns whether the face is active.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Write dataset group information in a DOM element.
virtual int valuesCount() const =0
Returns the values count.
Class that represents a dataset group stored in memory The QgsMeshMemoryDataset objects stores in a Q...
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:94
QgsMeshDatasetValue represents single dataset value.
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
Abstract class that represents a dataset group.