QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
83  Q_DECL_DEPRECATED QgsMeshCalcUtils( QgsMeshLayer *layer,
84  const QStringList &usedGroupNames,
85  const QgsInterval &relativeTime );
86 
105  QgsMeshCalcUtils( QgsMeshLayer *layer,
106  const QStringList &usedGroupNames,
107  const QStringList &usedGroupNamesForAggregate,
108  const QgsInterval &relativeTime,
109  const QgsInterval &startTime,
110  const QgsInterval &endTime );
111 
112 
114  bool isValid() const;
115 
117  const QgsMeshLayer *layer() const;
118 
120  std::shared_ptr<const QgsMeshMemoryDatasetGroup> group( const QString &groupName ) const;
121 
123  void ones( QgsMeshMemoryDatasetGroup &group1 ) const;
124 
126  void nodata( QgsMeshMemoryDatasetGroup &group1 ) const;
127 
129  std::shared_ptr<QgsMeshMemoryDataset> number( double val, double time ) const;
130 
132  void copy( QgsMeshMemoryDatasetGroup &group1, const QString &groupName, bool forAggregate = false ) const;
133 
135  std::shared_ptr<QgsMeshMemoryDataset> copy( std::shared_ptr<const QgsMeshMemoryDataset> dataset0 ) const;
136 
138  void transferDatasets( QgsMeshMemoryDatasetGroup &group1, QgsMeshMemoryDatasetGroup &group2 ) const;
139 
141  void expand( QgsMeshMemoryDatasetGroup &group1,
142  const QgsMeshMemoryDatasetGroup &group2 ) const;
143 
145  void number( QgsMeshMemoryDatasetGroup &group1, double val ) const;
146 
148  void addIf( QgsMeshMemoryDatasetGroup &trueGroup,
149  const QgsMeshMemoryDatasetGroup &falseGroup,
150  const QgsMeshMemoryDatasetGroup &condition ) const;
151 
153  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsRectangle &extent ) const;
154 
156  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsGeometry &mask ) const;
157 
159  void logicalNot( QgsMeshMemoryDatasetGroup &group1 ) const;
160 
162  void changeSign( QgsMeshMemoryDatasetGroup &group1 ) const;
163 
165  void abs( QgsMeshMemoryDatasetGroup &group1 ) const;
166 
168  void sumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
169 
171  void minimumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
172 
174  void maximumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
175 
177  void averageAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
178 
180  void add( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
181 
183  void subtract( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
184 
186  void multiply( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
187 
189  void divide( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
190 
192  void power( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
193 
195  void equal( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
196 
198  void notEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
199 
201  void greaterThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
202 
204  void lesserThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
205 
207  void lesserEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
208 
210  void greaterEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
211 
213  void logicalAnd( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
214 
216  void logicalOr( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
217 
219  void minimum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
220 
222  void maximum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
223 
225  static QgsMeshDatasetGroupMetadata::DataType determineResultDataType( QgsMeshLayer *layer, const QStringList &usedGroupNames );
226 
228  QgsMeshDatasetGroupMetadata::DataType outputType() const;
229 
230  private:
231  double ffilter( double val1, double filter ) const;
232  double fadd( double val1, double val2 ) const;
233  double fsubtract( double val1, double val2 ) const;
234  double fmultiply( double val1, double val2 ) const;
235  double fdivide( double val1, double val2 ) const;
236  double fpower( double val1, double val2 ) const;
237  double fequal( double val1, double val2 ) const;
238  double fnotEqual( double val1, double val2 ) const;
239  double fgreaterThan( double val1, double val2 ) const;
240  double flesserThan( double val1, double val2 ) const;
241  double flesserEqual( double val1, double val2 ) const;
242  double fgreaterEqual( double val1, double val2 ) const;
243  double flogicalAnd( double val1, double val2 ) const;
244  double flogicalOr( double val1, double val2 ) const;
245  double flogicalNot( double val1 ) const;
246  double fchangeSign( double val1 ) const;
247  double fmin( double val1, double val2 ) const;
248  double fmax( double val1, double val2 ) const;
249  double fabs( double val1 ) const;
250  double fsumAggregated( QVector<double> &vals ) const;
251  double fminimumAggregated( QVector<double> &vals ) const;
252  double fmaximumAggregated( QVector<double> &vals ) const;
253  double faverageAggregated( QVector<double> &vals ) const;
254 
262  std::shared_ptr<QgsMeshMemoryDatasetGroup> createMemoryDatasetGroup( const QString &datasetGroupName,
263  const QgsInterval &relativeTime = QgsInterval(),
264  const QgsInterval &startTime = QgsInterval(),
265  const QgsInterval &endTime = QgsInterval() ) const;
266 
275  std::shared_ptr<const QgsMeshMemoryDatasetGroup> group( const QString &groupName, bool isAggregate ) const;
276 
280  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshMemoryDatasetGroup &grp ) const;
281 
285  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshDatasetIndex &datasetIndex ) const;
286 
290  std::shared_ptr<QgsMeshMemoryDataset> createMemoryDataset( const QgsMeshDatasetGroupMetadata::DataType type ) const;
291 
295  std::shared_ptr<QgsMeshMemoryDataset> canditateDataset( QgsMeshMemoryDatasetGroup &group,
296  int datasetIndex ) const;
297 
301  std::shared_ptr<const QgsMeshMemoryDataset> constCandidateDataset( const QgsMeshMemoryDatasetGroup &group,
302  int datasetIndex ) const;
303 
307  int datasetCount( const QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
308 
314  void activate( std::shared_ptr<QgsMeshMemoryDataset> dataset,
315  std::shared_ptr<const QgsMeshMemoryDataset> refDataset = nullptr ) const;
316 
318  void activate( QgsMeshMemoryDatasetGroup &group ) const;
319 
321  void populateSpatialFilter( QgsMeshMemoryDatasetGroup &filter, const QgsRectangle &extent ) const; // create a filter from extent
322 
324  void populateMaskFilter( QgsMeshMemoryDatasetGroup &filter, const QgsGeometry &mask ) const; // create a filter from mask
325 
327  void func1( QgsMeshMemoryDatasetGroup &group,
328  std::function<double( double )> func ) const;
329 
331  void func2( QgsMeshMemoryDatasetGroup &group1,
332  const QgsMeshMemoryDatasetGroup &group2,
333  std::function<double( double, double )> func ) const;
334 
336  void funcAggr( QgsMeshMemoryDatasetGroup &group1,
337  std::function<double( QVector<double>& )> func ) const;
338 
339  const QgsTriangularMesh *triangularMesh() const;
340  const QgsMesh *nativeMesh() const;
341  void updateMesh() const;
342 
343  QgsMeshLayer *mMeshLayer;
344  bool mIsValid;
347  QVector<double> mTimes;
348  QMap < QString, std::shared_ptr<QgsMeshMemoryDatasetGroup> > mDatasetGroupMap;
349  QMap < QString, std::shared_ptr<QgsMeshMemoryDatasetGroup> > mDatasetGroupMapForAggregate;
350 
351  bool mIgnoreTime = false; // with virtual datasetgroup, we only consider the current time step, except for aggregate function where we don't care about time value
352 };
353 
355 
356 #endif // QGSMESHCALCUTILS_H
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:125
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:97
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.