Skip to content
Permalink
Browse files

[3D] Fix missing Z support for point layers (#5560)

  • Loading branch information
nirvn committed Nov 8, 2017
1 parent ccd142f commit 17c7e2fbca126457603f739665aba48e7ac65d3c
@@ -161,7 +161,7 @@ QMatrix4x4 Qgs3DUtils::stringToMatrix4x4( const QString &str )
return m;
}

QList<QVector3D> Qgs3DUtils::positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &request )
QList<QVector3D> Qgs3DUtils::positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &request, AltitudeClamping altClamp )
{
QList<QVector3D> positions;
QgsFeature f;
@@ -174,8 +174,25 @@ QList<QVector3D> Qgs3DUtils::positions( const Qgs3DMapSettings &map, QgsVectorLa
const QgsAbstractGeometry *g = f.geometry().constGet();
if ( const QgsPoint *pt = qgsgeometry_cast< const QgsPoint *>( g ) )
{
// TODO: use Z coordinates if the point is 3D
float h = map.terrainGenerator()->heightAt( pt->x(), pt->y(), map ) * map.terrainVerticalScale();
float geomZ = 0;
if ( pt->is3D() )
{
geomZ = pt->z();
}
float terrainZ = map.terrainGenerator()->heightAt( pt->x(), pt->y(), map ) * map.terrainVerticalScale();
float h;
switch ( altClamp )
{
case AltClampAbsolute:
h = geomZ;
break;
case AltClampTerrain:
h = terrainZ;
break;
case AltClampRelative:
h = terrainZ + geomZ;
break;
}
positions.append( QVector3D( pt->x() - map.originX(), h, -( pt->y() - map.originY() ) ) );
//qDebug() << positions.last();
}
@@ -77,7 +77,7 @@ class _3D_EXPORT Qgs3DUtils
/**
* Calculates (x,y,z) position of point in the Point vector layers
*/
static QList<QVector3D> positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &req );
static QList<QVector3D> positions( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsFeatureRequest &req, AltitudeClamping altClamp );

/**
Returns true if bbox is completely outside the current viewing volume.
@@ -20,6 +20,7 @@


QgsPoint3DSymbol::QgsPoint3DSymbol()
: mAltClamping( AltClampRelative )
{
}

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

QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
elem.appendChild( elemDataProperties );

QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
mMaterial.writeXml( elemMaterial );
elem.appendChild( elemMaterial );
@@ -52,6 +57,9 @@ void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &c

void QgsPoint3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );

QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
mMaterial.readXml( elemMaterial );

@@ -40,6 +40,11 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;

//! Returns method that determines altitude (whether to clamp to feature to terrain)
AltitudeClamping altitudeClamping() const { return mAltClamping; }
//! Sets method that determines altitude (whether to clamp to feature to terrain)
void setAltitudeClamping( AltitudeClamping altClamping ) { mAltClamping = altClamping; }

//! Returns material used for shading of the symbol
QgsPhongMaterialSettings material() const { return mMaterial; }
//! Sets material used for shading of the symbol
@@ -79,6 +84,8 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol
void setTransform( const QMatrix4x4 &transform ) { mTransform = transform; }

private:
AltitudeClamping mAltClamping; //! how to handle altitude of vector features

QgsPhongMaterialSettings mMaterial; //!< Defines appearance of objects
Shape mShape = Cylinder; //!< What kind of shape to use
QVariantMap mShapeProperties; //!< Key-value dictionary of shape's properties (different keys for each shape)
@@ -184,7 +184,7 @@ void QgsPoint3DSymbolInstancedEntityFactory::addEntityForNotSelectedPoints( cons
QgsPoint3DSymbolInstancedEntityNode::QgsPoint3DSymbolInstancedEntityNode( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol, const QgsFeatureRequest &req, Qt3DCore::QNode *parent )
: Qt3DCore::QEntity( parent )
{
QList<QVector3D> pos = Qgs3DUtils::positions( map, layer, req );
QList<QVector3D> pos = Qgs3DUtils::positions( map, layer, req, symbol.altitudeClamping() );
addComponent( renderer( symbol, pos ) );
}

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

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

// get nodes
QList<QVector3D> positions = Qgs3DUtils::positions( map, layer, req );
QList<QVector3D> positions = Qgs3DUtils::positions( map, layer, req, symbol.altitudeClamping() );
Q_FOREACH ( const QVector3D &position, positions )
{
// build the entity
@@ -36,6 +36,7 @@ QgsPoint3DSymbolWidget::QgsPoint3DSymbolWidget( QWidget *parent )
setSymbol( QgsPoint3DSymbol() );
onShapeChanged();

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

void QgsPoint3DSymbolWidget::setSymbol( const QgsPoint3DSymbol &symbol )
{
cboAltClamping->setCurrentIndex( ( int ) symbol.altitudeClamping() );

QVariantMap vm = symbol.shapeProperties();
int index = cboShape->findData( symbol.shape() );
cboShape->setCurrentIndex( index != -1 ? index : 1 ); // use cylinder by default if shape is not set
@@ -196,6 +199,7 @@ QgsPoint3DSymbol QgsPoint3DSymbolWidget::symbol() const
tr.rotate( rot );

QgsPoint3DSymbol sym;
sym.setAltitudeClamping( ( AltitudeClamping ) cboAltClamping->currentIndex() );
sym.setShape( ( QgsPoint3DSymbol::Shape ) cboShape->itemData( cboShape->currentIndex() ).toInt() );
sym.setShapeProperties( vm );
sym.setMaterial( widgetMaterial->material() );
@@ -151,24 +151,50 @@
</item>
</layout>
</item>
<item row="8" column="0" colspan="2">
<widget class="QgsPhongMaterialWidget" name="widgetMaterial" native="true"/>
<item row="8" column="0">
<widget class="QLabel" name="labelAltClamping">
<property name="text">
<string>Altitude Clamping</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="cboAltClamping">
<item>
<property name="text">
<string>Absolute</string>
</property>
</item>
<item>
<property name="text">
<string>Relative</string>
</property>
</item>
<item>
<property name="text">
<string>Terrain</string>
</property>
</item>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QgsPhongMaterialWidget" name="widgetMaterial" native="true"/>
</item>
<item row="10" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<item row="11" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<item row="12" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLabel" name="label_5">

0 comments on commit 17c7e2f

Please sign in to comment.
You can’t perform that action at this time.