QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
32
34{
35 auto result = std::make_unique<QgsMesh3DSymbol>();
36
37 result->mAltClamping = mAltClamping;
38 result->mHeight = mHeight;
39 result->mMaterialSettings.reset( mMaterialSettings->clone() );
40 result->mAddBackFaces = mAddBackFaces;
41 result->mCullingMode = mCullingMode;
42 result->mEnabled = mEnabled;
43 result->mSmoothedTriangles = mSmoothedTriangles;
44 result->mWireframeEnabled = mWireframeEnabled;
45 result->mWireframeLineWidth = mWireframeLineWidth;
46 result->mWireframeLineColor = mWireframeLineColor;
47 result->mLevelOfDetailIndex = mLevelOfDetailIndex;
48 result->mVerticalScale = mVerticalScale;
49 result->mVerticalDatasetGroupIndex = mVerticalDatasetGroupIndex;
50 result->mIsVerticalMagnitudeRelative = mIsVerticalMagnitudeRelative;
51 result->mRenderingStyle = mRenderingStyle;
52 result->mColorRampShader = mColorRampShader;
53 result->mSingleColor = mSingleColor;
54 result->mArrowsEnabled = mArrowsEnabled;
55 result->mArrowsSpacing = mArrowsSpacing;
56 result->mArrowsFixedSize = mArrowsFixedSize;
57 result->mArrowsColor = mArrowsColor;
58 result->mMaximumTextureSize = mMaximumTextureSize;
59 copyBaseSettings( result.get() );
60 return result.release();
61}
62
63void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
64{
65 QDomDocument doc = elem.ownerDocument();
66
67 //Simple symbol
68 QDomElement elemDataProperties = doc.createElement( u"data"_s );
69 elemDataProperties.setAttribute( u"alt-clamping"_s, Qgs3DUtils::altClampingToString( mAltClamping ) );
70 elemDataProperties.setAttribute( u"height"_s, mHeight );
71 elemDataProperties.setAttribute( u"add-back-faces"_s, mAddBackFaces ? u"1"_s : u"0"_s );
72 elem.appendChild( elemDataProperties );
73
74 QDomElement elemMaterial = doc.createElement( u"material"_s );
75 mMaterialSettings->writeXml( elemMaterial, context );
76 elem.appendChild( elemMaterial );
77
78 //Advanced symbol
79 QDomElement elemAdvancedSettings = doc.createElement( u"advanced-settings"_s );
80 elemAdvancedSettings.setAttribute( u"renderer-3d-enabled"_s, mEnabled ? u"1"_s : u"0"_s );
81 elemAdvancedSettings.setAttribute( u"culling-mode"_s, Qgs3DUtils::cullingModeToString( mCullingMode ) );
82 elemAdvancedSettings.setAttribute( u"smoothed-triangle"_s, mSmoothedTriangles ? u"1"_s : u"0"_s );
83 elemAdvancedSettings.setAttribute( u"wireframe-enabled"_s, mWireframeEnabled ? u"1"_s : u"0"_s );
84 elemAdvancedSettings.setAttribute( u"wireframe-line-width"_s, mWireframeLineWidth );
85 elemAdvancedSettings.setAttribute( u"wireframe-line-color"_s, QgsColorUtils::colorToString( mWireframeLineColor ) );
86 elemAdvancedSettings.setAttribute( u"level-of-detail"_s, mLevelOfDetailIndex );
87 elemAdvancedSettings.setAttribute( u"vertical-scale"_s, mVerticalScale );
88 elemAdvancedSettings.setAttribute( u"vertical-group-index"_s, mVerticalDatasetGroupIndex );
89 elemAdvancedSettings.setAttribute( u"vertical-relative"_s, mIsVerticalMagnitudeRelative ? u"1"_s : u"0"_s );
90 elemAdvancedSettings.setAttribute( u"texture-type"_s, static_cast<int>( mRenderingStyle ) );
91 elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc, context ) );
92 elemAdvancedSettings.setAttribute( u"min-color-ramp-shader"_s, mColorRampShader.minimumValue() );
93 elemAdvancedSettings.setAttribute( u"max-color-ramp-shader"_s, mColorRampShader.maximumValue() );
94 elemAdvancedSettings.setAttribute( u"texture-single-color"_s, QgsColorUtils::colorToString( mSingleColor ) );
95 elemAdvancedSettings.setAttribute( u"arrows-enabled"_s, mArrowsEnabled ? u"1"_s : u"0"_s );
96 elemAdvancedSettings.setAttribute( u"arrows-spacing"_s, mArrowsSpacing );
97 elemAdvancedSettings.setAttribute( u"arrows-fixed-size"_s, mArrowsFixedSize ? u"1"_s : u"0"_s );
98 elem.appendChild( elemAdvancedSettings );
99
100 QDomElement elemDDP = doc.createElement( u"data-defined-properties"_s );
101 mDataDefinedProperties.writeXml( elemDDP, propertyDefinitions() );
102 elem.appendChild( elemDDP );
103}
104
105void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
106{
107 //Simple symbol
108 const QDomElement elemDataProperties = elem.firstChildElement( u"data"_s );
109 mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( u"alt-clamping"_s ) );
110 mHeight = elemDataProperties.attribute( u"height"_s ).toFloat();
111 mAddBackFaces = elemDataProperties.attribute( u"add-back-faces"_s ).toInt();
112
113 const QDomElement elemMaterial = elem.firstChildElement( u"material"_s );
114 mMaterialSettings->readXml( elemMaterial, context );
115
116 //Advanced symbol
117 const QDomElement elemAdvancedSettings = elem.firstChildElement( u"advanced-settings"_s );
118 mEnabled = elemAdvancedSettings.attribute( u"renderer-3d-enabled"_s ).toInt();
119 mCullingMode = Qgs3DUtils::cullingModeFromString( elemAdvancedSettings.attribute( u"culling-mode"_s, u"back"_s ) );
120 mSmoothedTriangles = elemAdvancedSettings.attribute( u"smoothed-triangle"_s ).toInt();
121 mWireframeEnabled = elemAdvancedSettings.attribute( u"wireframe-enabled"_s ).toInt();
122 mWireframeLineWidth = elemAdvancedSettings.attribute( u"wireframe-line-width"_s ).toDouble();
123 mWireframeLineColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( u"wireframe-line-color"_s ) );
124 mLevelOfDetailIndex = elemAdvancedSettings.attribute( u"level-of-detail"_s ).toInt();
125 mVerticalScale = elemAdvancedSettings.attribute( "vertical-scale" ).toDouble();
126 mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt();
127 mIsVerticalMagnitudeRelative = elemAdvancedSettings.attribute( "vertical-relative" ).toInt();
128 mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( u"texture-type"_s ).toInt() );
129 mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ), context );
130 mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( u"min-color-ramp-shader"_s ).toDouble() );
131 mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( u"max-color-ramp-shader"_s ).toDouble() );
132 mSingleColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( u"texture-single-color"_s ) );
133 mArrowsEnabled = elemAdvancedSettings.attribute( u"arrows-enabled"_s ).toInt();
134 if ( elemAdvancedSettings.hasAttribute( u"arrows-spacing"_s ) )
135 mArrowsSpacing = elemAdvancedSettings.attribute( u"arrows-spacing"_s ).toDouble();
136 mArrowsFixedSize = elemAdvancedSettings.attribute( u"arrows-fixed-size"_s ).toInt();
137 const QDomElement elemDDP = elem.firstChildElement( u"data-defined-properties"_s );
138 if ( !elemDDP.isNull() )
139 mDataDefinedProperties.readXml( elemDDP, propertyDefinitions() );
140}
141
143{
144 return mSmoothedTriangles;
145}
146
147void QgsMesh3DSymbol::setSmoothedTriangles( bool smoothTriangles )
148{
149 mSmoothedTriangles = smoothTriangles;
150}
151
153{
154 return mWireframeEnabled;
155}
156
158{
159 mWireframeEnabled = wireframeEnabled;
160}
161
163{
164 return mWireframeLineWidth;
165}
166
168{
169 mWireframeLineWidth = wireframeLineWidth;
170}
171
173{
174 return mWireframeLineColor;
175}
176
178{
179 mWireframeLineColor = wireframeLineColor;
180}
181
183{
184 return mVerticalScale;
185}
186
188{
189 mVerticalScale = verticalScale;
190}
191
193{
194 return mColorRampShader;
195}
196
201
203{
204 return mSingleColor;
205}
206
207void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
208{
209 mSingleColor = color;
210}
211
213{
214 return mRenderingStyle;
215}
216
218{
219 mRenderingStyle = coloringType;
220}
221
223{
224 return mVerticalDatasetGroupIndex;
225}
226
231
233{
234 return mIsVerticalMagnitudeRelative;
235}
236
237void QgsMesh3DSymbol::setIsVerticalMagnitudeRelative( bool isVerticalScaleIsRelative )
238{
239 mIsVerticalMagnitudeRelative = isVerticalScaleIsRelative;
240}
241
243{
244 return mArrowsEnabled;
245}
246
247void QgsMesh3DSymbol::setArrowsEnabled( bool vectorEnabled )
248{
249 mArrowsEnabled = vectorEnabled;
250}
251
253{
254 return mArrowsSpacing;
255}
256
258{
259 mArrowsSpacing = arrowsSpacing;
260}
261
263{
264 return mMaximumTextureSize;
265}
266
268{
269 mMaximumTextureSize = maximumTextureSize;
270}
271
273{
274 return mArrowsFixedSize;
275}
276
277void QgsMesh3DSymbol::setArrowsFixedSize( bool arrowsFixeSize )
278{
279 mArrowsFixedSize = arrowsFixeSize;
280}
281
283{
284 return mLevelOfDetailIndex;
285}
286
288{
289 mLevelOfDetailIndex = lod;
290}
291
293{
294 if ( mAltClamping != other.mAltClamping
295 || mHeight != other.mHeight
296 || mAddBackFaces != other.mAddBackFaces
297 || mEnabled != other.mEnabled
298 || mCullingMode != other.mCullingMode
299 || mSmoothedTriangles != other.mSmoothedTriangles
300 || mWireframeEnabled != other.mWireframeEnabled
301 || !qgsDoubleNear( mWireframeLineWidth, other.mWireframeLineWidth )
302 || mWireframeLineColor != other.mWireframeLineColor
303 || mLevelOfDetailIndex != other.mLevelOfDetailIndex
304 || !qgsDoubleNear( mVerticalScale, other.mVerticalScale )
305 || mVerticalDatasetGroupIndex != other.mVerticalDatasetGroupIndex
306 || mIsVerticalMagnitudeRelative != other.mIsVerticalMagnitudeRelative
307 || mRenderingStyle != other.mRenderingStyle
308 || mColorRampShader != other.mColorRampShader
309 || mSingleColor != other.mSingleColor
310 || mArrowsEnabled != other.mArrowsEnabled
311 || !qgsDoubleNear( mArrowsSpacing, other.mArrowsSpacing )
312 || mArrowsFixedSize != other.mArrowsFixedSize
313 || mArrowsColor != other.mArrowsColor
314 || mMaximumTextureSize != other.mMaximumTextureSize )
315 return false;
316
317 if ( !mMaterialSettings->equals( other.materialSettings() ) )
318 return false;
319
320 // base class properties
322 return false;
323
324 return true;
325}
326
328{
329 return !( *this == other );
330}
331
333{
334 return mEnabled;
335}
336
337void QgsMesh3DSymbol::setEnabled( bool enabled )
338{
339 mEnabled = enabled;
340}
341
343{
344 return mCullingMode;
345}
346
348{
349 mCullingMode = mode;
350}
351
353{
354 return mMaterialSettings.get();
355}
356
358{
359 if ( materialSettings == mMaterialSettings.get() )
360 return;
361
362 mMaterialSettings.reset( materialSettings );
363}
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:6975