QGIS API Documentation 4.3.0-Master (16eddb2670e)
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 "qgsbox3d.h"
32
33#include <QString>
34#include <QTime>
35
36#define SIP_NO_FILE
37
38using namespace Qt::StringLiterals;
39
40
41namespace Qt3DCore
42{
43 class QEntity;
44}
45
46struct QgsChunkListEntry;
47struct QgsChunkQueueJob;
48class QgsChunkLoader;
49
50
63struct QgsChunkNodeId
64{
68 QgsChunkNodeId( int _d = -1, int _x = -1, int _y = -1, int _z = -1 )
69 : d( _d )
70 , x( _x )
71 , y( _y )
72 , z( _z )
73 {}
74
80 QgsChunkNodeId( long long id )
81 : uniqueId( id )
82 {}
83
84 int d = 0;
85 int x = 0;
86 int y = 0;
87 int z = 0;
88 long long uniqueId = -1;
89
91 QString text() const
92 {
93 if ( uniqueId != -1 )
94 return QString::number( uniqueId );
95 else if ( z == -1 )
96 return u"%1/%2/%3"_s.arg( d ).arg( x ).arg( y ); // quadtree
97 else
98 return u"%1/%2/%3/%4"_s.arg( d ).arg( x ).arg( y ).arg( z ); // octree
99 }
100
101 bool operator==( const QgsChunkNodeId &other ) const
102 {
103 return ( uniqueId == -1 && other.uniqueId == -1 && d == other.d && x == other.x && y == other.y && z == other.z ) || ( uniqueId != -1 && uniqueId == other.uniqueId );
104 }
105
106 bool operator!=( const QgsChunkNodeId &other ) const { return !( *this == other ); }
107};
108
125class QgsChunkNode
126{
127 public:
129 QgsChunkNode( const QgsChunkNodeId &nodeId, const QgsBox3D &box3D, float error, QgsChunkNode *parent = nullptr );
130
131 ~QgsChunkNode();
132
151 enum State
152 {
153 Skeleton,
154 QueuedForLoad,
155 Loading,
156 Loaded,
157 QueuedForUpdate,
158 Updating,
159 };
160
162 QgsBox3D box3D() const { return mBox3D; }
164 float error() const { return mError; }
166 QgsChunkNodeId tileId() const { return mNodeId; }
168 QgsChunkNode *parent() const { return mParent; }
170 int childCount() const { return mChildren.count(); }
172 QgsChunkNode *const *children() const { return mChildren.constData(); }
174 Qgis::TileRefinementProcess refinementProcess() const { return mRefinementProcess; }
176 State state() const { return mState; }
177
179 QgsChunkListEntry *loaderQueueEntry() const { return mLoaderQueueEntry; }
181 QgsChunkListEntry *replacementQueueEntry() const { return mReplacementQueueEntry; }
183 QgsChunkQueueJob *loaderJob() const { return mLoaderJob; }
185 Qt3DCore::QEntity *entity() const { return mEntity; }
187 QgsChunkQueueJob *updateJob() const { return mUpdateJob; }
188
190 bool allChildChunksResident( QTime currentTime ) const;
191
193 bool hasChildrenPopulated() const { return mChildrenPopulated; }
194
196 void populateChildren( const QVector<QgsChunkNode *> &children );
197
199 void setRefinementProcess( Qgis::TileRefinementProcess refinementProcess ) { mRefinementProcess = refinementProcess; }
200
202 int level() const;
203
205 QList<QgsChunkNode *> descendants();
206
207 //
208 // changes of states in the state machine (see State enum)
209 //
210
212 void setQueuedForLoad( QgsChunkListEntry *entry );
213
215 void cancelQueuedForLoad();
216
218 void setLoading( QgsChunkQueueJob &job );
219
221 void cancelLoading();
222
224 void setLoaded( Qt3DCore::QEntity *mEntity );
225
227 void unloadChunk();
228
230 void setQueuedForUpdate( QgsChunkListEntry *entry );
231
233 void cancelQueuedForUpdate();
234
236 void setUpdating( QgsChunkQueueJob &job );
237
239 void cancelUpdating();
240
242 void setUpdated();
243
245 void replaceEntity( Qt3DCore::QEntity *newEntity );
246
248 bool creatingChildren() const;
249
251 void setCreatingChildren( bool creatingChildren );
252
254 void setExactBox3D( const QgsBox3D &box3D );
255
263 void updateParentBoundingBoxesRecursively() const;
264
266 void setHasData( bool hasData ) { mHasData = hasData; }
268 bool hasData() const { return mHasData; }
269
270 private:
271 QgsBox3D mBox3D;
272 float mError;
273
274 QgsChunkNodeId mNodeId;
275
276 QgsChunkNode *mParent;
277 QVector<QgsChunkNode *> mChildren;
278 bool mChildrenPopulated = false;
279
280 State mState = Skeleton;
281
283
284 QgsChunkListEntry *mLoaderQueueEntry = nullptr;
285 QgsChunkListEntry *mReplacementQueueEntry = nullptr;
286
287 QgsChunkQueueJob *mLoaderJob = nullptr;
288 Qt3DCore::QEntity *mEntity = nullptr;
289
290 QgsChunkQueueJob *mUpdateJob = nullptr;
291
292 QTime mEntityCreatedTime;
293 bool mHasData = true;
294
295 bool mCreatingChildren = false;
296};
297
299
300#endif // CHUNKNODE_H
TileRefinementProcess
Tiled scene tile refinement processes.
Definition qgis.h:6476
@ Replacement
When tile is refined then its children should be used in place of itself.
Definition qgis.h:6477
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)