insert new bounds into tree
| 538 | |
| 539 | // insert new bounds into tree |
| 540 | IncrementalAABBTreeNode* IncrementalAABBTree::insert(const PoolIndex index, const PxBounds3* bounds, NodeList& changedLeaf) |
| 541 | { |
| 542 | PX_SIMD_GUARD; |
| 543 | |
| 544 | // get the bounds, reset the W value |
| 545 | const Vec4V minV = V4ClearW(V4LoadU(&bounds[index].minimum.x)); |
| 546 | const Vec4V maxV = V4ClearW(V4LoadU(&bounds[index].maximum.x)); |
| 547 | |
| 548 | // check if tree is empty |
| 549 | if(!mRoot) |
| 550 | { |
| 551 | // make it a leaf |
| 552 | AABBTreeIndices* indices = mIndicesPool.construct(index); |
| 553 | mRoot = reinterpret_cast<IncrementalAABBTreeNode*> (mNodesPool.allocate()); |
| 554 | mRoot->mBVMin = minV; |
| 555 | mRoot->mBVMax = maxV; |
| 556 | mRoot->mIndices = indices; |
| 557 | mRoot->mChilds[1] = NULL; |
| 558 | mRoot->mParent = NULL; |
| 559 | |
| 560 | return mRoot; |
| 561 | } |
| 562 | else |
| 563 | { |
| 564 | // check if root is a leaf |
| 565 | if(mRoot->isLeaf()) |
| 566 | { |
| 567 | // if we still can insert the primitive into the leaf, or we need to split |
| 568 | if(mRoot->getNbPrimitives() < NB_OBJECTS_PER_NODE) |
| 569 | { |
| 570 | // simply add the primitive into the current leaf |
| 571 | addPrimitiveIntoNode(mRoot, index, minV, maxV); |
| 572 | return mRoot; |
| 573 | } |
| 574 | else |
| 575 | { |
| 576 | // need to split the node |
| 577 | // check if the leaf is not marked as changed, we need to remove it |
| 578 | if(!changedLeaf.empty()) |
| 579 | { |
| 580 | PX_ASSERT(changedLeaf.size() == 1); |
| 581 | if(changedLeaf[0] == mRoot) |
| 582 | changedLeaf.popBack(); |
| 583 | } |
| 584 | IncrementalAABBTreeNode* retNode = splitLeafNode(mRoot, index, minV, maxV, bounds); |
| 585 | mRoot = retNode->mParent; |
| 586 | IncrementalAABBTreeNode* sibling = (mRoot->mChilds[0] == retNode) ? mRoot->mChilds[1] : mRoot->mChilds[0]; |
| 587 | if(sibling->isLeaf()) |
| 588 | changedLeaf.pushBack(sibling); |
| 589 | changedLeaf.pushBack(retNode); |
| 590 | return retNode; |
| 591 | } |
| 592 | } |
| 593 | else |
| 594 | { |
| 595 | const Vec4V testCenterV = V4Add(maxV, minV); |
| 596 | IncrementalAABBTreeNode* returnNode = NULL; |
| 597 | IncrementalAABBTreeNode* rotationNode = NULL; // store a node that seems not balanced |
no test coverage detected