21#include <Qt3DCore/QEntity>
25QgsChunkNode::QgsChunkNode(
const QgsChunkNodeId &nodeId,
const QgsBox3D &box3D,
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::setExactBox3D(
const QgsBox3D &box3D )
248void QgsChunkNode::updateParentBoundingBoxesRecursively()
const
250 QgsChunkNode *currentNode = parent();
251 while ( currentNode )
253 QgsChunkNode *
const *currentNodeChildren = currentNode->children();
254 double xMin = std::numeric_limits<double>::max();
255 double xMax = -std::numeric_limits<double>::max();
256 double yMin = std::numeric_limits<double>::max();
257 double yMax = -std::numeric_limits<double>::max();
258 double zMin = std::numeric_limits<double>::max();
259 double zMax = -std::numeric_limits<double>::max();
261 for (
int i = 0; i < currentNode->childCount(); ++i )
263 const QgsBox3D childBox3D = currentNodeChildren[i]->box3D();
285 const QgsBox3D currentNodeBox3D = xMin > xMax || yMin > yMax || zMin > zMax ?
QgsBox3D() :
QgsBox3D( xMin, yMin, zMin, xMax, yMax, zMax );
287 currentNode->setExactBox3D( currentNodeBox3D );
288 currentNode = currentNode->parent();
A 3-dimensional box composed of x, y, z coordinates.
double yMaximum() const
Returns the maximum y value.
double xMinimum() const
Returns the minimum x value.
double zMaximum() const
Returns the maximum z value.
double xMaximum() const
Returns the maximum x value.
double zMinimum() const
Returns the minimum z value.
double yMinimum() const
Returns the minimum y value.
bool isEmpty() const
Returns true if the box is empty.