Skip to content

Commit 17c7e2f

Browse files
authoredNov 8, 2017
[3D] Fix missing Z support for point layers (#5560)
1 parent ccd142f commit 17c7e2f

File tree

7 files changed

+73
-11
lines changed

7 files changed

+73
-11
lines changed
 

‎src/3d/qgs3dutils.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ QMatrix4x4 Qgs3DUtils::stringToMatrix4x4( const QString &str )
161161
return m;
162162
}
163163

164-
QList<QVector3D> Qgs3DUtils::positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &request )
164+
QList<QVector3D> Qgs3DUtils::positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &request, AltitudeClamping altClamp )
165165
{
166166
QList<QVector3D> positions;
167167
QgsFeature f;
@@ -174,8 +174,25 @@ QList<QVector3D> Qgs3DUtils::positions( const Qgs3DMapSettings &map, QgsVectorLa
174174
const QgsAbstractGeometry *g = f.geometry().constGet();
175175
if ( const QgsPoint *pt = qgsgeometry_cast< const QgsPoint *>( g ) )
176176
{
177-
// TODO: use Z coordinates if the point is 3D
178-
float h = map.terrainGenerator()->heightAt( pt->x(), pt->y(), map ) * map.terrainVerticalScale();
177+
float geomZ = 0;
178+
if ( pt->is3D() )
179+
{
180+
geomZ = pt->z();
181+
}
182+
float terrainZ = map.terrainGenerator()->heightAt( pt->x(), pt->y(), map ) * map.terrainVerticalScale();
183+
float h;
184+
switch ( altClamp )
185+
{
186+
case AltClampAbsolute:
187+
h = geomZ;
188+
break;
189+
case AltClampTerrain:
190+
h = terrainZ;
191+
break;
192+
case AltClampRelative:
193+
h = terrainZ + geomZ;
194+
break;
195+
}
179196
positions.append( QVector3D( pt->x() - map.originX(), h, -( pt->y() - map.originY() ) ) );
180197
//qDebug() << positions.last();
181198
}

‎src/3d/qgs3dutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _3D_EXPORT Qgs3DUtils
7777
/**
7878
* Calculates (x,y,z) position of point in the Point vector layers
7979
*/
80-
static QList<QVector3D> positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &req );
80+
static QList<QVector3D> positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &req, AltitudeClamping altClamp );
8181

