Skip to content

Commit

Permalink
Merge pull request #33 from dave3d/VTKMemoryTest
Browse files Browse the repository at this point in the history
Update the sitk2vtk test to test memory allocation
  • Loading branch information
dave3d authored Jun 21, 2023
2 parents 74858d7 + 5529774 commit 5131b74
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -e .[vtk,dask,pyside] -r test/requirements.txt
sudo apt-get update
sudo apt install libegl1
- name: Test with pytest
Expand Down Expand Up @@ -81,4 +82,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: python-packages
path: dist
path: dist
2 changes: 1 addition & 1 deletion SimpleITK/utilities/vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def sitk2vtk(image: sitk.Image) -> vtk.vtkImageData:
vtk_image.SetDirectionMatrix(direction)

# Set pixel data
depth_array = vtknp.numpy_to_vtk(sitk.GetArrayViewFromImage(image).ravel())
depth_array = vtknp.numpy_to_vtk(sitk.GetArrayFromImage(image).ravel())
depth_array.SetNumberOfComponents(ncomp)
vtk_image.GetPointData().SetScalars(depth_array)

Expand Down
8 changes: 8 additions & 0 deletions test/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import gc

import SimpleITK as sitk
import SimpleITK.utilities as sitkutils
Expand Down Expand Up @@ -37,8 +38,15 @@ def f(_img):

def test_sitktovtk():
img = sitk.Image([10, 10, 5], sitk.sitkFloat32)
img = img + 42.0
vtk_img = sitkutils.sitk2vtk(img)

# free the SimpleITK image's memory
img = None
gc.collect()

assert vtk_img.GetScalarComponentAsFloat(0, 0, 0, 0) == 42.0


def test_fft_initialization():
fixed_img = sitk.Image([1024, 512], sitk.sitkInt8)
Expand Down

0 comments on commit 5131b74

Please sign in to comment.