Skip to content

Commit 5b206ec

Browse files
authored
Merge pull request #3485 from PranjalSahu/pranjal1
ENH: Adding Python wrapping for itkPointsLocator
2 parents ec510c1 + ba3c191 commit 5b206ec

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
itk_wrap_class("itk::PointsLocator" POINTER_WITH_2_SUPERCLASSES)
2+
itk_wrap_template("PS${ITKM_F}3" "itk::VectorContainer<${ITKT_UL}, itk::Point<float, 3> >")
3+
itk_end_wrap_class()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if(ITK_WRAP_PYTHON)
2+
itk_python_add_test(NAME itkPointsLocatorPythonTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/itkPointsLocatorTest.py)
3+
endif()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)