Skip to content

Commit

Permalink
initial highlighting implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 17, 2021
1 parent ab0eba2 commit 6de83cd
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 4 deletions.
10 changes: 10 additions & 0 deletions python/core/auto_generated/pointcloud/qgspointcloudlayer.sip.in
Expand Up @@ -130,6 +130,16 @@ Sets the 2D ``renderer`` for the point cloud.
Ownership of ``renderer`` is transferred to the layer.

.. seealso:: :py:func:`renderer`
%End

void setHighlightedPoints( const QVector<QPointF> &points );
%Docstring
Sets the points that will be highlighted when the layer is rendered
%End

QVector<QPointF> highlightedPoints() const;
%Docstring
Returns the list of the points that need to be highlighted when the layer is rendered
%End

private:
Expand Down
Expand Up @@ -26,7 +26,7 @@ Encapsulates the render context for a 2D point cloud rendering operation.
public:

QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset,
double zValueScale, double zValueFixedOffset );
double zValueScale, double zValueFixedOffset, const QVector<QPointF> &highlightedPoints );
%Docstring
Constructor for QgsPointCloudRenderContext.

Expand All @@ -38,6 +38,8 @@ taken from the point cloud index.

The ``zValueFixedOffset`` argument specifies any constant offset value which must be added to z values
taken from the point cloud index.

The ``highlightedPoints`` argument specifies highlighted points during rendering
%End


Expand Down Expand Up @@ -135,6 +137,11 @@ Returns any constant offset which must be applied to z values taken from the poi
Scaling of z values via :py:func:`~QgsPointCloudRenderContext.zValueScale` should be applied before the :py:func:`~QgsPointCloudRenderContext.zValueFixedOffset`.
%End

bool isPointHighlighted( const QPointF &p ) const;
%Docstring
Returns whether the point cloud point ``p`` should be highlighted
%End


private:
QgsPointCloudRenderContext( const QgsPointCloudRenderContext &rh );
Expand Down
2 changes: 2 additions & 0 deletions src/3d/qgspointcloudlayer3drenderer.cpp
Expand Up @@ -108,6 +108,8 @@ QgsPointCloudLayer3DRenderer *QgsPointCloudLayer3DRenderer::clone() const
QgsAbstract3DSymbol *symbolClone = mSymbol->clone();
r->setSymbol( dynamic_cast<QgsPointCloud3DSymbol *>( symbolClone ) );
}
r->setShowBoundingBoxes( mShowBoundingBoxes );
r->setMaximumScreenError( mMaximumScreenError );
return r;
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -621,3 +621,8 @@ void QgsPointCloudLayer::setRenderer( QgsPointCloudRenderer *renderer )
emit rendererChanged();
emit styleChanged();
}

void QgsPointCloudLayer::setHighlightedPoints( const QVector<QPointF> &points )
{
mHighlightedPoints = points;
}
12 changes: 12 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.h
Expand Up @@ -167,6 +167,16 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
*/
void setRenderer( QgsPointCloudRenderer *renderer SIP_TRANSFER );

/**
* Sets the points that will be highlighted when the layer is rendered
*/
void setHighlightedPoints( const QVector<QPointF> &points );

/**
* Returns the list of the points that need to be highlighted when the layer is rendered
*/
QVector<QPointF> highlightedPoints() const { return mHighlightedPoints; }

private slots:
void onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state );

Expand All @@ -183,6 +193,8 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
std::unique_ptr<QgsPointCloudRenderer> mRenderer;

QgsPointCloudLayerElevationProperties *mElevationProperties = nullptr;

QVector<QPointF> mHighlightedPoints;
};


Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Expand Up @@ -64,7 +64,7 @@ QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *laye

bool QgsPointCloudLayerRenderer::render()
{
QgsPointCloudRenderContext context( *renderContext(), mScale, mOffset, mZScale, mZOffset );
QgsPointCloudRenderContext context( *renderContext(), mScale, mOffset, mZScale, mZOffset, mLayer->highlightedPoints() );

// Set up the render configuration options
QPainter *painter = context.renderContext().painter();
Expand Down
6 changes: 5 additions & 1 deletion src/core/pointcloud/qgspointcloudrenderer.cpp
Expand Up @@ -25,12 +25,13 @@
#include "qgslogger.h"
#include "qgscircle.h"

QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset, double zValueScale, double zValueFixedOffset )
QgsPointCloudRenderContext::QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset, double zValueScale, double zValueFixedOffset, const QVector<QPointF> &highlightedPoints )
: mRenderContext( context )
, mScale( scale )
, mOffset( offset )
, mZValueScale( zValueScale )
, mZValueFixedOffset( zValueFixedOffset )
, mHighlightedPoints( highlightedPoints )
{

}
Expand Down Expand Up @@ -195,6 +196,8 @@ void QgsPointCloudRenderer::setPointSymbol( PointSymbol symbol )
mPointSymbol = symbol;
}



QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer, const QgsRenderContext &renderContext, const QgsGeometry &geometry, double toleranceForPointIdentification )
{
QVector<QVariantMap> selectedPoints;
Expand Down Expand Up @@ -283,3 +286,4 @@ QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer,

return selectedPoints;
}

27 changes: 26 additions & 1 deletion src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -53,9 +53,11 @@ class CORE_EXPORT QgsPointCloudRenderContext
*
* The \a zValueFixedOffset argument specifies any constant offset value which must be added to z values
* taken from the point cloud index.
*
* The \a highlightedPoints argument specifies highlighted points during rendering
*/
QgsPointCloudRenderContext( QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset,
double zValueScale, double zValueFixedOffset );
double zValueScale, double zValueFixedOffset, const QVector<QPointF> &highlightedPoints );

//! QgsPointCloudRenderContext cannot be copied.
QgsPointCloudRenderContext( const QgsPointCloudRenderContext &rh ) = delete;
Expand Down Expand Up @@ -154,6 +156,11 @@ class CORE_EXPORT QgsPointCloudRenderContext
*/
double zValueFixedOffset() const { return mZValueFixedOffset; }

/**
* Returns whether the point cloud point \a p should be highlighted
*/
bool isPointHighlighted( const QPointF &p ) const { return mHighlightedPoints.contains( p ); }

#ifndef SIP_RUN

/**
Expand Down Expand Up @@ -209,6 +216,7 @@ class CORE_EXPORT QgsPointCloudRenderContext
double mZValueScale = 1.0;
double mZValueFixedOffset = 0;

QVector<QPointF> mHighlightedPoints;
};


Expand Down Expand Up @@ -511,6 +519,7 @@ class CORE_EXPORT QgsPointCloudRenderer
*/
void drawPoint( double x, double y, const QColor &color, QgsPointCloudRenderContext &context ) const
{
QPointF originalXY( x, y );
context.renderContext().mapToPixel().transformInPlace( x, y );
QPainter *painter = context.renderContext().painter();
switch ( mPointSymbol )
Expand All @@ -529,6 +538,22 @@ class CORE_EXPORT QgsPointCloudRenderer
mPainterPenWidth, mPainterPenWidth ) );
break;
};
if ( context.isPointHighlighted( originalXY ) )
{
QPen highlightPen( QColor( 255 - color.red(), 255 - color.green(), 255 - color.blue() ), 0.3 * mPainterPenWidth );
painter->setPen( highlightPen );
switch ( mPointSymbol )
{
case Square:
painter->drawRect( QRectF( x - mPainterPenWidth * 0.65, y - mPainterPenWidth * 0.65,
mPainterPenWidth * 1.3, mPainterPenWidth * 1.3 ) );
break;
case Circle:
painter->drawEllipse( QRectF( x - mPainterPenWidth * 0.65, y - mPainterPenWidth * 0.65,
mPainterPenWidth * 1.3, mPainterPenWidth * 1.3 ) );
break;
}
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -517,8 +517,16 @@ bool QgsMapToolIdentify::identifyPointCloudLayer( QList<QgsMapToolIdentify::Iden

const QVector<QVariantMap> points = renderer->identify( layer, context, geometry, searchRadiusMapUnits );

QVector<QPointF> highlightedPoints;
for ( const QVariantMap &point : points )
{
highlightedPoints.push_back( QPointF( point[QStringLiteral( "X" ) ].toDouble(), point[QStringLiteral( "Y" ) ].toDouble() ) );
}
layer->setHighlightedPoints( highlightedPoints );

fromPointCloudIdentificationToIdentifyResults( layer, points, *results );

layer->triggerRepaint();
return true;
}

Expand Down

0 comments on commit 6de83cd

Please sign in to comment.