Skip to content

Commit 374bea6

Browse files
PranjalSahuthewtex
authored andcommitted
ENH: Adding Python test for itk::PolyLineCell conversion
1 parent d56e249 commit 374bea6

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

.github/workflows/build-test-package.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ jobs:
1717
- os: ubuntu-18.04
1818
c-compiler: "gcc"
1919
cxx-compiler: "g++"
20+
itk-git-tag: "v5.3rc04"
2021
cmake-build-type: "MinSizeRel"
2122
- os: windows-2019
2223
c-compiler: "cl.exe"
2324
cxx-compiler: "cl.exe"
25+
itk-git-tag: "v5.3rc04"
2426
cmake-build-type: "Release"
2527
- os: macos-10.15
2628
c-compiler: "clang"
2729
cxx-compiler: "clang++"
30+
itk-git-tag: "v5.3rc04"
2831
cmake-build-type: "MinSizeRel"
2932

3033
steps:
@@ -135,7 +138,13 @@ jobs:
135138
strategy:
136139
max-parallel: 2
137140
matrix:
141+
<<<<<<< HEAD
138142
python-version: [37, 38, 39, 310]
143+
=======
144+
python-version: [36, 37, 38, 39]
145+
include:
146+
- itk-python-git-tag: "46dd4156e3adfa7cda8952cbec786fbd063ebc79"
147+
>>>>>>> f70eb6d (ENH: Adding Python test for itk::PolyLineCell conversion)
139148

140149
steps:
141150
- uses: actions/checkout@v2
@@ -171,7 +180,11 @@ jobs:
171180
max-parallel: 2
172181
matrix:
173182
include:
183+
<<<<<<< HEAD
174184
- itk-python-git-tag: "v5.3rc04"
185+
=======
186+
- itk-python-git-tag: "46dd4156e3adfa7cda8952cbec786fbd063ebc79"
187+
>>>>>>> f70eb6d (ENH: Adding Python test for itk::PolyLineCell conversion)
175188

176189
steps:
177190
- uses: actions/checkout@v2
@@ -207,7 +220,11 @@ jobs:
207220
matrix:
208221
python-version-minor: [7, 8, 9, 10]
209222
include:
223+
<<<<<<< HEAD
210224
- itk-python-git-tag: "v5.3rc04"
225+
=======
226+
- itk-python-git-tag: "46dd4156e3adfa7cda8952cbec786fbd063ebc79"
227+
>>>>>>> f70eb6d (ENH: Adding Python test for itk::PolyLineCell conversion)
211228

212229
steps:
213230
- name: Get specific version of CMake, Ninja

wrapping/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ itk_python_expression_add_test(NAME itkMeshToPolyDataFilterPythonTest
22
EXPRESSION "filt = itk.MeshToPolyDataFilter.New()")
33
itk_python_add_test(NAME itkMeshToPolyDataFilterPythonTest2
44
COMMAND itkMeshToPolyDataFilterTest2.py)
5+
itk_python_add_test(NAME itkPolyLineCellTest
6+
COMMAND itkPolyLineCellTest.py)
57
itk_python_expression_add_test(NAME itkPolyDataPythonTest
68
EXPRESSION "poly_data = itk.PolyData.New()")
79

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import itk
2+
import numpy as np
3+
import os
4+
5+
# Create a test mesh
6+
mesh_input = itk.Mesh[itk.D, 3].New()
7+
8+
# Inserting 5 points in the Mesh
9+
points_arr = np.array([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 2, 1, 2, 3]).astype('float32')
10+
points_vc = itk.vector_container_from_array(points_arr.flatten())
11+
mesh_input.SetPoints(points_vc)
12+
13+
# Inserting 3 cells comprising 1 PolyLine Cell and 2 Line Cells
14+
# LINES 3 10
15+
# 2 0 1
16+
# 3 0 2 5
17+
# 2 3 4
18+
before_cells_array = np.array([1, 2, 0, 1, 10, 3, 0, 2, 5, 1, 2, 3, 4]).astype('uint64')
19+
mesh_input.SetCellsArray(itk.vector_container_from_array(before_cells_array))
20+
21+
# Convert Mesh to PolyData
22+
filter = itk.MeshToPolyDataFilter[type(mesh_input)].New(Input=mesh_input)
23+
filter.Update()
24+
poly_data = filter.GetOutput()
25+
assert(type(poly_data) == itk.PolyData[itk.D])
26+
lines = poly_data.GetLines()
27+
28+
# Check the count of points in line cells of polydata
29+
assert(lines.Size() == 10)
30+
31+
filter = itk.PolyDataToMeshFilter[type(poly_data)].New(Input=poly_data)
32+
filter.Update()
33+
mesh_output = filter.GetOutput()
34+
35+
assert(mesh_output.GetNumberOfPoints() == mesh_input.GetNumberOfPoints())
36+
assert(mesh_output.GetNumberOfCells() == mesh_input.GetNumberOfCells())
37+
38+
# Check if points are same
39+
for i in range(0, mesh_output.GetNumberOfPoints()):
40+
assert(mesh_output.GetPoint(i) == mesh_input.GetPoint(i))
41+
42+
# Check if cells are same
43+
after_cells_array = itk.array_from_vector_container(mesh_output.GetCellsArray())
44+
assert(np.array_equal(before_cells_array, after_cells_array))

0 commit comments

Comments
 (0)