| 195 | } |
| 196 | |
| 197 | bool OctreeAvailability::addSubtree( |
| 198 | const OctreeTileID& tileID, |
| 199 | AvailabilitySubtree&& newSubtree) noexcept { |
| 200 | |
| 201 | if (tileID.level == 0) { |
| 202 | if (this->_pRoot) { |
| 203 | // The root subtree already exists. |
| 204 | return false; |
| 205 | } else { |
| 206 | // Set the root subtree. |
| 207 | this->_pRoot = std::make_unique<AvailabilityNode>(); |
| 208 | this->_pRoot->setLoadedSubtree( |
| 209 | std::move(newSubtree), |
| 210 | this->_maximumChildrenSubtrees); |
| 211 | return true; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if (!this->_pRoot) { |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | AvailabilityNode* pNode = this->_pRoot.get(); |
| 220 | uint32_t level = 0; |
| 221 | |
| 222 | while (pNode && pNode->subtree && tileID.level > level) { |
| 223 | AvailabilitySubtree& subtree = *pNode->subtree; |
| 224 | |
| 225 | AvailabilityAccessor subtreeAvailabilityAccessor( |
| 226 | subtree.subtreeAvailability, |
| 227 | subtree); |
| 228 | |
| 229 | uint32_t levelsLeft = tileID.level - level; |
| 230 | |
| 231 | // The given subtree to add must fall exactly at the end of an existing |
| 232 | // subtree. |
| 233 | if (levelsLeft < this->_subtreeLevels) { |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | // TODO: consolidate duplicated code here... |
| 238 | |
| 239 | uint32_t subtreeRelativeMask = ~(0xFFFFFFFF << levelsLeft); |
| 240 | uint32_t levelsLeftAfterChildren = levelsLeft - this->_subtreeLevels; |
| 241 | uint32_t childSubtreeMortonIndex = getMortonIndex( |
| 242 | (tileID.x & subtreeRelativeMask) >> levelsLeftAfterChildren, |
| 243 | (tileID.y & subtreeRelativeMask) >> levelsLeftAfterChildren, |
| 244 | (tileID.z & subtreeRelativeMask) >> levelsLeftAfterChildren); |
| 245 | |
| 246 | // Check if the needed child subtree exists. |
| 247 | bool childSubtreeAvailable = false; |
| 248 | uint32_t childSubtreeIndex = 0; |
| 249 | |
| 250 | if (subtreeAvailabilityAccessor.isConstant()) { |
| 251 | childSubtreeAvailable = subtreeAvailabilityAccessor.getConstant(); |
| 252 | childSubtreeIndex = childSubtreeMortonIndex; |
| 253 | } else if (subtreeAvailabilityAccessor.isBufferView()) { |
| 254 | uint32_t byteIndex = childSubtreeMortonIndex >> 3; |
no test coverage detected