Skip to content

Commit

Permalink
ENH: Adding Python test for itk::PolyLineCell conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
PranjalSahu authored and thewtex committed Sep 12, 2022
1 parent d56e249 commit 374bea6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/build-test-package.yml
Expand Up @@ -17,14 +17,17 @@ jobs:
- os: ubuntu-18.04
c-compiler: "gcc"
cxx-compiler: "g++"
itk-git-tag: "v5.3rc04"
cmake-build-type: "MinSizeRel"
- os: windows-2019
c-compiler: "cl.exe"
cxx-compiler: "cl.exe"
itk-git-tag: "v5.3rc04"
cmake-build-type: "Release"
- os: macos-10.15
c-compiler: "clang"
cxx-compiler: "clang++"
itk-git-tag: "v5.3rc04"
cmake-build-type: "MinSizeRel"

steps:
Expand Down Expand Up @@ -135,7 +138,13 @@ jobs:
strategy:
max-parallel: 2
matrix:
<<<<<<< HEAD
python-version: [37, 38, 39, 310]
=======
python-version: [36, 37, 38, 39]
include:
- itk-python-git-tag: "46dd4156e3adfa7cda8952cbec786fbd063ebc79"
>>>>>>> f70eb6d (ENH: Adding Python test for itk::PolyLineCell conversion)

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -171,7 +180,11 @@ jobs:
max-parallel: 2
matrix:
include:
<<<<<<< HEAD
- itk-python-git-tag: "v5.3rc04"
=======
- itk-python-git-tag: "46dd4156e3adfa7cda8952cbec786fbd063ebc79"
>>>>>>> f70eb6d (ENH: Adding Python test for itk::PolyLineCell conversion)

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -207,7 +220,11 @@ jobs:
matrix:
python-version-minor: [7, 8, 9, 10]
include:
<<<<<<< HEAD
- itk-python-git-tag: "v5.3rc04"
=======
- itk-python-git-tag: "46dd4156e3adfa7cda8952cbec786fbd063ebc79"
>>>>>>> f70eb6d (ENH: Adding Python test for itk::PolyLineCell conversion)

steps:
- name: Get specific version of CMake, Ninja
Expand Down
2 changes: 2 additions & 0 deletions wrapping/test/CMakeLists.txt
Expand Up @@ -2,6 +2,8 @@ itk_python_expression_add_test(NAME itkMeshToPolyDataFilterPythonTest
EXPRESSION "filt = itk.MeshToPolyDataFilter.New()")
itk_python_add_test(NAME itkMeshToPolyDataFilterPythonTest2
COMMAND itkMeshToPolyDataFilterTest2.py)
itk_python_add_test(NAME itkPolyLineCellTest
COMMAND itkPolyLineCellTest.py)
itk_python_expression_add_test(NAME itkPolyDataPythonTest
EXPRESSION "poly_data = itk.PolyData.New()")

Expand Down
44 changes: 44 additions & 0 deletions wrapping/test/itkPolyLineCellTest.py
@@ -0,0 +1,44 @@
import itk
import numpy as np
import os

# Create a test mesh
mesh_input = itk.Mesh[itk.D, 3].New()

# Inserting 5 points in the Mesh
points_arr = np.array([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 2, 1, 2, 3]).astype('float32')
points_vc = itk.vector_container_from_array(points_arr.flatten())
mesh_input.SetPoints(points_vc)

# Inserting 3 cells comprising 1 PolyLine Cell and 2 Line Cells
# LINES 3 10
# 2 0 1
# 3 0 2 5
# 2 3 4
before_cells_array = np.array([1, 2, 0, 1, 10, 3, 0, 2, 5, 1, 2, 3, 4]).astype('uint64')
mesh_input.SetCellsArray(itk.vector_container_from_array(before_cells_array))

# Convert Mesh to PolyData
filter = itk.MeshToPolyDataFilter[type(mesh_input)].New(Input=mesh_input)
filter.Update()
poly_data = filter.GetOutput()
assert(type(poly_data) == itk.PolyData[itk.D])
lines = poly_data.GetLines()

# Check the count of points in line cells of polydata
assert(lines.Size() == 10)

filter = itk.PolyDataToMeshFilter[type(poly_data)].New(Input=poly_data)
filter.Update()
mesh_output = filter.GetOutput()

assert(mesh_output.GetNumberOfPoints() == mesh_input.GetNumberOfPoints())
assert(mesh_output.GetNumberOfCells() == mesh_input.GetNumberOfCells())

# Check if points are same
for i in range(0, mesh_output.GetNumberOfPoints()):
assert(mesh_output.GetPoint(i) == mesh_input.GetPoint(i))

# Check if cells are same
after_cells_array = itk.array_from_vector_container(mesh_output.GetCellsArray())
assert(np.array_equal(before_cells_array, after_cells_array))

0 comments on commit 374bea6

Please sign in to comment.