QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmeshcalcutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshcalcutils.h
3  ------------------
4  begin : December 18th, 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 QGSMESHCALCUTILS_H
19 #define QGSMESHCALCUTILS_H
20 
21 #define SIP_NO_FILE
22 
24 
25 #include <QStringList>
26 #include <QMap>
27 #include <QVector>
28 
29 #include <algorithm>
30 #include <functional>
31 #include <math.h>
32 #include <numeric>
33 
34 #include "qgsrectangle.h"
35 #include "qgsmeshlayer.h"
36 #include "qgsmeshdataprovider.h"
37 #include "qgis_core.h"
38 
48 class CORE_EXPORT QgsMeshCalcUtils
49 {
50  public:
51 
62  QgsMeshCalcUtils( QgsMeshLayer *layer,
63  const QStringList &usedGroupNames,
64  double startTime,
65  double endTime );
66 
78  QgsMeshCalcUtils( QgsMeshLayer *layer,
79  const QStringList &usedGroupNames,
80  const QgsInterval &relativeTime );
81 
83  bool isValid() const;
84 
86  const QgsMeshLayer *layer() const;
87 
89  std::shared_ptr<const QgsMeshMemoryDatasetGroup> group( const QString &groupName ) const;
90 
92  void ones( QgsMeshMemoryDatasetGroup &group1 ) const;
93 
95  void nodata( QgsMeshMemoryDatasetGroup &group1 ) const;
96 
98  std::shared_ptr<QgsMeshMemoryDataset> number( double val, double time ) const;
99 
101  void copy( QgsMeshMemoryDatasetGroup &group1, const QString &groupName ) const;
102 
104  std::shared_ptr<QgsMeshMemoryDataset> copy( std::shared_ptr<const QgsMeshMemoryDataset> dataset0 ) const;
105 
107  void transferDatasets( QgsMeshMemoryDatasetGroup &group1, QgsMeshMemoryDatasetGroup &group2 ) const;
108 
110  void expand( QgsMeshMemoryDatasetGroup &group1,
111  const QgsMeshMemoryDatasetGroup &group2 ) const;
112 
114  void number( QgsMeshMemoryDatasetGroup &group1, double val ) const;
115 
117  void addIf( QgsMeshMemoryDatasetGroup &trueGroup,
118  const QgsMeshMemoryDatasetGroup &falseGroup,
119  const QgsMeshMemoryDatasetGroup &condition ) const;
120 
122  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsRectangle &extent ) const;
123 
125  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsGeometry &mask ) const;
126 
128  void logicalNot( QgsMeshMemoryDatasetGroup &group1 ) const;
129 
131  void changeSign( QgsMeshMemoryDatasetGroup &group1 ) const;
132 
134  void abs( QgsMeshMemoryDatasetGroup &group1 ) const;
135 
137  void sumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
138 
140  void minimumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
141 
143  void maximumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
144 
146  void averageAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
147 
149  void add( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
150 
152  void subtract( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
153 
155  void multiply( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
156 
158  void divide( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
159 
161  void power( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
162 
164  void equal( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
165 
167  void notEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
168 
170  void greaterThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
171 
173  void lesserThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
174 
176  void lesserEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
177 
179  void greaterEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
180 
182  void logicalAnd( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
183 
185  void logicalOr( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
186 
188  void minimum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
189 
191  void maximum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
192 
194  static QgsMeshDatasetGroupMetadata::DataType determineResultDataType( QgsMeshLayer *layer, const QStringList &usedGroupNames );
195 
197  QgsMeshDatasetGroupMetadata::DataType outputType() const;
198 
199  private:
200  double ffilter( double val1, double filter ) const;
201  double fadd( double val1, double val2 ) const;
202  double fsubtract( double val1, double val2 ) const;
203  double fmultiply( double val1, double val2 ) const;
204  double fdivide( double val1, double val2 ) const;
205  double fpower( double val1, double val2 ) const;
206  double fequal( double val1, double val2 ) const;
207  double fnotEqual( double val1, double val2 ) const;
208  double fgreaterThan( double val1, double val2 ) const;
209  double flesserThan( double val1, double val2 ) const;
210  double flesserEqual( double val1, double val2 ) const;
211  double fgreaterEqual( double val1, double val2 ) const;
212  double flogicalAnd( double val1, double val2 ) const;
213  double flogicalOr( double val1, double val2 ) const;
214  double flogicalNot( double val1 ) const;
215  double fchangeSign( double val1 ) const;
216  double fmin( double val1, double val2 ) const;
217  double fmax( double val1, double val2 ) const;
218  double fabs( double val1 ) const;
219  double fsumAggregated( QVector<double> &vals ) const;
220  double fminimumAggregated( QVector<double> &vals ) const;
221  double fmaximumAggregated( QVector<double> &vals ) const;
222  double faverageAggregated( QVector<double> &vals ) const;
223 
231  std::shared_ptr<QgsMeshMemoryDatasetGroup> createMemoryDatasetGroup( const QString &datasetGroupName, const QgsInterval &relativeTime = QgsInterval() ) const;
232 
236  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshMemoryDatasetGroup &grp ) const;
237 
241  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshDatasetIndex &datasetIndex ) const;
242 
246  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshDatasetGroupMetadata::DataType type ) const;
247 
251  std::shared_ptr<QgsMeshMemoryDataset> canditateDataset( QgsMeshMemoryDatasetGroup &group,
252  int datasetIndex ) const;
253 
257  std::shared_ptr<const QgsMeshMemoryDataset> constCandidateDataset( const QgsMeshMemoryDatasetGroup &group,
258  int datasetIndex ) const;
259 
263  int datasetCount( const QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
264 
270  void activate( std::shared_ptr<QgsMeshMemoryDataset> dataset,
271  std::shared_ptr<const QgsMeshMemoryDataset> refDataset = nullptr ) const;
272 
274  void activate( QgsMeshMemoryDatasetGroup &group ) const;
275 
277  void populateSpatialFilter( QgsMeshMemoryDatasetGroup &filter, const QgsRectangle &extent ) const; // create a filter from extent
278 
280  void populateMaskFilter( QgsMeshMemoryDatasetGroup &filter, const QgsGeometry &mask ) const; // create a filter from mask
281 
283  void func1( QgsMeshMemoryDatasetGroup &group,
284  std::function<double( double )> func ) const;
285 
287  void func2( QgsMeshMemoryDatasetGroup &group1,
288  const QgsMeshMemoryDatasetGroup &group2,
289  std::function<double( double, double )> func ) const;
290 
292  void funcAggr( QgsMeshMemoryDatasetGroup &group1,
293  std::function<double( QVector<double>& )> func ) const;
294 
295  const QgsTriangularMesh *triangularMesh() const;
296  const QgsMesh *nativeMesh() const;
297  void updateMesh() const;
298 
299  QgsMeshLayer *mMeshLayer;
300  bool mIsValid;
302  QVector<double> mTimes;
304  QMap < QString, std::shared_ptr<QgsMeshMemoryDatasetGroup> > mDatasetGroupMap;
305 };
306 
308 
309 #endif // QGSMESHCALCUTILS_H
qgsrectangle.h
QgsMesh
Mesh - vertices, edges and faces.
Definition: qgsmeshdataprovider.h:58
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsMeshDatasetIndex
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Definition: qgsmeshdataset.h:47
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
qgsmeshlayer.h
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsMeshDatasetGroupMetadata::DataType
DataType
Location of where data is specified for datasets in the dataset group.
Definition: qgsmeshdataset.h:355
QgsInterval
A representation of the interval between two datetime values.
Definition: qgsinterval.h:41
QgsTriangularMesh
Triangular/Derived Mesh is mesh with vertices in map coordinates.
Definition: qgstriangularmesh.h:50
qgsmeshdataprovider.h
QgsMeshMemoryDatasetGroup
Class that represents a dataset group stored in memory The QgsMeshMemoryDataset objects stores in a Q...
Definition: qgsmeshdataset.h:727