QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsmesh3dsymbol.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmesh3dsymbol.cpp
3 -------------------
4 Date : January 2019
5 Copyright : (C) 2019 by Peter Petrik
6 Email : zilolv at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsmesh3dsymbol.h"
17#include "qgs3dtypes.h"
18#include "qgs3dutils.h"
19#include "qgscolorutils.h"
21
23 : mMaterialSettings( std::make_unique< QgsPhongMaterialSettings >() )
24{
25
26}
27
29
31{
32 std::unique_ptr< QgsMesh3DSymbol > result = std::make_unique< QgsMesh3DSymbol >();
33
34 result->mAltClamping = mAltClamping;
35 result->mHeight = mHeight;
36 result->mMaterialSettings.reset( mMaterialSettings->clone() );
37 result->mAddBackFaces = mAddBackFaces;
38 result->mCullingMode = mCullingMode;
39 result->mEnabled = mEnabled;
40 result->mSmoothedTriangles = mSmoothedTriangles;
41 result->mWireframeEnabled = mWireframeEnabled;
42 result->mWireframeLineWidth = mWireframeLineWidth;
43 result->mWireframeLineColor = mWireframeLineColor;
44 result->mLevelOfDetailIndex = mLevelOfDetailIndex;
45 result->mVerticalScale = mVerticalScale;
46 result->mVerticalDatasetGroupIndex = mVerticalDatasetGroupIndex;
47 result->mIsVerticalMagnitudeRelative = mIsVerticalMagnitudeRelative;
48 result->mRenderingStyle = mRenderingStyle;
49 result->mColorRampShader = mColorRampShader;
50 result->mSingleColor = mSingleColor;
51 result->mArrowsEnabled = mArrowsEnabled;
52 result->mArrowsSpacing = mArrowsSpacing;
53 result->mArrowsFixedSize = mArrowsFixedSize;
54 result->mArrowsColor = mArrowsColor;
55 result->mMaximumTextureSize = mMaximumTextureSize;
56 copyBaseSettings( result.get() );
57 return result.release();
58}
59
60void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
61{
62 QDomDocument doc = elem.ownerDocument();
63
64 //Simple symbol
65 QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
66 elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
67 elemDataProperties.setAttribute( QStringLiteral( "height" ), mHeight );
68 elemDataProperties.setAttribute( QStringLiteral( "add-back-faces" ), mAddBackFaces ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
69 elem.appendChild( elemDataProperties );
70
71 QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
72 mMaterialSettings->writeXml( elemMaterial, context );
73 elem.appendChild( elemMaterial );
74
75 //Advanced symbol
76 QDomElement elemAdvancedSettings = doc.createElement( QStringLiteral( "advanced-settings" ) );
77 elemAdvancedSettings.setAttribute( QStringLiteral( "renderer-3d-enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
78 elemAdvancedSettings.setAttribute( QStringLiteral( "culling-mode" ), Qgs3DUtils::cullingModeToString( mCullingMode ) );
79 elemAdvancedSettings.setAttribute( QStringLiteral( "smoothed-triangle" ), mSmoothedTriangles ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
80 elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-enabled" ), mWireframeEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
81 elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-width" ), mWireframeLineWidth );
82 elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-color" ), QgsColorUtils::colorToString( mWireframeLineColor ) );
83 elemAdvancedSettings.setAttribute( QStringLiteral( "level-of-detail" ), mLevelOfDetailIndex );
84 elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-scale" ), mVerticalScale );
85 elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-group-index" ), mVerticalDatasetGroupIndex );
86 elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-relative" ), mIsVerticalMagnitudeRelative ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
87 elemAdvancedSettings.setAttribute( QStringLiteral( "texture-type" ), mRenderingStyle );
88 elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc, context ) );
89 elemAdvancedSettings.setAttribute( QStringLiteral( "min-color-ramp-shader" ), mColorRampShader.minimumValue() );
90 elemAdvancedSettings.setAttribute( QStringLiteral( "max-color-ramp-shader" ), mColorRampShader.maximumValue() );
91 elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsColorUtils::colorToString( mSingleColor ) );
92 elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-enabled" ), mArrowsEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
93 elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-spacing" ), mArrowsSpacing );
94 elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-fixed-size" ), mArrowsFixedSize ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
95 elem.appendChild( elemAdvancedSettings );
96
97 QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
99 elem.appendChild( elemDDP );
100}
101
102void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
103{
104 //Simple symbol
105 const QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
106 mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
107 mHeight = elemDataProperties.attribute( QStringLiteral( "height" ) ).toFloat();
108 mAddBackFaces = elemDataProperties.attribute( QStringLiteral( "add-back-faces" ) ).toInt();
109
110 const QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
111 mMaterialSettings->readXml( elemMaterial, context );
112
113 //Advanced symbol
114 const QDomElement elemAdvancedSettings = elem.firstChildElement( QStringLiteral( "advanced-settings" ) );
115 mEnabled = elemAdvancedSettings.attribute( QStringLiteral( "renderer-3d-enabled" ) ).toInt();
116 mCullingMode = Qgs3DUtils::cullingModeFromString( elemAdvancedSettings.attribute( QStringLiteral( "culling-mode" ), QStringLiteral( "back" ) ) );
117 mSmoothedTriangles = elemAdvancedSettings.attribute( QStringLiteral( "smoothed-triangle" ) ).toInt();
118 mWireframeEnabled = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-enabled" ) ).toInt();
119 mWireframeLineWidth = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-width" ) ).toDouble();
120 mWireframeLineColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-color" ) ) );
121 mLevelOfDetailIndex = elemAdvancedSettings.attribute( QStringLiteral( "level-of-detail" ) ).toInt();
122 mVerticalScale = elemAdvancedSettings.attribute( "vertical-scale" ).toDouble();
123 mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt();
124 mIsVerticalMagnitudeRelative = elemAdvancedSettings.attribute( "vertical-relative" ).toInt();
125 mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( QStringLiteral( "texture-type" ) ).toInt() );
126 mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ), context );
127 mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( QStringLiteral( "min-color-ramp-shader" ) ).toDouble() );
128 mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() );
129 mSingleColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) );
130 mArrowsEnabled = elemAdvancedSettings.attribute( QStringLiteral( "arrows-enabled" ) ).toInt();
131 if ( elemAdvancedSettings.hasAttribute( QStringLiteral( "arrows-spacing" ) ) )
132 mArrowsSpacing = elemAdvancedSettings.attribute( QStringLiteral( "arrows-spacing" ) ).toDouble();
133 mArrowsFixedSize = elemAdvancedSettings.attribute( QStringLiteral( "arrows-fixed-size" ) ).toInt();
134 const QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
135 if ( !elemDDP.isNull() )
137}
138
140{
141 return mSmoothedTriangles;
142}
143
144void QgsMesh3DSymbol::setSmoothedTriangles( bool smoothTriangles )
145{
146 mSmoothedTriangles = smoothTriangles;
147}
148
150{
151 return mWireframeEnabled;
152}
153
154void QgsMesh3DSymbol::setWireframeEnabled( bool wireframeEnabled )
155{
156 mWireframeEnabled = wireframeEnabled;
157}
158
160{
161 return mWireframeLineWidth;
162}
163
164void QgsMesh3DSymbol::setWireframeLineWidth( double wireframeLineWidth )
165{
166 mWireframeLineWidth = wireframeLineWidth;
167}
168
170{
171 return mWireframeLineColor;
172}
173
174void QgsMesh3DSymbol::setWireframeLineColor( const QColor &wireframeLineColor )
175{
176 mWireframeLineColor = wireframeLineColor;
177}
178
180{
181 return mVerticalScale;
182}
183
184void QgsMesh3DSymbol::setVerticalScale( double verticalScale )
185{
186 mVerticalScale = verticalScale;
187}
188
190{
191 return mColorRampShader;
192}
193
195{
196 mColorRampShader = colorRampShader;
197}
198
200{
201 return mSingleColor;
202}
203
204void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
205{
206 mSingleColor = color;
207}
208
210{
211 return mRenderingStyle;
212}
213
215{
216 mRenderingStyle = coloringType;
217}
218
220{
221 return mVerticalDatasetGroupIndex;
222}
223
224void QgsMesh3DSymbol::setVerticalDatasetGroupIndex( int verticalDatasetGroupIndex )
225{
226 mVerticalDatasetGroupIndex = verticalDatasetGroupIndex;
227}
228
230{
231 return mIsVerticalMagnitudeRelative;
232}
233
234void QgsMesh3DSymbol::setIsVerticalMagnitudeRelative( bool isVerticalScaleIsRelative )
235{
236 mIsVerticalMagnitudeRelative = isVerticalScaleIsRelative;
237}
238
240{
241 return mArrowsEnabled;
242}
243
244void QgsMesh3DSymbol::setArrowsEnabled( bool vectorEnabled )
245{
246 mArrowsEnabled = vectorEnabled;
247}
248
250{
251 return mArrowsSpacing;
252}
253
254void QgsMesh3DSymbol::setArrowsSpacing( double arrowsSpacing )
255{
256 mArrowsSpacing = arrowsSpacing;
257}
258
260{
261 return mMaximumTextureSize;
262}
263
264void QgsMesh3DSymbol::setMaximumTextureSize( int maximumTextureSize )
265{
266 mMaximumTextureSize = maximumTextureSize;
267}
268
270{
271 return mArrowsFixedSize;
272}
273
274void QgsMesh3DSymbol::setArrowsFixedSize( bool arrowsFixeSize )
275{
276 mArrowsFixedSize = arrowsFixeSize;
277}
278
280{
281 return mLevelOfDetailIndex;
282}
283
285{
286 mLevelOfDetailIndex = lod;
287}
288
290{
291 return mEnabled;
292}
293
294void QgsMesh3DSymbol::setEnabled( bool enabled )
295{
296 mEnabled = enabled;
297}
298
300{
301 return mCullingMode;
302}
303
305{
306 mCullingMode = mode;
307}
308
310{
311 return mMaterialSettings.get();
312}
313
315{
316 if ( materialSettings == mMaterialSettings.get() )
317 return;
318
319 mMaterialSettings.reset( materialSettings );
320}
CullingMode
Triangle culling mode.
Definition: qgs3dtypes.h:36
static Qgs3DTypes::CullingMode cullingModeFromString(const QString &str)
Converts a string to a value from CullingMode enum.
Definition: qgs3dutils.cpp:342
static Qgis::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:294
static QString cullingModeToString(Qgs3DTypes::CullingMode mode)
Converts a value from CullingMode enum to a string.
Definition: qgs3dutils.cpp:326
static QString altClampingToString(Qgis::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:279
virtual void copyBaseSettings(QgsAbstract3DSymbol *destination) const
Copies base class settings from this object to a destination object.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
QgsPropertyCollection mDataDefinedProperties
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes configuration to a new DOM element.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads configuration from the given DOM element.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
double arrowsSpacing() const
Returns the arrow spacing.
bool wireframeEnabled() const
Returns if the mesh wireframe.
void setWireframeLineColor(const QColor &wireframeLineColor)
Sets wireframe line color.
bool isVerticalMagnitudeRelative() const
Returns if the vertical component of the mesh is relative to the mesh vertices Z value.
void setWireframeEnabled(bool wireframeEnabled)
Sets if the mesh wireframe.
bool smoothedTriangles() const
Returns if mesh triangle are smoothed.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes symbol configuration to the given DOM element.
QgsAbstractMaterialSettings * materialSettings() const
Returns material settings used for shading of the symbol.
void setWireframeLineWidth(double wireframeLineWidth)
Sets wireframe line width.
QColor wireframeLineColor() const
Returns wireframe line color.
bool arrowsEnabled() const
Returns if arrows are enabled for 3D rendering.
void setIsVerticalMagnitudeRelative(bool isVerticalMagnitudeRelative)
Sets if the vertical component of the mesh is relative to the mesh vertices Z value.
void setMaterialSettings(QgsAbstractMaterialSettings *materialSettings SIP_TRANSFER)
Sets the material settings used for shading of the symbol.
void setLevelOfDetailIndex(int lod)
Returns the index of the level of detail of the mesh that is the position of the simplified mesh that...
void setArrowsSpacing(double arrowsSpacing)
Sets the arrow spacing.
void setCullingMode(const Qgs3DTypes::CullingMode &mode)
Sets culling mode.
double verticalScale() const
Returns mesh vertical scale.
void setVerticalDatasetGroupIndex(int verticalDatasetGroupIndex)
Sets the index of the dataset group that will be used to render the vertical component of the 3D mesh...
QgsMesh3DSymbol()
Constructor for QgsMesh3DSymbol.
void setArrowsFixedSize(bool arrowsFixedSize)
Sets if the arrow size is fixed.
Qgs3DTypes::CullingMode cullingMode() const
Returns culling mode.
int levelOfDetailIndex() const
Returns the index of the level of detail of the mesh that is the position of the simplified mesh that...
void setArrowsEnabled(bool arrowsEnabled)
Sets if arrows are enabled for 3D rendering.
void setVerticalScale(double verticalScale)
Sets mesh vertical scale.
QgsColorRampShader colorRampShader() const
Returns the color ramp shader used to render the color.
QgsMesh3DSymbol::RenderingStyle renderingStyle() const
Returns the rendering style.
void setSmoothedTriangles(bool smoothTriangles)
Sets if the mesh triangles have to been smoothed.
void setColorRampShader(const QgsColorRampShader &colorRampShader)
Sets the color ramp shader used to render the color.
bool arrowsFixedSize() const
Returns if the arrow size is fixed.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads symbol configuration from the given DOM element.
void setSingleMeshColor(const QColor &singleMeshColor)
Sets the single color.
QColor singleMeshColor() const
Returns the single color.
int verticalDatasetGroupIndex() const
Returns the index of the dataset group that will be used to render the vertical component of the 3D m...
void setRenderingStyle(const QgsMesh3DSymbol::RenderingStyle &textureType)
Sets the rendering style.
~QgsMesh3DSymbol() override
void setMaximumTextureSize(int maximumTextureSize)
Sets the maximum texture size supported by the hardware Used to store the GL_MAX_TEXTURE_SIZE value t...
bool isEnabled() const
Returns if the 3d rendering is enabled.
double wireframeLineWidth() const
Returns wireframe line width.
void setEnabled(bool enabled)
Sets if the 3d rendering is enabled.
QgsMesh3DSymbol * clone() const override SIP_FACTORY
Returns a new instance of the symbol with the same settings.
RenderingStyle
How to render the color of the mesh.
int maximumTextureSize() const
Returns the maximum texture size supported by the hardware Used to store the GL_MAX_TEXTURE_SIZE valu...
double maximumValue() const
Returns the minimum value for the raster shader.
virtual void setMaximumValue(double value)
Sets the maximum value for the raster shader.
virtual void setMinimumValue(double value)
Sets the minimum value for the raster shader.
double minimumValue() const
Returns the maximum value for the raster shader.
The class is used as a container of context for various read/write operations on other objects.