本文整理汇总了Python中vtk.util方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.util方法的具体用法?Python vtk.util怎么用?Python vtk.util使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vtk
的用法示例。
在下文中一共展示了vtk.util方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_volume_data
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import util [as 别名]
def _get_volume_data(self):
if self.object is None:
return None
elif isinstance(self.object, np.ndarray):
return self._volume_from_array(self._subsample_array(self.object))
else:
available_serializer = [v for k, v in VTKVolume._serializers.items() if isinstance(self.object, k)]
if not available_serializer:
import vtk
from vtk.util import numpy_support
def volume_serializer(inst):
imageData = inst.object
array = numpy_support.vtk_to_numpy(imageData.GetPointData().GetScalars())
dims = imageData.GetDimensions()[::-1]
inst.spacing = imageData.GetSpacing()[::-1]
inst.origin = imageData.GetOrigin()
return inst._volume_from_array(inst._subsample_array(array.reshape(dims, order='C')))
VTKVolume.register_serializer(vtk.vtkImageData, volume_serializer)
serializer = volume_serializer
else:
serializer = available_serializer[0]
return serializer(self)
示例2: _vtk_to_vtkjs
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import util [as 别名]
def _vtk_to_vtkjs(data_array):
from vtk.util.numpy_support import vtk_to_numpy
# From vtkType.h
_vtk_data_type_to_vtkjs_type = {
2: 'Int8Array',
15: 'Int8Array',
3: 'Uint8Array',
4: 'Int16Array',
5: 'Uint16Array',
6: 'Int32Array',
7: 'Uint32Array',
8: 'BigInt64Array',
9: 'BigUint64Array',
10: 'Float32Array',
11: 'Float64Array',
16: 'BigInt64Array',
17: 'BigUint64Array',
}
vtk_data_type = data_array.GetDataType()
data_type = _vtk_data_type_to_vtkjs_type[vtk_data_type]
numpy_array = vtk_to_numpy(data_array)
if vtk_data_type == 8 or vtk_data_type == 16:
ii32 = np.iinfo(np.int32)
value_range = data_array.GetValueRange()
if value_range[0] < ii32.min or value_range[1] > ii32.max:
raise ValueError(
'64 integers are not supported yet by WebGL / vtk.js')
numpy_array = numpy_array.astype(np.int32)
data_type = 'Int32Array'
elif vtk_data_type == 9 or vtk_data_type == 17:
ui32 = np.iinfo(np.uint32)
value_range = data_array.GetValueRange()
if value_range[0] < ui32.min or value_range[1] > ui32.max:
raise ValueError(
'64 integers are not supported by WebGL / vtk.js yet')
numpy_array = numpy_array.astype(np.uint32)
data_type = 'Uint32Array'
return data_type, numpy_array
示例3: to_itk_image
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import util [as 别名]
def to_itk_image(image_like):
if isinstance(image_like, itk.Image):
return image_like
if is_arraylike(image_like):
array = np.asarray(image_like)
case_use_view = array.flags['OWNDATA']
if have_dask and isinstance(image_like, dask.array.core.Array):
case_use_view = False
array = np.ascontiguousarray(array)
if case_use_view:
image_from_array = itk.image_view_from_array(array)
else:
image_from_array = itk.image_from_array(array)
return image_from_array
elif have_vtk and isinstance(image_like, vtk.vtkImageData):
from vtk.util import numpy_support as vtk_numpy_support
array = vtk_numpy_support.vtk_to_numpy(
image_like.GetPointData().GetScalars())
array.shape = tuple(image_like.GetDimensions())[::-1]
image_from_array = itk.image_view_from_array(array)
image_from_array.SetSpacing(image_like.GetSpacing())
image_from_array.SetOrigin(image_like.GetOrigin())
return image_from_array
elif have_simpleitk and isinstance(image_like, sitk.Image):
array = sitk.GetArrayViewFromImage(image_like)
image_from_array = itk.image_view_from_array(array)
image_from_array.SetSpacing(image_like.GetSpacing())
image_from_array.SetOrigin(image_like.GetOrigin())
direction = image_like.GetDirection()
npdirection = np.asarray(direction)
npdirection = np.reshape(npdirection, (-1, 3))
itkdirection = itk.matrix_from_array(npdirection)
image_from_array.SetDirection(itkdirection)
return image_from_array
elif have_imagej:
import imglyb
if isinstance(image_like,
imglyb.util.ReferenceGuardingRandomAccessibleInterval):
array = imglyb.to_numpy(image_like)
image_from_array = itk.image_view_from_array(array)
return image_from_array
elif isinstance(image_like, itk.ProcessObject):
return itk.output(image_like)
return None