Check if the node structure is valid (for debugging purpose)
| 769 | |
| 770 | // Check if the node structure is valid (for debugging purpose) |
| 771 | void DynamicAABBTree::checkNode(int32 nodeID) const { |
| 772 | |
| 773 | if (nodeID == TreeNode::NULL_TREE_NODE) return; |
| 774 | |
| 775 | // If it is the root |
| 776 | if (nodeID == mRootNodeID) { |
| 777 | assert(mNodes[nodeID].parentID == TreeNode::NULL_TREE_NODE); |
| 778 | } |
| 779 | |
| 780 | // Get the children nodes |
| 781 | TreeNode* pNode = mNodes + nodeID; |
| 782 | assert(!pNode->isLeaf()); |
| 783 | int32 leftChild = pNode->children[0]; |
| 784 | int32 rightChild = pNode->children[1]; |
| 785 | |
| 786 | assert(pNode->height >= 0); |
| 787 | assert(pNode->aabb.getVolume() > 0); |
| 788 | |
| 789 | // If the current node is a leaf |
| 790 | if (pNode->isLeaf()) { |
| 791 | |
| 792 | // Check that there are no children |
| 793 | assert(leftChild == TreeNode::NULL_TREE_NODE); |
| 794 | assert(rightChild == TreeNode::NULL_TREE_NODE); |
| 795 | assert(pNode->height == 0); |
| 796 | } |
| 797 | else { |
| 798 | |
| 799 | // Check that the children node IDs are valid |
| 800 | assert(0 <= leftChild && leftChild < mNbAllocatedNodes); |
| 801 | assert(0 <= rightChild && rightChild < mNbAllocatedNodes); |
| 802 | |
| 803 | // Check that the children nodes have the correct parent node |
| 804 | assert(mNodes[leftChild].parentID == nodeID); |
| 805 | assert(mNodes[rightChild].parentID == nodeID); |
| 806 | |
| 807 | // Check the height of node |
| 808 | int height = 1 + std::max(mNodes[leftChild].height, mNodes[rightChild].height); |
| 809 | assert(mNodes[nodeID].height == height); |
| 810 | |
| 811 | // Check the AABB of the node |
| 812 | AABB aabb; |
| 813 | aabb.mergeTwoAABBs(mNodes[leftChild].aabb, mNodes[rightChild].aabb); |
| 814 | assert(aabb.getMin() == mNodes[nodeID].aabb.getMin()); |
| 815 | assert(aabb.getMax() == mNodes[nodeID].aabb.getMax()); |
| 816 | |
| 817 | // Recursively check the children nodes |
| 818 | checkNode(leftChild); |
| 819 | checkNode(rightChild); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | // Compute the height of the tree |
| 824 | int DynamicAABBTree::computeHeight() { |
nothing calls this directly
no test coverage detected