QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgschunknode.h
Go to the documentation of this file.
1/***************************************************************************
2 qgschunknode.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 QGSCHUNKNODE_H
17#define QGSCHUNKNODE_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 "qgis.h"
31#include "qgsaabb.h"
32#include "qgsbox3d.h"
33
34#include <QString>
35#include <QTime>
36
37using namespace Qt::StringLiterals;
38
39#define SIP_NO_FILE
40
41namespace Qt3DCore
42{
43 class QEntity;
44}
45
46struct QgsChunkListEntry;
47class QgsChunkLoader;
48class QgsChunkQueueJob;
49class QgsChunkQueueJobFactory;
50
51
64struct QgsChunkNodeId
65{
69 QgsChunkNodeId( int _d = -1, int _x = -1, int _y = -1, int _z = -1 )
70 : d( _d ), x( _x ), y( _y ), z( _z ) {}
71
77 QgsChunkNodeId( long long id )
78 : uniqueId( id )
79 {}
80
81 int d = 0;
82 int x = 0;
83 int y = 0;
84 int z = 0;
85 long long uniqueId = -1;
86
88 QString text() const
89 {
90 if ( uniqueId != -1 )
91 return QString::number( uniqueId );
92 else if ( z == -1 )
93 return u"%1/%2/%3"_s.arg( d ).arg( x ).arg( y ); // quadtree
94 else
95 return u"%1/%2/%3/%4"_s.arg( d ).arg( x ).arg( y ).arg( z ); // octree
96 }
97
98 bool operator==( const QgsChunkNodeId &other ) const
99 {
100 return ( uniqueId == -1 && other.uniqueId == -1 && d == other.d && x == other.x && y == other.y && z == other.z )
101 || ( uniqueId != -1 && uniqueId == other.uniqueId );
102 }
103
104 bool operator!=( const QgsChunkNodeId &other ) const
105 {
106 return !( *this == other );
107 }
108};
109
126class QgsChunkNode
127{
128 public:
130 QgsChunkNode( const QgsChunkNodeId &nodeId, const QgsBox3D &box3D, float error, QgsChunkNode *parent = nullptr );
131
132 ~QgsChunkNode();
133
152 enum State
153 {
154 Skeleton,
155 QueuedForLoad,
156 Loading,
157 Loaded,
158 QueuedForUpdate,
159 Updating,
160 };
161
163 QgsBox3D box3D() const { return mBox3D; }
165 float error() const { return mError; }
167 QgsChunkNodeId tileId() const { return mNodeId; }
169 QgsChunkNode *parent() const { return mParent; }
171 int childCount() const { return mChildren.count(); }
173 QgsChunkNode *const *children() const { return mChildren.constData(); }
175 Qgis::TileRefinementProcess refinementProcess() const { return mRefinementProcess; }
177 State state() const { return mState; }
178
180 QgsChunkListEntry *loaderQueueEntry() const { return mLoaderQueueEntry; }
182 QgsChunkListEntry *replacementQueueEntry() const { return mReplacementQueueEntry; }
184 QgsChunkLoader *loader() const { return mLoader; }
186 Qt3DCore::QEntity *entity() const { return mEntity; }
188 QgsChunkQueueJob *updater() const { return mUpdater; }
189
191 bool allChildChunksResident( QTime currentTime ) const;
192
194 bool hasChildrenPopulated() const { return mChildrenPopulated; }
195
197 void populateChildren( const QVector<QgsChunkNode *> &children );
198
200 void setRefinementProcess( Qgis::TileRefinementProcess refinementProcess ) { mRefinementProcess = refinementProcess; }
201
203 int level() const;
204
206 QList<QgsChunkNode *> descendants();
207
208 //
209 // changes of states in the state machine (see State enum)
210 //
211
213 void setQueuedForLoad( QgsChunkListEntry *entry );
214
216 void cancelQueuedForLoad();
217
219 void setLoading( QgsChunkLoader *chunkLoader );
220
222 void cancelLoading();
223
225 void setLoaded( Qt3DCore::QEntity *mEntity );
226
228 void unloadChunk();
229
231 void setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory );
232
234 void cancelQueuedForUpdate();
235
237 void setUpdating();
238
240 void cancelUpdating();
241
243 void setUpdated();
244
246 void replaceEntity( Qt3DCore::QEntity *newEntity );
247
249 void setExactBox3D( const QgsBox3D &box3D );
250
258 void updateParentBoundingBoxesRecursively() const;
259
261 void setHasData( bool hasData ) { mHasData = hasData; }
263 bool hasData() const { return mHasData; }
264
265 private:
266 QgsBox3D mBox3D;
267 float mError;
268
269 QgsChunkNodeId mNodeId;
270
271 QgsChunkNode *mParent;
272 QVector<QgsChunkNode *> mChildren;
273 bool mChildrenPopulated = false;
274
275 State mState = Skeleton;
276
278
279 QgsChunkListEntry *mLoaderQueueEntry = nullptr;
280 QgsChunkListEntry *mReplacementQueueEntry = nullptr;
281
282 QgsChunkLoader *mLoader = nullptr;
283 Qt3DCore::QEntity *mEntity = nullptr;
284
285 QgsChunkQueueJobFactory *mUpdaterFactory = nullptr;
286 QgsChunkQueueJob *mUpdater = nullptr;
287
288 QTime mEntityCreatedTime;
289 bool mHasData = true;
290};
291
293
294#endif // CHUNKNODE_H
TileRefinementProcess
Tiled scene tile refinement processes.
Definition qgis.h:5922
@ Replacement
When tile is refined then its children should be used in place of itself.
Definition qgis.h:5923
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)