QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 #include <numeric>
32 
33 #define SIP_NO_FILE
34 
35 class QgsAABB;
36 class QgsChunkNode;
37 class QgsChunkList;
38 class QgsChunkQueueJob;
39 class QgsChunkLoaderFactory;
40 class QgsChunkBoundsEntity;
41 class QgsChunkQueueJobFactory;
42 
43 #include <QVector3D>
44 #include <QMatrix4x4>
45 
46 #include <QTime>
47 
48 #include "qgsfeatureid.h"
49 #include "qgschunknode_p.h"
50 
51 namespace Qt3DRender
52 {
53  class QPickEvent;
54 }
55 
62 class QgsChunkedEntity : public Qt3DCore::QEntity
63 {
64  Q_OBJECT
65  public:
67  QgsChunkedEntity( float tau, QgsChunkLoaderFactory *loaderFactory, bool ownsFactory, int primitivesBudget = std::numeric_limits<int>::max(), Qt3DCore::QNode *parent = nullptr );
68  ~QgsChunkedEntity() override;
69 
71  struct SceneState
72  {
73  QVector3D cameraPos;
74  float cameraFov;
75  int screenSizePx;
76  QMatrix4x4 viewProjectionMatrix;
77  };
78 
80  void update( const SceneState &state );
81 
83  bool needsUpdate() const { return mNeedsUpdate; }
84 
86  void setShowBoundingBoxes( bool enabled );
87 
89  void updateNodes( const QList<QgsChunkNode *> &nodes, QgsChunkQueueJobFactory *updateJobFactory );
90 
92  QList<QgsChunkNode *> activeNodes() const { return mActiveNodes; }
94  QgsChunkNode *rootNode() const { return mRootNode; }
95 
97  int pendingJobsCount() const;
98 
100  void setPickingEnabled( bool enabled );
102  bool hasPickingEnabled() const { return mPickingEnabled; }
103 
105  void setUsingAdditiveStrategy( bool additive ) { mAdditiveStrategy = additive; }
106 
112  bool usingAditiveStrategy() const { return mAdditiveStrategy; }
113 
114  protected:
116  void cancelActiveJob( QgsChunkQueueJob *job );
117  void cancelActiveJobs();
119  void setNeedsUpdate( bool needsUpdate ) { mNeedsUpdate = needsUpdate; }
120 
121  private:
122  void update( QgsChunkNode *node, const SceneState &state );
123 
125  void requestResidency( QgsChunkNode *node );
126 
127  void startJobs();
128  QgsChunkQueueJob *startJob( QgsChunkNode *node );
129 
130  private slots:
131  void onActiveJobFinished();
132 
133  void onPickEvent( Qt3DRender::QPickEvent *event );
134 
135  signals:
137  void pendingJobsCountChanged();
138 
140  void newEntityCreated( Qt3DCore::QEntity *entity );
141 
143  void pickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
144 
145  protected:
147  QgsChunkNode *mRootNode = nullptr;
149  bool mNeedsUpdate = false;
150 
158  float mTau;
160  QgsChunkLoaderFactory *mChunkLoaderFactory = nullptr;
162  bool mOwnsFactory = true;
164  QgsChunkList *mChunkLoaderQueue = nullptr;
166  QgsChunkList *mReplacementQueue = nullptr;
168  QList<QgsChunkNode *> mActiveNodes;
170  int mFrustumCulled = 0;
171 
172  // TODO: max. length for loading queue
173 
174  QTime mCurrentTime;
175 
177  int mMaxLoadedChunks = 512;
178 
180  QgsChunkBoundsEntity *mBboxesEntity = nullptr;
181 
183  QList<QgsChunkQueueJob *> mActiveJobs;
184 
186  bool mPickingEnabled = false;
187 
192  bool mAdditiveStrategy = false;
193 
194  bool mIsValid = true;
195 
196  int mPrimitivesBudget = std::numeric_limits<int>::max();
197 };
198 
200 
201 #endif // QGSCHUNKEDENTITY_P_H
3
Definition: qgsaabb.h:34
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28