-
-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Adding Python test for itkPointsLocator
- Loading branch information
1 parent
a4002b1
commit ba3c191
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if(ITK_WRAP_PYTHON) | ||
itk_python_add_test(NAME itkPointsLocatorPythonTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/itkPointsLocatorTest.py) | ||
endif() |
50 changes: 50 additions & 0 deletions
50
Modules/Registration/Common/wrapping/test/itkPointsLocatorTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# ========================================================================== | ||
# | ||
# Copyright NumFOCUS | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ========================================================================== | ||
|
||
# For testing itk PointsLocator in Python | ||
import itk | ||
|
||
# Create points on a plane | ||
pointset = itk.PointSet[itk.F, 3].New() | ||
pointset.SetPoint(0, [0, 0, 0]) | ||
pointset.SetPoint(1, [0, 1, 0]) | ||
pointset.SetPoint(2, [1, 0, 0]) | ||
pointset.SetPoint(3, [1, 1, 0]) | ||
|
||
# Create PointsLocator | ||
pl = itk.PointsLocator.New() | ||
pl.SetPoints(pointset.GetPoints()) | ||
pl.Initialize() | ||
|
||
# Query tree for one point | ||
vl = itk.VectorContainer[itk.UL, itk.UL].New() | ||
pl.FindClosestNPoints(pointset.GetPoint(0), 3, vl) | ||
assert vl.Size() == 3 | ||
assert vl.GetElement(0) == 0 | ||
assert vl.GetElement(1) == 1 | ||
assert vl.GetElement(2) == 2 | ||
|
||
# Check points within radius | ||
pl.FindPointsWithinRadius(pointset.GetPoint(0), 2, vl) | ||
assert vl.Size() == 4 | ||
|
||
pl.FindPointsWithinRadius(pointset.GetPoint(0), 1.1, vl) | ||
assert vl.Size() == 3 | ||
assert vl.GetElement(0) == 0 | ||
assert vl.GetElement(1) == 1 | ||
assert vl.GetElement(2) == 2 |