25using namespace Qt::StringLiterals;
37 renderEdl( elevation, image, context );
39 if ( mRenderHillshading )
40 renderHillshading( elevation, image, context );
65 mRenderHillshading = active;
70 return mRenderHillshading;
75 return mHillshadingZFactor;
80 mHillshadingZFactor = zFactor;
85 return mHillshadingMultiDir;
90 mHillshadingMultiDir = multiDirectional;
95 return mLightAltitude;
105 return mLightAzimuth;
115 elem.setAttribute( u
"is-active"_s, mIsActive ? 1 : 0 );
117 elem.setAttribute( u
"combined-method"_s,
static_cast<int>( mCombinedElevationMethod ) );
119 elem.setAttribute( u
"edl-is-active"_s, mRenderEdl ? 1 : 0 );
120 elem.setAttribute( u
"edl-strength"_s,
qgsDoubleToString( mEyeDomeLightingStrength ) );
121 elem.setAttribute( u
"edl-distance"_s,
qgsDoubleToString( mEyeDomeLightingDistance ) );
122 elem.setAttribute( u
"edl-distance-unit"_s,
static_cast<int>( mEyeDomeLightingDistanceUnit ) );
124 elem.setAttribute( u
"hillshading-is-active"_s, mRenderHillshading ? 1 : 0 );
125 elem.setAttribute( u
"hillshading-z-factor"_s,
qgsDoubleToString( mHillshadingZFactor ) );
126 elem.setAttribute( u
"hillshading-is-multidirectional"_s, mHillshadingMultiDir ? 1 : 0 );
134 if ( element.hasAttribute( u
"is-active"_s ) )
135 mIsActive = element.attribute( u
"is-active"_s ).toInt() == 1;
137 if ( element.hasAttribute( u
"combined-method"_s ) )
140 if ( element.hasAttribute( u
"edl-is-active"_s ) )
141 mRenderEdl = element.attribute( u
"edl-is-active"_s ).toInt() == 1;
143 if ( element.hasAttribute( u
"edl-strength"_s ) )
144 mEyeDomeLightingStrength = element.attribute( u
"edl-strength"_s ).toDouble();
146 if ( element.hasAttribute( u
"edl-distance"_s ) )
147 mEyeDomeLightingDistance = element.attribute( u
"edl-distance"_s ).toDouble();
149 if ( element.hasAttribute( u
"edl-distance-unit"_s ) )
150 mEyeDomeLightingDistanceUnit =
static_cast<Qgis::RenderUnit>( element.attribute( u
"edl-distance-unit"_s ).toInt() );
152 if ( element.hasAttribute( u
"hillshading-is-active"_s ) )
153 mRenderHillshading = element.attribute( u
"hillshading-is-active"_s ).toInt() == 1;
155 if ( element.hasAttribute( u
"hillshading-z-factor"_s ) )
156 mHillshadingZFactor = element.attribute( u
"hillshading-z-factor"_s ).toDouble();
158 if ( element.hasAttribute( u
"hillshading-is-multidirectional"_s ) )
159 mHillshadingMultiDir = element.attribute( u
"hillshading-is-multidirectional"_s ).toInt() == 1;
161 if ( element.hasAttribute( u
"light-altitude"_s ) )
162 mLightAltitude = element.attribute( u
"light-altitude"_s ).toDouble();
164 if ( element.hasAttribute( u
"light-azimuth"_s ) )
165 mLightAzimuth = element.attribute( u
"light-azimuth"_s ).toDouble();
170 return mCombinedElevationMethod;
175 mCombinedElevationMethod = newCombinedElevationMethod;
180 return mEyeDomeLightingDistanceUnit;
185 mEyeDomeLightingDistanceUnit = newEyeDomeLightingDistanceUnit;
190 return mEyeDomeLightingDistance;
195 mEyeDomeLightingDistance = distance;
200 return mEyeDomeLightingStrength;
205 mEyeDomeLightingStrength = strength;
210 double strength = mEyeDomeLightingStrength;
211 double distanceDouble = context.
convertToPainterUnits( mEyeDomeLightingDistance, mEyeDomeLightingDistanceUnit );
212 int distance =
static_cast<int>( std::round( distanceDouble ) );
227 effPixelSize = pixelSize;
229 elevation.
applyHillshading( image, mHillshadingMultiDir, mLightAltitude, mLightAzimuth, mHillshadingZFactor, effPixelSize, effPixelSize );
DistanceUnit
Units of distance.
@ Unknown
Unknown distance unit.
ElevationMapCombineMethod
Methods used to select the elevation when two elevation maps are combined.
RenderUnit
Rendering size units.
Qgis::DistanceUnit lengthUnits() const
Returns the units of distance for length calculations made by this object.
Stores a digital elevation model in a raster image which may get updated as a part of the map layer r...
void applyEyeDomeLighting(QImage &image, int distance, float strength, float rendererScale) const
Applies eye dome lighting effect to the given image.
QImage rawElevationImage() const
Returns raw elevation image with elevations encoded as color values.
void applyHillshading(QImage &image, bool multiDirectional, double altitude, double azimuth, double zFactor, double cellSizeX, double cellSizeY) const
Applies hill shading effect to the given image.
Qgis::ElevationMapCombineMethod combinedElevationMethod() const
Returns the method used when conbining different elevation sources.
bool isActiveHillshading() const
Returns whether the hillshading is active.
void setCombinedElevationMethod(Qgis::ElevationMapCombineMethod method)
Sets the method used when conbining different elevation sources.
bool isActive() const
Returns whether this shading renderer is active.
void setActive(bool active)
Sets whether this shading renderer is active.
double hillshadingZFactor() const
Returns the z factor used by the hill shading method.
QgsElevationShadingRenderer()
double eyeDomeLightingStrength() const
Returns the strength of the eye dome lighting method.
void setLightAzimuth(double lightAzimuth)
Sets the azimuth of the light (degree) that can be used by some methods (e.g.
double lightAltitude() const
Returns the altitude of the light (degree) that can be used by some methods (e.g.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes configuration on a DOM element.
void setHillshadingMultidirectional(bool multiDirectional)
Sets whether the hill shading method is multidirectional.
double eyeDomeLightingDistance() const
Returns the distance of the eye dome lighting method, that is the distance where the effect is apply ...
void setLightAltitude(double lightAltitude)
Sets the altitude of the light (degree) that can be used by some methods (e.g.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads configuration from a DOM element.
void renderShading(const QgsElevationMap &elevation, QImage &image, const QgsRenderContext &context) const
Render shading on image condidering the elevation map elevation and the renderer context context If e...
void setEyeDomeLightingStrength(double strength)
Sets the strength of the eye dome lighting method.
void setEyeDomeLightingDistanceUnit(Qgis::RenderUnit unit)
Sets the unit of the distance of the eye dome lighting method set by setEyeDomeLightingDistance().
void setActiveHillshading(bool active)
Sets active the hillshading.
bool isHillshadingMultidirectional() const
Returns whether the hill shading method is multidirectional.
void setHillshadingZFactor(double zFactor)
Sets the z factor used by the hill shading method.
bool isActiveEyeDomeLighting() const
Returns whether eye-dome lighting shading method is active.
void setEyeDomeLightingDistance(double distance)
Sets the distance of the eye dome lighting method, that is the distance where the effect is apply fro...
void setActiveEyeDomeLighting(bool active)
Sets active the eye-dome lighting shading method.
double lightAzimuth() const
Returns the azimuth of the light (degree) that can be used by some methods (e.g.
Qgis::RenderUnit eyeDomeLightingDistanceUnit() const
Returns the unit of the distance of the eye dome lighting method returned by eyeDomeLightingDistance(...
double mapUnitsPerPixel() const
Returns the current map units per pixel.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
const QgsDistanceArea & distanceArea() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
double rendererScale() const
Returns the renderer map scale.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.