Skip to content

Commit

Permalink
Implement a temporary rendering of the root bounding volume
Browse files Browse the repository at this point in the history
as a 2d renderer for QgsTiledMeshLayer

(Handy for debugging for now)
  • Loading branch information
nyalldawson committed Jul 17, 2023
1 parent 7e35792 commit 1979bc6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/core/tiledmesh/qgstiledmeshlayerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@


#include "qgstiledmeshlayerrenderer.h"
#include "qgscurve.h"
#include "qgstiledmeshboundingvolume.h"
#include "qgstiledmeshlayer.h"
#include "qgsfeedback.h"
#include "qgsmapclippingutils.h"
#include "qgsrendercontext.h"
#include "qgscurvepolygon.h"
#include "qgslinesymbol.h"

QgsTiledMeshLayerRenderer::QgsTiledMeshLayerRenderer( QgsTiledMeshLayer *layer, QgsRenderContext &context )
: QgsMapLayerRenderer( layer->id(), &context )
Expand All @@ -31,7 +35,11 @@ QgsTiledMeshLayerRenderer::QgsTiledMeshLayerRenderer( QgsTiledMeshLayer *layer,
if ( !layer->dataProvider() ) // || !layer->renderer() )
return;

mMeshCrs = layer->dataProvider()->meshCrs();

mClippingRegions = QgsMapClippingUtils::collectClippingRegionsForLayer( *renderContext(), layer );
if ( const QgsAbstractTiledMeshNodeBoundingVolume *layerBoundingVolume = layer->dataProvider()->boundingVolume() )
mLayerBoundingVolume.reset( layerBoundingVolume->clone() );

mReadyToCompose = false;
}
Expand Down Expand Up @@ -62,6 +70,41 @@ bool QgsTiledMeshLayerRenderer::render()
mElapsedTimer.start();
}

if ( mLayerBoundingVolume )
{
const QgsCoordinateTransform transform = QgsCoordinateTransform( mMeshCrs, renderContext()->coordinateTransform().destinationCrs(), renderContext()->transformContext() );
try
{
std::unique_ptr< QgsAbstractGeometry > rootBoundsGeometry( mLayerBoundingVolume->as2DGeometry( transform ) );
if ( QgsCurvePolygon *polygon = qgsgeometry_cast< QgsCurvePolygon * >( rootBoundsGeometry.get() ) )
{
QPolygonF rootBoundsPoly = polygon->exteriorRing()->asQPolygonF();

// remove non-finite points, e.g. infinite or NaN points caused by reprojecting errors
rootBoundsPoly.erase( std::remove_if( rootBoundsPoly.begin(), rootBoundsPoly.end(),
[]( const QPointF point )
{
return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
} ), rootBoundsPoly.end() );

QPointF *ptr = rootBoundsPoly.data();
for ( int i = 0; i < rootBoundsPoly.size(); ++i, ++ptr )
{
renderContext()->mapToPixel().transformInPlace( ptr->rx(), ptr->ry() );
}

QgsLineSymbol symbol;
symbol.startRender( *renderContext() );
symbol.renderPolyline( rootBoundsPoly, nullptr, *renderContext() );
symbol.stopRender( *renderContext() );
}
}
catch ( QgsCsException & )
{
QgsDebugError( QStringLiteral( "Error transforming root bounding volume" ) );
}
}

mReadyToCompose = true;
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/tiledmesh/qgstiledmeshlayerrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "qgis_core.h"
#include "qgsmaplayerrenderer.h"
#include "qgscoordinatereferencesystem.h"

#include <memory>
#include <QElapsedTimer>
Expand All @@ -29,6 +30,8 @@
class QgsTiledMeshLayer;
class QgsFeedback;
class QgsMapClippingRegion;
class QgsAbstractTiledMeshNodeBoundingVolume;


/**
* \ingroup core
Expand Down Expand Up @@ -60,6 +63,9 @@ class CORE_EXPORT QgsTiledMeshLayerRenderer: public QgsMapLayerRenderer
bool mBlockRenderUpdates = false;
QElapsedTimer mElapsedTimer;

QgsCoordinateReferenceSystem mMeshCrs;
std::unique_ptr< QgsAbstractTiledMeshNodeBoundingVolume > mLayerBoundingVolume;

std::unique_ptr<QgsFeedback> mFeedback = nullptr;
};

Expand Down

0 comments on commit 1979bc6

Please sign in to comment.