25using namespace Qt::StringLiterals;
36 renderEdl( elevation, image, context );
38 if ( mRenderHillshading )
39 renderHillshading( elevation, image, context );
64 mRenderHillshading = active;
69 return mRenderHillshading;
74 return mHillshadingZFactor;
79 mHillshadingZFactor = zFactor;
84 return mHillshadingMultiDir;
89 mHillshadingMultiDir = multiDirectional;
94 return mLightAltitude;
104 return mLightAzimuth;
114 elem.setAttribute( u
"is-active"_s, mIsActive ? 1 : 0 );
116 elem.setAttribute( u
"combined-method"_s,
static_cast<int>( mCombinedElevationMethod ) );
118 elem.setAttribute( u
"edl-is-active"_s, mRenderEdl ? 1 : 0 );
119 elem.setAttribute( u
"edl-strength"_s,
qgsDoubleToString( mEyeDomeLightingStrength ) );
120 elem.setAttribute( u
"edl-distance"_s,
qgsDoubleToString( mEyeDomeLightingDistance ) );
121 elem.setAttribute( u
"edl-distance-unit"_s,
static_cast<int>( mEyeDomeLightingDistanceUnit ) );
123 elem.setAttribute( u
"hillshading-is-active"_s, mRenderHillshading ? 1 : 0 );
124 elem.setAttribute( u
"hillshading-z-factor"_s,
qgsDoubleToString( mHillshadingZFactor ) );
125 elem.setAttribute( u
"hillshading-is-multidirectional"_s, mHillshadingMultiDir ? 1 : 0 );
133 if ( element.hasAttribute( u
"is-active"_s ) )
134 mIsActive = element.attribute( u
"is-active"_s ).toInt() == 1;
136 if ( element.hasAttribute( u
"combined-method"_s ) )
139 if ( element.hasAttribute( u
"edl-is-active"_s ) )
140 mRenderEdl = element.attribute( u
"edl-is-active"_s ).toInt() == 1;
142 if ( element.hasAttribute( u
"edl-strength"_s ) )
143 mEyeDomeLightingStrength = element.attribute( u
"edl-strength"_s ).toDouble();
145 if ( element.hasAttribute( u
"edl-distance"_s ) )
146 mEyeDomeLightingDistance = element.attribute( u
"edl-distance"_s ).toDouble();
148 if ( element.hasAttribute( u
"edl-distance-unit"_s ) )
149 mEyeDomeLightingDistanceUnit =
static_cast<Qgis::RenderUnit>( element.attribute( u
"edl-distance-unit"_s ).toInt() );
151 if ( element.hasAttribute( u
"hillshading-is-active"_s ) )
152 mRenderHillshading = element.attribute( u
"hillshading-is-active"_s ).toInt() == 1;
154 if ( element.hasAttribute( u
"hillshading-z-factor"_s ) )
155 mHillshadingZFactor = element.attribute( u
"hillshading-z-factor"_s ).toDouble();
157 if ( element.hasAttribute( u
"hillshading-is-multidirectional"_s ) )
158 mHillshadingMultiDir = element.attribute( u
"hillshading-is-multidirectional"_s ).toInt() == 1;
160 if ( element.hasAttribute( u
"light-altitude"_s ) )
161 mLightAltitude = element.attribute( u
"light-altitude"_s ).toDouble();
163 if ( element.hasAttribute( u
"light-azimuth"_s ) )
164 mLightAzimuth = element.attribute( u
"light-azimuth"_s ).toDouble();
169 return mCombinedElevationMethod;
174 mCombinedElevationMethod = newCombinedElevationMethod;
179 return mEyeDomeLightingDistanceUnit;
184 mEyeDomeLightingDistanceUnit = newEyeDomeLightingDistanceUnit;
189 return mEyeDomeLightingDistance;
194 mEyeDomeLightingDistance = distance;
199 return mEyeDomeLightingStrength;
204 mEyeDomeLightingStrength = strength;
209 double strength = mEyeDomeLightingStrength;
210 double distanceDouble = context.
convertToPainterUnits( mEyeDomeLightingDistance, mEyeDomeLightingDistanceUnit );
211 int distance =
static_cast<int>( std::round( distanceDouble ) );
226 effPixelSize = pixelSize;
228 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.