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 )
39 for (
int i = 0; i < 8; ++i )
40 mChildren[i] =
nullptr;
43QgsChunkNode::~QgsChunkNode()
45 Q_ASSERT( mState == Skeleton );
46 Q_ASSERT( !mLoaderQueueEntry );
47 Q_ASSERT( !mReplacementQueueEntry );
50 Q_ASSERT( !mUpdater );
51 Q_ASSERT( !mUpdaterFactory );
53 for (
int i = 0; i < childCount(); ++i )
57bool QgsChunkNode::allChildChunksResident( QTime currentTime )
const
59 Q_ASSERT( mChildCount != -1 );
60 for (
int i = 0; i < childCount(); ++i )
64 if ( mChildren[i]->mHasData && !mChildren[i]->mEntity )
66 Q_UNUSED( currentTime )
73void QgsChunkNode::populateChildren(
const QVector<QgsChunkNode *> &children )
75 Q_ASSERT( mChildCount == -1 );
76 mChildCount = children.count();
77 for (
int i = 0; i < mChildCount; ++i )
78 mChildren[i] = children[i];
81int QgsChunkNode::level()
const
84 QgsChunkNode *p = mParent;
93QList<QgsChunkNode *> QgsChunkNode::descendants()
95 QList<QgsChunkNode *> lst;
98 for (
int i = 0; i < childCount(); ++i )
101 lst << mChildren[i]->descendants();
107void QgsChunkNode::setQueuedForLoad( QgsChunkListEntry *entry )
109 Q_ASSERT( mState == Skeleton );
110 Q_ASSERT( !mLoaderQueueEntry );
111 Q_ASSERT( !mLoader );
113 mState = QgsChunkNode::QueuedForLoad;
114 mLoaderQueueEntry = entry;
117void QgsChunkNode::cancelQueuedForLoad()
119 Q_ASSERT( mState == QueuedForLoad );
120 Q_ASSERT( mLoaderQueueEntry );
122 delete mLoaderQueueEntry;
123 mLoaderQueueEntry =
nullptr;
125 mState = QgsChunkNode::Skeleton;
128void QgsChunkNode::setLoading( QgsChunkLoader *chunkLoader )
130 Q_ASSERT( mState == QueuedForLoad );
131 Q_ASSERT( !mLoader );
132 Q_ASSERT( mLoaderQueueEntry );
135 mLoader = chunkLoader;
136 mLoaderQueueEntry =
nullptr;
139void QgsChunkNode::cancelLoading()
141 Q_ASSERT( mState == QgsChunkNode::Loading );
143 Q_ASSERT( !mLoaderQueueEntry );
144 Q_ASSERT( !mEntity );
145 Q_ASSERT( !mReplacementQueueEntry );
149 mState = QgsChunkNode::Skeleton;
152void QgsChunkNode::setLoaded( Qt3DCore::QEntity *newEntity )
154 Q_ASSERT( mState == QgsChunkNode::Loading );
156 Q_ASSERT( !mLoaderQueueEntry );
157 Q_ASSERT( !mReplacementQueueEntry );
160 mEntityCreatedTime = QTime::currentTime();
164 mState = QgsChunkNode::Loaded;
165 mReplacementQueueEntry =
new QgsChunkListEntry(
this );
168void QgsChunkNode::unloadChunk()
170 Q_ASSERT( mState == QgsChunkNode::Loaded );
172 Q_ASSERT( mReplacementQueueEntry );
177 delete mReplacementQueueEntry;
178 mReplacementQueueEntry =
nullptr;
179 mState = QgsChunkNode::Skeleton;
182void QgsChunkNode::setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory )
184 Q_ASSERT( mState == QgsChunkNode::Loaded );
186 Q_ASSERT( mReplacementQueueEntry );
187 Q_ASSERT( !mLoaderQueueEntry );
188 Q_ASSERT( !mUpdater );
189 Q_ASSERT( !mUpdaterFactory );
191 mState = QueuedForUpdate;
192 mLoaderQueueEntry = entry;
193 mUpdaterFactory = updateJobFactory;
196void QgsChunkNode::cancelQueuedForUpdate()
198 Q_ASSERT( mState == QueuedForUpdate );
200 Q_ASSERT( mLoaderQueueEntry );
201 Q_ASSERT( mUpdaterFactory );
202 Q_ASSERT( !mUpdater );
205 mUpdaterFactory =
nullptr;
207 delete mLoaderQueueEntry;
208 mLoaderQueueEntry =
nullptr;
211void QgsChunkNode::setUpdating()
213 Q_ASSERT( mState == QgsChunkNode::QueuedForUpdate );
215 Q_ASSERT( mReplacementQueueEntry );
216 Q_ASSERT( mLoaderQueueEntry );
217 Q_ASSERT( !mUpdater );
218 Q_ASSERT( mUpdaterFactory );
221 mUpdater = mUpdaterFactory->createJob(
this );
222 mUpdaterFactory =
nullptr;
223 mLoaderQueueEntry =
nullptr;
226void QgsChunkNode::cancelUpdating()
228 Q_ASSERT( mState == QgsChunkNode::Updating );
229 Q_ASSERT( mUpdater );
230 Q_ASSERT( !mLoaderQueueEntry );
237void QgsChunkNode::setUpdated()
239 Q_ASSERT( mState == QgsChunkNode::Updating );
240 Q_ASSERT( mUpdater );
241 Q_ASSERT( !mLoaderQueueEntry );
242 Q_ASSERT( mReplacementQueueEntry );
246 mState = QgsChunkNode::Loaded;
249void QgsChunkNode::setExactBbox(
const QgsAABB &box )
256void QgsChunkNode::updateParentBoundingBoxesRecursively()
const
258 QgsChunkNode *currentNode = parent();
259 while ( currentNode )
261 QgsChunkNode *
const *currentNodeChildren = currentNode->children();
262 float xMin = std::numeric_limits< float >::max();
263 float xMax = -std::numeric_limits< float >::max();
264 float yMin = std::numeric_limits< float >::max();
265 float yMax = -std::numeric_limits< float >::max();
266 float zMin = std::numeric_limits< float >::max();
267 float zMax = -std::numeric_limits< float >::max();
268 for (
int i = 0; i < currentNode->childCount(); ++i )
270 const QgsAABB childBBox = currentNodeChildren[i]->bbox();
271 if ( childBBox.
xMin < xMin )
272 xMin = childBBox.
xMin;
273 if ( childBBox.
yMin < yMin )
274 yMin = childBBox.
yMin;
275 if ( childBBox.
zMin < zMin )
276 zMin = childBBox.
zMin;
277 if ( childBBox.
xMax > xMax )
278 xMax = childBBox.
xMax;
279 if ( childBBox.
yMax > yMax )
280 yMax = childBBox.
yMax;
281 if ( childBBox.
zMax > zMax )
282 zMax = childBBox.
zMax;
284 currentNode->setExactBbox(
QgsAABB( xMin, yMin, zMin, xMax, yMax, zMax ) );
285 currentNode = currentNode->parent();