diff --git a/.gitattributes b/.gitattributes index 2aca73b..b580fea 100644 --- a/.gitattributes +++ b/.gitattributes @@ -135,6 +135,7 @@ icons/zh_TW.bmp -text invesalius/.svnignore -text invesalius/data/bases.py -text invesalius/data/co_registration.py -text +invesalius/data/converters.py -text invesalius/gui/preferences.py -text locale/de/LC_MESSAGES/invesalius.mo -text locale/el/LC_MESSAGES/invesalius.mo -text diff --git a/invesalius/data/converters.py b/invesalius/data/converters.py new file mode 100644 index 0000000..c9c6b24 --- /dev/null +++ b/invesalius/data/converters.py @@ -0,0 +1,58 @@ +#-------------------------------------------------------------------------- +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer +# Homepage: http://www.softwarepublico.gov.br +# Contact: invesalius@cti.gov.br +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt) +#-------------------------------------------------------------------------- +# Este programa e software livre; voce pode redistribui-lo e/ou +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme +# publicada pela Free Software Foundation; de acordo com a versao 2 +# da Licenca. +# +# Este programa eh distribuido na expectativa de ser util, mas SEM +# QUALQUER GARANTIA; sem mesmo a garantia implicita de +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais +# detalhes. +#-------------------------------------------------------------------------- + +import numpy +import vtk +from vtk.util import numpy_support + +def to_vtk(n_array, spacing, slice_number, orientation): + try: + dz, dy, dx = n_array.shape + except ValueError: + dy, dx = n_array.shape + dz = 1 + + v_image = numpy_support.numpy_to_vtk(n_array.flat) + + if orientation == 'AXIAL': + extent = (0, dx -1, 0, dy -1, slice_number, slice_number + dz - 1) + elif orientation == 'SAGITAL': + dx, dy, dz = dz, dx, dy + extent = (slice_number, slice_number + dx - 1, 0, dy - 1, 0, dz - 1) + elif orientation == 'CORONAL': + dx, dy, dz = dx, dz, dy + extent = (0, dx - 1, slice_number, slice_number + dy - 1, 0, dz - 1) + + # Generating the vtkImageData + image = vtk.vtkImageData() + image.SetOrigin(0, 0, 0) + image.SetSpacing(spacing) + image.SetNumberOfScalarComponents(1) + image.SetDimensions(dx, dy, dz) + image.SetExtent(extent) + image.SetScalarType(numpy_support.get_vtk_array_type(n_array.dtype)) + image.AllocateScalars() + image.GetPointData().SetScalars(v_image) + image.Update() + + image_copy = vtk.vtkImageData() + image_copy.DeepCopy(image) + image_copy.Update() + + return image_copy diff --git a/invesalius/data/surface_process.py b/invesalius/data/surface_process.py index d645993..13c6913 100644 --- a/invesalius/data/surface_process.py +++ b/invesalius/data/surface_process.py @@ -6,7 +6,7 @@ import numpy import vtk import i18n -import converters +import data.converters from scipy import ndimage class SurfaceProcess(multiprocessing.Process): -- libgit2 0.21.2