| 702 | return returnVal; |
| 703 | } |
| 704 | int vtkPKdTree::DivideRegion(vtkKdNode* kd, int L, int level, int tag) |
| 705 | { |
| 706 | if (!this->DivideTest(kd->GetNumberOfPoints(), level)) |
| 707 | return -1; |
| 708 | |
| 709 | int numpoints = kd->GetNumberOfPoints(); |
| 710 | int R = L + numpoints - 1; |
| 711 | |
| 712 | if (numpoints < 2) |
| 713 | { |
| 714 | // Special case: not enough points to go around. |
| 715 | int p = this->WhoHas(L); |
| 716 | if (this->MyId != p) |
| 717 | return -1; |
| 718 | |
| 719 | int maxdim = this->SelectCutDirection(kd); |
| 720 | kd->SetDim(maxdim); |
| 721 | |
| 722 | vtkKdNode* left = vtkKdNode::New(); |
| 723 | vtkKdNode* right = vtkKdNode::New(); |
| 724 | kd->AddChildNodes(left, right); |
| 725 | |
| 726 | double bounds[6]; |
| 727 | kd->GetBounds(bounds); |
| 728 | |
| 729 | float* val = this->GetLocalVal(L); |
| 730 | |
| 731 | double coord; |
| 732 | if (numpoints > 0) |
| 733 | { |
| 734 | coord = val[maxdim]; |
| 735 | } |
| 736 | else |
| 737 | { |
| 738 | coord = (bounds[maxdim * 2] + bounds[maxdim * 2 + 1]) * 0.5; |
| 739 | } |
| 740 | |
| 741 | left->SetBounds(bounds[0], ((maxdim == XDIM) ? coord : bounds[1]), bounds[2], |
| 742 | ((maxdim == YDIM) ? coord : bounds[3]), bounds[4], ((maxdim == ZDIM) ? coord : bounds[5])); |
| 743 | |
| 744 | left->SetNumberOfPoints(numpoints); |
| 745 | |
| 746 | right->SetBounds(((maxdim == XDIM) ? coord : bounds[0]), bounds[1], |
| 747 | ((maxdim == YDIM) ? coord : bounds[2]), bounds[3], ((maxdim == ZDIM) ? coord : bounds[4]), |
| 748 | bounds[5]); |
| 749 | |
| 750 | right->SetNumberOfPoints(0); |
| 751 | |
| 752 | // Set the data bounds tightly around L. This will inevitably mean some |
| 753 | // regions that are empty will have their data bounds outside of them. |
| 754 | // Hopefully, that will not screw up anything down the road. |
| 755 | left->SetDataBounds(val[0], val[0], val[1], val[1], val[2], val[2]); |
| 756 | right->SetDataBounds(val[0], val[0], val[1], val[1], val[2], val[2]); |
| 757 | |
| 758 | // Return L as the midpoint to guarantee that both left and right trees |
| 759 | // are "owned" by the same process as the parent. This is important |
| 760 | // because only one process has not culled this node in the tree. |
| 761 | return L; |
no test coverage detected