QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgschunkedentity_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgschunkedentity_p.h
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSCHUNKEDENTITY_P_H
17 #define QGSCHUNKEDENTITY_P_H
18 
20 
21 //
22 // W A R N I N G
23 // -------------
24 //
25 // This file is not part of the QGIS API. It exists purely as an
26 // implementation detail. This header file may change from version to
27 // version without notice, or even be removed.
28 //
29 
30 #include <Qt3DCore/QEntity>
31 
32 class QgsAABB;
33 class QgsChunkNode;
34 class QgsChunkList;
35 class QgsChunkQueueJob;
36 class QgsChunkLoaderFactory;
37 class QgsChunkBoundsEntity;
38 class QgsChunkQueueJobFactory;
39 
40 #include <QVector3D>
41 #include <QMatrix4x4>
42 
43 #include <QTime>
44 
45 #include "qgsfeatureid.h"
46 
47 namespace Qt3DRender
48 {
49  class QPickEvent;
50 }
51 
58 class QgsChunkedEntity : public Qt3DCore::QEntity
59 {
60  Q_OBJECT
61  public:
63  QgsChunkedEntity( const QgsAABB &rootBbox, float rootError, float mTau, int mMaxLevel, QgsChunkLoaderFactory *loaderFactory, Qt3DCore::QNode *parent = nullptr );
64  ~QgsChunkedEntity() override;
65 
67  struct SceneState
68  {
69  QVector3D cameraPos;
70  float cameraFov;
71  int screenSizePx;
72  QMatrix4x4 viewProjectionMatrix;
73  };
74 
76  void update( const SceneState &state );
77 
79  bool needsUpdate() const { return mNeedsUpdate; }
80 
82  void setShowBoundingBoxes( bool enabled );
83 
85  void updateNodes( const QList<QgsChunkNode *> &nodes, QgsChunkQueueJobFactory *updateJobFactory );
86 
88  QList<QgsChunkNode *> activeNodes() const { return mActiveNodes; }
90  QgsChunkNode *rootNode() const { return mRootNode; }
91 
93  int pendingJobsCount() const;
94 
96  void setPickingEnabled( bool enabled );
98  bool hasPickingEnabled() const { return mPickingEnabled; }
99 
100  protected:
102  void cancelActiveJob( QgsChunkQueueJob *job );
103  void cancelActiveJobs();
105  void setNeedsUpdate( bool needsUpdate ) { mNeedsUpdate = needsUpdate; }
106 
107  private:
108  void update( QgsChunkNode *node, const SceneState &state );
109 
111  void requestResidency( QgsChunkNode *node );
112 
113  void startJobs();
114  QgsChunkQueueJob *startJob( QgsChunkNode *node );
115 
116  private slots:
117  void onActiveJobFinished();
118 
119  void onPickEvent( Qt3DRender::QPickEvent *event );
120 
121  signals:
123  void pendingJobsCountChanged();
124 
126  void newEntityCreated( Qt3DCore::QEntity *entity );
127 
129  void pickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
130 
131  protected:
133  QgsChunkNode *mRootNode = nullptr;
135  bool mNeedsUpdate = false;
136 
144  float mTau;
146  int mMaxLevel;
148  QgsChunkLoaderFactory *mChunkLoaderFactory = nullptr;
150  QgsChunkList *mChunkLoaderQueue = nullptr;
152  QgsChunkList *mReplacementQueue = nullptr;
154  QList<QgsChunkNode *> mActiveNodes;
156  int mFrustumCulled = 0;
157 
158  // TODO: max. length for loading queue
159 
160  QTime mCurrentTime;
161 
163  int mMaxLoadedChunks = 512;
164 
166  QgsChunkBoundsEntity *mBboxesEntity = nullptr;
167 
169  QList<QgsChunkQueueJob *> mActiveJobs;
170 
172  bool mPickingEnabled = false;
173 };
174 
176 
177 #endif // QGSCHUNKEDENTITY_P_H
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:30
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25