21#include <Qt3DCore/QEntity>
25QgsChunkNode::QgsChunkNode(
const QgsChunkNodeId &nodeId,
const QgsAABB &bbox,
float error, QgsChunkNode *parent )
31 , mLoaderQueueEntry( nullptr )
32 , mReplacementQueueEntry( nullptr )
35 , mUpdaterFactory( nullptr )
40QgsChunkNode::~QgsChunkNode()
42 Q_ASSERT( mState == Skeleton );
43 Q_ASSERT( !mLoaderQueueEntry );
44 Q_ASSERT( !mReplacementQueueEntry );
47 Q_ASSERT( !mUpdater );
48 Q_ASSERT( !mUpdaterFactory );
50 qDeleteAll( mChildren );
53bool QgsChunkNode::allChildChunksResident( QTime currentTime )
const
55 Q_ASSERT( mChildrenPopulated );
56 for (
int i = 0; i < childCount(); ++i )
58 if ( mChildren[i]->mHasData && !mChildren[i]->mEntity )
60 Q_UNUSED( currentTime )
67void QgsChunkNode::populateChildren(
const QVector<QgsChunkNode *> &children )
69 Q_ASSERT( !mChildrenPopulated );
70 mChildrenPopulated =
true;
74int QgsChunkNode::level()
const
77 QgsChunkNode *p = mParent;
86QList<QgsChunkNode *> QgsChunkNode::descendants()
88 QList<QgsChunkNode *> lst;
91 for (
int i = 0; i < childCount(); ++i )
93 lst << mChildren[i]->descendants();
99void QgsChunkNode::setQueuedForLoad( QgsChunkListEntry *entry )
101 Q_ASSERT( mState == Skeleton );
102 Q_ASSERT( !mLoaderQueueEntry );
103 Q_ASSERT( !mLoader );
105 mState = QgsChunkNode::QueuedForLoad;
106 mLoaderQueueEntry = entry;
109void QgsChunkNode::cancelQueuedForLoad()
111 Q_ASSERT( mState == QueuedForLoad );
112 Q_ASSERT( mLoaderQueueEntry );
114 delete mLoaderQueueEntry;
115 mLoaderQueueEntry =
nullptr;
117 mState = QgsChunkNode::Skeleton;
120void QgsChunkNode::setLoading( QgsChunkLoader *chunkLoader )
122 Q_ASSERT( mState == QueuedForLoad );
123 Q_ASSERT( !mLoader );
124 Q_ASSERT( mLoaderQueueEntry );
127 mLoader = chunkLoader;
128 mLoaderQueueEntry =
nullptr;
131void QgsChunkNode::cancelLoading()
133 Q_ASSERT( mState == QgsChunkNode::Loading );
135 Q_ASSERT( !mLoaderQueueEntry );
136 Q_ASSERT( !mEntity );
137 Q_ASSERT( !mReplacementQueueEntry );
141 mState = QgsChunkNode::Skeleton;
144void QgsChunkNode::setLoaded( Qt3DCore::QEntity *newEntity )
146 Q_ASSERT( mState == QgsChunkNode::Loading );
148 Q_ASSERT( !mLoaderQueueEntry );
149 Q_ASSERT( !mReplacementQueueEntry );
152 mEntityCreatedTime = QTime::currentTime();
156 mState = QgsChunkNode::Loaded;
157 mReplacementQueueEntry =
new QgsChunkListEntry(
this );
160void QgsChunkNode::unloadChunk()
162 Q_ASSERT( mState == QgsChunkNode::Loaded );
164 Q_ASSERT( mReplacementQueueEntry );
169 delete mReplacementQueueEntry;
170 mReplacementQueueEntry =
nullptr;
171 mState = QgsChunkNode::Skeleton;
174void QgsChunkNode::setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory )
176 Q_ASSERT( mState == QgsChunkNode::Loaded );
178 Q_ASSERT( mReplacementQueueEntry );
179 Q_ASSERT( !mLoaderQueueEntry );
180 Q_ASSERT( !mUpdater );
181 Q_ASSERT( !mUpdaterFactory );
183 mState = QueuedForUpdate;
184 mLoaderQueueEntry = entry;
185 mUpdaterFactory = updateJobFactory;
188void QgsChunkNode::cancelQueuedForUpdate()
190 Q_ASSERT( mState == QueuedForUpdate );
192 Q_ASSERT( mLoaderQueueEntry );
193 Q_ASSERT( mUpdaterFactory );
194 Q_ASSERT( !mUpdater );
197 mUpdaterFactory =
nullptr;
199 delete mLoaderQueueEntry;
200 mLoaderQueueEntry =
nullptr;
203void QgsChunkNode::setUpdating()
205 Q_ASSERT( mState == QgsChunkNode::QueuedForUpdate );
207 Q_ASSERT( mReplacementQueueEntry );
208 Q_ASSERT( mLoaderQueueEntry );
209 Q_ASSERT( !mUpdater );
210 Q_ASSERT( mUpdaterFactory );
213 mUpdater = mUpdaterFactory->createJob(
this );
214 mUpdaterFactory =
nullptr;
215 mLoaderQueueEntry =
nullptr;
218void QgsChunkNode::cancelUpdating()
220 Q_ASSERT( mState == QgsChunkNode::Updating );
221 Q_ASSERT( mUpdater );
222 Q_ASSERT( !mLoaderQueueEntry );
229void QgsChunkNode::setUpdated()
231 Q_ASSERT( mState == QgsChunkNode::Updating );
232 Q_ASSERT( mUpdater );
233 Q_ASSERT( !mLoaderQueueEntry );
234 Q_ASSERT( mReplacementQueueEntry );
238 mState = QgsChunkNode::Loaded;
241void QgsChunkNode::setExactBbox(
const QgsAABB &box )
248void QgsChunkNode::updateParentBoundingBoxesRecursively()
const
250 QgsChunkNode *currentNode = parent();
251 while ( currentNode )
253 QgsChunkNode *
const *currentNodeChildren = currentNode->children();
254 float xMin = std::numeric_limits< float >::max();
255 float xMax = -std::numeric_limits< float >::max();
256 float yMin = std::numeric_limits< float >::max();
257 float yMax = -std::numeric_limits< float >::max();
258 float zMin = std::numeric_limits< float >::max();
259 float zMax = -std::numeric_limits< float >::max();
261 for (
int i = 0; i < currentNode->childCount(); ++i )
263 const QgsAABB childBBox = currentNodeChildren[i]->bbox();
269 if ( childBBox.
xMin < xMin )
270 xMin = childBBox.
xMin;
271 if ( childBBox.
yMin < yMin )
272 yMin = childBBox.
yMin;
273 if ( childBBox.
zMin < zMin )
274 zMin = childBBox.
zMin;
275 if ( childBBox.
xMax > xMax )
276 xMax = childBBox.
xMax;
277 if ( childBBox.
yMax > yMax )
278 yMax = childBBox.
yMax;
279 if ( childBBox.
zMax > zMax )
280 zMax = childBBox.
zMax;
285 const QgsAABB currentNodeBbox = xMin < xMax && yMin < yMax && zMin < zMax ?
QgsAABB( xMin, yMin, zMin, xMax, yMax, zMax ) :
QgsAABB();
287 currentNode->setExactBbox( currentNodeBbox );
288 currentNode = currentNode->parent();
bool isEmpty() const
Returns true if any of xExtent(), yExtent() or zExtent() is zero, false otherwise.