Skip to content

Commit

Permalink
Optionally show bounding boxes for vector layer entities (for debugging)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 12, 2020
1 parent 9009971 commit 5b9b2e4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 8 deletions.
Expand Up @@ -39,6 +39,15 @@ of tiles.
void setZoomLevelsCount( int count );
%Docstring
Sets number of zoom levels. See zoomLevelsCount() documentation for more details.
%End

void setShowBoundingBoxes( bool enabled );
%Docstring
Sets whether to display bounding boxes of entity's tiles (for debugging)
%End
bool showBoundingBoxes() const;
%Docstring
Returns whether to display bounding boxes of entity's tiles (for debugging)
%End

void writeXml( QDomElement &elem ) const;
Expand Down
9 changes: 8 additions & 1 deletion src/3d/chunks/qgschunkedentity_p.h
Expand Up @@ -133,7 +133,14 @@ class QgsChunkedEntity : public Qt3DCore::QEntity
QgsChunkNode *mRootNode = nullptr;
//! A chunk has been loaded recently? let's display it!
bool mNeedsUpdate = false;
//! max. allowed screen space error

/**
* Maximum allowed screen space error (in pixels).
* If the value is negative, it means that the screen space error
* does not need to be taken into account. This essentially means that
* the chunked entity will try to go deeper into the tree of chunks until
* it reaches leafs.
*/
float mTau;
//! maximum allowed depth of quad tree
int mMaxLevel;
Expand Down
2 changes: 1 addition & 1 deletion src/3d/chunks/qgschunknode_p.h
Expand Up @@ -194,7 +194,7 @@ class QgsChunkNode

private:
QgsAABB mBbox; //!< Bounding box in world coordinates
float mError; //!< Error of the node in world coordinates
float mError; //!< Error of the node in world coordinates (negative error means that chunk at this level has no data, but there may be children that do)

int mTileX, mTileY, mTileZ; //!< Chunk coordinates (for use with a tiling scheme)

Expand Down
2 changes: 2 additions & 0 deletions src/3d/qgsabstractvectorlayer3drenderer.cpp
Expand Up @@ -25,6 +25,7 @@ void QgsVectorLayer3DTilingSettings::writeXml( QDomElement &elem ) const

QDomElement elemTiling = doc.createElement( QStringLiteral( "vector-layer-3d-tiling" ) );
elemTiling.setAttribute( QStringLiteral( "zoom-levels-count" ), mZoomLevelsCount );
elemTiling.setAttribute( QStringLiteral( "show-bounding-boxes" ), mShowBoundingBoxes ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elem.appendChild( elemTiling );
}

Expand All @@ -34,6 +35,7 @@ void QgsVectorLayer3DTilingSettings::readXml( const QDomElement &elem )
if ( !elemTiling.isNull() )
{
mZoomLevelsCount = elemTiling.attribute( QStringLiteral( "zoom-levels-count" ) ).toInt();
mShowBoundingBoxes = elemTiling.attribute( QStringLiteral( "show-bounding-boxes" ) ).toInt();
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/3d/qgsabstractvectorlayer3drenderer.h
Expand Up @@ -52,13 +52,19 @@ class _3D_EXPORT QgsVectorLayer3DTilingSettings
*/
void setZoomLevelsCount( int count ) { mZoomLevelsCount = count; }

//! Sets whether to display bounding boxes of entity's tiles (for debugging)
void setShowBoundingBoxes( bool enabled ) { mShowBoundingBoxes = enabled; }
//! Returns whether to display bounding boxes of entity's tiles (for debugging)
bool showBoundingBoxes() const { return mShowBoundingBoxes; }

//! Writes content of the object to XML
void writeXml( QDomElement &elem ) const;
//! Reads content of the object from XML
void readXml( const QDomElement &elem );

private:
int mZoomLevelsCount = 3;
bool mShowBoundingBoxes = false;
};


Expand Down
6 changes: 3 additions & 3 deletions src/3d/qgsrulebasedchunkloader_p.cpp
Expand Up @@ -169,12 +169,12 @@ QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode

