Skip to content

Commit

Permalink
3d: Use absolute clamping for 3d data by default
Browse files Browse the repository at this point in the history
When providing a project DTM/DEM, the default behavior for vector
feature with a z-component is to offset the $z coordinates from the
terrain elevation model in the elevation profile view. However, the
geometry coordinates are supposed to be absolute.

So it makes more sense, to only use the $z coordinate by default in
that case.

The different unit tests are updated accordingly.

Closes: #59757
  • Loading branch information
T4mmi authored and ptitjano committed Jan 20, 2025
1 parent 2c6677f commit 46d5638
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/3d/symbols/qgsline3dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class _3D_EXPORT QgsLine3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTORS

private:
//! how to handle altitude of vector features
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative;
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute;
//! how to handle clamping of vertices of individual features
Qgis::AltitudeBinding mAltBinding = Qgis::AltitudeBinding::Centroid;

Expand Down
2 changes: 1 addition & 1 deletion src/3d/symbols/qgslinevertexdata_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct QgsLineVertexData
bool withAdjacency = false; //!< Whether line strip with adjacency primitive will be used

// extra info to calculate elevation
Qgis::AltitudeClamping altClamping = Qgis::AltitudeClamping::Relative;
Qgis::AltitudeClamping altClamping = Qgis::AltitudeClamping::Absolute;
Qgis::AltitudeBinding altBinding = Qgis::AltitudeBinding::Vertex;
float baseHeight = 0;
Qgs3DRenderContext renderContext; // used for altitude clamping
Expand Down
2 changes: 1 addition & 1 deletion src/3d/symbols/qgsmesh3dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol
#endif

//! how to handle altitude of vector features
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative;
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute;
float mHeight = 0.0f; //!< Base height of triangles
std::unique_ptr<QgsAbstractMaterialSettings> mMaterialSettings; //!< Defines appearance of objects
bool mAddBackFaces = false;
Expand Down
2 changes: 1 addition & 1 deletion src/3d/symbols/qgspoint3dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTOR

private:
//! how to handle altitude of vector features
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative;
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute;

std::unique_ptr<QgsAbstractMaterialSettings> mMaterialSettings; //!< Defines appearance of objects
Qgis::Point3DShape mShape = Qgis::Point3DShape::Cylinder; //!< What kind of shape to use
Expand Down
2 changes: 1 addition & 1 deletion src/3d/symbols/qgspolygon3dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCT

private:
//! how to handle altitude of vector features
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative;
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute;
//! how to handle clamping of vertices of individual features
Qgis::AltitudeBinding mAltBinding = Qgis::AltitudeBinding::Centroid;

Expand Down
9 changes: 9 additions & 0 deletions tests/src/3d/testqgs3drendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,15 @@ void TestQgs3DRendering::testAmbientOcclusion()
mapSettings.setLightSources( { defaultPointLight.clone() } );
mapSettings.setOutputDpi( 92 );

QgsPhongMaterialSettings materialSettings;
materialSettings.setAmbient( Qt::lightGray );
QgsPolygon3DSymbol *symbol3d = new QgsPolygon3DSymbol;
symbol3d->setMaterialSettings( materialSettings.clone() );
symbol3d->setExtrusionHeight( 10.f );
symbol3d->setAltitudeClamping( Qgis::AltitudeClamping::Relative );
QgsVectorLayer3DRenderer *renderer3d = new QgsVectorLayer3DRenderer( symbol3d );
mLayerBuildings->setRenderer3D( renderer3d );

// =========== creating Qgs3DMapScene
QPoint winSize = QPoint( 640, 480 ); // default window size

Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgsmesh3dsymbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def test_getters_and_setters(self):
self.assertEqual(symbol.cullingMode(), Qgs3DTypes.Front)

# Test altitude clamping
self.assertEqual(symbol.altitudeClamping(), Qgis.AltitudeClamping.Relative)
symbol.setAltitudeClamping(Qgis.AltitudeClamping.Absolute)
self.assertEqual(symbol.altitudeClamping(), Qgis.AltitudeClamping.Absolute)
symbol.setAltitudeClamping(Qgis.AltitudeClamping.Relative)
self.assertEqual(symbol.altitudeClamping(), Qgis.AltitudeClamping.Relative)

# Test height
self.assertEqual(symbol.height(), 0.0)
Expand Down Expand Up @@ -152,9 +152,9 @@ def test_equality(self):
self.assertEqual(symbol1, symbol2)

# Test altitude clamping
symbol2.setAltitudeClamping(Qgis.AltitudeClamping.Absolute)
self.assertNotEqual(symbol1, symbol2)
symbol2.setAltitudeClamping(Qgis.AltitudeClamping.Relative)
self.assertNotEqual(symbol1, symbol2)
symbol2.setAltitudeClamping(Qgis.AltitudeClamping.Absolute)
self.assertEqual(symbol1, symbol2)

# Test height
Expand Down

0 comments on commit 46d5638

Please sign in to comment.