|
| 1 | +# ========================================================================== |
| 2 | +# |
| 3 | +# Copyright NumFOCUS |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# ========================================================================== |
| 18 | + |
| 19 | +# For testing itk PointsLocator in Python |
| 20 | +import itk |
| 21 | + |
| 22 | +# Create points on a plane |
| 23 | +pointset = itk.PointSet[itk.F, 3].New() |
| 24 | +pointset.SetPoint(0, [0, 0, 0]) |
| 25 | +pointset.SetPoint(1, [0, 1, 0]) |
| 26 | +pointset.SetPoint(2, [1, 0, 0]) |
| 27 | +pointset.SetPoint(3, [1, 1, 0]) |
| 28 | + |
| 29 | +# Create PointsLocator |
| 30 | +pl = itk.PointsLocator.New() |
| 31 | +pl.SetPoints(pointset.GetPoints()) |
| 32 | +pl.Initialize() |
| 33 | + |
| 34 | +# Query tree for one point |
| 35 | +vl = itk.VectorContainer[itk.UL, itk.UL].New() |
| 36 | +pl.FindClosestNPoints(pointset.GetPoint(0), 3, vl) |
| 37 | +assert vl.Size() == 3 |
| 38 | +assert vl.GetElement(0) == 0 |
| 39 | +assert vl.GetElement(1) == 1 |
| 40 | +assert vl.GetElement(2) == 2 |
| 41 | + |
| 42 | +# Check points within radius |
| 43 | +pl.FindPointsWithinRadius(pointset.GetPoint(0), 2, vl) |
| 44 | +assert vl.Size() == 4 |
| 45 | + |
| 46 | +pl.FindPointsWithinRadius(pointset.GetPoint(0), 1.1, vl) |
| 47 | +assert vl.Size() == 3 |
| 48 | +assert vl.GetElement(0) == 0 |
| 49 | +assert vl.GetElement(1) == 1 |
| 50 | +assert vl.GetElement(2) == 2 |
0 commit comments