QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
33class QgsMeshLayer;
35class QgsRectangle;
36struct QgsMesh;
37
48class CORE_EXPORT QgsMeshDatasetIndex
49{
50 public:
52 QgsMeshDatasetIndex( int group = -1, int dataset = -1 );
54 int group() const;
56 int dataset() const;
58 bool isValid() const;
60 bool operator == ( QgsMeshDatasetIndex other ) const;
62 bool operator != ( QgsMeshDatasetIndex other ) const;
63 private:
64 int mGroupIndex = -1;
65 int mDatasetIndex = -1;
66};
67
79class CORE_EXPORT QgsMeshDatasetValue
80{
81 public:
83 QgsMeshDatasetValue( double x,
84 double y );
85
87 QgsMeshDatasetValue( double scalar );
88
91
94
96 void set( double scalar );
97
99 void setX( double x );
100
102 void setY( double y ) ;
103
105 double scalar() const;
106
108 double x() const;
109
111 double y() const;
112
113 bool operator==( QgsMeshDatasetValue other ) const;
114
115 private:
116 double mX = std::numeric_limits<double>::quiet_NaN();
117 double mY = std::numeric_limits<double>::quiet_NaN();
118};
119
137class CORE_EXPORT QgsMeshDataBlock
138{
139 public:
142 {
146 };
147
150
152 QgsMeshDataBlock( DataType type, int count );
153
155 DataType type() const;
156
158 int count() const;
159
161 bool isValid() const;
162
167 QgsMeshDatasetValue value( int index ) const;
168
173 bool active( int index ) const;
174
188 void setActive( const QVector<int> &vals );
189
201 QVector<int> active() const;
202
209 QVector<double> values() const;
210
220 void setValues( const QVector<double> &vals );
221
223 void setValid( bool valid );
224
225 private:
226 QVector<double> mDoubleBuffer;
227 QVector<int> mIntegerBuffer;
228 DataType mType;
229 int mSize = 0;
230 bool mIsValid = false;
231};
232
246class CORE_EXPORT QgsMesh3dDataBlock
247{
248 public:
251
254
256 QgsMesh3dDataBlock( int count, bool isVector );
257
259 void setValid( bool valid );
260
262 bool isValid() const;
263
265 bool isVector() const;
266
268 int count() const;
269
271 int firstVolumeIndex() const;
272
274 int lastVolumeIndex() const;
275
277 int volumesCount() const;
278
282 QVector<int> verticalLevelsCount() const;
283
287 void setVerticalLevelsCount( const QVector<int> &verticalLevelsCount );
288
292 QVector<double> verticalLevels() const;
293
297 void setVerticalLevels( const QVector<double> &verticalLevels );
298
302 QVector<int> faceToVolumeIndex() const;
303
307 void setFaceToVolumeIndex( const QVector<int> &faceToVolumeIndex );
308
314 QVector<double> values() const;
315
322 QgsMeshDatasetValue value( int volumeIndex ) const;
323
329 void setValues( const QVector<double> &doubleBuffer );
330
331 private:
332 int mSize = 0;
333 bool mIsValid = false;
334 bool mIsVector = false;
335 QVector<int> mVerticalLevelsCount;
336 QVector<double> mVerticalLevels;
337 QVector<int> mFaceToVolumeIndex;
338 QVector<double> mDoubleBuffer; // for scalar/vector values
339};
340
352{
353 public:
354
357 {
358 DataOnFaces = 0,
361 DataOnEdges
362 };
363
366
381 QgsMeshDatasetGroupMetadata( const QString &name,
382 const QString uri,
383 bool isScalar,
384 DataType dataType,
385 double minimum,
386 double maximum,
387 int maximumVerticalLevels,
388 const QDateTime &referenceTime,
389 bool isTemporal,
390 const QMap<QString, QString> &extraOptions );
391
395 QString name() const;
396
402 QString uri() const;
403
407 QMap<QString, QString> extraOptions() const;
408
412 bool isVector() const;
413
417 bool isScalar() const;
418
422 bool isTemporal() const;
423
429 DataType dataType() const;
430
434 double minimum() const;
435
439 double maximum() const;
440
446 int maximumVerticalLevelsCount() const;
447
453 QDateTime referenceTime() const;
454
455 private:
456 QString mName;
457 QString mUri;
458 bool mIsScalar = false;
459 DataType mDataType = DataType::DataOnFaces;
460 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
461 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
462 QMap<QString, QString> mExtraOptions;
463 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
464 QDateTime mReferenceTime;
465 bool mIsTemporal = false;
466};
467
478class CORE_EXPORT QgsMeshDatasetMetadata
479{
480 public:
483
493 QgsMeshDatasetMetadata( double time,
494 bool isValid,
495 double minimum,
496 double maximum,
497 int maximumVerticalLevels
498 );
499
503 double time() const;
504
508 bool isValid() const;
509
513 double minimum() const;
514
518 double maximum() const;
519
525 int maximumVerticalLevelsCount() const;
526
527 private:
528 double mTime = std::numeric_limits<double>::quiet_NaN();
529 bool mIsValid = false;
530 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
531 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
532 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
533};
534
535
543class CORE_EXPORT QgsMeshDataset
544{
545 public:
547 QgsMeshDataset() = default;
548
550 virtual ~QgsMeshDataset() = default;
551
553 virtual QgsMeshDatasetValue datasetValue( int valueIndex ) const = 0;
554
556 virtual QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const = 0;
557
559 virtual QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const = 0;
560
562 virtual bool isActive( int faceIndex ) const = 0;
563
565 virtual QgsMeshDatasetMetadata metadata() const = 0;
566
568 virtual int valuesCount() const = 0;
569};
570
578class CORE_EXPORT QgsMeshDatasetGroup
579{
580 public:
581
587 enum Type
588 {
593 };
594
598
600 QgsMeshDatasetGroup( const QString &name );
601
603 QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
604
606 virtual void initialize() = 0;
607
609 QgsMeshDatasetGroupMetadata groupMetadata() const;
610
612 virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const = 0 ;
613
615 virtual int datasetCount() const = 0;
616
618 virtual QgsMeshDataset *dataset( int index ) const = 0;
619
621 virtual QgsMeshDatasetGroup::Type type() const = 0;
622
624 double minimum() const;
625
627 double maximum() const;
628
630 void setMinimumMaximum( double min, double max ) const;
631
633 QString name() const;
634
636 void setName( const QString &name );
637
640
642 void setDataType( const QgsMeshDatasetGroupMetadata::DataType &dataType );
643
645 void addExtraMetadata( QString key, QString value );
647 QMap<QString, QString> extraMetadata() const;
648
650 bool isScalar() const;
651
653 void setIsScalar( bool isScalar );
654
656 bool checkValueCountPerDataset( int count ) const;
657
659 void calculateStatistic() const;
660
662 void setStatisticObsolete() const;
663
665 virtual QStringList datasetGroupNamesDependentOn() const;
666
668 virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
669
671 virtual QString description() const;
672
674 void setReferenceTime( const QDateTime &referenceTime );
675
676 protected:
677 QString mName;
678
680 QMap<QString, QString> mMetadata;
681 bool mIsScalar = true;
682
683 private:
684 mutable double mMinimum = std::numeric_limits<double>::quiet_NaN();
685 mutable double mMaximum = std::numeric_limits<double>::quiet_NaN();
686 mutable bool mIsStatisticObsolete = true;
687
688 void updateStatictic() const;
689
690 QDateTime mReferenceTime;
691};
692
693#ifndef SIP_RUN
694
704class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
705{
706 public:
709
710 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
711 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
712 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
713 QgsMeshDatasetMetadata metadata() const override;
714 bool isActive( int faceIndex ) const override;
715 int valuesCount() const override;
716
718 void calculateMinMax();
719
720 QVector<QgsMeshDatasetValue> values;
721 QVector<int> active;
722 double time = -1;
723 bool valid = false;
724 double minimum = std::numeric_limits<double>::quiet_NaN();
725 double maximum = std::numeric_limits<double>::quiet_NaN();
726};
727
738{
739 public:
743 QgsMeshMemoryDatasetGroup( const QString &name );
746
747 void initialize() override;
748 int datasetCount() const override;
749 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
750 QgsMeshDataset *dataset( int index ) const override;
752
754 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
755
757 void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
758
760 void clearDatasets();
761
763 std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
764
766 QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
767};
768
777{
778 public:
781
782 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
783 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;;
784 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;;
785 bool isActive( int ) const override {return true;};
786 QgsMeshDatasetMetadata metadata() const override;;
787 int valuesCount() const override;
788 private:
789 QgsMesh *mMesh;
790};
791
801{
802 public:
804 QgsMeshVerticesElevationDatasetGroup( QString name, QgsMesh *mesh );
805
806 void initialize() override;
807 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;;
808 int datasetCount() const override;;
809 QgsMeshDataset *dataset( int index ) const override;;
810 QgsMeshDatasetGroup::Type type() const override;
811 QDomElement writeXml( QDomDocument &, const QgsReadWriteContext & ) const override {return QDomElement();};
812
813 private:
814 std::unique_ptr<QgsMeshVerticesElevationDataset> mDataset;
815};
816
817#endif //SIP_RUN
818
844{
845 public:
846
851
860 QgsMeshDatasetGroupTreeItem( const QString &defaultName,
861 const QString &sourceName,
862 bool isVector,
863 int index );
864
871 QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
872
878
885
891 void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
892
901 void removeChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
902
908 QgsMeshDatasetGroupTreeItem *child( int row ) const;
909
917 QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
918
923 int childCount() const;
924
929 int totalChildCount() const;
930
937 QList<int> enabledDatasetGroupIndexes() const;
938
943 QgsMeshDatasetGroupTreeItem *parentItem() const;
944
949 int row() const;
950
956 QString name() const;
957
964 void setName( const QString &name );
965
973 QString providerName() const;
974
978 bool isVector() const;
979
983 int datasetGroupIndex() const;
984
988 bool isEnabled() const;
989
994 void setIsEnabled( bool isEnabled );
995
999 QString defaultName() const;
1000
1006 QgsMeshDatasetGroup::Type datasetGroupType() const;
1007
1014 QList<int> groupIndexDependencies() const;
1015
1021 QString description() const;
1022
1030 void setDatasetGroup( QgsMeshDatasetGroup *datasetGroup );
1031
1039 void setPersistentDatasetGroup( const QString &uri );
1040
1047 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
1048
1049 private:
1050 QgsMeshDatasetGroupTreeItem *mParent = nullptr;
1051 QList< QgsMeshDatasetGroupTreeItem * > mChildren;
1052 QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
1053
1054 // Data
1055 QString mUserName;
1056 QString mOriginalName;
1057 QString mSourceName;
1058 QgsMeshDatasetGroup::Type mDatasetGroupType = QgsMeshDatasetGroup::None;
1059 QString mDescription;
1060
1061 bool mIsVector = false;
1062 int mDatasetGroupIndex = -1;
1063 bool mIsEnabled = true;
1064
1065 QList<int> mDatasetGroupDependencies;
1066 QList<int> mDatasetGroupDependentOn;
1067
1068 QgsMeshDatasetGroupTreeItem *searchItemBySourceName( const QString &sourceName ) const;
1069 QgsMeshDatasetGroupTreeItem *rootItem() const;
1070 void freeAsDependency();
1071 void freeFromDependencies();
1072};
1073
1074#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 ~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.
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
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:100
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
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.
QgsMeshVerticesElevationDataset(QgsMesh *mesh)
Constructor.
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)
Mesh - vertices, edges and faces.