------------------------------------------------------------------------------ Method to form subdivision of space based on the points provided and subject to the constraints of levels and NumberOfPointsPerBucket. The result is directly addressable and of uniform subdivision.
| 830 | // subject to the constraints of levels and NumberOfPointsPerBucket. |
| 831 | // The result is directly addressable and of uniform subdivision. |
| 832 | void vtkPointLocator::BuildLocatorInternal() |
| 833 | { |
| 834 | int ndivs[3]; |
| 835 | vtkIdType idx; |
| 836 | vtkIdList* bucket; |
| 837 | vtkIdType numPts; |
| 838 | double x[3]; |
| 839 | typedef vtkIdList* vtkIdListPtr; |
| 840 | |
| 841 | vtkDebugMacro(<< "Hashing points..."); |
| 842 | this->Level = 1; // only single lowest level |
| 843 | |
| 844 | // Delete the current hash table values and reset dataset metrics to their original values. |
| 845 | this->FreeSearchStructure(); |
| 846 | |
| 847 | if (!this->DataSet || (numPts = this->DataSet->GetNumberOfPoints()) < 1) |
| 848 | { |
| 849 | // Missing datasets and datasets with no points are valid inputs and should not log an error. |
| 850 | // Searching for the closest point id is always -1 for this data. |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | // Size the root bucket. Initialize bucket data structure, compute |
| 855 | // level and divisions. |
| 856 | const double* bounds = this->DataSet->GetBounds(); |
| 857 | vtkIdType numBuckets = static_cast<vtkIdType>( |
| 858 | static_cast<double>(numPts) / static_cast<double>(this->NumberOfPointsPerBucket)); |
| 859 | |
| 860 | vtkBoundingBox bbox(bounds); |
| 861 | if (this->Automatic) |
| 862 | { |
| 863 | bbox.ComputeDivisions(numBuckets, this->Bounds, ndivs); |
| 864 | } |
| 865 | else |
| 866 | { |
| 867 | bbox.Inflate(); // make sure non-zero volume |
| 868 | bbox.GetBounds(this->Bounds); |
| 869 | for (int i = 0; i < 3; ++i) |
| 870 | { |
| 871 | ndivs[i] = (this->Divisions[i] < 1 ? 1 : this->Divisions[i]); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | this->Divisions[0] = ndivs[0]; |
| 876 | this->Divisions[1] = ndivs[1]; |
| 877 | this->Divisions[2] = ndivs[2]; |
| 878 | this->NumberOfBuckets = numBuckets = static_cast<vtkIdType>(ndivs[0]) * |
| 879 | static_cast<vtkIdType>(ndivs[1]) * static_cast<vtkIdType>(ndivs[2]); |
| 880 | |
| 881 | // Compute width of bucket in three directions |
| 882 | // |
| 883 | for (int i = 0; i < 3; ++i) |
| 884 | { |
| 885 | this->H[i] = (this->Bounds[2 * i + 1] - this->Bounds[2 * i]) / static_cast<double>(ndivs[i]); |
| 886 | } |
| 887 | |
| 888 | // Allocate the bins/buckets and initialize |
| 889 | this->HashTable = new vtkIdListPtr[numBuckets]; |
no test coverage detected