QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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
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:
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
249class CORE_EXPORT QgsMesh3DDataBlock
250{
251 public:
254
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
405 QString uri() const;
406
410 QMap<QString, QString> extraOptions() const;
411
415 bool isVector() const;
416
420 bool isScalar() const;
421
425 bool isTemporal() const;
426
432 DataType dataType() const;
433
437 double minimum() const;
438
442 double maximum() const;
443
449 int maximumVerticalLevelsCount() const;
450
456 QDateTime referenceTime() const;
457
458 private:
459 QString mName;
460 QString mUri;
461 bool mIsScalar = false;
462 DataType mDataType = DataType::DataOnFaces;
463 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
464 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
465 QMap<QString, QString> mExtraOptions;
466 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
467 QDateTime mReferenceTime;
468 bool mIsTemporal = false;
469};
470
481class CORE_EXPORT QgsMeshDatasetMetadata
482{
483 public:
486
496 QgsMeshDatasetMetadata( double time,
497 bool isValid,
498 double minimum,
499 double maximum,
500 int maximumVerticalLevels
501 );
502
506 double time() const;
507
511 bool isValid() const;
512
516 double minimum() const;
517
521 double maximum() const;
522
528 int maximumVerticalLevelsCount() const;
529
530 private:
531 double mTime = std::numeric_limits<double>::quiet_NaN();
532 bool mIsValid = false;
533 double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
534 double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
535 int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
536};
537
538
546class CORE_EXPORT QgsMeshDataset
547{
548 public:
550 QgsMeshDataset() = default;
551
553 virtual ~QgsMeshDataset() = default;
554
556 virtual QgsMeshDatasetValue datasetValue( int valueIndex ) const = 0;
557
559 virtual QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const = 0;
560
562 virtual QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const = 0;
563
565 virtual bool isActive( int faceIndex ) const = 0;
566
568 virtual QgsMeshDatasetMetadata metadata() const = 0;
569
571 virtual int valuesCount() const = 0;
572};
573
581class CORE_EXPORT QgsMeshDatasetGroup
582{
583 public:
584
597
601
603 QgsMeshDatasetGroup( const QString &name );
604
606 QgsMeshDatasetGroup( const QString &name, QgsMeshDatasetGroupMetadata::DataType dataType );
607
609 virtual void initialize() = 0;
610
612 QgsMeshDatasetGroupMetadata groupMetadata() const;
613
615 virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const = 0 ;
616
618 virtual int datasetCount() const = 0;
619
621 virtual QgsMeshDataset *dataset( int index ) const = 0;
622
624 virtual QgsMeshDatasetGroup::Type type() const = 0;
625
627 double minimum() const;
628
630 double maximum() const;
631
633 void setMinimumMaximum( double min, double max ) const;
634
636 QString name() const;
637
639 void setName( const QString &name );
640
643
645 void setDataType( const QgsMeshDatasetGroupMetadata::DataType &dataType );
646
648 void addExtraMetadata( QString key, QString value );
650 QMap<QString, QString> extraMetadata() const;
651
653 bool isScalar() const;
654
656 void setIsScalar( bool isScalar );
657
659 bool checkValueCountPerDataset( int count ) const;
660
662 void calculateStatistic() const;
663
665 void setStatisticObsolete() const;
666
668 virtual QStringList datasetGroupNamesDependentOn() const;
669
671 virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
672
674 virtual QString description() const;
675
677 void setReferenceTime( const QDateTime &referenceTime );
678
679 protected:
680 QString mName;
681
683 QMap<QString, QString> mMetadata;
684 bool mIsScalar = true;
685
686 private:
687 mutable double mMinimum = std::numeric_limits<double>::quiet_NaN();
688 mutable double mMaximum = std::numeric_limits<double>::quiet_NaN();
689 mutable bool mIsStatisticObsolete = true;
690
691 void updateStatictic() const;
692
693 QDateTime mReferenceTime;
694};
695
696#ifndef SIP_RUN
697
707class CORE_EXPORT QgsMeshMemoryDataset: public QgsMeshDataset
708{
709 public:
712
713 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
714 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;
715 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;
716 QgsMeshDatasetMetadata metadata() const override;
717 bool isActive( int faceIndex ) const override;
718 int valuesCount() const override;
719
721 void calculateMinMax();
722
723 QVector<QgsMeshDatasetValue> values;
724 QVector<int> active;
725 double time = -1;
726 bool valid = false;
727 double minimum = std::numeric_limits<double>::quiet_NaN();
728 double maximum = std::numeric_limits<double>::quiet_NaN();
729};
730
741{
742 public:
746 QgsMeshMemoryDatasetGroup( const QString &name );
749
750 void initialize() override;
751 int datasetCount() const override;
752 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;
753 QgsMeshDataset *dataset( int index ) const override;
755
757 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
758
760 void addDataset( std::shared_ptr<QgsMeshMemoryDataset> dataset );
761
763 void clearDatasets();
764
766 std::shared_ptr<const QgsMeshMemoryDataset> constDataset( int index ) const;
767
769 QVector<std::shared_ptr<QgsMeshMemoryDataset>> memoryDatasets;
770};
771
780{
781 public:
784
785 QgsMeshDatasetValue datasetValue( int valueIndex ) const override;
786 QgsMeshDataBlock datasetValues( bool isScalar, int valueIndex, int count ) const override;;
787 QgsMeshDataBlock areFacesActive( int faceIndex, int count ) const override;;
788 bool isActive( int ) const override {return true;};
789 QgsMeshDatasetMetadata metadata() const override;;
790 int valuesCount() const override;
791 private:
792 QgsMesh *mMesh;
793};
794
804{
805 public:
807 QgsMeshVerticesElevationDatasetGroup( QString name, QgsMesh *mesh );
808
809 void initialize() override;
810 QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const override;;
811 int datasetCount() const override;;
812 QgsMeshDataset *dataset( int index ) const override;;
813 QgsMeshDatasetGroup::Type type() const override;
814 QDomElement writeXml( QDomDocument &, const QgsReadWriteContext & ) const override {return QDomElement();};
815
816 private:
817 std::unique_ptr<QgsMeshVerticesElevationDataset> mDataset;
818};
819
820#endif //SIP_RUN
821
847{
848 public:
849
854
863 QgsMeshDatasetGroupTreeItem( const QString &defaultName,
864 const QString &sourceName,
865 bool isVector,
866 int index );
867
874 QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
875
881
888
894 void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
895
902 void removeChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
903
909 QgsMeshDatasetGroupTreeItem *child( int row ) const;
910
918 QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
919
924 int childCount() const;
925
930 int totalChildCount() const;
931
938 QList<int> enabledDatasetGroupIndexes() const;
939
944 QgsMeshDatasetGroupTreeItem *parentItem() const;
945
950 int row() const;
951
957 QString name() const;
958
965 void setName( const QString &name );
966
974 QString providerName() const;
975
979 bool isVector() const;
980
984 int datasetGroupIndex() const;
985
989 bool isEnabled() const;
990
995 void setIsEnabled( bool isEnabled );
996
1000 QString defaultName() const;
1001
1007 QgsMeshDatasetGroup::Type datasetGroupType() const;
1008
1015 QList<int> groupIndexDependencies() const;
1016
1022 QString description() const;
1023
1031 void setDatasetGroup( QgsMeshDatasetGroup *datasetGroup );
1032
1040 void setPersistentDatasetGroup( const QString &uri );
1041
1048 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
1049
1050 private:
1051 QgsMeshDatasetGroupTreeItem *mParent = nullptr;
1052 QList< QgsMeshDatasetGroupTreeItem * > mChildren;
1053 QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
1054
1055 // Data
1056 QString mUserName;
1057 QString mOriginalName;
1058 QString mSourceName;
1059 QgsMeshDatasetGroup::Type mDatasetGroupType = QgsMeshDatasetGroup::None;
1060 QString mDescription;
1061
1062 bool mIsVector = false;
1063 int mDatasetGroupIndex = -1;
1064 bool mIsEnabled = true;
1065
1066 QList<int> mDatasetGroupDependencies;
1067 QList<int> mDatasetGroupDependentOn;
1068
1069 QgsMeshDatasetGroupTreeItem *searchItemBySourceName( const QString &sourceName ) const;
1070 QgsMeshDatasetGroupTreeItem *rootItem() const;
1071 void freeAsDependency();
1072 void freeFromDependencies();
1073};
1074
1075#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.