QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgssymbollayerutils.h"
18 #include "qgs3dutils.h"
20 
22  : mMaterial( qgis::make_unique< QgsPhongMaterialSettings >() )
23 {
24 
25 }
26 
28 
30 {
31  std::unique_ptr< QgsMesh3DSymbol > result = qgis::make_unique< QgsMesh3DSymbol >();
32 
33  result->mAltClamping = mAltClamping;
34  result->mHeight = mHeight;
35  result->mMaterial.reset( mMaterial->clone() );
36  result->mAddBackFaces = mAddBackFaces;
37  result->mEnabled = mEnabled;
38  result->mSmoothedTriangles = mSmoothedTriangles;
39  result->mWireframeEnabled = mWireframeEnabled;
40  result->mWireframeLineWidth = mWireframeLineWidth;
41  result->mWireframeLineColor = mWireframeLineColor;
42  result->mVerticalScale = mVerticalScale;
43  result->mVerticalDatasetGroupIndex = mVerticalDatasetGroupIndex;
44  result->mIsVerticalMagnitudeRelative = mIsVerticalMagnitudeRelative;
45  result->mRenderingStyle = mRenderingStyle;
46  result->mColorRampShader = mColorRampShader;
47  result->mSingleColor = mSingleColor;
48  result->mArrowsEnabled = mArrowsEnabled;
49  result->mArrowsSpacing = mArrowsSpacing;
50  result->mArrowsFixedSize = mArrowsFixedSize;
51  result->mArrowsColor = mArrowsColor;
52  result->mMaximumTextureSize = mMaximumTextureSize;
53  copyBaseSettings( result.get() );
54  return result.release();
55 }
56 
57 void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
58 {
59  Q_UNUSED( context )
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  mMaterial->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( "smoothed-triangle" ), mSmoothedTriangles ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
78  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-enabled" ), mWireframeEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
79  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-width" ), mWireframeLineWidth );
80  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-color" ), QgsSymbolLayerUtils::encodeColor( mWireframeLineColor ) );
81  elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-scale" ), mVerticalScale );
82  elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-group-index" ), mVerticalDatasetGroupIndex );
83  elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-relative" ), mIsVerticalMagnitudeRelative ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
84  elemAdvancedSettings.setAttribute( QStringLiteral( "texture-type" ), mRenderingStyle );
85  elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc ) );
86  elemAdvancedSettings.setAttribute( QStringLiteral( "min-color-ramp-shader" ), mColorRampShader.minimumValue() );
87  elemAdvancedSettings.setAttribute( QStringLiteral( "max-color-ramp-shader" ), mColorRampShader.maximumValue() );
88  elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) );
89  elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-enabled" ), mArrowsEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
90  elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-spacing" ), mArrowsSpacing );
91  elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-fixed-size" ), mArrowsFixedSize ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
92  elem.appendChild( elemAdvancedSettings );
93 
94  QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
96  elem.appendChild( elemDDP );
97 }
98 
99 void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
100 {
101  Q_UNUSED( context )
102 
103  //Simple symbol
104  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  QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
110  mMaterial->readXml( elemMaterial, context );
111 
112  //Advanced symbol
113  QDomElement elemAdvancedSettings = elem.firstChildElement( QStringLiteral( "advanced-settings" ) );
114  mEnabled = elemAdvancedSettings.attribute( QStringLiteral( "renderer-3d-enabled" ) ).toInt();
115  mSmoothedTriangles = elemAdvancedSettings.attribute( QStringLiteral( "smoothed-triangle" ) ).toInt();
116  mWireframeEnabled = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-enabled" ) ).toInt();
117  mWireframeLineWidth = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-width" ) ).toDouble();
118  mWireframeLineColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-color" ) ) );
119  mVerticalScale = elemAdvancedSettings.attribute( "vertical-scale" ).toDouble();
120  mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt();
121  mIsVerticalMagnitudeRelative = elemAdvancedSettings.attribute( "vertical-relative" ).toInt();
122  mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( QStringLiteral( "texture-type" ) ).toInt() );
123  mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ) );
124  mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( QStringLiteral( "min-color-ramp-shader" ) ).toDouble() );
125  mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() );
126  mSingleColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) );
127  mArrowsEnabled = elemAdvancedSettings.attribute( QStringLiteral( "arrows-enabled" ) ).toInt();
128  if ( elemAdvancedSettings.hasAttribute( QStringLiteral( "arrows-spacing" ) ) )
129  mArrowsSpacing = elemAdvancedSettings.attribute( QStringLiteral( "arrows-spacing" ) ).toDouble();
130  mArrowsFixedSize = elemAdvancedSettings.attribute( QStringLiteral( "arrows-fixed-size" ) ).toInt();
131  QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
132  if ( !elemDDP.isNull() )
134 }
135 
137 {
138  return mSmoothedTriangles;
139 }
140 
141 void QgsMesh3DSymbol::setSmoothedTriangles( bool smoothTriangles )
142 {
143  mSmoothedTriangles = smoothTriangles;
144 }
145 
147 {
148  return mWireframeEnabled;
149 }
150 
151 void QgsMesh3DSymbol::setWireframeEnabled( bool wireframeEnabled )
152 {
153  mWireframeEnabled = wireframeEnabled;
154 }
155 
157 {
158  return mWireframeLineWidth;
159 }
160 
161 void QgsMesh3DSymbol::setWireframeLineWidth( double wireframeLineWidth )
162 {
163  mWireframeLineWidth = wireframeLineWidth;
164 }
165 
167 {
168  return mWireframeLineColor;
169 }
170 
171 void QgsMesh3DSymbol::setWireframeLineColor( const QColor &wireframeLineColor )
172 {
173  mWireframeLineColor = wireframeLineColor;
174 }
175 
177 {
178  return mVerticalScale;
179 }
180 
181 void QgsMesh3DSymbol::setVerticalScale( double verticalScale )
182 {
183  mVerticalScale = verticalScale;
184 }
185 
187 {
188  return mColorRampShader;
189 }
190 
192 {
193  mColorRampShader = colorRampShader;
194 }
195 
197 {
198  return mSingleColor;
199 }
200 
201 void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
202 {
203  mSingleColor = color;
204 }
205 
207 {
208  return mRenderingStyle;
209 }
210 
212 {
213  mRenderingStyle = coloringType;
214 }
215 
217 {
218  return mVerticalDatasetGroupIndex;
219 }
220 
221 void QgsMesh3DSymbol::setVerticalDatasetGroupIndex( int verticalDatasetGroupIndex )
222 {
223  mVerticalDatasetGroupIndex = verticalDatasetGroupIndex;
224 }
225 
227 {
228  return mIsVerticalMagnitudeRelative;
229 }
230 
231 void QgsMesh3DSymbol::setIsVerticalMagnitudeRelative( bool isVerticalScaleIsRelative )
232 {
233  mIsVerticalMagnitudeRelative = isVerticalScaleIsRelative;
234 }
235 
237 {
238  return mArrowsEnabled;
239 }
240 
241 void QgsMesh3DSymbol::setArrowsEnabled( bool vectorEnabled )
242 {
243  mArrowsEnabled = vectorEnabled;
244 }
245 
247 {
248  return mArrowsSpacing;
249 }
250 
251 void QgsMesh3DSymbol::setArrowsSpacing( double arrowsSpacing )
252 {
253  mArrowsSpacing = arrowsSpacing;
254 }
255 
257 {
258  return mMaximumTextureSize;
259 }
260 
261 void QgsMesh3DSymbol::setMaximumTextureSize( int maximumTextureSize )
262 {
263  mMaximumTextureSize = maximumTextureSize;
264 }
265 
267 {
268  return mArrowsFixedSize;
269 }
270 
271 void QgsMesh3DSymbol::setArrowsFixedSize( bool arrowsFixeSize )
272 {
273  mArrowsFixedSize = arrowsFixeSize;
274 }
275 
277 {
278  return mEnabled;
279 }
280 
281 void QgsMesh3DSymbol::setEnabled( bool enabled )
282 {
283  mEnabled = enabled;
284 }
285 
286 
288 {
289  return mMaterial.get();
290 }
291 
293 {
294  if ( material == mMaterial.get() )
295  return;
296 
297  mMaterial.reset( material );
298 }
QgsMesh3DSymbol::setArrowsEnabled
void setArrowsEnabled(bool arrowsEnabled)
Sets if arrows are enabled for 3D rendering.
Definition: qgsmesh3dsymbol.cpp:241
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsMesh3DSymbol::smoothedTriangles
bool smoothedTriangles() const
Returns if mesh triangle are smoothed.
Definition: qgsmesh3dsymbol.cpp:136
QgsMesh3DSymbol::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads symbol configuration from the given DOM element.
Definition: qgsmesh3dsymbol.cpp:99
QgsMesh3DSymbol::setWireframeLineWidth
void setWireframeLineWidth(double wireframeLineWidth)
Sets wireframe line width.
Definition: qgsmesh3dsymbol.cpp:161
QgsMesh3DSymbol::verticalDatasetGroupIndex
int verticalDatasetGroupIndex() const
Returns the index of the dataset group that will be used to render the vertical component of the 3D m...
Definition: qgsmesh3dsymbol.cpp:216
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsColorRampShader::writeXml
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
Definition: qgscolorrampshader.cpp:502
qgsmesh3dsymbol.h
qgssymbollayerutils.h
QgsAbstractPropertyCollection::readXml
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Definition: qgspropertycollection.cpp:108
QgsMesh3DSymbol::setEnabled
void setEnabled(bool enabled)
Sets if the 3d rendering is enabled.
Definition: qgsmesh3dsymbol.cpp:281
QgsRasterShaderFunction::maximumValue
double maximumValue() const
Returns the minimum value for the raster shader.
Definition: qgsrastershaderfunction.h:119
QgsMesh3DSymbol::setVerticalDatasetGroupIndex
void setVerticalDatasetGroupIndex(int verticalDatasetGroupIndex)
Sets the index of the dataset group that will be used to render the vertical component of the 3D mesh...
Definition: qgsmesh3dsymbol.cpp:221
QgsMesh3DSymbol::setRenderingStyle
void setRenderingStyle(const QgsMesh3DSymbol::RenderingStyle &textureType)
Sets the rendering style.
Definition: qgsmesh3dsymbol.cpp:211
QgsMesh3DSymbol::arrowsFixedSize
bool arrowsFixedSize() const
Returns if the arrow size is fixed.
Definition: qgsmesh3dsymbol.cpp:266
QgsAbstract3DSymbol::copyBaseSettings
void copyBaseSettings(QgsAbstract3DSymbol *destination) const
Copies base class settings from this object to a destination object.
Definition: qgsabstract3dsymbol.cpp:33
QgsMesh3DSymbol
3 3D symbol that draws mesh geometry as planar triangles.
Definition: qgsmesh3dsymbol.h:44
QgsMesh3DSymbol::material
QgsAbstractMaterialSettings * material() const
Returns material used for shading of the symbol.
Definition: qgsmesh3dsymbol.cpp:287
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsColorRampShader
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Definition: qgscolorrampshader.h:40
QgsMesh3DSymbol::isVerticalMagnitudeRelative
bool isVerticalMagnitudeRelative() const
Returns if the vertical component of the mesh is relative to the mesh vertices Z value.
Definition: qgsmesh3dsymbol.cpp:226
QgsMesh3DSymbol::setArrowsSpacing
void setArrowsSpacing(double arrowsSpacing)
Sets the arrow spacing.
Definition: qgsmesh3dsymbol.cpp:251
QgsMesh3DSymbol::setColorRampShader
void setColorRampShader(const QgsColorRampShader &colorRampShader)
Sets the color ramp shader used to render the color.
Definition: qgsmesh3dsymbol.cpp:191
QgsPhongMaterialSettings
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
Definition: qgsphongmaterialsettings.h:37
QgsMesh3DSymbol::setSingleMeshColor
void setSingleMeshColor(const QColor &singleMeshColor)
Sets the single color.
Definition: qgsmesh3dsymbol.cpp:201
QgsMesh3DSymbol::renderingStyle
QgsMesh3DSymbol::RenderingStyle renderingStyle() const
Returns the rendering style.
Definition: qgsmesh3dsymbol.cpp:206
QgsMesh3DSymbol::setWireframeLineColor
void setWireframeLineColor(const QColor &wireframeLineColor)
Sets wireframe line color.
Definition: qgsmesh3dsymbol.cpp:171
QgsMesh3DSymbol::wireframeLineColor
QColor wireframeLineColor() const
Returns wireframe line color.
Definition: qgsmesh3dsymbol.cpp:166
QgsMesh3DSymbol::colorRampShader
QgsColorRampShader colorRampShader() const
Returns the color ramp shader used to render the color.
Definition: qgsmesh3dsymbol.cpp:186
QgsAbstractMaterialSettings
3 Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:105
qgs3dutils.h
QgsAbstract3DSymbol::propertyDefinitions
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
Definition: qgsabstract3dsymbol.cpp:27
QgsMesh3DSymbol::setVerticalScale
void setVerticalScale(double verticalScale)
Sets mesh vertical scale.
Definition: qgsmesh3dsymbol.cpp:181
QgsRasterShaderFunction::setMaximumValue
virtual void setMaximumValue(double value)
Sets the maximum value for the raster shader.
Definition: qgsrastershaderfunction.cpp:30
QgsMesh3DSymbol::setIsVerticalMagnitudeRelative
void setIsVerticalMagnitudeRelative(bool isVerticalMagnitudeRelative)
Sets if the vertical component of the mesh is relative to the mesh vertices Z value.
Definition: qgsmesh3dsymbol.cpp:231
QgsAbstract3DSymbol::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgsabstract3dsymbol.h:99
QgsColorRampShader::readXml
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
Definition: qgscolorrampshader.cpp:533
Qgs3DUtils::altClampingToString
static QString altClampingToString(Qgs3DTypes::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:184
QgsRasterShaderFunction::minimumValue
double minimumValue() const
Returns the maximum value for the raster shader.
Definition: qgsrastershaderfunction.h:112
QgsMesh3DSymbol::~QgsMesh3DSymbol
~QgsMesh3DSymbol() override
QgsMesh3DSymbol::clone
QgsMesh3DSymbol * clone() const override SIP_FACTORY
Returns a new instance of the symbol with the same settings.
Definition: qgsmesh3dsymbol.cpp:29
Qgs3DUtils::altClampingFromString
static Qgs3DTypes::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:196
QgsMesh3DSymbol::setArrowsFixedSize
void setArrowsFixedSize(bool arrowsFixedSize)
Sets if the arrow size is fixed.
Definition: qgsmesh3dsymbol.cpp:271
QgsMesh3DSymbol::arrowsEnabled
bool arrowsEnabled() const
Returns if arrows are enabled for 3D rendering.
Definition: qgsmesh3dsymbol.cpp:236
QgsMesh3DSymbol::setMaterial
void setMaterial(QgsAbstractMaterialSettings *material SIP_TRANSFER)
Sets the material settings used for shading of the symbol.
Definition: qgsmesh3dsymbol.cpp:292
QgsMesh3DSymbol::RenderingStyle
RenderingStyle
How to render the color of the mesh.
Definition: qgsmesh3dsymbol.h:53
QgsMesh3DSymbol::setSmoothedTriangles
void setSmoothedTriangles(bool smoothTriangles)
Sets if the mesh triangles have to been smoothed.
Definition: qgsmesh3dsymbol.cpp:141
QgsMesh3DSymbol::setMaximumTextureSize
void setMaximumTextureSize(int maximumTextureSize)
Sets the maximum texture size supported by the hardware Used to store the GL_MAX_TEXTURE_SIZE value t...
Definition: qgsmesh3dsymbol.cpp:261
QgsMesh3DSymbol::wireframeEnabled
bool wireframeEnabled() const
Returns if the mesh wireframe.
Definition: qgsmesh3dsymbol.cpp:146
qgsphongmaterialsettings.h
QgsMesh3DSymbol::verticalScale
double verticalScale() const
Returns mesh vertical scale.
Definition: qgsmesh3dsymbol.cpp:176
QgsMesh3DSymbol::arrowsSpacing
double arrowsSpacing() const
Returns the arrow spacing.
Definition: qgsmesh3dsymbol.cpp:246
QgsMesh3DSymbol::setWireframeEnabled
void setWireframeEnabled(bool wireframeEnabled)
Sets if the mesh wireframe.
Definition: qgsmesh3dsymbol.cpp:151
QgsMesh3DSymbol::isEnabled
bool isEnabled() const
Returns if the 3d rendering is enabled.
Definition: qgsmesh3dsymbol.cpp:276
QgsMesh3DSymbol::QgsMesh3DSymbol
QgsMesh3DSymbol()
Constructor for QgsMesh3DSymbol.
Definition: qgsmesh3dsymbol.cpp:21
QgsAbstractPropertyCollection::writeXml
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Definition: qgspropertycollection.cpp:99
QgsRasterShaderFunction::setMinimumValue
virtual void setMinimumValue(double value)
Sets the minimum value for the raster shader.
Definition: qgsrastershaderfunction.cpp:38
QgsMesh3DSymbol::wireframeLineWidth
double wireframeLineWidth() const
Returns wireframe line width.
Definition: qgsmesh3dsymbol.cpp:156
QgsMesh3DSymbol::singleMeshColor
QColor singleMeshColor() const
Returns the single color.
Definition: qgsmesh3dsymbol.cpp:196
QgsMesh3DSymbol::maximumTextureSize
int maximumTextureSize() const
Returns the maximum texture size supported by the hardware Used to store the GL_MAX_TEXTURE_SIZE valu...
Definition: qgsmesh3dsymbol.cpp:256
QgsMesh3DSymbol::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes symbol configuration to the given DOM element.
Definition: qgsmesh3dsymbol.cpp:57