MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / addSubtree

Method addSubtree

CesiumGeometry/src/QuadtreeAvailability.cpp:211–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211bool QuadtreeAvailability::addSubtree(
212 const QuadtreeTileID& tileID,
213 AvailabilitySubtree&& newSubtree) noexcept {
214
215 if (tileID.level == 0) {
216 if (this->_pRoot) {
217 // The root subtree already exists.
218 return false;
219 } else {
220 // Set the root subtree.
221 this->_pRoot = std::make_unique<AvailabilityNode>();
222 this->_pRoot->setLoadedSubtree(
223 std::move(newSubtree),
224 this->_maximumChildrenSubtrees);
225 return true;
226 }
227 }
228
229 if (!this->_pRoot) {
230 return false;
231 }
232
233 AvailabilityNode* pNode = this->_pRoot.get();
234 uint32_t level = 0;
235
236 while (pNode && pNode->subtree && tileID.level > level) {
237 AvailabilitySubtree& subtree = *pNode->subtree;
238
239 AvailabilityAccessor subtreeAvailabilityAccessor(
240 subtree.subtreeAvailability,
241 subtree);
242
243 uint32_t levelsLeft = tileID.level - level;
244
245 // The given subtree to add must fall exactly at the end of an existing
246 // subtree.
247 if (levelsLeft < this->_subtreeLevels) {
248 return false;
249 }
250
251 // TODO: consolidate duplicated code here...
252
253 uint32_t subtreeRelativeMask = ~(0xFFFFFFFF << levelsLeft);
254 uint32_t levelsLeftAfterChildren = levelsLeft - this->_subtreeLevels;
255 uint32_t childSubtreeMortonIndex = getMortonIndex(
256 (tileID.x & subtreeRelativeMask) >> levelsLeftAfterChildren,
257 (tileID.y & subtreeRelativeMask) >> levelsLeftAfterChildren);
258
259 // Check if the needed child subtree exists.
260 bool childSubtreeAvailable = false;
261 uint32_t childSubtreeIndex = 0;
262
263 if (subtreeAvailabilityAccessor.isConstant()) {
264 childSubtreeAvailable = subtreeAvailabilityAccessor.getConstant();
265 childSubtreeIndex = childSubtreeMortonIndex;
266 } else if (subtreeAvailabilityAccessor.isBufferView()) {
267 uint32_t byteIndex = childSubtreeMortonIndex >> 3;
268 uint8_t bitIndex = static_cast<uint8_t>(childSubtreeMortonIndex & 7);

Callers

nothing calls this directly

Calls 5

countOnesInBufferFunction · 0.85
countOnesInByteFunction · 0.85
setLoadedSubtreeMethod · 0.80
getMortonIndexFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected