QGIS API Documentation  3.17.0-Master (a035f434f4)
qgschunknode_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgschunknode_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 QGSCHUNKNODE_P_H
17 #define QGSCHUNKNODE_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 "qgsaabb.h"
31 
32 #include <QTime>
33 
34 #define SIP_NO_FILE
35 
36 namespace Qt3DCore
37 {
38  class QEntity;
39 }
40 
41 struct QgsChunkListEntry;
42 class QgsChunkLoader;
43 class QgsChunkQueueJob;
44 class QgsChunkQueueJobFactory;
45 
46 
54 struct QgsChunkNodeId
55 {
57  QgsChunkNodeId( int _d = -1, int _x = -1, int _y = -1, int _z = -1 )
58  : d( _d ), x( _x ), y( _y ), z( _z ) {}
59 
60  int d, x, y, z;
61 
63  QString text() const
64  {
65  if ( z == -1 )
66  return QStringLiteral( "%1/%2/%3" ).arg( d ).arg( x ).arg( y ); // quadtree
67  else
68  return QStringLiteral( "%1/%2/%3/%4" ).arg( d ).arg( x ).arg( y ).arg( z ); // octree
69  }
70 
71  bool operator==( const QgsChunkNodeId &other ) const
72  {
73  return d == other.d && x == other.x && y == other.y && z == other.z;
74  }
75 
76  bool operator!=( const QgsChunkNodeId &other ) const
77  {
78  return !( *this == other );
79  }
80 };
81 
96 class QgsChunkNode
97 {
98  public:
99 
101  QgsChunkNode( const QgsChunkNodeId &nodeId, const QgsAABB &bbox, float error, QgsChunkNode *parent = nullptr );
102 
103  ~QgsChunkNode();
104 
123  enum State
124  {
125  Skeleton,
126  QueuedForLoad,
127  Loading,
128  Loaded,
129  QueuedForUpdate,
130  Updating,
131  };
132 
134  QgsAABB bbox() const { return mBbox; }
136  float error() const { return mError; }
138  QgsChunkNodeId tileId() const { return mNodeId; }
140  QgsChunkNode *parent() const { return mParent; }
142  int childCount() const { return mChildCount; }
144  QgsChunkNode *const *children() const { return mChildren; }
146  State state() const { return mState; }
147 
149  QgsChunkListEntry *loaderQueueEntry() const { return mLoaderQueueEntry; }
151  QgsChunkListEntry *replacementQueueEntry() const { return mReplacementQueueEntry; }
153  QgsChunkLoader *loader() const { return mLoader; }
155  Qt3DCore::QEntity *entity() const { return mEntity; }
157  QgsChunkQueueJob *updater() const { return mUpdater; }
158 
160  bool allChildChunksResident( QTime currentTime ) const;
161 
163  void populateChildren( const QVector<QgsChunkNode *> &children );
164 
166  int level() const;
167 
169  QList<QgsChunkNode *> descendants();
170 
171  //
172  // changes of states in the state machine (see State enum)
173  //
174 
176  void setQueuedForLoad( QgsChunkListEntry *entry );
177 
179  void cancelQueuedForLoad();
180 
182  void setLoading( QgsChunkLoader *chunkLoader );
183 
185  void cancelLoading();
186 
188  void setLoaded( Qt3DCore::QEntity *mEntity );
189 
191  void unloadChunk();
192 
194  void setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory );
195 
197  void cancelQueuedForUpdate();
198 
200  void setUpdating();
201 
203  void cancelUpdating();
204 
206  void setUpdated();
207 
209  void setExactBbox( const QgsAABB &box );
210 
212  void setHasData( bool hasData ) { mHasData = hasData; }
214  bool hasData() const { return mHasData; }
215 
216  private:
217  QgsAABB mBbox;
218  float mError;
219 
220  QgsChunkNodeId mNodeId;
221 
222  QgsChunkNode *mParent;
223  QgsChunkNode *mChildren[8];
224  int mChildCount = -1;
225 
226  State mState;
227 
228  QgsChunkListEntry *mLoaderQueueEntry;
229  QgsChunkListEntry *mReplacementQueueEntry;
230 
231  QgsChunkLoader *mLoader;
232  Qt3DCore::QEntity *mEntity;
233 
234  QgsChunkQueueJobFactory *mUpdaterFactory;
235  QgsChunkQueueJob *mUpdater;
236 
237  QTime mEntityCreatedTime;
238  bool mHasData = true;
239 };
240 
242 
243 #endif // CHUNKNODE_H
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:33
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)