QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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"
25#include "qgsapplication.h"
26#include "random"
27
29
30class 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:
42 virtual void addAlgorithmParams() = 0;
43
44 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
45
49 virtual Qgis::DataType getRasterDataType( int typeId ) = 0;
50 virtual bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) = 0;
51
55 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
56
60 virtual long generateRandomLongValue( std::mt19937 &mersenneTwister ) = 0;
61 virtual double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) = 0;
62
63 private:
64 QgsRectangle mExtent;
66 double mPixelSize = 0;
68};
69
70
71class QgsRandomUniformRasterAlgorithm : public QgsRandomRasterAlgorithmBase
72{
73 public:
74 QgsRandomUniformRasterAlgorithm() = default;
75 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomRaster.svg" ) ); }
76 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomRaster.svg" ) ); }
77 QString name() const override;
78 QString displayName() const override;
79 QStringList tags() const override;
80 QString shortHelpString() const override;
81 QgsRandomUniformRasterAlgorithm *createInstance() const override SIP_FACTORY;
82
83 protected:
84 void addAlgorithmParams() final;
85 Qgis::DataType getRasterDataType( int typeId ) final;
86 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
87 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
88 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
89
90 private:
91 double mRandomUpperBound = 0;
92 double mRandomLowerBound = 0;
93 std::uniform_int_distribution<long> mRandomUniformIntDistribution;
94 std::uniform_real_distribution<double> mRandomUniformDoubleDistribution;
95};
96
97class QgsRandomBinomialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
98{
99 public:
100 QgsRandomBinomialRasterAlgorithm() = default;
101 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
102 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomNormalRaster.svg" ) ); }
103 QString name() const override;
104 QString displayName() const override;
105 QStringList tags() const override;
106 QString shortHelpString() const override;
107 QgsRandomBinomialRasterAlgorithm *createInstance() const override SIP_FACTORY;
108
109 protected:
110 void addAlgorithmParams() final;
111 Qgis::DataType getRasterDataType( int typeId ) final;
112 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
113 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
114 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
115
116 private:
117 std::binomial_distribution<long> mRandombinomialDistribution;
118};
119
120class QgsRandomExponentialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
121{
122 public:
123 QgsRandomExponentialRasterAlgorithm() = default;
124 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
125 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
126 QString name() const override;
127 QString displayName() const override;
128 QStringList tags() const override;
129 QString shortHelpString() const override;
130 QgsRandomExponentialRasterAlgorithm *createInstance() const override SIP_FACTORY;
131
132 protected:
133 void addAlgorithmParams() final;
134 Qgis::DataType getRasterDataType( int typeId ) final;
135 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
136 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
137 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
138
139 private:
140 std::exponential_distribution<double> mRandomExponentialDistribution;
141};
142
143
144class QgsRandomGammaRasterAlgorithm : public QgsRandomRasterAlgorithmBase
145{
146 public:
147 QgsRandomGammaRasterAlgorithm() = default;
148 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomGammaRaster.svg" ) ); }
149 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomGammaRaster.svg" ) ); }
150 QString name() const override;
151 QString displayName() const override;
152 QStringList tags() const override;
153 QString shortHelpString() const override;
154 QgsRandomGammaRasterAlgorithm *createInstance() const override SIP_FACTORY;
155
156 protected:
157 void addAlgorithmParams() final;
158 Qgis::DataType getRasterDataType( int typeId ) final;
159 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
160 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
161 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
162
163 private:
164 std::gamma_distribution<double> mRandomGammaDistribution;
165};
166
167class QgsRandomGeometricRasterAlgorithm : public QgsRandomRasterAlgorithmBase
168{
169 public:
170 QgsRandomGeometricRasterAlgorithm() = default;
171 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
172 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
173 QString name() const override;
174 QString displayName() const override;
175 QStringList tags() const override;
176 QString shortHelpString() const override;
177 QgsRandomGeometricRasterAlgorithm *createInstance() const override SIP_FACTORY;
178
179 protected:
180 void addAlgorithmParams() override;
181 Qgis::DataType getRasterDataType( int typeId ) override;
182 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) override;
183 long generateRandomLongValue( std::mt19937 &mersenneTwister ) override;
184 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) override;
185
186 private:
187 std::geometric_distribution<long> mRandomGeometricDistribution;
188};
189
190
191class QgsRandomNegativeBinomialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
192{
193 public:
194 QgsRandomNegativeBinomialRasterAlgorithm() = default;
195 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
196 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
197 QString name() const override;
198 QString displayName() const override;
199 QStringList tags() const override;
200 QString shortHelpString() const override;
201 QgsRandomNegativeBinomialRasterAlgorithm *createInstance() const override SIP_FACTORY;
202
203 protected:
204 void addAlgorithmParams() final;
205 Qgis::DataType getRasterDataType( int typeId ) final;
206 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
207 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
208 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
209
210 private:
211 std::negative_binomial_distribution<long> mRandomNegativeBinomialDistribution;
212};
213
214class QgsRandomNormalRasterAlgorithm : public QgsRandomRasterAlgorithmBase
215{
216 public:
217 QgsRandomNormalRasterAlgorithm() = default;
218 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
219 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
220 QString name() const override;
221 QString displayName() const override;
222 QStringList tags() const override;
223 QString shortHelpString() const override;
224 QgsRandomNormalRasterAlgorithm *createInstance() const override SIP_FACTORY;
225
226 protected:
227 void addAlgorithmParams() final;
228 Qgis::DataType getRasterDataType( int typeId ) final;
229 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
230 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
231 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
232
233 private:
234 std::normal_distribution<double> mRandomNormalDistribution;
235};
236
237class QgsRandomPoissonRasterAlgorithm : public QgsRandomRasterAlgorithmBase
238{
239 public:
240 QgsRandomPoissonRasterAlgorithm() = default;
241 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomPoissonRaster.svg" ) ); }
242 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomPoissonRaster.svg" ) ); }
243 QString name() const override;
244 QString displayName() const override;
245 QStringList tags() const override;
246 QString shortHelpString() const override;
247 QgsRandomPoissonRasterAlgorithm *createInstance() const override SIP_FACTORY;
248
249 protected:
250 void addAlgorithmParams() final;
251 Qgis::DataType getRasterDataType( int typeId ) final;
252 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
253 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
254 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
255
256 private:
257 std::poisson_distribution<long> mRandomPoissonDistribution;
258};
259
260
262
263#endif // QGSRANDOMRASTERALGORITHM_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
DataType
Raster data types.
Definition qgis.h:351
@ UnknownDataType
Unknown or unspecified type.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
This class represents a coordinate reference system (CRS).
Abstract base class for processing algorithms.
virtual QString group() const
Returns the name of the group this algorithm belongs to.
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm to run using the specified parameters.
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
virtual QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0
Runs the algorithm using the specified parameters.
virtual void initAlgorithm(const QVariantMap &configuration=QVariantMap())=0
Initializes the algorithm using the specified configuration.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
A rectangle specified with double values.
#define SIP_FACTORY
Definition qgis_sip.h:76