QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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#include <QDateTime>
26#include <QDomElement>
27
28#include <limits>
29#include <memory>
30
31#include "qgis_core.h"
32#include "qgis_sip.h"
33
34class QgsMeshLayer;
36class QgsRectangle;
37class QDomDocument;
39
40struct QgsMesh;
41
52class CORE_EXPORT QgsMeshDatasetIndex
53{
54 public:
56 QgsMeshDatasetIndex( int group = -1, int dataset = -1 );
58 int group() const;
60 int dataset() const;
62 bool isValid() const;
63
64 bool operator == ( QgsMeshDatasetIndex other ) const;
65 bool operator != ( QgsMeshDatasetIndex other ) const;
66 private:
67 int mGroupIndex = -1;
68 int mDatasetIndex = -1;
69};
70
82class CORE_EXPORT QgsMeshDatasetValue
83{
84 public:
86 QgsMeshDatasetValue( double x,
87 double y );
88
90 QgsMeshDatasetValue( double scalar );
91
94
96
98 void set( double scalar );
99
101 void setX( double x );
102
104 void setY( double y ) ;
105
107 double scalar() const;
108
110 double x() const;
111
113 double y() const;
114
115 bool operator==( QgsMeshDatasetValue other ) const;
116
117 private:
118 double mX = std::numeric_limits<double>::quiet_NaN();
119 double mY = std::numeric_limits<double>::quiet_NaN();
120};
121
139class CORE_EXPORT QgsMeshDataBlock
140{
141 public:
149
152
154 QgsMeshDataBlock( DataType type, int count );
155
157 DataType type() const;
158
160 int count() const;
161
163 bool isValid() const;
164
169 QgsMeshDatasetValue value( int index ) const;
170
175 bool active( int index ) const;
176
190 void setActive( const QVector<int> &vals );
191
203 QVector<int> active() const;
204
211 QVector<double> values() const;
212
222 void setValues( const QVector<double> &vals );
223
225 void setValid( bool valid );
226
227 private:
228 QVector<double> mDoubleBuffer;
229 QVector<int> mIntegerBuffer;
230 DataType mType;
231 int mSize = 0;
232 bool mIsValid = false;
233};
234
251class CORE_EXPORT QgsMesh3DDataBlock
252{
253 public:
257
259 QgsMesh3DDataBlock( int count, bool isVector );
260
262 void setValid( bool valid );
263
265 bool isValid() const;
266
268 bool isVector() const;
269
271 int count() const;
272
274 int firstVolumeIndex() const;
275
277 int lastVolumeIndex() const;
278
280 int volumesCount() const;
281
285 QVector<int> verticalLevelsCount() const;
286
290 void setVerticalLevelsCount( const QVector<int> &verticalLevelsCount );
291
295 QVector<double> verticalLevels() const;
296
300 void setVerticalLevels( const QVector<double> &verticalLevels );
301
305 QVector<int> faceToVolumeIndex() const;
306
310 void setFaceToVolumeIndex( const QVector<int> &faceToVolumeIndex );
311
317 QVector<double> values() const;
318
325 QgsMeshDatasetValue value( int volumeIndex ) const;
326
332 void setValues( const QVector<double> &doubleBuffer );
333
334 private:
335 int mSize = 0;
336 bool mIsValid = false;
337 bool mIsVector = false;
338 QVector<int> mVerticalLevelsCount;
339 QVector<double> mVerticalLevels;
340 QVector<int> mFaceToVolumeIndex;
341 QVector<double> mDoubleBuffer; // for scalar/vector values
342};
343
355{
356 public:
357
360 {
361 DataOnFaces = 0,
364 DataOnEdges
365 };
366
369
384 QgsMeshDatasetGroupMetadata( const QString &name,
385 const QString uri,
386 bool isScalar,
387 DataType dataType,
388 double minimum,
389 double maximum,
390 int maximumVerticalLevels,
391 const QDateTime &referenceTime,
392 bool isTemporal,
393 const QMap<QString, QString> &extraOptions );
394
398 QString name() const;
399
408 QString parentQuantityName() const;
409
415 QString uri() const;
416
420 QMap<QString, QString> extraOptions() const;
421
425 bool isVector() const;
426
430 bool isScalar() const;
431
435 bool isTemporal() const;
436
442 DataType dataType() const;
443
447 double minimum() const;
448
452 double maximum() const;
453
459 int maximumVerticalLevelsCount() const;
460
466 QDateTime referenceTime() const;
467
468 private:
469 QString mName;
470 QString mParentQuantityName;
471 QString mUri;
472 bool mIsScalar = false;
473 DataType mDataType = DataType::DataOnFaces;
474 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
475 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
476 QMap<QString, QString> mExtraOptions;
477 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
478 QDateTime mReferenceTime;
479 bool mIsTemporal = false;
480};
481
492class CORE_EXPORT QgsMeshDatasetMetadata
493{
494 public:
497
507 QgsMeshDatasetMetadata( double time,
508 bool isValid,
509 double minimum,
510 double maximum,
511 int maximumVerticalLevels
512 );
513
517 double time() const;
518
522 bool isValid() const;
523
527 double minimum() const;
528
532 double maximum() const;
533
539 int maximumVerticalLevelsCount() const;
540
541 private:
542 double mTime = std::numeric_limits<double>::quiet_NaN();
543 bool mIsValid = false;
544 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
545 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
546 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
547};
548
549
557class CORE_EXPORT QgsMeshDataset
558{
559 public:
560
561 QgsMeshDataset() = default;
562
563 virtual ~QgsMeshDataset() = default;
564
566 virtual QgsMeshDatasetValue datasetValue( int valueIndex ) const = 0;
567
569 virtual QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const = 0;
570
572 virtual QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const = 0;
573
575 virtual bool isActive( int faceIndex ) const = 0;
576
578 virtual QgsMeshDatasetMetadata metadata() const = 0;
579
581 virtual int valuesCount() const = 0;
582};
583
591class CORE_EXPORT QgsMeshDatasetGroup
592{
593 public:
594
607
610
612 QgsMeshDatasetGroup( const QString &name );
613
615 QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
616
618 virtual void initialize() = 0;
619
621 QgsMeshDatasetGroupMetadata groupMetadata() const;
622
624 virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const = 0 ;
625
627 virtual int datasetCount() const = 0;
628
630 virtual QgsMeshDataset *dataset( int index ) const = 0;
631
633 virtual QgsMeshDatasetGroup::Type type() const = 0;
634
636 double minimum() const;
637
639 double maximum() const;
640
642 void setMinimumMaximum( double min, double max ) const;
643
645 QString name() const;
646
648 void setName( const QString &name );
649
652
654 void setDataType( const QgsMeshDatasetGroupMetadata::DataType &dataType );
655
657 void addExtraMetadata( QString key, QString value );
659 QMap<QString, QString> extraMetadata() const;
660
662 bool isScalar() const;
663
665 void setIsScalar( bool isScalar );
666
668 bool checkValueCountPerDataset( int count ) const;
669
671 void calculateStatistic() const;
672
674 void setStatisticObsolete() const;
675
677 virtual QStringList datasetGroupNamesDependentOn() const;
678
680 virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
681
683 virtual QString description() const;
684
686 void setReferenceTime( const QDateTime &referenceTime );
687
688 protected:
689 QString mName;
690
692 QMap<QString, QString> mMetadata;
693 bool mIsScalar = true;
694
695 private:
696 mutable double mMinimum = std::numeric_limits<double>::quiet_NaN();
697 mutable double mMaximum = std::numeric_limits<double>::quiet_NaN();
698 mutable bool mIsStatisticObsolete = true;
699
700 void updateStatistic() const;
701
702 QDateTime mReferenceTime;
703};
704
705#ifndef SIP_RUN
706
716class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
717{
718 public:
719
721
722 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
723 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
724 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
725 QgsMeshDatasetMetadata metadata() const override;
726 bool isActive( int faceIndex ) const override;
727 int valuesCount() const override;
728
730 void calculateMinMax();
731
732 QVector<QgsMeshDatasetValue> values;
733 QVector<int> active;
734 double time = -1;
735 bool valid = false;
736 double minimum = std::numeric_limits<double>::quiet_NaN();
737 double maximum = std::numeric_limits<double>::quiet_NaN();
738};
739
750{
751 public:
752
755 QgsMeshMemoryDatasetGroup( const QString &name );
758
759 void initialize() override;
760 int datasetCount() const override;
761 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
762 QgsMeshDataset *dataset( int index ) const override;
764
766 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
767
769 void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
770
772 void clearDatasets();
773
775 std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
776
778 QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
779};
780
789{
790 public:
793
794 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
795 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;;
796 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;;
797 bool isActive( int ) const override {return true;};
798 QgsMeshDatasetMetadata metadata() const override;;
799 int valuesCount() const override;
800 private:
801 QgsMesh *mMesh;
802};
803
813{
814 public:
816 QgsMeshVerticesElevationDatasetGroup( QString name, QgsMesh *mesh );
817
818 void initialize() override;
819 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;;
820 int datasetCount() const override;;
821 QgsMeshDataset *dataset( int index ) const override;;
822 QgsMeshDatasetGroup::Type type() const override;
823 QDomElement writeXml( QDomDocument &, const QgsReadWriteContext & ) const override {return QDomElement();};
824
825 private:
826 std::unique_ptr<QgsMeshVerticesElevationDataset> mDataset;
827};
828
829#endif //SIP_RUN
830
856{
857 public:
858
863
872 QgsMeshDatasetGroupTreeItem( const QString &defaultName,
873 const QString &sourceName,
874 bool isVector,
875 int index );
876
883 QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
884
890
897
903 void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
904
911 void removeChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
912
918 QgsMeshDatasetGroupTreeItem *child( int row ) const;
919
927 QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
928
933 int childCount() const;
934
939 int totalChildCount() const;
940
947 QList<int> enabledDatasetGroupIndexes() const;
948
953 QgsMeshDatasetGroupTreeItem *parentItem() const;
954
959 int row() const;
960
966 QString name() const;
967
974 void setName( const QString &name );
975
983 QString providerName() const;
984
988 bool isVector() const;
989
993 int datasetGroupIndex() const;
994
998 bool isEnabled() const;
999
1004 void setIsEnabled( bool isEnabled );
1005
1009 QString defaultName() const;
1010
1016 QgsMeshDatasetGroup::Type datasetGroupType() const;
1017
1024 QList<int> groupIndexDependencies() const;
1025
1031 QString description() const;
1032
1040 void setDatasetGroup( QgsMeshDatasetGroup *datasetGroup );
1041
1049 void setPersistentDatasetGroup( const QString &uri );
1050
1057 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
1058
1059 private:
1060 QgsMeshDatasetGroupTreeItem *mParent = nullptr;
1061 QList< QgsMeshDatasetGroupTreeItem * > mChildren;
1062 QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
1063
1064 // Data
1065 QString mUserName;
1066 QString mOriginalName;
1067 QString mSourceName;
1068 QgsMeshDatasetGroup::Type mDatasetGroupType = QgsMeshDatasetGroup::Unknown;
1069 QString mDescription;
1070
1071 bool mIsVector = false;
1072 int mDatasetGroupIndex = -1;
1073 bool mIsEnabled = true;
1074
1075 QList<int> mDatasetGroupDependencies;
1076 QList<int> mDatasetGroupDependentOn;
1077
1078 QgsMeshDatasetGroupTreeItem *searchItemBySourceName( const QString &sourceName ) const;
1079 QgsMeshDatasetGroupTreeItem *rootItem() const;
1080 void freeAsDependency(); // cppcheck-suppress functionConst
1081 void freeFromDependencies(); // cppcheck-suppress functionConst
1082};
1083
1084#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
virtual ~QgsMeshDatasetGroup()
QMap< QString, QString > mMetadata
Type
Type of the dataset group.
@ Unknown
Generic type used for non typed dataset group.
@ Virtual
Virtual Dataset group defined by a formula.
@ Memory
Temporary dataset group in memory.
@ Persistent
Dataset group store in a file.
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.
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
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
Abstract class that represents a dataset.
QgsMeshDataset()=default
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
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.
Class that represents a dataset group stored in memory.
QgsMeshMemoryDatasetGroup()=default
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
QVector< QgsMeshDatasetValue > values
QVector< int > active
Class that represents a dataset group with elevation value of the vertices of a existing mesh that ca...
QDomElement writeXml(QDomDocument &, const QgsReadWriteContext &) const override
Write dataset group information in a DOM element.
Class that represents a dataset with elevation value of the vertices of a existing mesh that can be e...
QgsMeshDatasetValue datasetValue(int valueIndex) const override
Returns the value with index valueIndex.
bool isActive(int) const override
Returns whether the face is active.
int valuesCount() const override
Returns the values count.
QgsMeshDataBlock areFacesActive(int faceIndex, int count) const override
Returns whether faces are active.
QgsMeshDatasetMetadata metadata() const override
Returns the metadata of the dataset.
QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const override
Returns count values from valueIndex.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
#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)
Mesh - vertices, edges and faces.