Skip to content

Commit

Permalink
Modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 9, 2018
1 parent cf72827 commit 4c9a23e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 49 deletions.
48 changes: 9 additions & 39 deletions src/analysis/raster/qgsrelief.cpp
Expand Up @@ -35,30 +35,17 @@ QgsRelief::QgsRelief( const QString &inputFile, const QString &outputFile, const
: mInputFile( inputFile )
, mOutputFile( outputFile )
, mOutputFormat( outputFormat )
, mCellSizeX( 0.0 )
, mCellSizeY( 0.0 )
, mInputNodataValue( -1 )
, mOutputNodataValue( -1 )
, mZFactor( 1.0 )
, mSlopeFilter( qgis::make_unique< QgsSlopeFilter >( inputFile, outputFile, outputFormat ) )
, mAspectFilter( qgis::make_unique< QgsAspectFilter > ( inputFile, outputFile, outputFormat ) )
, mHillshadeFilter285( qgis::make_unique< QgsHillshadeFilter >( inputFile, outputFile, outputFormat, 285, 30 ) )
, mHillshadeFilter300( qgis::make_unique< QgsHillshadeFilter >( inputFile, outputFile, outputFormat, 300, 30 ) )
, mHillshadeFilter315( qgis::make_unique< QgsHillshadeFilter >( inputFile, outputFile, outputFormat, 315, 30 ) )
{
mSlopeFilter = new QgsSlopeFilter( inputFile, outputFile, outputFormat );
mAspectFilter = new QgsAspectFilter( inputFile, outputFile, outputFormat );
mHillshadeFilter285 = new QgsHillshadeFilter( inputFile, outputFile, outputFormat, 285, 30 );
mHillshadeFilter300 = new QgsHillshadeFilter( inputFile, outputFile, outputFormat, 300, 30 );
mHillshadeFilter315 = new QgsHillshadeFilter( inputFile, outputFile, outputFormat, 315, 30 );

/*mReliefColors = calculateOptimizedReliefClasses();
setDefaultReliefColors();*/
}

QgsRelief::~QgsRelief()
{
delete mSlopeFilter;
delete mAspectFilter;
delete mHillshadeFilter285;
delete mHillshadeFilter300;
delete mHillshadeFilter315;
}
QgsRelief::~QgsRelief() = default;

void QgsRelief::clearReliefColors()
{
Expand Down Expand Up @@ -517,13 +504,8 @@ bool QgsRelief::exportFrequencyDistributionToCsv( const QString &file )
//2. go through raster cells and get frequency of classes

//store elevation frequency in 256 elevation classes
double frequency[252];
double frequency[252] = {0};
double frequencyClassRange = ( minMax[1] - minMax[0] ) / 252.0;
//initialize to zero
for ( int i = 0; i < 252; ++i )
{
frequency[i] = 0;
}

float *scanLine = ( float * ) CPLMalloc( sizeof( float ) * nCellsX );
int elevationClass = -1;
Expand Down Expand Up @@ -603,13 +585,8 @@ QList< QgsRelief::ReliefColor > QgsRelief::calculateOptimizedReliefClasses()
//2. go through raster cells and get frequency of classes

//store elevation frequency in 256 elevation classes
double frequency[252];
double frequency[252] = {0};
double frequencyClassRange = ( minMax[1] - minMax[0] ) / 252.0;
//initialize to zero
for ( int i = 0; i < 252; ++i )
{
frequency[i] = 0;
}

float *scanLine = ( float * ) CPLMalloc( sizeof( float ) * nCellsX );
int elevationClass = -1;
Expand All @@ -625,14 +602,7 @@ QList< QgsRelief::ReliefColor > QgsRelief::calculateOptimizedReliefClasses()
for ( int j = 0; j < nCellsX; ++j )
{
elevationClass = frequencyClassForElevation( scanLine[j], minMax[0], frequencyClassRange );
if ( elevationClass < 0 )
{
elevationClass = 0;
}
else if ( elevationClass >= 252 )
{
elevationClass = 251;
}
elevationClass = std::max( std::min( elevationClass, 251 ), 0 );
frequency[elevationClass] += 1.0;
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/analysis/raster/qgsrelief.h
Expand Up @@ -84,20 +84,20 @@ class ANALYSIS_EXPORT QgsRelief
QString mOutputFile;
QString mOutputFormat;

double mCellSizeX;
double mCellSizeY;
double mCellSizeX = 0.0;
double mCellSizeY = 0.0;
//! The nodata value of the input layer
float mInputNodataValue;
float mInputNodataValue = -1;
//! The nodata value of the output layer
float mOutputNodataValue;
float mOutputNodataValue = -1;

double mZFactor;
double mZFactor = 1;

QgsSlopeFilter *mSlopeFilter = nullptr;
QgsAspectFilter *mAspectFilter = nullptr;
QgsHillshadeFilter *mHillshadeFilter285 = nullptr;
QgsHillshadeFilter *mHillshadeFilter300 = nullptr;
QgsHillshadeFilter *mHillshadeFilter315 = nullptr;
std::unique_ptr< QgsSlopeFilter > mSlopeFilter;
std::unique_ptr< QgsAspectFilter > mAspectFilter;
std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter285;
std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter300;
std::unique_ptr< QgsHillshadeFilter > mHillshadeFilter315;

//relief colors and corresponding elevations
QList< ReliefColor > mReliefColors;
Expand Down

0 comments on commit 4c9a23e

Please sign in to comment.