QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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
28
30{
31 std::unique_ptr<QgsMesh3DSymbol> result = std::make_unique<QgsMesh3DSymbol>();
32
33 result->mAltClamping = mAltClamping;
34 result->mHeight = mHeight;
35 result->mMaterialSettings.reset( mMaterialSettings->clone() );
36 result->mAddBackFaces = mAddBackFaces;
37 result->mCullingMode = mCullingMode;
38 result->mEnabled = mEnabled;
39 result->mSmoothedTriangles = mSmoothedTriangles;
40 result->mWireframeEnabled = mWireframeEnabled;
41 result->mWireframeLineWidth = mWireframeLineWidth;
42 result->mWireframeLineColor = mWireframeLineColor;
43 result->mLevelOfDetailIndex = mLevelOfDetailIndex;
44 result->mVerticalScale = mVerticalScale;
45 result->mVerticalDatasetGroupIndex = mVerticalDatasetGroupIndex;
46 result->mIsVerticalMagnitudeRelative = mIsVerticalMagnitudeRelative;
47 result->mRenderingStyle = mRenderingStyle;
48 result->mColorRampShader = mColorRampShader;
49 result->mSingleColor = mSingleColor;
50 result->mArrowsEnabled = mArrowsEnabled;
51 result->mArrowsSpacing = mArrowsSpacing;
52 result->mArrowsFixedSize = mArrowsFixedSize;
53 result->mArrowsColor = mArrowsColor;
54 result->mMaximumTextureSize = mMaximumTextureSize;
55 copyBaseSettings( result.get() );
56 return result.release();
57}
58
59void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
60{
61 QDomDocument doc = elem.ownerDocument();
62
63 //Simple symbol
64 QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
65 elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
66 elemDataProperties.setAttribute( QStringLiteral( "height" ), mHeight );
67 elemDataProperties.setAttribute( QStringLiteral( "add-back-faces" ), mAddBackFaces ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
68 elem.appendChild( elemDataProperties );
69
70 QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
71 mMaterialSettings->writeXml( elemMaterial, context );
72 elem.appendChild( elemMaterial );
73
74 //Advanced symbol
75 QDomElement elemAdvancedSettings = doc.createElement( QStringLiteral( "advanced-settings" ) );
76 elemAdvancedSettings.setAttribute( QStringLiteral( "renderer-3d-enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
77 elemAdvancedSettings.setAttribute( QStringLiteral( "culling-mode" ), Qgs3DUtils::cullingModeToString( mCullingMode ) );
78 elemAdvancedSettings.setAttribute( QStringLiteral( "smoothed-triangle" ), mSmoothedTriangles ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
79 elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-enabled" ), mWireframeEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
80 elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-width" ), mWireframeLineWidth );
81 elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-color" ), QgsColorUtils::colorToString( mWireframeLineColor ) );
82 elemAdvancedSettings.setAttribute( QStringLiteral( "level-of-detail" ), mLevelOfDetailIndex );
83 elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-scale" ), mVerticalScale );
84 elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-group-index" ), mVerticalDatasetGroupIndex );
85 elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-relative" ), mIsVerticalMagnitudeRelative ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
86 elemAdvancedSettings.setAttribute( QStringLiteral( "texture-type" ), static_cast<int>( mRenderingStyle ) );
87 elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc, context ) );
88 elemAdvancedSettings.setAttribute( QStringLiteral( "min-color-ramp-shader" ), mColorRampShader.minimumValue() );
89 elemAdvancedSettings.setAttribute( QStringLiteral( "max-color-ramp-shader" ), mColorRampShader.maximumValue() );
90 elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsColorUtils::colorToString( mSingleColor ) );
91 elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-enabled" ), mArrowsEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
92 elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-spacing" ), mArrowsSpacing );
93 elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-fixed-size" ), mArrowsFixedSize ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
94 elem.appendChild( elemAdvancedSettings );
95
96 QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
98 elem.appendChild( elemDDP );
99}
100
101void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
102{
103 //Simple symbol
104 const QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
105 mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
106 mHeight = elemDataProperties.attribute( QStringLiteral( "height" ) ).toFloat();
107 mAddBackFaces = elemDataProperties.attribute( QStringLiteral( "add-back-faces" ) ).toInt();
108
109 const QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
110 mMaterialSettings->readXml( elemMaterial, context );
111
112 //Advanced symbol
113 const QDomElement elemAdvancedSettings = elem.firstChildElement( QStringLiteral( "advanced-settings" ) );
114 mEnabled = elemAdvancedSettings.attribute( QStringLiteral( "renderer-3d-enabled" ) ).toInt();
115 mCullingMode = Qgs3DUtils::cullingModeFromString( elemAdvancedSettings.attribute( QStringLiteral( "culling-mode" ), QStringLiteral( "back" ) ) );
116 mSmoothedTriangles = elemAdvancedSettings.attribute( QStringLiteral( "smoothed-triangle" ) ).toInt();
117 mWireframeEnabled = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-enabled" ) ).toInt();
118 mWireframeLineWidth = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-width" ) ).toDouble();
119 mWireframeLineColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-color" ) ) );
120 mLevelOfDetailIndex = elemAdvancedSettings.attribute( QStringLiteral( "level-of-detail" ) ).toInt();
121 mVerticalScale = elemAdvancedSettings.attribute( "vertical-scale" ).toDouble();
122 mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt();
123 mIsVerticalMagnitudeRelative = elemAdvancedSettings.attribute( "vertical-relative" ).toInt();
124 mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( QStringLiteral( "texture-type" ) ).toInt() );
125 mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ), context );
126 mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( QStringLiteral( "min-color-ramp-shader" ) ).toDouble() );
127 mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() );
128 mSingleColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) );
129 mArrowsEnabled = elemAdvancedSettings.attribute( QStringLiteral( "arrows-enabled" ) ).toInt();
130 if ( elemAdvancedSettings.hasAttribute( QStringLiteral( "arrows-spacing" ) ) )
131 mArrowsSpacing = elemAdvancedSettings.attribute( QStringLiteral( "arrows-spacing" ) ).toDouble();
132 mArrowsFixedSize = elemAdvancedSettings.attribute( QStringLiteral( "arrows-fixed-size" ) ).toInt();
133 const QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
134 if ( !elemDDP.isNull() )
136}
137
139{
140 return mSmoothedTriangles;
141}
142
143void QgsMesh3DSymbol::setSmoothedTriangles( bool smoothTriangles )
144{
145 mSmoothedTriangles = smoothTriangles;
146}
147
149{
150 return mWireframeEnabled;
151}
152
153void QgsMesh3DSymbol::setWireframeEnabled( bool wireframeEnabled )
154{
155 mWireframeEnabled = wireframeEnabled;
156}
157
159{
160 return mWireframeLineWidth;
161}
162
163void QgsMesh3DSymbol::setWireframeLineWidth( double wireframeLineWidth )
164{
165 mWireframeLineWidth = wireframeLineWidth;
166}
167
169{
170 return mWireframeLineColor;
171}
172
173void QgsMesh3DSymbol::setWireframeLineColor( const QColor &wireframeLineColor )
174{
175 mWireframeLineColor = wireframeLineColor;
176}
177
179{
180 return mVerticalScale;
181}
182
183void QgsMesh3DSymbol::setVerticalScale( double verticalScale )
184{
185 mVerticalScale = verticalScale;
186}
187
189{
190 return mColorRampShader;
191}
192
194{
195 mColorRampShader = colorRampShader;
196}
197
199{
200 return mSingleColor;
201}
202
203void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
204{
205 mSingleColor = color;
206}
207
209{
210 return mRenderingStyle;
211}
212
214{
215 mRenderingStyle = coloringType;
216}
217
219{
220 return mVerticalDatasetGroupIndex;
221}
222
223void QgsMesh3DSymbol::setVerticalDatasetGroupIndex( int verticalDatasetGroupIndex )
224{
225 mVerticalDatasetGroupIndex = verticalDatasetGroupIndex;
226}
227
229{
230 return mIsVerticalMagnitudeRelative;
231}
232
233void QgsMesh3DSymbol::setIsVerticalMagnitudeRelative( bool isVerticalScaleIsRelative )
234{
235 mIsVerticalMagnitudeRelative = isVerticalScaleIsRelative;
236}
237
239{
240 return mArrowsEnabled;
241}
242
243void QgsMesh3DSymbol::setArrowsEnabled( bool vectorEnabled )
244{
245 mArrowsEnabled = vectorEnabled;
246}
247
249{
250 return mArrowsSpacing;
251}
252
253void QgsMesh3DSymbol::setArrowsSpacing( double arrowsSpacing )
254{
255 mArrowsSpacing = arrowsSpacing;
256}
257
259{
260 return mMaximumTextureSize;
261}
262
263void QgsMesh3DSymbol::setMaximumTextureSize( int maximumTextureSize )
264{
265 mMaximumTextureSize = maximumTextureSize;
266}
267
269{
270 return mArrowsFixedSize;
271}
272
273void QgsMesh3DSymbol::setArrowsFixedSize( bool arrowsFixeSize )
274{
275 mArrowsFixedSize = arrowsFixeSize;
276}
277
279{
280 return mLevelOfDetailIndex;
281}
282
284{
285 mLevelOfDetailIndex = lod;
286}
287
289{
290 if ( mAltClamping != other.mAltClamping
291 || mHeight != other.mHeight
292 || mAddBackFaces != other.mAddBackFaces
293 || mEnabled != other.mEnabled
294 || mCullingMode != other.mCullingMode
295 || mSmoothedTriangles != other.mSmoothedTriangles
296 || mWireframeEnabled != other.mWireframeEnabled
297 || !qgsDoubleNear( mWireframeLineWidth, other.mWireframeLineWidth )
298 || mWireframeLineColor != other.mWireframeLineColor
299 || mLevelOfDetailIndex != other.mLevelOfDetailIndex
300 || !qgsDoubleNear( mVerticalScale, other.mVerticalScale )
301 || mVerticalDatasetGroupIndex != other.mVerticalDatasetGroupIndex
302 || mIsVerticalMagnitudeRelative != other.mIsVerticalMagnitudeRelative
303 || mRenderingStyle != other.mRenderingStyle
304 || mColorRampShader != other.mColorRampShader
305 || mSingleColor != other.mSingleColor
306 || mArrowsEnabled != other.mArrowsEnabled
307 || !qgsDoubleNear( mArrowsSpacing, other.mArrowsSpacing )
308 || mArrowsFixedSize != other.mArrowsFixedSize
309 || mArrowsColor != other.mArrowsColor
310 || mMaximumTextureSize != other.mMaximumTextureSize )
311 return false;
312
313 if ( !mMaterialSettings->equals( other.materialSettings() ) )
314 return false;
315
316 // base class properties
318 return false;
319
320 return true;
321}
322
324{
325 return !( *this == other );
326}
327
329{
330 return mEnabled;
331}
332
333void QgsMesh3DSymbol::setEnabled( bool enabled )
334{
335 mEnabled = enabled;
336}
337
339{
340 return mCullingMode;
341}
342
344{
345 mCullingMode = mode;
346}
347
349{
350 return mMaterialSettings.get();
351}
352
354{
355 if ( materialSettings == mMaterialSettings.get() )
356 return;
357
358 mMaterialSettings.reset( materialSettings );
359}
CullingMode
Triangle culling mode.
Definition qgs3dtypes.h:35
static Qgs3DTypes::CullingMode cullingModeFromString(const QString &str)
Converts a string to a value from CullingMode enum.
static Qgis::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
static QString cullingModeToString(Qgs3DTypes::CullingMode mode)
Converts a value from CullingMode enum to a string.
static QString altClampingToString(Qgis::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
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...
bool operator==(const QgsMesh3DSymbol &other) const
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.
bool operator!=(const QgsMesh3DSymbol &other) const
QColor singleMeshColor() const
Returns the single color.
RenderingStyle
How to render the color of the mesh.
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.
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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6024