QgsRuleBasedChunkedEntity::QgsRuleBasedChunkedEntity( QgsVectorLayer *vl, double zMin, double zMax, const QgsVectorLayer3DTilingSettings &tilingSettings, QgsRuleBased3DRenderer::Rule *rootRule, const Qgs3DMapSettings &map )
: QgsChunkedEntity( Qgs3DUtils::layerToWorldExtent( vl->extent(), zMin, zMax, vl->crs(), map.origin(), map.crs(), map.transformContext() ),
-1, // rootError TODO: negative error should mean that the node does not contain anything
-1, // tau = max. allowed screen error. TODO: negative tau should mean that we need to go until leaves are reached
-1, // rootError (negative error means that the node does not contain anything)
-1, // max. allowed screen error (negative tau means that we need to go until leaves are reached)
tilingSettings.zoomLevelsCount() - 1,
new QgsRuleBasedChunkLoaderFactory( map, vl, rootRule, tilingSettings.zoomLevelsCount() - 1 ) )
{
setShowBoundingBoxes( true );
setShowBoundingBoxes( tilingSettings.showBoundingBoxes() );
}

QgsRuleBasedChunkedEntity::~QgsRuleBasedChunkedEntity()
Expand Down
5 changes: 3 additions & 2 deletions src/3d/qgsvectorlayerchunkloader_p.cpp
Expand Up @@ -155,11 +155,12 @@ QgsChunkLoader *QgsVectorLayerChunkLoaderFactory::createChunkLoader( QgsChunkNod

QgsVectorLayerChunkedEntity::QgsVectorLayerChunkedEntity( QgsVectorLayer *vl, double zMin, double zMax, const QgsVectorLayer3DTilingSettings &tilingSettings, QgsAbstract3DSymbol *symbol, const Qgs3DMapSettings &map )
: QgsChunkedEntity( Qgs3DUtils::layerToWorldExtent( vl->extent(), zMin, zMax, vl->crs(), map.origin(), map.crs(), map.transformContext() ),
-1, // rootError TODO: negative error should mean that the node does not contain anything
-1, // tau = max. allowed screen error. TODO: negative tau should mean that we need to go until leaves are reached
-1, // rootError (negative error means that the node does not contain anything)
-1, // max. allowed screen error (negative tau means that we need to go until leaves are reached)
tilingSettings.zoomLevelsCount() - 1,
new QgsVectorLayerChunkLoaderFactory( map, vl, symbol, tilingSettings.zoomLevelsCount() - 1 ) )
{
setShowBoundingBoxes( tilingSettings.showBoundingBoxes() );
}

QgsVectorLayerChunkedEntity::~QgsVectorLayerChunkedEntity()
Expand Down
3 changes: 3 additions & 0 deletions src/app/3d/qgsvectorlayer3dpropertieswidget.cpp
Expand Up @@ -22,17 +22,20 @@ QgsVectorLayer3DPropertiesWidget::QgsVectorLayer3DPropertiesWidget( QWidget *par
{
setupUi( this );

connect( chkShowBoundingBoxes, &QCheckBox::clicked, this, &QgsVectorLayer3DPropertiesWidget::changed );
connect( spinZoomLevelsCount, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsVectorLayer3DPropertiesWidget::changed );
}

void QgsVectorLayer3DPropertiesWidget::load( QgsAbstractVectorLayer3DRenderer *renderer )
{
whileBlocking( spinZoomLevelsCount )->setValue( renderer->tilingSettings().zoomLevelsCount() );
whileBlocking( chkShowBoundingBoxes )->setChecked( renderer->tilingSettings().showBoundingBoxes() );
}

void QgsVectorLayer3DPropertiesWidget::apply( QgsAbstractVectorLayer3DRenderer *renderer )
{
QgsVectorLayer3DTilingSettings tilingSettings;
tilingSettings.setZoomLevelsCount( spinZoomLevelsCount->value() );
tilingSettings.setShowBoundingBoxes( chkShowBoundingBoxes->isChecked() );
renderer->setTilingSettings( tilingSettings );
}
9 changes: 8 additions & 1 deletion src/ui/3d/qgsvectorlayer3dpropertieswidget.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>539</width>
<height>90</height>
<height>145</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -38,6 +38,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="chkShowBoundingBoxes">
<property name="text">
<string>Show bounding boxes of tiles</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit 5b9b2e4

Please sign in to comment.