Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move VTK utilities to sub-module #28

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions SimpleITK/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,3 @@
"resize",
"__version__",
]

from importlib.util import find_spec

try:
find_spec("vtk")
from .vtk import sitk2vtk, vtk2sitk

__all__.extend(["sitk2vtk", "vtk2sitk"])

_has_vtk = True
except ImportError:
_has_vtk = False

del find_spec
6 changes: 6 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ API
:members:

.. automodule:: SimpleITK.utilities.dask
:members:

.. automodule:: SimpleITK.utilities.pyside
:members

.. automodule:: SimpleITK.utilities.vtk
:members:
28 changes: 0 additions & 28 deletions test/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import math
import gc

import SimpleITK as sitk
import SimpleITK.utilities as sitkutils
from numpy.testing import assert_allclose
import vtk


def test_Logger():
Expand Down Expand Up @@ -37,31 +34,6 @@ def f(_img):
assert img[0, 0, z] == z


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_vtktositk():
source = vtk.vtkImageSinusoidSource()
source.Update()
img = source.GetOutput()

sitkimg = sitkutils.vtk2sitk(img)
source = None
img = None
gc.collect()

assert sitkimg[0, 0, 0] == 255.0


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

Expand Down
29 changes: 29 additions & 0 deletions test/test_vtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import SimpleITK as sitk
from SimpleITK.utilities.vtk import sitk2vtk, vtk2sitk
import vtk
import gc


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

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

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


def test_vtktositk():
source = vtk.vtkImageSinusoidSource()
source.Update()
img = source.GetOutput()

sitkimg = vtk2sitk(img)
source = None
img = None
gc.collect()

assert sitkimg[0, 0, 0] == 255.0