2121QgsHillshadeFilter::QgsHillshadeFilter ( const QString &inputFile, const QString &outputFile, const QString &outputFormat, double lightAzimuth,
2222 double lightAngle )
2323 : QgsDerivativeFilter( inputFile, outputFile, outputFormat )
24+ <<<<<<< 573283f0dcf022e84bd615e84fd2656043a9722b
2425 , mLightAzimuth( static_cast <float >( lightAzimuth ) )
2526 , mLightAngle( static_cast <float >( lightAngle ) )
2627 , mCosZenithRad( std::cos( static_cast <float >( lightAngle * M_PI ) / 180.0f ) )
2728 , mSinZenithRad( std::sin( static_cast <float >( lightAngle * M_PI ) / 180.0f ) )
2829 , mAzimuthRad( static_cast <float >( lightAzimuth * M_PI ) / 180.0f )
30+ =======
31+ , mLightAzimuth( lightAzimuth )
32+ , mLightAngle( lightAngle )
33+ , mCosZenithRad( std::cos( mLightAngle * M_PI / 180.0 ) )
34+ , mSinZenithRad( std::sin( mLightAngle * M_PI / 180.0 ) )
35+ , mAzimuthRad( mLightAzimuth * M_PI / 180.0 )
36+ >>>>>>> [opencl] Fix small OpenCL alg issues
2937{
3038}
3139
@@ -46,12 +54,17 @@ float QgsHillshadeFilter::processNineCellWindow( float *x11, float *x21, float *
4654 float aspect_rad = 0 ;
4755 if ( derX == 0 && derY == 0 ) // aspect undefined, take a neutral value. Better solutions?
4856 {
57+ <<<<<<< 573283f0dcf022e84bd615e84fd2656043a9722b
4958 aspect_rad = mAzimuthRad / 2 .0f ;
59+ =======
60+ aspect_rad = mAzimuthRad / 2.0 ;
61+ >>>>>>> [opencl] Fix small OpenCL alg issues
5062 }
5163 else
5264 {
5365 aspect_rad = M_PI + std::atan2 ( derX, derY );
5466 }
67+ <<<<<<< 573283f0dcf022e84bd615e84fd2656043a9722b
5568 return std::max ( 0 .0f , 255 .0f * ( ( mCosZenithRad * std::cos ( slope_rad ) ) +
5669 ( mSinZenithRad * std::sin ( slope_rad ) *
5770 std::cos ( mAzimuthRad - aspect_rad ) ) ) );
@@ -84,23 +97,34 @@ void QgsHillshadeFilter::addExtraRasterParams( std::vector<float> ¶ms )
8497
8598#endif
8699=======
100+ =======
101+ return std::max( 0.0 , 255.0 * ( ( mCosZenithRad * std::cos ( slope_rad ) ) +
102+ ( mSinZenithRad * std::sin ( slope_rad ) *
103+ std::cos( mAzimuthRad - aspect_rad ) ) ) );
104+ }
105+
106+ #ifdef HAVE_OPENCL
107+
108+ >>>>>>> [opencl] Fix small OpenCL alg issues
87109void QgsHillshadeFilter::addExtraRasterParams ( std::vector<float > ¶ms )
88110{
89- float azimuthRad = -1 * mLightAzimuth * M_PI / 180.0 ;
90- float zenithRad = std::max ( 0 .0f , 90 .0f - mLightAngle ) * M_PI / 180.0 ;
91- float cosZenithRad = std::cos ( zenithRad );
92- float cos_az_mul_cos_alt_mul_z = std::cos ( azimuthRad ) * cosZenithRad * mZFactor ;
93- float sin_az_mul_cos_alt_mul_z = std::sin ( azimuthRad ) * cosZenithRad * mZFactor ;
94- float cos_az_mul_cos_alt_mul_z_mul_254 = 254.0 * cos_az_mul_cos_alt_mul_z;
95- float sin_az_mul_cos_alt_mul_z_mul_254 = 254.0 * sin_az_mul_cos_alt_mul_z;
96- float square_z = mZFactor * mZFactor ;
97- float sin_altRadians_mul_254 = 254.0 * std::sin ( zenithRad );
98-
99- // For fast formula from GDAL DEM
100- params.push_back ( cos_az_mul_cos_alt_mul_z_mul_254 ); // 5
101- params.push_back ( sin_az_mul_cos_alt_mul_z_mul_254 ); // 6
102- params.push_back ( square_z ); // 7
103- params.push_back ( sin_altRadians_mul_254 ); // 8
111+
112+ // Original CPU formula
113+ float zenith_rad = mLightAngle * M_PI / 180.0 ;
114+ float azimuth_rad = mLightAzimuth * M_PI / 180.0 ;
115+ params.push_back ( zenith_rad ); // 5
116+ params.push_back ( azimuth_rad ); // 6
117+
118+ /*
119+ params.push_back( std::cos( mLightAngle * M_PI / 180.0 ) ); // cos_zenith_rad 5
120+ params.push_back( mLightAzimuth * M_PI / 180.0 ); // azimuth_rad 6
121+ params.push_back( std::sin( mLightAzimuth * M_PI / 180.0 ) ); // sin_zenith_rad 7
122+ */
104123
105124}
125+ <<<<<<< 573283f0dcf022e84bd615e84fd2656043a9722b
106126>>>>>>> [opencl] Use fast formula for hillshade
127+ =======
128+
129+ #endif
130+ >>>>>>> [opencl] Fix small OpenCL alg issues
0 commit comments