QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
378  QgsMeshDatasetGroupMetadata( const QString &name,
379  const QString uri,
380  bool isScalar,
381  DataType dataType,
382  double minimum,
383  double maximum,
384  int maximumVerticalLevels,
385  const QDateTime &referenceTime,
386  bool isTemporal,
387  const QMap<QString, QString> &extraOptions );
388 
392  QString name() const;
393 
399  QString uri() const;
400 
404  QMap<QString, QString> extraOptions() const;
405 
409  bool isVector() const;
410 
414  bool isScalar() const;
415 
419  bool isTemporal() const;
420 
426  DataType dataType() const;
427 
431  double minimum() const;
432 
436  double maximum() const;
437 
443  int maximumVerticalLevelsCount() const;
444 
450  QDateTime referenceTime() const;
451 
452  private:
453  QString mName;
454  QString mUri;
455  bool mIsScalar = false;
456  DataType mDataType = DataType::DataOnFaces;
457  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
458  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
459  QMap<QString, QString> mExtraOptions;
460  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
461  QDateTime mReferenceTime;
462  bool mIsTemporal = false;
463 };
464 
475 class CORE_EXPORT QgsMeshDatasetMetadata
476 {
477  public:
480 
490  QgsMeshDatasetMetadata( double time,
491  bool isValid,
492  double minimum,
493  double maximum,
494  int maximumVerticalLevels
495  );
496 
500  double time() const;
501 
505  bool isValid() const;
506 
510  double minimum() const;
511 
515  double maximum() const;
516 
522  int maximumVerticalLevelsCount() const;
523 
524  private:
525  double mTime = std::numeric_limits<double>::quiet_NaN();
526  bool mIsValid = false;
527  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
528  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
529  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
530 };
531 
532 
540 class CORE_EXPORT QgsMeshDataset
541 {
542  public:
544  QgsMeshDataset() = default;
545 
547  virtual ~QgsMeshDataset() = default;
548 
550  virtual QgsMeshDatasetValue datasetValue( int valueIndex ) const = 0;
551 
553  virtual QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const = 0;
554 
556  virtual QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const = 0;
557 
559  virtual bool isActive( int faceIndex ) const = 0;
560 
562  virtual QgsMeshDatasetMetadata metadata() const = 0;
563 
565  virtual int valuesCount() const = 0;
566 };
567 
575 class CORE_EXPORT QgsMeshDatasetGroup
576 {
577  public:
578 
584  enum Type
585  {
590  };
591 
593  QgsMeshDatasetGroup() = default;
595 
597  QgsMeshDatasetGroup( const QString &name );
598 
600  QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
601 
603  virtual void initialize() = 0;
604 
606  QgsMeshDatasetGroupMetadata groupMetadata() const;
607 
609  virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const = 0 ;
610 
612  virtual int datasetCount() const = 0;
613 
615  virtual QgsMeshDataset *dataset( int index ) const = 0;
616 
618  virtual QgsMeshDatasetGroup::Type type() const = 0;
619 
621  double minimum() const;
622 
624  double maximum() const;
625 
627  void setMinimumMaximum( double min, double max );
628 
630  QString name() const;
631 
633  void setName( const QString &name );
634 
636  QgsMeshDatasetGroupMetadata::DataType dataType() const;
637 
639  void setDataType( const QgsMeshDatasetGroupMetadata::DataType &dataType );
640 
642  void addExtraMetadata( QString key, QString value );
644  QMap<QString, QString> extraMetadata() const;
645 
647  bool isScalar() const;
648 
650  void setIsScalar( bool isScalar );
651 
653  bool checkValueCountPerDataset( int count ) const;
654 
656  void calculateStatistic();
657 
659  virtual QStringList datasetGroupNamesDependentOn() const;
660 
662  virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
663 
665  virtual QString description() const;
666 
668  void setReferenceTime( const QDateTime &referenceTime );
669 
670  protected:
671  QString mName;
672 
674  QMap<QString, QString> mMetadata;
675  bool mIsScalar = true;
676 
677  private:
678  double mMinimum = std::numeric_limits<double>::quiet_NaN();
679  double mMaximum = std::numeric_limits<double>::quiet_NaN();
680 
681  QDateTime mReferenceTime;
682 };
683 
684 #ifndef SIP_RUN
685 
694 class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
695 {
696  public:
698  QgsMeshMemoryDataset() = default;
699 
700  QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
701  QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
702  QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
703  QgsMeshDatasetMetadata metadata() const override;
704  bool isActive( int faceIndex ) const override;
705  int valuesCount() const override;
706 
708  void calculateMinMax();
709 
710  QVector<QgsMeshDatasetValue> values;
711  QVector<int> active;
712  double time = -1;
713  bool valid = false;
714  double minimum = std::numeric_limits<double>::quiet_NaN();
715  double maximum = std::numeric_limits<double>::quiet_NaN();
716 };
717 
727 {
728  public:
732  QgsMeshMemoryDatasetGroup( const QString &name );
734  QgsMeshMemoryDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
735 
736  void initialize() override;
737  int datasetCount() const override;
738  QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
739  QgsMeshDataset *dataset( int index ) const override;
740  virtual QgsMeshDatasetGroup::Type type() const override {return QgsMeshDatasetGroup::Memory;}
741 
743  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
744 
746  void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
747 
749  void clearDatasets();
750 
752  std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
753 
755  QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
756 };
757 
758 #endif //SIP_RUN
759 
785 {
786  public:
787 
792 
801  QgsMeshDatasetGroupTreeItem( const QString &defaultName,
802  const QString &sourceName,
803  bool isVector,
804  int index );
805 
812  QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
813 
819 
826 
833  void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
834 
843  void removeChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
844 
850  QgsMeshDatasetGroupTreeItem *child( int row ) const;
851 
859  QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
860 
865  int childCount() const;
866 
871  int totalChildCount() const;
872 
877  QgsMeshDatasetGroupTreeItem *parentItem() const;
878 
883  int row() const;
884 
890  QString name() const;
891 
898  void setName( const QString &name );
899 
907  QString providerName() const;
908 
912  bool isVector() const;
913 
917  int datasetGroupIndex() const;
918 
922  bool isEnabled() const;
923 
928  void setIsEnabled( bool isEnabled );
929 
933  QString defaultName() const;
934 
940  QgsMeshDatasetGroup::Type datasetGroupType() const;
941 
948  QList<int> groupIndexDependencies() const;
949 
955  QString description() const;
956 
964  void setDatasetGroup( QgsMeshDatasetGroup *datasetGroup );
965 
973  void setPersistentDatasetGroup( const QString &uri );
974 
981  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
982 
983  private:
984  QgsMeshDatasetGroupTreeItem *mParent = nullptr;
985  QList< QgsMeshDatasetGroupTreeItem * > mChildren;
986  QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
987 
988  // Data
989  QString mUserName;
990  QString mOriginalName;
991  QString mSourceName;
992  QgsMeshDatasetGroup::Type mDatasetGroupType = QgsMeshDatasetGroup::None;
993  QString mDescription;
994 
995  bool mIsVector = false;
996  int mDatasetGroupIndex = -1;
997  bool mIsEnabled = true;
998 
999  QList<int> mDatasetGroupDependencies;
1000  QList<int> mDatasetGroupDependentOn;
1001 
1002  QgsMeshDatasetGroupTreeItem *searchItemBySourceName( const QString &sourceName ) const;
1003  QgsMeshDatasetGroupTreeItem *rootItem() const;
1004  void freeAsDependency();
1005  void freeFromDependencies();
1006 };
1007 
1008 #endif // QGSMESHDATASET_H
QgsMeshDatasetGroup::QgsMeshDatasetGroup
QgsMeshDatasetGroup()=default
Default constructor.
QgsMeshDatasetGroupMetadata::DataOnVolumes
@ DataOnVolumes
Data is defined on volumes.
Definition: qgsmeshdataset.h:358
QgsMeshDataset::metadata
virtual QgsMeshDatasetMetadata metadata() const =0
Returns the metadata of the dataset.
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsMeshDataBlock::ScalarDouble
@ ScalarDouble
Scalar double values.
Definition: qgsmeshdataset.h:142
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:400
QgsMeshDatasetGroup::writeXml
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Write dataset group information in a DOM element.
QgsMeshMemoryDataset
Class to store memory dataset The QgsMeshDatasetValue objects and whether the faces are active are st...
Definition: qgsmeshdataset.h:695
QgsMeshDataset::~QgsMeshDataset
virtual ~QgsMeshDataset()=default
Destructor.
QgsMeshDataset::areFacesActive
virtual QgsMeshDataBlock areFacesActive(int faceIndex, int count) const =0
Returns whether faces are active.
QgsMeshDatasetGroup::datasetCount
virtual int datasetCount() const =0
Returns the count of datasets in the group.
QgsMeshDatasetValue
QgsMeshDatasetValue represents single dataset value.
Definition: qgsmeshdataset.h:78
QgsMeshDataset
Abstract class that represents a dataset.
Definition: qgsmeshdataset.h:541
QgsMeshDatasetGroup::Persistent
@ Persistent
Generic type used for non typed dataset group.
Definition: qgsmeshdataset.h:587
QgsMeshMemoryDataset::active
QVector< int > active
Definition: qgsmeshdataset.h:711
QgsMeshDatasetGroupTreeItem
Tree item for display of the mesh dataset groups.
Definition: qgsmeshdataset.h:785
qgspoint.h
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:405
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsMeshDatasetMetadata
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
Definition: qgsmeshdataset.h:476
QgsMesh3dDataBlock
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame.
Definition: qgsmeshdataset.h:245
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMeshDataset::datasetValue
virtual QgsMeshDatasetValue datasetValue(int valueIndex) const =0
Returns the value with index valueIndex.
QgsMeshDatasetGroupMetadata::DataOnVertices
@ DataOnVertices
Data is defined on vertices.
Definition: qgsmeshdataset.h:357
QgsMeshMemoryDatasetGroup::type
virtual QgsMeshDatasetGroup::Type type() const override
Returns the type of dataset group.
Definition: qgsmeshdataset.h:740
QgsMesh3dDataBlock::QgsMesh3dDataBlock
QgsMesh3dDataBlock()
Constructs an invalid block.
QgsMeshDatasetGroupTreeItem::QgsMeshDatasetGroupTreeItem
QgsMeshDatasetGroupTreeItem()
Constructor for an empty dataset group tree item.
QgsMeshDataBlock::Vector2DDouble
@ Vector2DDouble
Vector double pairs (x1, y1, x2, y2, ... )
Definition: qgsmeshdataset.h:143
QgsMeshDatasetIndex
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Definition: qgsmeshdataset.h:47
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
QgsMeshDataset::datasetValues
virtual QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const =0
Returns count values from valueIndex.
QgsMeshDatasetValue::~QgsMeshDatasetValue
~QgsMeshDatasetValue()=default
Dtor.
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMeshDataBlock::DataType
DataType
Type of data stored in the block.
Definition: qgsmeshdataset.h:140
QgsMeshDatasetGroup::initialize
virtual void initialize()=0
Initialize the dataset group.
QgsMeshDatasetGroup::None
@ None
Definition: qgsmeshdataset.h:586
QgsMeshDatasetGroup::type
virtual QgsMeshDatasetGroup::Type type() const =0
Returns the type of dataset group.
QgsMeshDatasetGroup::dataset
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
QgsMeshMemoryDataset::QgsMeshMemoryDataset
QgsMeshMemoryDataset()=default
Constructor.
QgsMeshDatasetGroup
Abstract class that represents a dataset group.
Definition: qgsmeshdataset.h:576
QgsMeshDatasetGroup::datasetMetadata
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns the metadata of the dataset with index datasetIndex.
QgsMeshDatasetGroup::mMetadata
QMap< QString, QString > mMetadata
Definition: qgsmeshdataset.h:674
QgsMeshDatasetGroup::mName
QString mName
Definition: qgsmeshdataset.h:671
QgsMeshMemoryDatasetGroup::QgsMeshMemoryDatasetGroup
QgsMeshMemoryDatasetGroup()=default
Constructor.
QgsMeshDatasetGroupMetadata
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
Definition: qgsmeshdataset.h:350
QgsMeshDatasetGroupMetadata::DataType
DataType
Location of where data is specified for datasets in the dataset group.
Definition: qgsmeshdataset.h:355
QgsMeshDataBlock::ActiveFlagInteger
@ ActiveFlagInteger
Integer boolean flag whether face is active.
Definition: qgsmeshdataset.h:141
QgsMeshDatasetGroup::Type
Type
Type of the dataset group.
Definition: qgsmeshdataset.h:585
QgsMeshMemoryDatasetGroup::memoryDatasets
QVector< std::shared_ptr< QgsMeshMemoryDataset > > memoryDatasets
Contains all the memory datasets.
Definition: qgsmeshdataset.h:755
qgsdataprovider.h
QgsMeshDataBlock
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
Definition: qgsmeshdataset.h:136
QgsMeshDatasetGroup::~QgsMeshDatasetGroup
virtual ~QgsMeshDatasetGroup()
QgsMeshDatasetMetadata::QgsMeshDatasetMetadata
QgsMeshDatasetMetadata()=default
Constructs an empty metadata object.
QgsMeshDataset::isActive
virtual bool isActive(int faceIndex) const =0
Returns whether the face is active.
QgsMeshDataset::valuesCount
virtual int valuesCount() const =0
Returns the values count.
QgsMeshDatasetGroupMetadata::QgsMeshDatasetGroupMetadata
QgsMeshDatasetGroupMetadata()=default
Constructs an empty metadata object.
QgsMeshDataset::QgsMeshDataset
QgsMeshDataset()=default
Constructor.
QgsMeshMemoryDatasetGroup
Class that represents a dataset group stored in memory The QgsMeshMemoryDataset objects stores in a Q...
Definition: qgsmeshdataset.h:727
QgsMeshDatasetValue::QgsMeshDatasetValue
QgsMeshDatasetValue()=default
Default Ctor, initialize to NaN.
QgsMeshDatasetGroup::Virtual
@ Virtual
Temporary dataset group in memory.
Definition: qgsmeshdataset.h:589
QgsMeshDatasetGroup::Memory
@ Memory
Dataset group store in a file.
Definition: qgsmeshdataset.h:588
QgsMeshMemoryDataset::values
QVector< QgsMeshDatasetValue > values
Definition: qgsmeshdataset.h:710