QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "qgspoint.h"
30 #include "qgsdataprovider.h"
31 
32 
33 class QgsRectangle;
34 
45 class CORE_EXPORT QgsMeshDatasetIndex
46 {
47  public:
49  QgsMeshDatasetIndex( int group = -1, int dataset = -1 );
51  int group() const;
53  int dataset() const;
55  bool isValid() const;
57  bool operator == ( QgsMeshDatasetIndex other ) const;
59  bool operator != ( QgsMeshDatasetIndex other ) const;
60  private:
61  int mGroupIndex = -1;
62  int mDatasetIndex = -1;
63 };
64 
76 class CORE_EXPORT QgsMeshDatasetValue
77 {
78  public:
80  QgsMeshDatasetValue( double x,
81  double y );
82 
84  QgsMeshDatasetValue( double scalar );
85 
87  QgsMeshDatasetValue() = default;
88 
90  ~QgsMeshDatasetValue() = default;
91 
93  void set( double scalar );
94 
96  void setX( double x );
97 
99  void setY( double y ) ;
100 
102  double scalar() const;
103 
105  double x() const;
106 
108  double y() const;
109 
110  bool operator==( QgsMeshDatasetValue other ) const;
111 
112  private:
113  double mX = std::numeric_limits<double>::quiet_NaN();
114  double mY = std::numeric_limits<double>::quiet_NaN();
115 };
116 
134 class CORE_EXPORT QgsMeshDataBlock
135 {
136  public:
138  enum DataType
139  {
143  };
144 
147 
149  QgsMeshDataBlock( DataType type, int count );
150 
152  DataType type() const;
153 
155  int count() const;
156 
158  bool isValid() const;
159 
164  QgsMeshDatasetValue value( int index ) const;
165 
170  bool active( int index ) const;
171 
185  void setActive( const QVector<int> &vals );
186 
198  QVector<int> active() const;
199 
206  QVector<double> values() const;
207 
217  void setValues( const QVector<double> &vals );
218 
220  void setValid( bool valid );
221 
222  private:
223  QVector<double> mDoubleBuffer;
224  QVector<int> mIntegerBuffer;
225  DataType mType;
226  int mSize = 0;
227  bool mIsValid = false;
228 };
229 
243 class CORE_EXPORT QgsMesh3dDataBlock
244 {
245  public:
248 
251 
253  QgsMesh3dDataBlock( int count, bool isVector );
254 
256  void setValid( bool valid );
257 
259  bool isValid() const;
260 
262  bool isVector() const;
263 
265  int count() const;
266 
268  int firstVolumeIndex() const;
269 
271  int lastVolumeIndex() const;
272 
274  int volumesCount() const;
275 
279  QVector<int> verticalLevelsCount() const;
280 
284  void setVerticalLevelsCount( const QVector<int> &verticalLevelsCount );
285 
289  QVector<double> verticalLevels() const;
290 
294  void setVerticalLevels( const QVector<double> &verticalLevels );
295 
299  QVector<int> faceToVolumeIndex() const;
300 
304  void setFaceToVolumeIndex( const QVector<int> &faceToVolumeIndex );
305 
311  QVector<double> values() const;
312 
319  QgsMeshDatasetValue value( int volumeIndex ) const;
320 
326  void setValues( const QVector<double> &doubleBuffer );
327 
328  private:
329  int mSize = 0;
330  bool mIsValid = false;
331  bool mIsVector = false;
332  QVector<int> mVerticalLevelsCount;
333  QVector<double> mVerticalLevels;
334  QVector<int> mFaceToVolumeIndex;
335  QVector<double> mDoubleBuffer; // for scalar/vector values
336 };
337 
349 {
350  public:
351 
353  enum DataType
354  {
355  DataOnFaces = 0,
358  DataOnEdges
359  };
360 
362  QgsMeshDatasetGroupMetadata() = default;
363 
377  QgsMeshDatasetGroupMetadata( const QString &name,
378  bool isScalar,
379  DataType dataType,
380  double minimum,
381  double maximum,
382  int maximumVerticalLevels,
383  const QDateTime &referenceTime,
384  bool isTemporal,
385  const QMap<QString, QString> &extraOptions );
386 
390  QString name() const;
391 
395  QMap<QString, QString> extraOptions() const;
396 
400  bool isVector() const;
401 
405  bool isScalar() const;
406 
407 
411  bool isTemporal() const;
412 
413 
419  DataType dataType() const;
420 
424  double minimum() const;
425 
429  double maximum() const;
430 
436  int maximumVerticalLevelsCount() const;
437 
443  QDateTime referenceTime() const;
444 
445  private:
446  QString mName;
447  bool mIsScalar = false;
448  DataType mDataType = DataType::DataOnFaces;
449  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
450  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
451  QMap<QString, QString> mExtraOptions;
452  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
453  QDateTime mReferenceTime;
454  bool mIsTemporal = false;
455 };
456 
467 class CORE_EXPORT QgsMeshDatasetMetadata
468 {
469  public:
471  QgsMeshDatasetMetadata() = default;
472 
482  QgsMeshDatasetMetadata( double time,
483  bool isValid,
484  double minimum,
485  double maximum,
486  int maximumVerticalLevels
487  );
488 
492  double time() const;
493 
497  bool isValid() const;
498 
502  double minimum() const;
503 
507  double maximum() const;
508 
514  int maximumVerticalLevelsCount() const;
515 
516  private:
517  double mTime = std::numeric_limits<double>::quiet_NaN();
518  bool mIsValid = false;
519  double mMinimumValue = std::numeric_limits<double>::quiet_NaN();
520  double mMaximumValue = std::numeric_limits<double>::quiet_NaN();
521  int mMaximumVerticalLevelsCount = 0; // for 3d stacked meshes
522 };
523 
547 {
548  public:
549 
554 
562  QgsMeshDatasetGroupTreeItem( const QString &defaultName,
563  bool isVector,
564  int index );
565 
572  QgsMeshDatasetGroupTreeItem( const QDomElement &itemElement, const QgsReadWriteContext &context );
573 
579 
586 
593  void appendChild( QgsMeshDatasetGroupTreeItem *item SIP_TRANSFER );
594 
600  QgsMeshDatasetGroupTreeItem *child( int row ) const;
601 
609  QgsMeshDatasetGroupTreeItem *childFromDatasetGroupIndex( int index );
610 
615  int childCount() const;
616 
621  int totalChildCount() const;
622 
627  QgsMeshDatasetGroupTreeItem *parentItem() const;
628 
633  int row() const;
634 
640  QString name() const;
641 
648  void setName( const QString &name );
649 
653  bool isVector() const;
654 
658  int datasetGroupIndex() const;
659 
663  bool isEnabled() const;
664 
669  void setIsEnabled( bool isEnabled );
670 
674  QString defaultName() const;
675 
682  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
683 
684  private:
685  QgsMeshDatasetGroupTreeItem *mParent = nullptr;
686  QList< QgsMeshDatasetGroupTreeItem * > mChildren;
687  QMap<int, QgsMeshDatasetGroupTreeItem *> mDatasetGroupIndexToChild;
688 
689  // Data
690  QString mUserName;
691  QString mProviderName;
692  bool mIsVector = false;
693  int mDatasetGroupIndex = -1;
694  bool mIsEnabled = true;
695 };
696 
697 #endif // QGSMESHDATASET_H
QgsMeshDatasetGroupMetadata::DataOnVolumes
@ DataOnVolumes
Data is defined on volumes.
Definition: qgsmeshdataset.h:357
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsMeshDataBlock::ScalarDouble
@ ScalarDouble
Scalar double values.
Definition: qgsmeshdataset.h:141
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:399
QgsMeshDatasetValue
Definition: qgsmeshdataset.h:76
QgsMeshDatasetGroupTreeItem
Definition: qgsmeshdataset.h:546
qgspoint.h
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:404
QgsRectangle
Definition: qgsrectangle.h:41
QgsMeshDatasetMetadata
Definition: qgsmeshdataset.h:467
QgsMesh3dDataBlock
Definition: qgsmeshdataset.h:243
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMeshDatasetGroupMetadata::DataOnVertices
@ DataOnVertices
Data is defined on vertices.
Definition: qgsmeshdataset.h:356
QgsMeshDataBlock::Vector2DDouble
@ Vector2DDouble
Vector double pairs (x1, y1, x2, y2, ... )
Definition: qgsmeshdataset.h:142
QgsMeshDatasetIndex
Definition: qgsmeshdataset.h:45
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMeshDataBlock::DataType
DataType
Type of data stored in the block.
Definition: qgsmeshdataset.h:138
QgsMeshDatasetGroupMetadata
Definition: qgsmeshdataset.h:348
QgsMeshDatasetGroupMetadata::DataType
DataType
Location of where data is specified for datasets in the dataset group.
Definition: qgsmeshdataset.h:353
QgsMeshDataBlock::ActiveFlagInteger
@ ActiveFlagInteger
Integer boolean flag whether face is active.
Definition: qgsmeshdataset.h:140
qgsdataprovider.h
QgsMeshDataBlock
Definition: qgsmeshdataset.h:134