@@ -35,30 +35,17 @@ QgsRelief::QgsRelief( const QString &inputFile, const QString &outputFile, const
3535 : mInputFile( inputFile )
3636 , mOutputFile( outputFile )
3737 , mOutputFormat( outputFormat )
38- , mCellSizeX( 0.0 )
39- , mCellSizeY( 0.0 )
40- , mInputNodataValue( - 1 )
41- , mOutputNodataValue( - 1 )
42- , mZFactor( 1.0 )
38+ , mSlopeFilter( qgis::make_unique< QgsSlopeFilter >( inputFile, outputFile, outputFormat ) )
39+ , mAspectFilter( qgis::make_unique< QgsAspectFilter > ( inputFile, outputFile, outputFormat ) )
40+ , mHillshadeFilter285( qgis::make_unique< QgsHillshadeFilter >( inputFile, outputFile, outputFormat, 285 , 30 ) )
41+ , mHillshadeFilter300( qgis::make_unique< QgsHillshadeFilter >( inputFile, outputFile, outputFormat, 300 , 30 ) )
42+ , mHillshadeFilter315( qgis::make_unique< QgsHillshadeFilter >( inputFile, outputFile, outputFormat, 315 , 30 ) )
4343{
44- mSlopeFilter = new QgsSlopeFilter ( inputFile, outputFile, outputFormat );
45- mAspectFilter = new QgsAspectFilter ( inputFile, outputFile, outputFormat );
46- mHillshadeFilter285 = new QgsHillshadeFilter ( inputFile, outputFile, outputFormat, 285 , 30 );
47- mHillshadeFilter300 = new QgsHillshadeFilter ( inputFile, outputFile, outputFormat, 300 , 30 );
48- mHillshadeFilter315 = new QgsHillshadeFilter ( inputFile, outputFile, outputFormat, 315 , 30 );
49-
5044 /* mReliefColors = calculateOptimizedReliefClasses();
5145 setDefaultReliefColors();*/
5246}
5347
54- QgsRelief::~QgsRelief ()
55- {
56- delete mSlopeFilter ;
57- delete mAspectFilter ;
58- delete mHillshadeFilter285 ;
59- delete mHillshadeFilter300 ;
60- delete mHillshadeFilter315 ;
61- }
48+ QgsRelief::~QgsRelief () = default ;
6249
6350void QgsRelief::clearReliefColors ()
6451{
@@ -517,13 +504,8 @@ bool QgsRelief::exportFrequencyDistributionToCsv( const QString &file )
517504 // 2. go through raster cells and get frequency of classes
518505
519506 // store elevation frequency in 256 elevation classes
520- double frequency[252 ];
507+ double frequency[252 ] = { 0 } ;
521508 double frequencyClassRange = ( minMax[1 ] - minMax[0 ] ) / 252.0 ;
522- // initialize to zero
523- for ( int i = 0 ; i < 252 ; ++i )
524- {
525- frequency[i] = 0 ;
526- }
527509
528510 float *scanLine = ( float * ) CPLMalloc ( sizeof ( float ) * nCellsX );
529511 int elevationClass = -1 ;
@@ -603,13 +585,8 @@ QList< QgsRelief::ReliefColor > QgsRelief::calculateOptimizedReliefClasses()
603585 // 2. go through raster cells and get frequency of classes
604586
605587 // store elevation frequency in 256 elevation classes
606- double frequency[252 ];
588+ double frequency[252 ] = { 0 } ;
607589 double frequencyClassRange = ( minMax[1 ] - minMax[0 ] ) / 252.0 ;
608- // initialize to zero
609- for ( int i = 0 ; i < 252 ; ++i )
610- {
611- frequency[i] = 0 ;
612- }
613590
614591 float *scanLine = ( float * ) CPLMalloc ( sizeof ( float ) * nCellsX );
615592 int elevationClass = -1 ;
@@ -625,14 +602,7 @@ QList< QgsRelief::ReliefColor > QgsRelief::calculateOptimizedReliefClasses()
625602 for ( int j = 0 ; j < nCellsX; ++j )
626603 {
627604 elevationClass = frequencyClassForElevation ( scanLine[j], minMax[0 ], frequencyClassRange );
628- if ( elevationClass < 0 )
629- {
630- elevationClass = 0 ;
631- }
632- else if ( elevationClass >= 252 )
633- {
634- elevationClass = 251 ;
635- }
605+ elevationClass = std::max ( std::min ( elevationClass, 251 ), 0 );
636606 frequency[elevationClass] += 1.0 ;
637607 }
638608 }
0 commit comments