QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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_analysis.h"
38 
39 struct QgsMeshMemoryDatasetGroup;
40 struct QgsMeshMemoryDataset;
41 
51 class ANALYSIS_EXPORT QgsMeshCalcUtils
52 {
53  public:
54 
65  QgsMeshCalcUtils( QgsMeshLayer *layer,
66  const QStringList &usedGroupNames,
67  double startTime,
68  double endTime );
69 
71  bool isValid() const;
72 
74  const QgsMeshLayer *layer() const;
75 
77  std::shared_ptr<const QgsMeshMemoryDatasetGroup> group( const QString &groupName ) const;
78 
80  void ones( QgsMeshMemoryDatasetGroup &group1 ) const;
81 
83  void nodata( QgsMeshMemoryDatasetGroup &group1 ) const;
84 
86  std::shared_ptr<QgsMeshMemoryDataset> number( double val, double time ) const;
87 
89  void copy( QgsMeshMemoryDatasetGroup &group1, const QString &groupName ) const;
90 
92  std::shared_ptr<QgsMeshMemoryDataset> copy( std::shared_ptr<const QgsMeshMemoryDataset> dataset0 ) const;
93 
95  void transferDatasets( QgsMeshMemoryDatasetGroup &group1, QgsMeshMemoryDatasetGroup &group2 ) const;
96 
98  void expand( QgsMeshMemoryDatasetGroup &group1,
99  const QgsMeshMemoryDatasetGroup &group2 ) const;
100 
102  void number( QgsMeshMemoryDatasetGroup &group1, double val ) const;
103 
105  void addIf( QgsMeshMemoryDatasetGroup &trueGroup,
106  const QgsMeshMemoryDatasetGroup &falseGroup,
107  const QgsMeshMemoryDatasetGroup &condition ) const;
108 
110  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsRectangle &extent ) const;
111 
113  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsGeometry &mask ) const;
114 
116  void logicalNot( QgsMeshMemoryDatasetGroup &group1 ) const;
117 
119  void changeSign( QgsMeshMemoryDatasetGroup &group1 ) const;
120 
122  void abs( QgsMeshMemoryDatasetGroup &group1 ) const;
123 
125  void sumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
126 
128  void minimumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
129 
131  void maximumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
132 
134  void averageAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
135 
137  void add( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
138 
140  void subtract( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
141 
143  void multiply( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
144 
146  void divide( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
147 
149  void power( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
150 
152  void equal( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
153 
155  void notEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
156 
158  void greaterThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
159 
161  void lesserThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
162 
164  void lesserEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
165 
167  void greaterEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
168 
170  void logicalAnd( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
171 
173  void logicalOr( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
174 
176  void minimum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
177 
179  void maximum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
180 
182  static QgsMeshDatasetGroupMetadata::DataType determineResultDataType( QgsMeshLayer *layer, const QStringList &usedGroupNames );
183 
185  QgsMeshDatasetGroupMetadata::DataType outputType() const;
186 
187  private:
188  double ffilter( double val1, double filter ) const;
189  double fadd( double val1, double val2 ) const;
190  double fsubtract( double val1, double val2 ) const;
191  double fmultiply( double val1, double val2 ) const;
192  double fdivide( double val1, double val2 ) const;
193  double fpower( double val1, double val2 ) const;
194  double fequal( double val1, double val2 ) const;
195  double fnotEqual( double val1, double val2 ) const;
196  double fgreaterThan( double val1, double val2 ) const;
197  double flesserThan( double val1, double val2 ) const;
198  double flesserEqual( double val1, double val2 ) const;
199  double fgreaterEqual( double val1, double val2 ) const;
200  double flogicalAnd( double val1, double val2 ) const;
201  double flogicalOr( double val1, double val2 ) const;
202  double flogicalNot( double val1 ) const;
203  double fchangeSign( double val1 ) const;
204  double fmin( double val1, double val2 ) const;
205  double fmax( double val1, double val2 ) const;
206  double fabs( double val1 ) const;
207  double fsumAggregated( QVector<double> &vals ) const;
208  double fminimumAggregated( QVector<double> &vals ) const;
209  double fmaximumAggregated( QVector<double> &vals ) const;
210  double faverageAggregated( QVector<double> &vals ) const;
211 
219  std::shared_ptr<QgsMeshMemoryDatasetGroup> create( const QString &datasetGroupName ) const;
220 
224  std::shared_ptr<QgsMeshMemoryDataset> create( const QgsMeshMemoryDatasetGroup &grp ) const;
225 
229  std::shared_ptr<QgsMeshMemoryDataset> create( const QgsMeshDatasetGroupMetadata::DataType type ) const;
230 
234  std::shared_ptr<QgsMeshMemoryDataset> canditateDataset( QgsMeshMemoryDatasetGroup &group,
235  int datasetIndex ) const;
236 
240  std::shared_ptr<const QgsMeshMemoryDataset> constCandidateDataset( const QgsMeshMemoryDatasetGroup &group,
241  int datasetIndex ) const;
242 
246  int datasetCount( const QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
247 
253  void activate( std::shared_ptr<QgsMeshMemoryDataset> dataset,
254  std::shared_ptr<const QgsMeshMemoryDataset> refDataset = nullptr ) const;
255 
257  void activate( QgsMeshMemoryDatasetGroup &group ) const;
258 
260  void populateSpatialFilter( QgsMeshMemoryDatasetGroup &filter, const QgsRectangle &extent ) const; // create a filter from extent
261 
263  void populateMaskFilter( QgsMeshMemoryDatasetGroup &filter, const QgsGeometry &mask ) const; // create a filter from mask
264 
266  void func1( QgsMeshMemoryDatasetGroup &group,
267  std::function<double( double )> func ) const;
268 
270  void func2( QgsMeshMemoryDatasetGroup &group1,
271  const QgsMeshMemoryDatasetGroup &group2,
272  std::function<double( double, double )> func ) const;
273 
275  void funcAggr( QgsMeshMemoryDatasetGroup &group1,
276  std::function<double( QVector<double>& )> func ) const;
277 
278  const QgsTriangularMesh *triangularMesh() const;
279  const QgsMesh *nativeMesh() const;
280  void updateMesh() const;
281 
282  QgsMeshLayer *mMeshLayer;
283  bool mIsValid;
285  QVector<double> mTimes;
287  QMap < QString, std::shared_ptr<QgsMeshMemoryDatasetGroup> > mDatasetGroupMap;
288 };
289 
291 
292 #endif // QGSMESHCALCUTILS_H
qgsrectangle.h
QgsMesh
Definition: qgsmeshdataprovider.h:57
QgsRectangle
Definition: qgsrectangle.h:41
QgsMeshLayer
Definition: qgsmeshlayer.h:94
qgsmeshlayer.h
QgsGeometry
Definition: qgsgeometry.h:122
QgsMeshDatasetGroupMetadata::DataType
DataType
Location of where data is specified for datasets in the dataset group.
Definition: qgsmeshdataset.h:353
QgsTriangularMesh
Definition: qgstriangularmesh.h:49
qgsmeshdataprovider.h