mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-03 00:02:25 -05:00
fix use of Mersenne Twister in normal raster alg
This commit is contained in:
parent
f3aa8af6b2
commit
e6c7728b1a
@ -113,13 +113,16 @@ bool QgsNormalRasterAlgorithm::prepareAlgorithm( const QVariantMap ¶meters,
|
||||
mMean = parameterAsDouble( parameters, QStringLiteral( "MEAN" ), context );
|
||||
mStdev = parameterAsDouble( parameters, QStringLiteral( "STDEV" ), context );
|
||||
|
||||
mNormalDoubleDistribution = std::normal_distribution<double>( mMean, mStdev );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariantMap QgsNormalRasterAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
|
||||
{
|
||||
std::random_device rd {};
|
||||
std::mt19937 mersenneTwister{rd()};
|
||||
|
||||
std::normal_distribution<double> normalDoubleDistribution = std::normal_distribution<double>( mMean, mStdev );
|
||||
|
||||
const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
|
||||
QFileInfo fi( outputFile );
|
||||
const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
|
||||
@ -157,7 +160,7 @@ QVariantMap QgsNormalRasterAlgorithm::processAlgorithm( const QVariantMap ¶m
|
||||
std::vector<float> float32Row( cols );
|
||||
for ( int col = 0; col < cols; col++ )
|
||||
{
|
||||
float32Row[col] = static_cast<float>( mNormalDoubleDistribution( mRandomDevice ) );
|
||||
float32Row[col] = static_cast<float>( normalDoubleDistribution( mersenneTwister ) );
|
||||
}
|
||||
block.setData( QByteArray( reinterpret_cast<const char *>( float32Row.data() ), QgsRasterBlock::typeSize( Qgis::Float32 ) * cols ) );
|
||||
break;
|
||||
@ -167,7 +170,7 @@ QVariantMap QgsNormalRasterAlgorithm::processAlgorithm( const QVariantMap ¶m
|
||||
std::vector<double> float64Row( cols );
|
||||
for ( int col = 0; col < cols; col++ )
|
||||
{
|
||||
float64Row[col] = mNormalDoubleDistribution( mRandomDevice );
|
||||
float64Row[col] = normalDoubleDistribution( mersenneTwister );
|
||||
}
|
||||
block.setData( QByteArray( reinterpret_cast<const char *>( float64Row.data() ), QgsRasterBlock::typeSize( Qgis::Float64 ) * cols ) );
|
||||
break;
|
||||
|
@ -56,13 +56,9 @@ class QgsNormalRasterAlgorithm : public QgsProcessingAlgorithm
|
||||
double mPixelSize;
|
||||
Qgis::DataType mRasterDataType;
|
||||
int mTypeId;
|
||||
std::random_device mRandomDevice;
|
||||
std::mt19937 mMersenneTwister;
|
||||
|
||||
double mMean;
|
||||
double mStdev;
|
||||
|
||||
std::normal_distribution<double> mNormalDoubleDistribution;
|
||||
};
|
||||
|
||||
///@endcond PRIVATE
|
||||
|
Loading…
x
Reference in New Issue
Block a user