QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
49 class CORE_EXPORT QgsMeshCalcUtils
50 {
51  public:
52 
63  QgsMeshCalcUtils( QgsMeshLayer *layer,
64  const QStringList &usedGroupNames,
65  double startTime,
66  double endTime );
67 
79  QgsMeshCalcUtils( QgsMeshLayer *layer,
80  const QStringList &usedGroupNames,
81  const QgsInterval &relativeTime );
82 
84  bool isValid() const;
85 
87  const QgsMeshLayer *layer() const;
88 
90  std::shared_ptr<const QgsMeshMemoryDatasetGroup> group( const QString &groupName ) const;
91 
93  void ones( QgsMeshMemoryDatasetGroup &group1 ) const;
94 
96  void nodata( QgsMeshMemoryDatasetGroup &group1 ) const;
97 
99  std::shared_ptr<QgsMeshMemoryDataset> number( double val, double time ) const;
100 
102  void copy( QgsMeshMemoryDatasetGroup &group1, const QString &groupName ) const;
103 
105  std::shared_ptr<QgsMeshMemoryDataset> copy( std::shared_ptr<const QgsMeshMemoryDataset> dataset0 ) const;
106 
108  void transferDatasets( QgsMeshMemoryDatasetGroup &group1, QgsMeshMemoryDatasetGroup &group2 ) const;
109 
111  void expand( QgsMeshMemoryDatasetGroup &group1,
112  const QgsMeshMemoryDatasetGroup &group2 ) const;
113 
115  void number( QgsMeshMemoryDatasetGroup &group1, double val ) const;
116 
118  void addIf( QgsMeshMemoryDatasetGroup &trueGroup,
119  const QgsMeshMemoryDatasetGroup &falseGroup,
120  const QgsMeshMemoryDatasetGroup &condition ) const;
121 
123  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsRectangle &extent ) const;
124 
126  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsGeometry &mask ) const;
127 
129  void logicalNot( QgsMeshMemoryDatasetGroup &group1 ) const;
130 
132  void changeSign( QgsMeshMemoryDatasetGroup &group1 ) const;
133 
135  void abs( QgsMeshMemoryDatasetGroup &group1 ) const;
136 
138  void sumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
139 
141  void minimumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
142 
144  void maximumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
145 
147  void averageAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
148 
150  void add( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
151 
153  void subtract( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
154 
156  void multiply( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
157 
159  void divide( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
160 
162  void power( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
163 
165  void equal( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
166 
168  void notEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
169 
171  void greaterThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
172 
174  void lesserThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
175 
177  void lesserEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
178 
180  void greaterEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
181 
183  void logicalAnd( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
184 
186  void logicalOr( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
187 
189  void minimum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
190 
192  void maximum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
193 
195  static QgsMeshDatasetGroupMetadata::DataType determineResultDataType( QgsMeshLayer *layer, const QStringList &usedGroupNames );
196 
198  QgsMeshDatasetGroupMetadata::DataType outputType() const;
199 
200  private:
201  double ffilter( double val1, double filter ) const;
202  double fadd( double val1, double val2 ) const;
203  double fsubtract( double val1, double val2 ) const;
204  double fmultiply( double val1, double val2 ) const;
205  double fdivide( double val1, double val2 ) const;
206  double fpower( double val1, double val2 ) const;
207  double fequal( double val1, double val2 ) const;
208  double fnotEqual( double val1, double val2 ) const;
209  double fgreaterThan( double val1, double val2 ) const;
210  double flesserThan( double val1, double val2 ) const;
211  double flesserEqual( double val1, double val2 ) const;
212  double fgreaterEqual( double val1, double val2 ) const;
213  double flogicalAnd( double val1, double val2 ) const;
214  double flogicalOr( double val1, double val2 ) const;
215  double flogicalNot( double val1 ) const;
216  double fchangeSign( double val1 ) const;
217  double fmin( double val1, double val2 ) const;
218  double fmax( double val1, double val2 ) const;
219  double fabs( double val1 ) const;
220  double fsumAggregated( QVector<double> &vals ) const;
221  double fminimumAggregated( QVector<double> &vals ) const;
222  double fmaximumAggregated( QVector<double> &vals ) const;
223  double faverageAggregated( QVector<double> &vals ) const;
224 
232  std::shared_ptr<QgsMeshMemoryDatasetGroup> createMemoryDatasetGroup( const QString &datasetGroupName, const QgsInterval &relativeTime = QgsInterval() ) const;
233 
237  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshMemoryDatasetGroup &grp ) const;
238 
242  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshDatasetIndex &datasetIndex ) const;
243 
247  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshDatasetGroupMetadata::DataType type ) const;
248 
252  std::shared_ptr<QgsMeshMemoryDataset> canditateDataset( QgsMeshMemoryDatasetGroup &group,
253  int datasetIndex ) const;
254 
258  std::shared_ptr<const QgsMeshMemoryDataset> constCandidateDataset( const QgsMeshMemoryDatasetGroup &group,
259  int datasetIndex ) const;
260 
264  int datasetCount( const QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
265 
271  void activate( std::shared_ptr<QgsMeshMemoryDataset> dataset,
272  std::shared_ptr<const QgsMeshMemoryDataset> refDataset = nullptr ) const;
273 
275  void activate( QgsMeshMemoryDatasetGroup &group ) const;
276 
278  void populateSpatialFilter( QgsMeshMemoryDatasetGroup &filter, const QgsRectangle &extent ) const; // create a filter from extent
279 
281  void populateMaskFilter( QgsMeshMemoryDatasetGroup &filter, const QgsGeometry &mask ) const; // create a filter from mask
282 
284  void func1( QgsMeshMemoryDatasetGroup &group,
285  std::function<double( double )> func ) const;
286 
288  void func2( QgsMeshMemoryDatasetGroup &group1,
289  const QgsMeshMemoryDatasetGroup &group2,
290  std::function<double( double, double )> func ) const;
291 
293  void funcAggr( QgsMeshMemoryDatasetGroup &group1,
294  std::function<double( QVector<double>& )> func ) const;
295 
296  const QgsTriangularMesh *triangularMesh() const;
297  const QgsMesh *nativeMesh() const;
298  void updateMesh() const;
299 
300  QgsMeshLayer *mMeshLayer;
301  bool mIsValid;
304  QVector<double> mTimes;
305  QMap < QString, std::shared_ptr<QgsMeshMemoryDatasetGroup> > mDatasetGroupMap;
306 };
307 
309 
310 #endif // QGSMESHCALCUTILS_H
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
A representation of the interval between two datetime values.
Definition: qgsinterval.h:42
DataType
Location of where data is specified for datasets in the dataset group.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
Class that represents a dataset group stored in memory.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Triangular/Derived Mesh is mesh with vertices in map coordinates.
Mesh - vertices, edges and faces.