8282
/**
8383
Returns true if bbox is completely outside the current viewing volume.

‎src/3d/symbols/qgspoint3dsymbol.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121

2222
QgsPoint3DSymbol::QgsPoint3DSymbol()
23+
: mAltClamping( AltClampRelative )
2324
{
2425
}
2526

@@ -32,6 +33,10 @@ void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &c
3233
{
3334
QDomDocument doc = elem.ownerDocument();
3435

36+
QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
37+
elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
38+
elem.appendChild( elemDataProperties );
39+
3540
QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
3641
mMaterial.writeXml( elemMaterial );
3742
elem.appendChild( elemMaterial );
@@ -52,6 +57,9 @@ void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &c
5257

5358
void QgsPoint3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
5459
{
60+
QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
61+
mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
62+
5563
QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
5664
mMaterial.readXml( elemMaterial );
5765

‎src/3d/symbols/qgspoint3dsymbol.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol
4040
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
4141
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
4242

43+
//! Returns method that determines altitude (whether to clamp to feature to terrain)
44+
AltitudeClamping altitudeClamping() const { return mAltClamping; }
45+
//! Sets method that determines altitude (whether to clamp to feature to terrain)
46+
void setAltitudeClamping( AltitudeClamping altClamping ) { mAltClamping = altClamping; }
47+
4348
//! Returns material used for shading of the symbol
4449
QgsPhongMaterialSettings material() const { return mMaterial; }
4550
//! Sets material used for shading of the symbol
@@ -79,6 +84,8 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol
7984
void setTransform( const QMatrix4x4 &transform ) { mTransform = transform; }
8085

8186
private:
87+
AltitudeClamping mAltClamping; //! how to handle altitude of vector features
88+
8289
QgsPhongMaterialSettings mMaterial; //!< Defines appearance of objects
8390
Shape mShape = Cylinder; //!< What kind of shape to use
8491
QVariantMap mShapeProperties; //!< Key-value dictionary of shape's properties (different keys for each shape)

‎src/3d/symbols/qgspoint3dsymbol_p.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void QgsPoint3DSymbolInstancedEntityFactory::addEntityForNotSelectedPoints( cons
184184
QgsPoint3DSymbolInstancedEntityNode::QgsPoint3DSymbolInstancedEntityNode( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol, const QgsFeatureRequest &req, Qt3DCore::QNode *parent )
185185
: Qt3DCore::QEntity( parent )
186186
{
187-
QList<QVector3D> pos = Qgs3DUtils::positions( map, layer, req );
187+
QList<QVector3D> pos = Qgs3DUtils::positions( map, layer, req, symbol.altitudeClamping() );
188188
addComponent( renderer( symbol, pos ) );
189189
}
190190

@@ -358,7 +358,7 @@ void QgsPoint3DSymbolModelEntityFactory::addEntitiesForNotSelectedPoints( const
358358

359359
void QgsPoint3DSymbolModelEntityFactory::addSceneEntities( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &req, const QgsPoint3DSymbol &symbol, QgsPoint3DSymbolEntity *parent )
360360
{
361-
QList<QVector3D> positions = Qgs3DUtils::positions( map, layer, req );
361+
QList<QVector3D> positions = Qgs3DUtils::positions( map, layer, req, symbol.altitudeClamping() );
362362
Q_FOREACH ( const QVector3D &position, positions )
363363
{
364364
// build the entity
@@ -386,7 +386,7 @@ void QgsPoint3DSymbolModelEntityFactory::addMeshEntities( const Qgs3DMapSettings
386386
}
387387

388388
// get nodes
389-
QList<QVector3D> positions = Qgs3DUtils::positions( map, layer, req );
389+
QList<QVector3D> positions = Qgs3DUtils::positions( map, layer, req, symbol.altitudeClamping() );
390390
Q_FOREACH ( const QVector3D &position, positions )
391391
{
392392
// build the entity

‎src/app/3d/qgspoint3dsymbolwidget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ QgsPoint3DSymbolWidget::QgsPoint3DSymbolWidget( QWidget *parent )
3636
setSymbol( QgsPoint3DSymbol() );
3737
onShapeChanged();
3838

39+
connect( cboAltClamping, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPoint3DSymbolWidget::changed );
3940
connect( cboShape, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPoint3DSymbolWidget::onShapeChanged );
4041
QList<QDoubleSpinBox *> spinWidgets;
4142
spinWidgets << spinRadius << spinTopRadius << spinBottomRadius << spinMinorRadius << spinSize << spinLength;
@@ -86,6 +87,8 @@ void QgsPoint3DSymbolWidget::onOverwriteMaterialChecked( int state )
8687

8788
void QgsPoint3DSymbolWidget::setSymbol( const QgsPoint3DSymbol &symbol )
8889
{
90+
cboAltClamping->setCurrentIndex( ( int ) symbol.altitudeClamping() );
91+
8992
QVariantMap vm = symbol.shapeProperties();
9093
int index = cboShape->findData( symbol.shape() );
9194
cboShape->setCurrentIndex( index != -1 ? index : 1 ); // use cylinder by default if shape is not set
@@ -196,6 +199,7 @@ QgsPoint3DSymbol QgsPoint3DSymbolWidget::symbol() const
196199
tr.rotate( rot );
197200

198201
QgsPoint3DSymbol sym;
202+
sym.setAltitudeClamping( ( AltitudeClamping ) cboAltClamping->currentIndex() );
199203
sym.setShape( ( QgsPoint3DSymbol::Shape ) cboShape->itemData( cboShape->currentIndex() ).toInt() );
200204
sym.setShapeProperties( vm );
201205
sym.setMaterial( widgetMaterial->material() );

‎src/ui/3d/point3dsymbolwidget.ui

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,50 @@
151151
</item>
152152
</layout>
153153
</item>
154-
<item row="8" column="0" colspan="2">
155-
<widget class="QgsPhongMaterialWidget" name="widgetMaterial" native="true"/>
154+
<item row="8" column="0">
155+
<widget class="QLabel" name="labelAltClamping">
156+
<property name="text">
157+
<string>Altitude Clamping</string>
158+
</property>
159+
</widget>
160+
</item>
161+
<item row="8" column="1">
162+
<widget class="QComboBox" name="cboAltClamping">
163+
<item>
164+
<property name="text">
165+
<string>Absolute</string>
166+
</property>
167+
</item>
168+
<item>
169+
<property name="text">
170+
<string>Relative</string>
171+
</property>
172+
</item>
173+
<item>
174+
<property name="text">
175+
<string>Terrain</string>
176+
</property>
177+
</item>
178+
</widget>
156179
</item>
157180
<item row="9" column="0" colspan="2">
181+
<widget class="QgsPhongMaterialWidget" name="widgetMaterial" native="true"/>
182+
</item>
183+
<item row="10" column="0" colspan="2">
158184
<widget class="Line" name="line">
159185
<property name="orientation">
160186
<enum>Qt::Horizontal</enum>
161187
</property>
162188
</widget>
163189
</item>
164-
<item row="10" column="0" colspan="2">
190+
<item row="11" column="0" colspan="2">
165191
<widget class="Line" name="line_2">
166192
<property name="orientation">
167193
<enum>Qt::Horizontal</enum>
168194
</property>
169195
</widget>
170196
</item>
171-
<item row="11" column="0" colspan="2">
197+
<item row="12" column="0" colspan="2">
172198
<layout class="QGridLayout" name="gridLayout">
173199
<item row="0" column="1">
174200
<widget class="QLabel" name="label_5">

0 commit comments

Comments
 (0)
Please sign in to comment.