QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
62  QgsMeshCalcUtils( QgsMeshLayer *layer,
63  const QStringList &usedGroupNames,
64  double startTime,
65  double endTime );
66 
68  bool isValid() const;
69 
71  const QgsMeshLayer *layer() const;
72 
74  std::shared_ptr<const QgsMeshMemoryDatasetGroup> group( const QString &groupName ) const;
75 
77  void ones( QgsMeshMemoryDatasetGroup &group1 ) const;
78 
80  void nodata( QgsMeshMemoryDatasetGroup &group1 ) const;
81 
83  std::shared_ptr<QgsMeshMemoryDataset> number( double val, double time ) const;
84 
86  void copy( QgsMeshMemoryDatasetGroup &group1, const QString &groupName ) const;
87 
89  std::shared_ptr<QgsMeshMemoryDataset> copy( std::shared_ptr<const QgsMeshMemoryDataset> dataset0 ) const;
90 
92  void transferDatasets( QgsMeshMemoryDatasetGroup &group1, QgsMeshMemoryDatasetGroup &group2 ) const;
93 
95  void expand( QgsMeshMemoryDatasetGroup &group1,
96  const QgsMeshMemoryDatasetGroup &group2 ) const;
97 
99  void number( QgsMeshMemoryDatasetGroup &group1, double val ) const;
100 
102  void addIf( QgsMeshMemoryDatasetGroup &trueGroup,
103  const QgsMeshMemoryDatasetGroup &falseGroup,
104  const QgsMeshMemoryDatasetGroup &condition ) const;
105 
107  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsRectangle &extent ) const;
108 
110  void filter( QgsMeshMemoryDatasetGroup &group1, const QgsGeometry &mask ) const;
111 
113  void logicalNot( QgsMeshMemoryDatasetGroup &group1 ) const;
114 
116  void changeSign( QgsMeshMemoryDatasetGroup &group1 ) const;
117 
119  void abs( QgsMeshMemoryDatasetGroup &group1 ) const;
120 
122  void sumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
123 
125  void minimumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
126 
128  void maximumAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
129 
131  void averageAggregated( QgsMeshMemoryDatasetGroup &group1 ) const;
132 
134  void add( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
135 
137  void subtract( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
138 
140  void multiply( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
141 
143  void divide( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
144 
146  void power( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
147 
149  void equal( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
150 
152  void notEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
153 
155  void greaterThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
156 
158  void lesserThan( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
159 
161  void lesserEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
162 
164  void greaterEqual( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
165 
167  void logicalAnd( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
168 
170  void logicalOr( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
171 
173  void minimum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
174 
176  void maximum( QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
177 
178  private:
179  double ffilter( double val1, double filter ) const;
180  double fadd( double val1, double val2 ) const;
181  double fsubtract( double val1, double val2 ) const;
182  double fmultiply( double val1, double val2 ) const;
183  double fdivide( double val1, double val2 ) const;
184  double fpower( double val1, double val2 ) const;
185  double fequal( double val1, double val2 ) const;
186  double fnotEqual( double val1, double val2 ) const;
187  double fgreaterThan( double val1, double val2 ) const;
188  double flesserThan( double val1, double val2 ) const;
189  double flesserEqual( double val1, double val2 ) const;
190  double fgreaterEqual( double val1, double val2 ) const;
191  double flogicalAnd( double val1, double val2 ) const;
192  double flogicalOr( double val1, double val2 ) const;
193  double flogicalNot( double val1 ) const;
194  double fchangeSign( double val1 ) const;
195  double fmin( double val1, double val2 ) const;
196  double fmax( double val1, double val2 ) const;
197  double fabs( double val1 ) const;
198  double fsumAggregated( QVector<double> &vals ) const;
199  double fminimumAggregated( QVector<double> &vals ) const;
200  double fmaximumAggregated( QVector<double> &vals ) const;
201  double faverageAggregated( QVector<double> &vals ) const;
202 
208  std::shared_ptr<QgsMeshMemoryDatasetGroup> create( const QString &datasetGroupName ) const;
209 
213  std::shared_ptr<QgsMeshMemoryDataset> create( const QgsMeshMemoryDatasetGroup &grp ) const;
214 
218  std::shared_ptr<QgsMeshMemoryDataset> create( const QgsMeshDatasetGroupMetadata::DataType type ) const;
219 
223  std::shared_ptr<QgsMeshMemoryDataset> canditateDataset( QgsMeshMemoryDatasetGroup &group,
224  int datasetIndex ) const;
225 
229  std::shared_ptr<const QgsMeshMemoryDataset> constCandidateDataset( const QgsMeshMemoryDatasetGroup &group,
230  int datasetIndex ) const;
231 
235  int datasetCount( const QgsMeshMemoryDatasetGroup &group1, const QgsMeshMemoryDatasetGroup &group2 ) const;
236 
242  void activate( std::shared_ptr<QgsMeshMemoryDataset> dataset,
243  std::shared_ptr<const QgsMeshMemoryDataset> refDataset = nullptr ) const;
244 
246  void activate( QgsMeshMemoryDatasetGroup &group ) const;
247 
249  void populateSpatialFilter( QgsMeshMemoryDatasetGroup &filter, const QgsRectangle &extent ) const; // create a filter from extent
250 
252  void populateMaskFilter( QgsMeshMemoryDatasetGroup &filter, const QgsGeometry &mask ) const; // create a filter from mask
253 
255  void func1( QgsMeshMemoryDatasetGroup &group,
256  std::function<double( double )> func ) const;
257 
259  void func2( QgsMeshMemoryDatasetGroup &group1,
260  const QgsMeshMemoryDatasetGroup &group2,
261  std::function<double( double, double )> func ) const;
262 
264  void funcAggr( QgsMeshMemoryDatasetGroup &group1,
265  std::function<double( QVector<double>& )> func ) const;
266 
267  const QgsTriangularMesh *triangularMesh() const;
268  const QgsMesh *nativeMesh() const;
269  void updateMesh() const;
270 
271  QgsMeshLayer *mMeshLayer;
272  bool mIsValid;
274  QVector<double> mTimes;
276  QMap < QString, std::shared_ptr<QgsMeshMemoryDatasetGroup> > mDatasetGroupMap;
277 };
278 
280 
281 #endif // QGSMESHCALCUTILS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Triangular/Derived Mesh is mesh with vertices in map coordinates.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
DataType
Location of where data is specified for datasets in the dataset group.
Mesh - vertices and faces.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:90