Skip to content
Permalink
Browse files

save progress

  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Jan 13, 2021
1 parent 8a85cae commit a98ec51e5e0de90379b683a113504e469767036a
@@ -1098,3 +1098,16 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
QgsMessageOutput::showMessage( tr( "3D exporter warning" ), message, QgsMessageOutput::MessageText );
}
}

void Qgs3DMapScene::onRayCasted( const QVector3D &rayOrigin, QVector3D &rayDirection )
{
qDebug() << __PRETTY_FUNCTION__;
for ( QgsMapLayer *layer : mMap.layers() )
{
if ( layer->type() != QgsMapLayerType::PointCloudLayer ) continue;
if ( QgsPointCloudLayer *pc = dynamic_cast<QgsPointCloudLayer *>( layer ) )
{
pc->getPointsOnRay( rayOrigin, rayDirection );
}
}
}
@@ -134,6 +134,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
public slots:
//! Updates the temporale entities
void updateTemporal();
void onRayCasted( const QVector3D &rayOrigin, QVector3D &rayDirection );

private slots:
void onCameraChanged();
@@ -253,3 +253,26 @@ void Qgs3DMapCanvas::updateTemporalRange( const QgsDateTimeRange &temporalrange
mMap->setTemporalRange( temporalrange );
mScene->updateTemporal();
}


void Qgs3DMapCanvas::mouseReleased( QMouseEvent *event )
{
// qDebug() << __PRETTY_FUNCTION__ << " " << event->x() << " " << event->y();
QVector3D deviceCoords( event->x(), event->y(), 0.0 );
QSize windowSize = mEngine->size();
QVector3D normDeviceCoords( 2.0 * deviceCoords.x() / windowSize.width() - 1.0f, 1.0f - 2.0 * deviceCoords.y() / windowSize.height(), mEngine->camera()->nearPlane() );
// qDebug() << "NDC " << normDeviceCoords.x() << " " << normDeviceCoords.y() << " " << normDeviceCoords.z();
QVector4D rayClip( normDeviceCoords.x(), normDeviceCoords.y(), -1.0f, 0.0f );
QMatrix4x4 projMatrix = mEngine->camera()->projectionMatrix();
QMatrix4x4 viewMatrix = mEngine->camera()->viewMatrix();

QVector4D rayEye = projMatrix.inverted() * rayClip;
rayEye.setZ( -1.0f );
rayEye.setW( 0.0f );
QVector4D rayWorld4D = viewMatrix.inverted() * rayEye;
QVector3D rayWorld( rayWorld4D.x(), rayWorld4D.y(), rayWorld4D.z() );
rayWorld = rayWorld.normalized();
// qDebug() << "rayEye: " << rayEye;
// qDebug() << "rayWorld: " << rayWorld;
mScene->onRayCasted( QVector3D( rayEye ), rayWorld );
}
@@ -97,7 +97,8 @@ class Qgs3DMapCanvas : public QWidget
void fpsCountChanged( float fpsCount );
//! Emitted when the FPS counter is enabled or disabeld
void fpsCounterEnabledChanged( bool enabled );

public slots:
void mouseReleased( QMouseEvent *event );
private slots:
void updateTemporalRange( const QgsDateTimeRange &timeRange );

@@ -66,6 +66,7 @@ Qgs3DMapToolIdentify::Qgs3DMapToolIdentify( Qgs3DMapCanvas *canvas )
{
mPickHandler.reset( new Qgs3DMapToolIdentifyPickHandler( this ) );
connect( canvas, &Qgs3DMapCanvas::mapSettingsChanged, this, &Qgs3DMapToolIdentify::onMapSettingsChanged );
connect( this, &Qgs3DMapToolIdentify::mouseReleased, canvas, &Qgs3DMapCanvas::mouseReleased );
}

Qgs3DMapToolIdentify::~Qgs3DMapToolIdentify() = default;
@@ -19,6 +19,7 @@
#include "qgs3dmaptool.h"

#include <memory>
#include <QDebug>

namespace Qt3DRender
{
@@ -37,13 +38,19 @@ class Qgs3DMapToolIdentify : public Qgs3DMapTool
~Qgs3DMapToolIdentify() override;

void mousePressEvent( QMouseEvent *event ) override;
void mouseReleaseEvent( QMouseEvent *event ) override { Q_UNUSED( event )}
void mouseReleaseEvent( QMouseEvent *event ) override
{
Q_UNUSED( event )
emit mouseReleased( event );
}
void mouseMoveEvent( QMouseEvent *event ) override {Q_UNUSED( event )}

void activate() override;
void deactivate() override;

QCursor cursor() const override;
signals:
void mouseReleased( QMouseEvent *event );

private slots:
void onTerrainPicked( Qt3DRender::QPickEvent *event );
@@ -406,3 +406,27 @@ QVector<IndexedPointCloudNode> QgsPointCloudDataProvider::traverseTree(

return nodes;
}
QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::getPointsOnRay( const QVector3D &rayOrigin, const QVector3D &rayDirection )
{
QVector<QMap<QString, QVariant>> points;
return points;
}

QVector<IndexedPointCloudNode> QgsPointCloudDataProvider::getNodesIntersectingWithRay(
const QgsPointCloudIndex *pc, IndexedPointCloudNode n,
const QVector3D &rayOrigin, const QVector3D &rayDirectione )
{
QVector<IndexedPointCloudNode> nodes;

// TODO: check if the node actually intersects with the ray

nodes.append( n );

const QList<IndexedPointCloudNode> children = pc->nodeChildren( n );
for ( const IndexedPointCloudNode &nn : children )
{
nodes += getNodesIntersectingWithRay( pc, nn, rayOrigin, rayDirectione );
}

return nodes;
}
@@ -22,6 +22,7 @@
#include "qgsdataprovider.h"
#include "qgspointcloudattribute.h"
#include "qgsstatisticalsummary.h"
#include "qgspointcloudindex.h"
#include <memory>

class IndexedPointCloudNode;
@@ -120,6 +121,8 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
}
% End
#endif
QVector<QMap<QString, QVariant>> getPointsOnRay( const QVector3D &rayOrigin, const QVector3D &rayDirection ) SIP_SKIP;
QVector<IndexedPointCloudNode> getNodesIntersectingWithRay( const QgsPointCloudIndex *pc, IndexedPointCloudNode n, const QVector3D &rayOrigin, const QVector3D &rayDirection );

/**
* Returns flags containing the supported capabilities for the data provider.
@@ -208,7 +211,6 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
* providers will return NULLPTR.
*/
virtual QgsPointCloudRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;

#ifndef SIP_RUN

/**
@@ -621,3 +621,10 @@ void QgsPointCloudLayer::setRenderer( QgsPointCloudRenderer *renderer )
emit rendererChanged();
emit styleChanged();
}

QVector<QMap<QString, QVariant>> QgsPointCloudLayer::getPointsOnRay( const QVector3D &rayOrigin, const QVector3D &rayDirection )
{
QVector<QMap<QString, QVariant>> points = mDataProvider->getPointsOnRay( rayOrigin, rayDirection );
qDebug() << __PRETTY_FUNCTION__;
return points;
}
@@ -167,6 +167,7 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
*/
void setRenderer( QgsPointCloudRenderer *renderer SIP_TRANSFER );

QVector<QMap<QString, QVariant>> getPointsOnRay( const QVector3D &rayOrigin, const QVector3D &rayDirection );
private slots:
void onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state );

0 comments on commit a98ec51

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