Skip to content

Commit

Permalink
save progress
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Jan 13, 2021
1 parent 8a85cae commit a98ec51
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/3d/qgs3dmapscene.cpp
Expand Up @@ -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 );
}
}
}
1 change: 1 addition & 0 deletions src/3d/qgs3dmapscene.h
Expand Up @@ -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();
Expand Down
23 changes: 23 additions & 0 deletions src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -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 );
}
3 changes: 2 additions & 1 deletion src/app/3d/qgs3dmapcanvas.h
Expand Up @@ -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 );

Expand Down
1 change: 1 addition & 0 deletions src/app/3d/qgs3dmaptoolidentify.cpp
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/app/3d/qgs3dmaptoolidentify.h
Expand Up @@ -19,6 +19,7 @@
#include "qgs3dmaptool.h"

#include <memory>
#include <QDebug>

namespace Qt3DRender
{
Expand All @@ -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 );
Expand Down
24 changes: 24 additions & 0 deletions src/core/pointcloud/qgspointclouddataprovider.cpp
Expand Up @@ -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;
}
4 changes: 3 additions & 1 deletion src/core/pointcloud/qgspointclouddataprovider.h
Expand Up @@ -22,6 +22,7 @@
#include "qgsdataprovider.h"
#include "qgspointcloudattribute.h"
#include "qgsstatisticalsummary.h"
#include "qgspointcloudindex.h"
#include <memory>

class IndexedPointCloudNode;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

/**
Expand Down
7 changes: 7 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/core/pointcloud/qgspointcloudlayer.h
Expand Up @@ -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 );

Expand Down

0 comments on commit a98ec51

Please sign in to comment.