QGIS API Documentation 3.99.0-Master (357b655ed83)
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
18#include "qgs3dtypes.h"
19#include "qgs3dutils.h"
20#include "qgscolorutils.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
28 : mMaterialSettings( std::make_unique<QgsPhongMaterialSettings>() )
29{
30}
31
33
35{
36 auto result = std::make_unique<QgsMesh3DSymbol>();
37
38 result->mAltClamping = mAltClamping;
39 result->mHeight = mHeight;
40 result->mMaterialSettings.reset( mMaterialSettings->clone() );
41 result->mAddBackFaces = mAddBackFaces;
42 result->mCullingMode = mCullingMode;
43 result->mEnabled = mEnabled;
44 result->mSmoothedTriangles = mSmoothedTriangles;
45 result->mWireframeEnabled = mWireframeEnabled;
46 result->mWireframeLineWidth = mWireframeLineWidth;
47 result->mWireframeLineColor = mWireframeLineColor;
48 result->mLevelOfDetailIndex = mLevelOfDetailIndex;
49 result->mVerticalScale = mVerticalScale;
50 result->mVerticalDatasetGroupIndex = mVerticalDatasetGroupIndex;
51 result->mIsVerticalMagnitudeRelative = mIsVerticalMagnitudeRelative;
52 result->mRenderingStyle = mRenderingStyle;
53 result->mColorRampShader = mColorRampShader;
54 result->mSingleColor = mSingleColor;
55 result->mArrowsEnabled = mArrowsEnabled;
56 result->mArrowsSpacing = mArrowsSpacing;
57 result->mArrowsFixedSize = mArrowsFixedSize;
58 result->mArrowsColor = mArrowsColor;
59 result->mMaximumTextureSize = mMaximumTextureSize;
60 copyBaseSettings( result.get() );
61 return result.release();
62}
63
64void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
65{
66 QDomDocument doc = elem.ownerDocument();
67
68 //Simple symbol
69 QDomElement elemDataProperties = doc.createElement( u"data"_s );
70 elemDataProperties.setAttribute( u"alt-clamping"_s, Qgs3DUtils::altClampingToString( mAltClamping ) );
71 elemDataProperties.setAttribute( u"height"_s, mHeight );
72 elemDataProperties.setAttribute( u"add-back-faces"_s, mAddBackFaces ? u"1"_s : u"0"_s );
73 elem.appendChild( elemDataProperties );
74
75 QDomElement elemMaterial = doc.createElement( u"material"_s );
76 mMaterialSettings->writeXml( elemMaterial, context );
77 elem.appendChild( elemMaterial );
78
79 //Advanced symbol
80 QDomElement elemAdvancedSettings = doc.createElement( u"advanced-settings"_s );
81 elemAdvancedSettings.setAttribute( u"renderer-3d-enabled"_s, mEnabled ? u"1"_s : u"0"_s );
82 elemAdvancedSettings.setAttribute( u"culling-mode"_s, Qgs3DUtils::cullingModeToString( mCullingMode ) );
83 elemAdvancedSettings.setAttribute( u"smoothed-triangle"_s, mSmoothedTriangles ? u"1"_s : u"0"_s );
84 elemAdvancedSettings.setAttribute( u"wireframe-enabled"_s, mWireframeEnabled ? u"1"_s : u"0"_s );
85 elemAdvancedSettings.setAttribute( u"wireframe-line-width"_s, mWireframeLineWidth );
86 elemAdvancedSettings.setAttribute( u"wireframe-line-color"_s, QgsColorUtils::colorToString( mWireframeLineColor ) );
87 elemAdvancedSettings.setAttribute( u"level-of-detail"_s, mLevelOfDetailIndex );
88 elemAdvancedSettings.setAttribute( u"vertical-scale"_s, mVerticalScale );
89 elemAdvancedSettings.setAttribute( u"vertical-group-index"_s, mVerticalDatasetGroupIndex );
90 elemAdvancedSettings.setAttribute( u"vertical-relative"_s, mIsVerticalMagnitudeRelative ? u"1"_s : u"0"_s );
91 elemAdvancedSettings.setAttribute( u"texture-type"_s, static_cast<int>( mRenderingStyle ) );
92 elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc, context ) );
93 elemAdvancedSettings.setAttribute( u"min-color-ramp-shader"_s, mColorRampShader.minimumValue() );
94 elemAdvancedSettings.setAttribute( u"max-color-ramp-shader"_s, mColorRampShader.maximumValue() );
95 elemAdvancedSettings.setAttribute( u"texture-single-color"_s, QgsColorUtils::colorToString( mSingleColor ) );
96 elemAdvancedSettings.setAttribute( u"arrows-enabled"_s, mArrowsEnabled ? u"1"_s : u"0"_s );
97 elemAdvancedSettings.setAttribute( u"arrows-spacing"_s, mArrowsSpacing );
98 elemAdvancedSettings.setAttribute( u"arrows-fixed-size"_s, mArrowsFixedSize ? u"1"_s : u"0"_s );
99 elem.appendChild( elemAdvancedSettings );
100
101 QDomElement elemDDP = doc.createElement( u"data-defined-properties"_s );
102 mDataDefinedProperties.writeXml( elemDDP, propertyDefinitions() );
103 elem.appendChild( elemDDP );
104}
105
106void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
107{
108 //Simple symbol
109 const QDomElement elemDataProperties = elem.firstChildElement( u"data"_s );
110 mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( u"alt-clamping"_s ) );
111 mHeight = elemDataProperties.attribute( u"height"_s ).toFloat();
112 mAddBackFaces = elemDataProperties.attribute( u"add-back-faces"_s ).toInt();
113
114 const QDomElement elemMaterial = elem.firstChildElement( u"material"_s );
115 mMaterialSettings->readXml( elemMaterial, context );
116
117 //Advanced symbol
118 const QDomElement elemAdvancedSettings = elem.firstChildElement( u"advanced-settings"_s );
119 mEnabled = elemAdvancedSettings.attribute( u"renderer-3d-enabled"_s ).toInt();
120 mCullingMode = Qgs3DUtils::cullingModeFromString( elemAdvancedSettings.attribute( u"culling-mode"_s, u"back"_s ) );
121 mSmoothedTriangles = elemAdvancedSettings.attribute( u"smoothed-triangle"_s ).toInt();
122 mWireframeEnabled = elemAdvancedSettings.attribute( u"wireframe-enabled"_s ).toInt();
123 mWireframeLineWidth = elemAdvancedSettings.attribute( u"wireframe-line-width"_s ).toDouble();
124 mWireframeLineColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( u"wireframe-line-color"_s ) );
125 mLevelOfDetailIndex = elemAdvancedSettings.attribute( u"level-of-detail"_s ).toInt();
126 mVerticalScale = elemAdvancedSettings.attribute( "vertical-scale" ).toDouble();
127 mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt();
128 mIsVerticalMagnitudeRelative = elemAdvancedSettings.attribute( "vertical-relative" ).toInt();
129 mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( u"texture-type"_s ).toInt() );
130 mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ), context );
131 mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( u"min-color-ramp-shader"_s ).toDouble() );
132 mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( u"max-color-ramp-shader"_s ).toDouble() );
133 mSingleColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( u"texture-single-color"_s ) );
134 mArrowsEnabled = elemAdvancedSettings.attribute( u"arrows-enabled"_s ).toInt();
135 if ( elemAdvancedSettings.hasAttribute( u"arrows-spacing"_s ) )
136 mArrowsSpacing = elemAdvancedSettings.attribute( u"arrows-spacing"_s ).toDouble();
137 mArrowsFixedSize = elemAdvancedSettings.attribute( u"arrows-fixed-size"_s ).toInt();
138 const QDomElement elemDDP = elem.firstChildElement( u"data-defined-properties"_s );
139 if ( !elemDDP.isNull() )
140 mDataDefinedProperties.readXml( elemDDP, propertyDefinitions() );
141}
142
144{
145 return mSmoothedTriangles;
146}
147
148void QgsMesh3DSymbol::setSmoothedTriangles( bool smoothTriangles )
149{
150 mSmoothedTriangles = smoothTriangles;
151}
152
154{
155 return mWireframeEnabled;
156}
157
159{
160 mWireframeEnabled = wireframeEnabled;
161}
162
164{
165 return mWireframeLineWidth;
166}
167
169{
170 mWireframeLineWidth = wireframeLineWidth;
171}
172
174{
175 return mWireframeLineColor;
176}
177
179{
180 mWireframeLineColor = wireframeLineColor;
181}
182
184{
185 return mVerticalScale;
186}
187
189{
190 mVerticalScale = verticalScale;
191}
192
194{
195 return mColorRampShader;
196}
197
202
204{
205 return mSingleColor;
206}
207
208void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
209{
210 mSingleColor = color;
211}
212
214{
215 return mRenderingStyle;
216}
217
219{
220 mRenderingStyle = coloringType;
221}
222
224{
225 return mVerticalDatasetGroupIndex;
226}
227
232
234{
235 return mIsVerticalMagnitudeRelative;
236}
237
238void QgsMesh3DSymbol::setIsVerticalMagnitudeRelative( bool isVerticalScaleIsRelative )
239{
240 mIsVerticalMagnitudeRelative = isVerticalScaleIsRelative;
241}
242
244{
245 return mArrowsEnabled;
246}
247
248void QgsMesh3DSymbol::setArrowsEnabled( bool vectorEnabled )
249{
250 mArrowsEnabled = vectorEnabled;
251}
252
254{
255 return mArrowsSpacing;
256}
257
259{
260 mArrowsSpacing = arrowsSpacing;
261}
262
264{
265 return mMaximumTextureSize;
266}
267
269{
270 mMaximumTextureSize = maximumTextureSize;
271}
272
274{
275 return mArrowsFixedSize;
276}
277
278void QgsMesh3DSymbol::setArrowsFixedSize( bool arrowsFixeSize )
279{
280 mArrowsFixedSize = arrowsFixeSize;
281}
282
284{
285 return mLevelOfDetailIndex;
286}
287
289{
290 mLevelOfDetailIndex = lod;
291}
292
294{
295 if ( mAltClamping != other.mAltClamping
296 || mHeight != other.mHeight
297 || mAddBackFaces != other.mAddBackFaces
298 || mEnabled != other.mEnabled
299 || mCullingMode != other.mCullingMode
300 || mSmoothedTriangles != other.mSmoothedTriangles
301 || mWireframeEnabled != other.mWireframeEnabled
302 || !qgsDoubleNear( mWireframeLineWidth, other.mWireframeLineWidth )
303 || mWireframeLineColor != other.mWireframeLineColor
304 || mLevelOfDetailIndex != other.mLevelOfDetailIndex
305 || !qgsDoubleNear( mVerticalScale, other.mVerticalScale )
306 || mVerticalDatasetGroupIndex != other.mVerticalDatasetGroupIndex
307 || mIsVerticalMagnitudeRelative != other.mIsVerticalMagnitudeRelative
308 || mRenderingStyle != other.mRenderingStyle
309 || mColorRampShader != other.mColorRampShader
310 || mSingleColor != other.mSingleColor
311 || mArrowsEnabled != other.mArrowsEnabled
312 || !qgsDoubleNear( mArrowsSpacing, other.mArrowsSpacing )
313 || mArrowsFixedSize != other.mArrowsFixedSize
314 || mArrowsColor != other.mArrowsColor
315 || mMaximumTextureSize != other.mMaximumTextureSize )
316 return false;
317
318 if ( !mMaterialSettings->equals( other.materialSettings() ) )
319 return false;
320
321 // base class properties
323 return false;
324
325 return true;
326}
327
329{
330 return !( *this == other );
331}
332
334{
335 return mEnabled;
336}
337
338void QgsMesh3DSymbol::setEnabled( bool enabled )
339{
340 mEnabled = enabled;
341}
342
344{
345 return mCullingMode;
346}
347
349{
350 mCullingMode = mode;
351}
352
354{
355 return mMaterialSettings.get();
356}
357
359{
360 if ( materialSettings == mMaterialSettings.get() )
361 return;
362
363 mMaterialSettings.reset( materialSettings );
364}
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
Abstract base class for material settings.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
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...
Basic shading material used for rendering based on the Phong shading model with three color component...
A container for the context for various read/write operations on 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:6935