------------------------------------------------------------------------------
| 923 | |
| 924 | //------------------------------------------------------------------------------ |
| 925 | vtkIdType vtkModifiedBSPTree::FindCell( |
| 926 | double x[3], double, vtkGenericCell* cell, int& subId, double pcoords[3], double* weights) |
| 927 | { |
| 928 | this->BuildLocator(); |
| 929 | if (this->mRoot == nullptr) |
| 930 | { |
| 931 | return -1; |
| 932 | } |
| 933 | // check if x outside of bounds |
| 934 | if (!vtkAbstractCellLocator::IsInBounds(this->mRoot->Bounds, x)) |
| 935 | { |
| 936 | return -1; |
| 937 | } |
| 938 | vtkIdType cellId; |
| 939 | nodestack ns; |
| 940 | BSPNode* node; |
| 941 | ns.push(this->mRoot.get()); |
| 942 | double closestPoint[3], dist2; |
| 943 | // |
| 944 | while (!ns.empty()) |
| 945 | { |
| 946 | node = ns.top(); |
| 947 | ns.pop(); |
| 948 | if (node->mChild[0]) |
| 949 | { // this must be a parent node |
| 950 | if (node->mChild[0]->Inside(x)) |
| 951 | { |
| 952 | ns.push(node->mChild[0]); |
| 953 | } |
| 954 | if (node->mChild[1] && node->mChild[1]->Inside(x)) |
| 955 | { |
| 956 | ns.push(node->mChild[1]); |
| 957 | } |
| 958 | if (node->mChild[2]->Inside(x)) |
| 959 | { |
| 960 | ns.push(node->mChild[2]); |
| 961 | } |
| 962 | } |
| 963 | else |
| 964 | { // a leaf, so test the cells |
| 965 | for (int i = 0; i < node->num_cells; i++) |
| 966 | { |
| 967 | cellId = node->sorted_cell_lists[0][i]; |
| 968 | if (vtkAbstractCellLocator::InsideCellBounds(x, cellId)) |
| 969 | { |
| 970 | this->DataSet->GetCell(cellId, cell); |
| 971 | if (cell->EvaluatePosition(x, closestPoint, subId, pcoords, dist2, weights) == 1) |
| 972 | { |
| 973 | return cellId; |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | } |
| 978 | } |
| 979 | return -1; |
| 980 | } |
| 981 | |
| 982 | //------------------------------------------------------------------------------ |