Skip to content

Commit 4c9a23e

Browse files
committedAug 9, 2018
Modernize code
1 parent cf72827 commit 4c9a23e

File tree

2 files changed

+19
-49
lines changed

2 files changed

+19
-49
lines changed
 

‎src/analysis/raster/qgsrelief.cpp

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6350
void 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
}

‎src/analysis/raster/qgsrelief.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ class ANALYSIS_EXPORT QgsRelief
8484
QString mOutputFile;
8585
QString mOutputFormat;
8686

87-
double mCellSizeX;
88-
double mCellSizeY;
87+
double mCellSizeX = 0.0;
88+
double mCellSizeY = 0.0;
8989
//! The nodata value of the input layer
90-
float mInputNodataValue;
90+
float mInputNodataValue = -1;
9191
//! The nodata value of the output layer
92-
float mOutputNodataValue;
92+
float mOutputNodataValue = -1;
9393

94-
double mZFactor;
94+
double mZFactor = 1;
9595

96-
QgsSlopeFilter *mSlopeFilter = nullptr;
97-
QgsAspectFilter *mAspectFilter = nullptr;
98-
QgsHillshadeFilter *mHillshadeFilter285 = nullptr;
99-
QgsHillshadeFilter *mHillshadeFilter300 = nullptr;
100-
QgsHillshadeFilter *mHillshadeFilter315 = nullptr;
96+
std::unique_ptr< QgsSlopeFilter > mSlopeFilter;
97+
std::unique_ptr< QgsAspectFilter > mAspectFilter;
98+
std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter285;
99+
std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter300;
100+
std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter315;
101101

102102
//relief colors and corresponding elevations
103103
QList< ReliefColor > mReliefColors;

0 commit comments

Comments
 (0)
Please sign in to comment.