QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsalgorithmrandomraster.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsalgorithmrandomraster.h
3  ---------------------
4  begin : May 2020
5  copyright : (C) 2020 by Clemens Raffler
6  email : clemens dot raffler 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 QGSRANDOMRASTERALGORITHM_H
19 #define QGSRANDOMRASTERALGORITHM_H
20 
21 #define SIP_NO_FILE
22 
23 #include "qgis_sip.h"
24 #include "qgsprocessingalgorithm.h"
25 #include "qgsapplication.h"
26 #include "random"
27 
29 
30 class QgsRandomRasterAlgorithmBase : public QgsProcessingAlgorithm
31 {
32  public:
33  QString group() const final;
34  QString groupId() const final;
35  void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) final;
36 
37  protected:
38 
43  virtual void addAlgorithmParams() = 0;
44 
45  bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
46 
50  virtual Qgis::DataType getRasterDataType( int typeId ) = 0;
51  virtual bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) = 0;
52 
56  QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
57 
61  virtual long generateRandomLongValue( std::mt19937 &mersenneTwister ) = 0;
62  virtual double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) = 0;
63 
64  private:
65  QgsRectangle mExtent;
67  double mPixelSize;
68  Qgis::DataType mRasterDataType;
69 };
70 
71 
72 class QgsRandomUniformRasterAlgorithm : public QgsRandomRasterAlgorithmBase
73 {
74  public:
75  QgsRandomUniformRasterAlgorithm() = default;
76  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomRaster.svg" ) ); }
77  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomRaster.svg" ) ); }
78  QString name() const override;
79  QString displayName() const override;
80  QStringList tags() const override;
81  QString shortHelpString() const override;
82  QgsRandomUniformRasterAlgorithm *createInstance() const override SIP_FACTORY;
83 
84  protected:
85  void addAlgorithmParams() final;
86  Qgis::DataType getRasterDataType( int typeId ) final;
87  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
88  long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
89  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
90 
91  private:
92  double mRandomUpperBound;
93  double mRandomLowerBound;
94  std::uniform_int_distribution<long> mRandomUniformIntDistribution;
95  std::uniform_real_distribution<double> mRandomUniformDoubleDistribution;
96 };
97 
98 class QgsRandomBinomialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
99 {
100  public:
101  QgsRandomBinomialRasterAlgorithm() = default;
102  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
103  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomNormalRaster.svg" ) ); }
104  QString name() const override;
105  QString displayName() const override;
106  QStringList tags() const override;
107  QString shortHelpString() const override;
108  QgsRandomBinomialRasterAlgorithm *createInstance() const override SIP_FACTORY;
109 
110  protected:
111  void addAlgorithmParams() final;
112  Qgis::DataType getRasterDataType( int typeId ) final;
113  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
114  long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
115  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
116 
117  private:
118  std::binomial_distribution<long> mRandombinomialDistribution;
119 };
120 
121 class QgsRandomExponentialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
122 {
123  public:
124  QgsRandomExponentialRasterAlgorithm() = default;
125  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
126  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
127  QString name() const override;
128  QString displayName() const override;
129  QStringList tags() const override;
130  QString shortHelpString() const override;
131  QgsRandomExponentialRasterAlgorithm *createInstance() const override SIP_FACTORY;
132 
133  protected:
134  void addAlgorithmParams() final;
135  Qgis::DataType getRasterDataType( int typeId ) final;
136  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
137  long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
138  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
139 
140  private:
141  std::exponential_distribution<double> mRandomExponentialDistribution;
142 };
143 
144 
145 class QgsRandomGammaRasterAlgorithm : public QgsRandomRasterAlgorithmBase
146 {
147  public:
148  QgsRandomGammaRasterAlgorithm() = default;
149  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomGammaRaster.svg" ) ); }
150  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomGammaRaster.svg" ) ); }
151  QString name() const override;
152  QString displayName() const override;
153  QStringList tags() const override;
154  QString shortHelpString() const override;
155  QgsRandomGammaRasterAlgorithm *createInstance() const override SIP_FACTORY;
156 
157  protected:
158  void addAlgorithmParams() final;
159  Qgis::DataType getRasterDataType( int typeId ) final;
160  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
161  long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
162  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
163 
164  private:
165  std::gamma_distribution<double> mRandomGammaDistribution;
166 };
167 
168 class QgsRandomGeometricRasterAlgorithm : public QgsRandomRasterAlgorithmBase
169 {
170  public:
171  QgsRandomGeometricRasterAlgorithm() = default;
172  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
173  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
174  QString name() const override;
175  QString displayName() const override;
176  QStringList tags() const override;
177  QString shortHelpString() const override;
178  QgsRandomGeometricRasterAlgorithm *createInstance() const override SIP_FACTORY;
179 
180  protected:
181  void addAlgorithmParams() override;
182  Qgis::DataType getRasterDataType( int typeId ) override;
183  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) override;
184  long generateRandomLongValue( std::mt19937 &mersenneTwister ) override;
185  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) override;
186 
187  private:
188  std::geometric_distribution<long> mRandomGeometricDistribution;
189 };
190 
191 
192 class QgsRandomNegativeBinomialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
193 {
194  public:
195  QgsRandomNegativeBinomialRasterAlgorithm() = default;
196  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
197  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
198  QString name() const override;
199  QString displayName() const override;
200  QStringList tags() const override;
201  QString shortHelpString() const override;
202  QgsRandomNegativeBinomialRasterAlgorithm *createInstance() const override SIP_FACTORY;
203 
204  protected:
205  void addAlgorithmParams() final;
206  Qgis::DataType getRasterDataType( int typeId ) final;
207  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
208  long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
209  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
210 
211  private:
212  std::negative_binomial_distribution<long> mRandomNegativeBinomialDistribution;
213 };
214 
215 class QgsRandomNormalRasterAlgorithm : public QgsRandomRasterAlgorithmBase
216 {
217  public:
218  QgsRandomNormalRasterAlgorithm() = default;
219  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
220  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
221  QString name() const override;
222  QString displayName() const override;
223  QStringList tags() const override;
224  QString shortHelpString() const override;
225  QgsRandomNormalRasterAlgorithm *createInstance() const override SIP_FACTORY;
226 
227  protected:
228  void addAlgorithmParams() final;
229  Qgis::DataType getRasterDataType( int typeId ) final;
230  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
231  long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
232  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
233 
234  private:
235  std::normal_distribution<double> mRandomNormalDistribution;
236 };
237 
238 class QgsRandomPoissonRasterAlgorithm : public QgsRandomRasterAlgorithmBase
239 {
240  public:
241  QgsRandomPoissonRasterAlgorithm() = default;
242  QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomPoissonRaster.svg" ) ); }
243  QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomPoissonRaster.svg" ) ); }
244  QString name() const override;
245  QString displayName() const override;
246  QStringList tags() const override;
247  QString shortHelpString() const override;
248  QgsRandomPoissonRasterAlgorithm *createInstance() const override SIP_FACTORY;
249 
250  protected:
251  void addAlgorithmParams() final;
252  Qgis::DataType getRasterDataType( int typeId ) final;
253  bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
254  long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
255  double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
256 
257  private:
258  std::poisson_distribution<long> mRandomPoissonDistribution;
259 };
260 
261 
263 
264 #endif // QGSRANDOMRASTERALGORITHM_H
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:114
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:605
QgsProcessingFeedback
Definition: qgsprocessingfeedback.h:37
QgsProcessingAlgorithm::groupId
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:231
QgsProcessingAlgorithm::prepareAlgorithm
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Prepares the algorithm to run using the specified parameters.
Definition: qgsprocessingalgorithm.cpp:359
QgsApplication::iconPath
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Definition: qgsapplication.cpp:594
QgsRectangle
Definition: qgsrectangle.h:41
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgsapplication.h
QgsProcessingAlgorithm::processAlgorithm
virtual QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Runs the algorithm using the specified parameters.
QgsProcessingContext
Definition: qgsprocessingcontext.h:43
qgsprocessingalgorithm.h
qgis_sip.h
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsProcessingAlgorithm
Definition: qgsprocessingalgorithm.h:51
QgsProcessingAlgorithm::group
virtual QString group() const
Returns the name of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:222
Qgis
Definition: qgis.h:45
QgsProcessingAlgorithm::initAlgorithm
virtual void initAlgorithm(const QVariantMap &configuration=QVariantMap())=0
Initializes the algorithm using the specified configuration.