QGIS API Documentation 3.38.0-Grenoble (exported)
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;
64 bool operator == ( QgsMeshDatasetIndex other ) const;
66 bool operator != ( QgsMeshDatasetIndex other ) const;
67 private:
68 int mGroupIndex = -1;
69 int mDatasetIndex = -1;
70};
71
83class CORE_EXPORT QgsMeshDatasetValue
84{
85 public:
87 QgsMeshDatasetValue( double x,
88 double y );
89
91 QgsMeshDatasetValue( double scalar );
92
95
98
100 void set( double scalar );
101
103 void setX( double x );
104
106 void setY( double y ) ;
107
109 double scalar() const;
110
112 double x() const;
113
115 double y() const;
116
117 bool operator==( QgsMeshDatasetValue other ) const;
118
119 private:
120 double mX = std::numeric_limits<double>::quiet_NaN();
121 double mY = std::numeric_limits<double>::quiet_NaN();
122};
123
141class CORE_EXPORT QgsMeshDataBlock
142{
143 public:
151
154
156 QgsMeshDataBlock( DataType type, int count );
157
159 DataType type() const;
160
162 int count() const;
163
165 bool isValid() const;
166
171 QgsMeshDatasetValue value( int index ) const;
172
177 bool active( int index ) const;
178
192 void setActive( const QVector<int> &vals );
193
205 QVector<int> active() const;
206
213 QVector<double> values() const;
214
224 void setValues( const QVector<double> &vals );
225
227 void setValid( bool valid );
228
229 private:
230 QVector<double> mDoubleBuffer;
231 QVector<int> mIntegerBuffer;
232 DataType mType;
233 int mSize = 0;
234 bool mIsValid = false;
235};
236
253class CORE_EXPORT QgsMesh3DDataBlock
254{
255 public:
258
261
263 QgsMesh3DDataBlock( int count, bool isVector );
264
266 void setValid( bool valid );
267
269 bool isValid() const;
270
272 bool isVector() const;
273
275 int count() const;
276
278 int firstVolumeIndex() const;
279
281 int lastVolumeIndex() const;
282
284 int volumesCount() const;
285
289 QVector<int> verticalLevelsCount() const;
290
294 void setVerticalLevelsCount( const QVector<int> &verticalLevelsCount );
295
299 QVector<double> verticalLevels() const;
300
304 void setVerticalLevels( const QVector<double> &verticalLevels );
305
309 QVector<int> faceToVolumeIndex() const;
310
314 void setFaceToVolumeIndex( const QVector<int> &faceToVolumeIndex );
315
321 QVector<double> values() const;
322
329 QgsMeshDatasetValue value( int volumeIndex ) const;
330
336 void setValues( const QVector<double> &doubleBuffer );
337
338 private:
339 int mSize = 0;
340 bool mIsValid = false;
341 bool mIsVector = false;
342 QVector<int> mVerticalLevelsCount;
343 QVector<double> mVerticalLevels;
344 QVector<int> mFaceToVolumeIndex;
345 QVector<double> mDoubleBuffer; // for scalar/vector values
346};
347
359{
360 public:
361
364 {
365 DataOnFaces = 0,
368 DataOnEdges
369 };
370
373
388 QgsMeshDatasetGroupMetadata( const QString &name,
389 const QString uri,
390 bool isScalar,
391 DataType dataType,
392 double minimum,
393 double maximum,
394 int maximumVerticalLevels,
395 const QDateTime &referenceTime,
396 bool isTemporal,
397 const QMap<QString, QString> &extraOptions );
398
402 QString name() const;
403
412 QString parentQuantityName() const;
413
419 QString uri() const;
420
424 QMap<QString, QString> extraOptions() const;
425
429 bool isVector() const;
430
434 bool isScalar() const;
435
439 bool isTemporal() const;
440
446 DataType dataType() const;
447
451 double minimum() const;
452
456 double maximum() const;
457
463 int maximumVerticalLevelsCount() const;
464
470 QDateTime referenceTime() const;
471
472 private:
473 QString mName;
474 QString mParentQuantityName;
475 QString mUri;
476 bool mIsScalar = false;
477 DataType mDataType = DataType::DataOnFaces;
478 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
479 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
480 QMap<QString, QString> mExtraOptions;
481 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
482 QDateTime mReferenceTime;
483 bool mIsTemporal = false;
484};
485
496class CORE_EXPORT QgsMeshDatasetMetadata
497{
498 public:
501
511 QgsMeshDatasetMetadata( double time,
512 bool isValid,
513 double minimum,
514 double maximum,
515 int maximumVerticalLevels
516 );
517
521 double time() const;
522
526 bool isValid() const;
527
531 double minimum() const;
532
536 double maximum() const;
537
543 int maximumVerticalLevelsCount() const;
544
545 private:
546 double mTime = std::numeric_limits<double>::quiet_NaN();
547 bool mIsValid = false;
548 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
549 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
550 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
551};
552
553
561class CORE_EXPORT QgsMeshDataset
562{
563 public:
565 QgsMeshDataset() = default;
566
568 virtual ~QgsMeshDataset() = default;
569
571 virtual QgsMeshDatasetValue datasetValue( int valueIndex ) const = 0;
572
574 virtual QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const = 0;
575
577 virtual QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const = 0;
578
580 virtual bool isActive( int faceIndex ) const = 0;
581
583 virtual QgsMeshDatasetMetadata metadata() const = 0;
584
586 virtual int valuesCount() const = 0;
587};
588
596class CORE_EXPORT QgsMeshDatasetGroup
597{
598 public:
599
612
616
618 QgsMeshDatasetGroup( const QString &name );
619
621 QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
622
624 virtual void initialize() = 0;
625
627 QgsMeshDatasetGroupMetadata groupMetadata() const;
628
630 virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const = 0 ;
631
633 virtual int datasetCount() const = 0;
634
636 virtual QgsMeshDataset *dataset( int index ) const = 0;
637
639 virtual QgsMeshDatasetGroup::Type type() const = 0;
640
642 double minimum() const;
643
645 double maximum() const;
646
648 void setMinimumMaximum( double min, double max ) const;
649
651 QString name() const;
652
654 void setName( const QString &name );
655
658
660 void setDataType( const QgsMeshDatasetGroupMetadata::DataType &dataType );
661
663 void addExtraMetadata( QString key, QString value );
665 QMap<QString, QString> extraMetadata() const;
666
668 bool isScalar() const;
669
671 void setIsScalar( bool isScalar );
672
674 bool checkValueCountPerDataset( int count ) const;
675
677 void calculateStatistic() const;
678
680 void setStatisticObsolete() const;
681
683 virtual QStringList datasetGroupNamesDependentOn() const;
684
686 virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
687
689 virtual QString description() const;
690
692 void setReferenceTime( const QDateTime &referenceTime );
693
694 protected:
695 QString mName;
696
698 QMap<QString, QString> mMetadata;
699 bool mIsScalar = true;
700
701 private:
702 mutable double mMinimum = std::numeric_limits<double>::quiet_NaN();
703 mutable double mMaximum = std::numeric_limits<double>::quiet_NaN();
704 mutable bool mIsStatisticObsolete = true;
705
706 void updateStatistic() const;
707
708 QDateTime mReferenceTime;
709};
710
711#ifndef SIP_RUN
712
722class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
723{
724 public:
727
728 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
729 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
730 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
731 QgsMeshDatasetMetadata metadata() const override;
732 bool isActive( int faceIndex ) const override;
733 int valuesCount() const override;
734
736 void calculateMinMax();
737
738 QVector<QgsMeshDatasetValue> values;
739 QVector<int> active;
740 double time = -1;
741 bool valid = false;
742 double minimum = std::numeric_limits<double>::quiet_NaN();
743 double maximum = std::numeric_limits<double>::quiet_NaN();
744};
745
756{
757 public:
761 QgsMeshMemoryDatasetGroup( const QString &name );
764
765 void initialize() override;
766 int datasetCount() const override;
767 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
768 QgsMeshDataset *dataset( int index ) const override;
770
772 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
773
775 void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
776
778 void clearDatasets();
779
781 std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
782
784 QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
785};
786
795{
796 public:
799
800 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
801 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;;
802 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;;
803 bool isActive( int ) const override {return true;};
804 QgsMeshDatasetMetadata metadata() const override;;
805 int valuesCount() const override;
806 private:
807 QgsMesh *mMesh;
808};
809
819{
820 public:
822 QgsMeshVerticesElevationDatasetGroup( QString name, QgsMesh *mesh );
823
824 void initialize() override;
825 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;;
826 int datasetCount() const override;;
827 QgsMeshDataset *dataset( int index ) const override;;
828 QgsMeshDatasetGroup::Type type() const override;
829 QDomElement writeXml( QDomDocument &, const QgsReadWriteContext & ) const override {return QDomElement();};
830
831 private:
832 std::unique_ptr<QgsMeshVerticesElevationDataset> mDataset;
833};
834
835#endif //SIP_RUN
836
862{
863 public:
864
869
878 QgsMeshDatasetGroupTreeItem( const QString &defaultName,
879 const QString &sourceName,
880 bool isVector,
881 int index );
882
889 QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
890
896
903
909 void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
910
917 void removeChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
918
924 QgsMeshDatasetGroupTreeItem *child( int row ) const;
925
933 QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
934
939 int childCount() const;
940
945 int totalChildCount() const;
946
953 QList<int> enabledDatasetGroupIndexes() const;
954
959 QgsMeshDatasetGroupTreeItem *parentItem() const;
960
965 int row() const;
966
972 QString name() const;
973
980 void setName( const QString &name );
981
989 QString providerName() const;
990
994 bool isVector() const;
995
999 int datasetGroupIndex() const;
1000
1004 bool isEnabled() const;
1005
1010 void setIsEnabled( bool isEnabled );
1011
1015 QString defaultName() const;
1016
1022 QgsMeshDatasetGroup::Type datasetGroupType() const;
1023
1030 QList<int> groupIndexDependencies() const;
1031
1037 QString description() const;
1038
1046 void setDatasetGroup( QgsMeshDatasetGroup *datasetGroup );
1047
1055 void setPersistentDatasetGroup( const QString &uri );
1056
1063 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
1064
1065 private:
1066 QgsMeshDatasetGroupTreeItem *mParent = nullptr;
1067 QList< QgsMeshDatasetGroupTreeItem * > mChildren;
1068 QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
1069
1070 // Data
1071 QString mUserName;
1072 QString mOriginalName;
1073 QString mSourceName;
1074 QgsMeshDatasetGroup::Type mDatasetGroupType = QgsMeshDatasetGroup::None;
1075 QString mDescription;
1076
1077 bool mIsVector = false;
1078 int mDatasetGroupIndex = -1;
1079 bool mIsEnabled = true;
1080
1081 QList<int> mDatasetGroupDependencies;
1082 QList<int> mDatasetGroupDependentOn;
1083
1084 QgsMeshDatasetGroupTreeItem *searchItemBySourceName( const QString &sourceName ) const;
1085 QgsMeshDatasetGroupTreeItem *rootItem() const;
1086 void freeAsDependency();
1087 void freeFromDependencies();
1088};
1089
1090#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.
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.
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.