QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 "qgis_sip.h"
30 #include "qgspoint.h"
31 #include "qgsdataprovider.h"
32 
33 class QgsMeshLayer;
35 class QgsRectangle;
36 
47 class CORE_EXPORT QgsMeshDatasetIndex
48 {
49  public:
51  QgsMeshDatasetIndex( int group = -1, int dataset = -1 );
53  int group() const;
55  int dataset() const;
57  bool isValid() const;
59  bool operator == ( QgsMeshDatasetIndex other ) const;
61  bool operator != ( QgsMeshDatasetIndex other ) const;
62  private:
63  int mGroupIndex = -1;
64  int mDatasetIndex = -1;
65 };
66 
78 class CORE_EXPORT QgsMeshDatasetValue
79 {
80  public:
82  QgsMeshDatasetValue( double x,
83  double y );
84 
86  QgsMeshDatasetValue( double scalar );
87 
89  QgsMeshDatasetValue() = default;
90 
92  ~QgsMeshDatasetValue() = default;
93 
95  void set( double scalar );
96 
98  void setX( double x );
99 
101  void setY( double y ) ;
102 
104  double scalar() const;
105 
107  double x() const;
108 
110  double y() const;
111 
112  bool operator==( QgsMeshDatasetValue other ) const;
113 
114  private:
115  double mX = std::numeric_limits<double>::quiet_NaN();
116  double mY = std::numeric_limits<double>::quiet_NaN();
117 };
118 
136 class CORE_EXPORT QgsMeshDataBlock
137 {
138  public:
140  enum DataType
141  {
145  };
146 
149 
151  QgsMeshDataBlock( DataType type, int count );
152 
154  DataType type() const;
155 
157  int count() const;
158 
160  bool isValid() const;
161 
166  QgsMeshDatasetValue value( int index ) const;
167 
172  bool active( int index ) const;
173 
187  void setActive( const QVector<int> &vals );
188 
200  QVector<int> active() const;
201 
208  QVector<double> values() const;
209 
219  void setValues( const QVector<double> &vals );
220 
222  void setValid( bool valid );
223 
224  private:
225  QVector<double> mDoubleBuffer;
226  QVector<int> mIntegerBuffer;
227  DataType mType;
228  int mSize = 0;
229  bool mIsValid = false;
230 };
231 
245 class CORE_EXPORT QgsMesh3dDataBlock
246 {
247  public:
250 
253 
255  QgsMesh3dDataBlock( int count, bool isVector );
256 
258  void setValid( bool valid );
259 
261  bool isValid() const;
262 
264  bool isVector() const;
265 
267  int count() const;
268 
270  int firstVolumeIndex() const;
271 
273  int lastVolumeIndex() const;
274 
276  int volumesCount() const;
277 
281  QVector<int> verticalLevelsCount() const;
282 
286  void setVerticalLevelsCount( const QVector<int> &verticalLevelsCount );
287 
291  QVector<double> verticalLevels() const;
292 
296  void setVerticalLevels( const QVector<double> &verticalLevels );
297 
301  QVector<int> faceToVolumeIndex() const;
302 
306  void setFaceToVolumeIndex( const QVector<int> &faceToVolumeIndex );
307 
313  QVector<double> values() const;
314 
321  QgsMeshDatasetValue value( int volumeIndex ) const;
322 
328  void setValues( const QVector<double> &doubleBuffer );
329 
330  private:
331  int mSize = 0;
332  bool mIsValid = false;
333  bool mIsVector = false;
334  QVector<int> mVerticalLevelsCount;
335  QVector<double> mVerticalLevels;
336  QVector<int> mFaceToVolumeIndex;
337  QVector<double> mDoubleBuffer; // for scalar/vector values
338 };
339 
351 {
352  public:
353 
355  enum DataType
356  {
357  DataOnFaces = 0,
360  DataOnEdges
361  };
362 
365 
380  QgsMeshDatasetGroupMetadata( const QString &name,
381  const QString uri,
382  bool isScalar,
383  DataType dataType,
384  double minimum,
385  double maximum,
386  int maximumVerticalLevels,
387  const QDateTime &referenceTime,
388  bool isTemporal,
389  const QMap<QString, QString> &extraOptions );
390 
394  QString name() const;
395 
401  QString uri() const;
402 
406  QMap<QString, QString> extraOptions() const;
407 
411  bool isVector() const;
412 
416  bool isScalar() const;
417 
421  bool isTemporal() const;
422 
428  DataType dataType() const;
429 
433  double minimum() const;
434 
438  double maximum() const;
439 
445  int maximumVerticalLevelsCount() const;
446 
452  QDateTime referenceTime() const;
453 
454  private:
455  QString mName;
456  QString mUri;
457  bool mIsScalar = false;
458  DataType mDataType = DataType::DataOnFaces;
459  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
460  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
461  QMap<QString, QString> mExtraOptions;
462  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
463  QDateTime mReferenceTime;
464  bool mIsTemporal = false;
465 };
466 
477 class CORE_EXPORT QgsMeshDatasetMetadata
478 {
479  public:
482 
492  QgsMeshDatasetMetadata( double time,
493  bool isValid,
494  double minimum,
495  double maximum,
496  int maximumVerticalLevels
497  );
498 
502  double time() const;
503 
507  bool isValid() const;
508 
512  double minimum() const;
513 
517  double maximum() const;
518 
524  int maximumVerticalLevelsCount() const;
525 
526  private:
527  double mTime = std::numeric_limits<double>::quiet_NaN();
528  bool mIsValid = false;
529  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
530  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
531  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
532 };
533 
534 
542 class CORE_EXPORT QgsMeshDataset
543 {
544  public:
546  QgsMeshDataset() = default;
547 
549  virtual ~QgsMeshDataset() = default;
550 
552  virtual QgsMeshDatasetValue datasetValue( int valueIndex ) const = 0;
553 
555  virtual QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const = 0;
556 
558  virtual QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const = 0;
559 
561  virtual bool isActive( int faceIndex ) const = 0;
562 
564  virtual QgsMeshDatasetMetadata metadata() const = 0;
565 
567  virtual int valuesCount() const = 0;
568 };
569 
577 class CORE_EXPORT QgsMeshDatasetGroup
578 {
579  public:
580 
586  enum Type
587  {
592  };
593 
595  QgsMeshDatasetGroup() = default;
597 
599  QgsMeshDatasetGroup( const QString &name );
600 
602  QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
603 
605  virtual void initialize() = 0;
606 
608  QgsMeshDatasetGroupMetadata groupMetadata() const;
609 
611  virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const = 0 ;
612 
614  virtual int datasetCount() const = 0;
615 
617  virtual QgsMeshDataset *dataset( int index ) const = 0;
618 
620  virtual QgsMeshDatasetGroup::Type type() const = 0;
621 
623  double minimum() const;
624 
626  double maximum() const;
627 
629  void setMinimumMaximum( double min, double max );
630 
632  QString name() const;
633 
635  void setName( const QString &name );
636 
638  QgsMeshDatasetGroupMetadata::DataType dataType() const;
639 
641  void setDataType( const QgsMeshDatasetGroupMetadata::DataType &dataType );
642 
644  void addExtraMetadata( QString key, QString value );
646  QMap<QString, QString> extraMetadata() const;
647 
649  bool isScalar() const;
650 
652  void setIsScalar( bool isScalar );
653 
655  bool checkValueCountPerDataset( int count ) const;
656 
658  void calculateStatistic();
659 
661  virtual QStringList datasetGroupNamesDependentOn() const;
662 
664  virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
665 
667  virtual QString description() const;
668 
670  void setReferenceTime( const QDateTime &referenceTime );
671 
672  protected:
673  QString mName;
674 
676  QMap<QString, QString> mMetadata;
677  bool mIsScalar = true;
678 
679  private:
680  double mMinimum = std::numeric_limits<double>::quiet_NaN();
681  double mMaximum = std::numeric_limits<double>::quiet_NaN();
682 
683  QDateTime mReferenceTime;
684 };
685 
686 #ifndef SIP_RUN
687 
697 class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
698 {
699  public:
701  QgsMeshMemoryDataset() = default;
702 
703  QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
704  QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
705  QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
706  QgsMeshDatasetMetadata metadata() const override;
707  bool isActive( int faceIndex ) const override;
708  int valuesCount() const override;
709 
711  void calculateMinMax();
712 
713  QVector<QgsMeshDatasetValue> values;
714  QVector<int> active;
715  double time = -1;
716  bool valid = false;
717  double minimum = std::numeric_limits<double>::quiet_NaN();
718  double maximum = std::numeric_limits<double>::quiet_NaN();
719 };
720 
731 {
732  public:
736  QgsMeshMemoryDatasetGroup( const QString &name );
738  QgsMeshMemoryDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
739 
740  void initialize() override;
741  int datasetCount() const override;
742  QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
743  QgsMeshDataset *dataset( int index ) const override;
744  virtual QgsMeshDatasetGroup::Type type() const override {return QgsMeshDatasetGroup::Memory;}
745 
747  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
748 
750  void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
751 
753  void clearDatasets();
754 
756  std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
757 
759  QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
760 };
761 
762 #endif //SIP_RUN
763 
789 {
790  public:
791 
796 
805  QgsMeshDatasetGroupTreeItem( const QString &defaultName,
806  const QString &sourceName,
807  bool isVector,
808  int index );
809 
816  QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
817 
823 
830 
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)