QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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,
68  int primitivesBudget = std::numeric_limits<int>::max(),
69  Qt3DCore::QNode *parent = nullptr );
70  ~QgsChunkedEntity() override;
71 
73  struct SceneState
74  {
75  QVector3D cameraPos;
76  float cameraFov;
77  int screenSizePx;
78  QMatrix4x4 viewProjectionMatrix;
79  };
80 
82  void update( const SceneState &state );
83 
85  bool needsUpdate() const { return mNeedsUpdate; }
86 
88  void setShowBoundingBoxes( bool enabled );
89 
91  void updateNodes( const QList<QgsChunkNode *> &nodes, QgsChunkQueueJobFactory *updateJobFactory );
92 
94  QList<QgsChunkNode *> activeNodes() const { return mActiveNodes; }
96  QgsChunkNode *rootNode() const { return mRootNode; }
97 
99  int pendingJobsCount() const;
100 
102  void setPickingEnabled( bool enabled );
104  bool hasPickingEnabled() const { return mPickingEnabled; }
105 
107  void setUsingAdditiveStrategy( bool additive ) { mAdditiveStrategy = additive; }
108 
114  bool usingAditiveStrategy() const { return mAdditiveStrategy; }
115 
120  void setGpuMemoryLimit( double gpuMemoryLimit ) { mGpuMemoryLimit = gpuMemoryLimit; }
121 
126  double gpuMemoryLimit() const { return mGpuMemoryLimit; }
127 
128  static double calculateEntityGpuMemorySize( Qt3DCore::QEntity *entity );
129 
130  protected:
132  void cancelActiveJob( QgsChunkQueueJob *job );
133  void cancelActiveJobs();
135  void setNeedsUpdate( bool needsUpdate ) { mNeedsUpdate = needsUpdate; }
136 
137  private:
138  void update( QgsChunkNode *node, const SceneState &state );
139 
141  void pruneLoaderQueue( const SceneState &state );
142 
144  void requestResidency( QgsChunkNode *node );
145 
146  void startJobs();
147  QgsChunkQueueJob *startJob( QgsChunkNode *node );
148 
149  private slots:
150  void onActiveJobFinished();
151 
152  void onPickEvent( Qt3DRender::QPickEvent *event );
153 
154  signals:
156  void pendingJobsCountChanged();
157 
159  void newEntityCreated( Qt3DCore::QEntity *entity );
160 
162  void pickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
163 
164  protected:
166  QgsChunkNode *mRootNode = nullptr;
168  bool mNeedsUpdate = false;
169 
177  float mTau;
179  QgsChunkLoaderFactory *mChunkLoaderFactory = nullptr;
181  bool mOwnsFactory = true;
183  QgsChunkList *mChunkLoaderQueue = nullptr;
185  QgsChunkList *mReplacementQueue = nullptr;
187  QList<QgsChunkNode *> mActiveNodes;
189  int mFrustumCulled = 0;
190 
191  // TODO: max. length for loading queue
192 
193  QTime mCurrentTime;
194 
196  QgsChunkBoundsEntity *mBboxesEntity = nullptr;
197 
199  QList<QgsChunkQueueJob *> mActiveJobs;
200 
202  bool mPickingEnabled = false;
203 
208  bool mAdditiveStrategy = false;
209 
210  bool mIsValid = true;
211 
212  int mPrimitivesBudget = std::numeric_limits<int>::max();
213  double mGpuMemoryLimit = 500.0; // in megabytes
214 };
215 
217 
218 #endif // QGSCHUNKEDENTITY_P_H
qgschunknode_p.h
qgsfeatureid.h
Qt3DRender
Definition: qgs3dmapscene.h:28
QgsAABB
Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:33
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28