本文整理汇总了Python中vtk.vtkImageData方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkImageData方法的具体用法?Python vtk.vtkImageData怎么用?Python vtk.vtkImageData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vtk
的用法示例。
在下文中一共展示了vtk.vtkImageData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getDepthMapData
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def getDepthMapData(self, viewId):
mapId = self.reader.GetCurrentMapId(viewId)
if mapId < 0:
return None, None
depthImage = vtk.vtkImageData()
transform = vtk.vtkTransform()
self.reader.GetDataForMapId(viewId, mapId, depthImage, transform)
dims = depthImage.GetDimensions()
d = vnp.getNumpyFromVtk(depthImage, 'ImageScalars')
d = d.reshape(dims[1], dims[0])
t = np.array([[transform.GetMatrix().GetElement(r, c) for c in range(4)] for r in range(4)])
return d, t
示例2: dump_image_data
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def dump_image_data(dataset_dir, data_dir, dataset, color_array_info, root=None, compress=True):
"""Dump image data object to vtkjs."""
if root is None:
root = {}
root['vtkClass'] = 'vtkImageData'
container = root
container['spacing'] = dataset.GetSpacing()
container['origin'] = dataset.GetOrigin()
container['extent'] = dataset.GetExtent()
dump_all_arrays(dataset_dir, data_dir, dataset, container, compress)
return root
# -----------------------------------------------------------------------------
示例3: _get_volume_data
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [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)
示例4: RequestData
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def RequestData(self, request, inInfo, outInfo):
"""Used by pipeline to generate output"""
# Get output:
output = vtk.vtkImageData.GetData(outInfo, 0)
# Perform Read if needed
if self.__raster is None:
self._read_up_front()
self._get_raw_data()
self._build_image_data(output)
# Now add the data based on what the user has selected
for name, band in self.__raster.bands.items():
data = band.data
output.GetPointData().AddArray(interface.convert_array(data.flatten(), name=name))
if self.__scheme is not None:
colors = self.__raster.GetRGB(scheme=self.__scheme).reshape((-1,3))
output.GetPointData().SetScalars(interface.convert_array(colors, name=self.__scheme))
output.GetPointData().SetActiveScalars(self.__scheme)
return 1
示例5: __init__
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def __init__(self, extent=(10, 10, 10, 1), order='C',
spacing=(1.0, 1.0, 1.0), origin=(0.0, 0.0, 0.0),
dims=(0, 1, 2, 3), dt=1.0, points=False, **kwargs):
FilterBase.__init__(self, nInputPorts=1, nOutputPorts=1,
inputType='vtkTable', outputType='vtkImageData', **kwargs)
if len(extent) != 4:
raise _helpers.PVGeoError('`extent` must be of length 4.')
self.__extent = list(extent)
self.__dims = list(dims) # these are indexes for the filter to use on the reshape.
# NOTE: self.__dims[0] is the x axis index, etc., self.__dims[3] is the time axis
self.__spacing = list(spacing) # image data spacing
self.__origin = list(origin) # image data origin
self.__order = list(order) # unpacking order: 'C' or 'F'
self.__data = None # this is where we hold the data so entire filter does
# not execute on every time step. Data will be a disctionary of 4D arrays
# each 4D array will be in (nx, ny, nz, nt) shape
self.__needToRun = True
self.__timesteps = None
self.__dt = dt
# Optional parameter to switch between cell and point data
self.__usePointData = points
self.__needToUpdateOutput = True
示例6: _build_image_data
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def _build_image_data(self, img):
"""Internal helper to consturct the output"""
if self.__needToUpdateOutput:
# Clean out the output data object
img.DeepCopy(vtk.vtkImageData())
self.__needToUpdateOutput = False
ext = self.__extent
dims = self.__dims
nx, ny, nz = ext[dims[0]], ext[dims[1]], ext[dims[2]]
if not self.__usePointData:
nx += 1
ny += 1
nz += 1
sx, sy, sz = self.__spacing[0],self.__spacing[1],self.__spacing[2]
ox, oy, oz = self.__origin[0],self.__origin[1],self.__origin[2]
img.SetDimensions(nx, ny, nz)
img.SetSpacing(sx, sy, sz)
img.SetOrigin(ox, oy, oz)
return img
示例7: numpy_to_image
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def numpy_to_image(numpy_array):
"""
@brief Convert a numpy 2D or 3D array to a vtkImageData object
@param numpy_array 2D or 3D numpy array containing image data
@return vtkImageData with the numpy_array content
"""
shape = numpy_array.shape
if len(shape) < 2:
raise Exception('numpy array must have dimensionality of at least 2')
h, w = shape[0], shape[1]
c = 1
if len(shape) == 3:
c = shape[2]
# Reshape 2D image to 1D array suitable for conversion to a
# vtkArray with numpy_support.numpy_to_vtk()
linear_array = np.reshape(numpy_array, (w*h, c))
vtk_array = numpy_to_vtk(linear_array)
image = vtkImageData()
image.SetDimensions(w, h, 1)
image.AllocateScalars()
image.GetPointData().GetScalars().DeepCopy(vtk_array)
return image
示例8: add_image
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def add_image(self, image):
img_mapper = vtk.vtkImageMapper()
img_actor = vtk.vtkActor2D()
img_data = vtk.vtkImageData()
img_data.SetDimensions(image.shape[0], image.shape[1], 1)
img_data.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 3)
for x in range(0, image.shape[0]):
for y in range(0, image.shape[1]):
pixel = img_data.GetScalarPointer(x, y, 0)
pixel = np.array(image[x, y, :])
img_mapper.SetInputData(img_data)
img_mapper.SetColorWindow(255)
img_mapper.SetColorLevel(127.5)
img_actor.SetMapper(img_mapper)
self.renderer.AddActor(img_actor)
示例9: clone
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def clone(self):
"""
Returns a Clone of an ImageDataBase instance
"""
imagedata = vtkImageData()
imagedata.DeepCopy(self._imagedata)
clone = copy.copy(self)
clone.set_imagedata(imagedata)
clone.set_actor(actor_from_imagedata(self._imagedata))
return clone
示例10: test_multi_block_init_vtk
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def test_multi_block_init_vtk():
multi = vtk.vtkMultiBlockDataSet()
multi.SetBlock(0, vtk.vtkRectilinearGrid())
multi.SetBlock(1, vtk.vtkStructuredGrid())
multi = MultiBlock(multi)
assert isinstance(multi, MultiBlock)
assert multi.n_blocks == 2
assert isinstance(multi.GetBlock(0), RectilinearGrid)
assert isinstance(multi.GetBlock(1), StructuredGrid)
multi = vtk.vtkMultiBlockDataSet()
multi.SetBlock(0, vtk.vtkRectilinearGrid())
multi.SetBlock(1, vtk.vtkStructuredGrid())
multi = MultiBlock(multi, deep=True)
assert isinstance(multi, MultiBlock)
assert multi.n_blocks == 2
assert isinstance(multi.GetBlock(0), RectilinearGrid)
assert isinstance(multi.GetBlock(1), StructuredGrid)
# Test nested structure
multi = vtk.vtkMultiBlockDataSet()
multi.SetBlock(0, vtk.vtkRectilinearGrid())
multi.SetBlock(1, vtk.vtkImageData())
nested = vtk.vtkMultiBlockDataSet()
nested.SetBlock(0, vtk.vtkUnstructuredGrid())
nested.SetBlock(1, vtk.vtkStructuredGrid())
multi.SetBlock(2, nested)
# Wrap the nested structure
multi = MultiBlock(multi)
assert isinstance(multi, MultiBlock)
assert multi.n_blocks == 3
assert isinstance(multi.GetBlock(0), RectilinearGrid)
assert isinstance(multi.GetBlock(1), UniformGrid)
assert isinstance(multi.GetBlock(2), MultiBlock)
示例11: __init__
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def __init__(self, *args, **kwargs):
"""Initialize the texture."""
assert_empty_kwargs(**kwargs)
if len(args) == 1:
if isinstance(args[0], vtk.vtkTexture):
self._from_texture(args[0])
elif isinstance(args[0], np.ndarray):
self._from_array(args[0])
elif isinstance(args[0], vtk.vtkImageData):
self._from_image_data(args[0])
elif isinstance(args[0], str):
self._from_texture(pyvista.read_texture(args[0]))
else:
raise TypeError('Table unable to be made from ({})'.format(type(args[0])))
示例12: _clip_with_function
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def _clip_with_function(dataset, function, invert=True, value=0.0):
"""Clip using an implicit function (internal helper)."""
if isinstance(dataset, vtk.vtkPolyData):
alg = vtk.vtkClipPolyData()
# elif isinstance(dataset, vtk.vtkImageData):
# alg = vtk.vtkClipVolume()
# alg.SetMixed3DCellGeneration(True)
else:
alg = vtk.vtkTableBasedClipDataSet()
alg.SetInputDataObject(dataset) # Use the grid as the data we desire to cut
alg.SetValue(value)
alg.SetClipFunction(function) # the implicit function
alg.SetInsideOut(invert) # invert the clip if needed
alg.Update() # Perform the Cut
return _get_output(alg)
示例13: points
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def points(self, points):
"""Points cannot be set.
This setter overrides the base class's setter to ensure a user does not
attempt to set them. See https://github.com/pyvista/pyvista/issues/713.
"""
raise AttributeError("The points cannot be set. The points of "
"`UniformGrid`/`vtkImageData` are implicitly defined by the "
"`origin`, `spacing`, and `dimensions` of the grid."
)
示例14: applies
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def applies(cls, obj):
if ((isinstance(obj, np.ndarray) and obj.ndim == 3) or
any([isinstance(obj, k) for k in cls._serializers.keys()])):
return True
elif 'vtk' not in sys.modules:
return False
else:
import vtk
return isinstance(obj, vtk.vtkImageData)
示例15: register_serializer
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkImageData [as 别名]
def register_serializer(cls, class_type, serializer):
"""
Register a seriliazer for a given type of class.
A serializer is a function which take an instance of `class_type`
(like a vtk.vtkImageData) as input and return a numpy array of the data
"""
cls._serializers.update({class_type:serializer})