本文整理汇总了Python中vtk.vtkUnstructuredGrid方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkUnstructuredGrid方法的具体用法?Python vtk.vtkUnstructuredGrid怎么用?Python vtk.vtkUnstructuredGrid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vtk
的用法示例。
在下文中一共展示了vtk.vtkUnstructuredGrid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_voxel
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def create_voxel(self):
numberOfVertices = 8
points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(0, 1, 0)
points.InsertNextPoint(1, 1, 0)
points.InsertNextPoint(0, 0, 1)
points.InsertNextPoint(1, 0, 1)
points.InsertNextPoint(0, 1, 1)
points.InsertNextPoint(1, 1, 1)
voxel = vtk.vtkVoxel()
for i in range(0, numberOfVertices):
voxel.GetPointIds().SetId(i, i)
ugrid = vtk.vtkUnstructuredGrid()
ugrid.SetPoints(points)
ugrid.InsertNextCell(voxel.GetCellType(), voxel.GetPointIds())
gfilter = vtk.vtkGeometryFilter()
gfilter.SetInput(ugrid)
gfilter.Update()
return gfilter
示例2: createDEM_v2
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def createDEM_v2():
ds = xr.open_dataset('../data/output/Peru_20160601-20180530_comp4.nc')
points = vtk.vtkPoints()
quad = vtk.vtkQuad()
cells = vtk.vtkCellArray()
numPoints = ds.south_north.size*ds.west_east.size
print('Write points \n')
for i,j in product(ds.south_north.values,ds.west_east.values):
points.InsertNextPoint(ds.lat.isel(south_north=i,west_east=j), ds.lon.isel(south_north=i,west_east=j), ds.HGT.sel(south_north=i,west_east=j).values/6370000.0)
print('Write cells \n')
for idx in range(points.GetNumberOfPoints()-ds.west_east.size):
if (idx%ds.west_east.size != 0):
quad.GetPointIds().SetId(0,idx)
quad.GetPointIds().SetId(1,idx+1)
quad.GetPointIds().SetId(2,idx+ds.west_east.size+1)
quad.GetPointIds().SetId(3,idx+ds.west_east.size)
cells.InsertNextCell(quad)
print('Create unstructured grid \n')
grid = vtk.vtkUnstructuredGrid()
grid.SetPoints(points)
grid.SetCells(vtk.VTK_QUAD, cells)
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName('cosipy.vtu')
writer.SetInputData(grid)
writer.Write()
示例3: test_multi_block_init_vtk
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [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)
示例4: test_multi_block_append
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def test_multi_block_append(ant, sphere, uniform, airplane, rectilinear):
"""This puts all of the example data objects into a a MultiBlock container"""
multi = MultiBlock()
# Add and test examples
datasets = (ant, sphere, uniform, airplane, rectilinear)
for i, dataset in enumerate(datasets):
multi.append(dataset)
assert multi.n_blocks == i + 1
assert isinstance(multi[i], type(dataset))
assert multi.bounds is not None
# Now overwrite a block
multi[4] = pyvista.Sphere()
assert isinstance(multi[4], PolyData)
multi[4] = vtk.vtkUnstructuredGrid()
assert isinstance(multi[4], pyvista.UnstructuredGrid)
示例5: setVisibilityGrids
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def setVisibilityGrids(self, n):
a = self._vtkren.GetActors()
a.InitTraversal()
s = a.GetNextItem()
while s:
grid = s.GetMapper().GetInput()
if vtk.vtkUnstructuredGrid.SafeDownCast(grid):
s.SetVisibility(n)
s = a.GetNextItem()
示例6: selectionCellId
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def selectionCellId(self, grid, ptid):
if self.actorpt is not None:
self._vtkren.RemoveActor(self.actorpt)
if grid is None:
return
ids = vtk.vtkIdTypeArray()
ids.SetNumberOfComponents(1)
ids.InsertNextValue(ptid)
selectionNode = vtk.vtkSelectionNode()
selectionNode.SetFieldType(0)
selectionNode.SetContentType(4)
selectionNode.SetSelectionList(ids)
selection = vtk.vtkSelection()
selection.AddNode(selectionNode)
extractSelection = vtk.vtkExtractSelection()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
extractSelection.SetInputData(0, grid)
extractSelection.SetInputData(1, selection)
extractSelection.Update()
selected = vtk.vtkUnstructuredGrid()
selected.ShallowCopy(extractSelection.GetOutput())
selectedMapper = vtk.vtkDataSetMapper()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
selectedMapper.SetInputData(selected)
self.actorpt = vtk.vtkActor()
self.actorpt.SetMapper(selectedMapper)
self.actorpt.GetProperty().SetColor(0, 1, 0)
self.actorpt.GetProperty().SetPointSize(6)
self.actorpt.PickableOff()
self.actorpt.DragableOff()
self._vtkren.AddActor(self.actorpt)
self._iren.Render()
示例7: selectionPointId
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def selectionPointId(self, grid, ptid):
if self.actorpt is not None:
self._vtkren.RemoveActor(self.actorpt)
if grid is None:
return
ids = vtk.vtkIdTypeArray()
ids.SetNumberOfComponents(1)
ids.InsertNextValue(ptid)
selectionNode = vtk.vtkSelectionNode()
selectionNode.SetFieldType(1)
selectionNode.SetContentType(4)
selectionNode.SetSelectionList(ids)
selection = vtk.vtkSelection()
selection.AddNode(selectionNode)
extractSelection = vtk.vtkExtractSelection()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
extractSelection.SetInputData(0, grid)
extractSelection.SetInputData(1, selection)
extractSelection.Update()
selected = vtk.vtkUnstructuredGrid()
selected.ShallowCopy(extractSelection.GetOutput())
selectedMapper = vtk.vtkDataSetMapper()
if VTK_VERSION_MAJOR < 8:
raise RuntimeError("VTK version is too old, please upgrade")
selectedMapper.SetInputData(selected)
self.actorpt = vtk.vtkActor()
self.actorpt.SetMapper(selectedMapper)
self.actorpt.GetProperty().SetColor(0, 1, 0)
self.actorpt.GetProperty().SetPointSize(6)
self.actorpt.PickableOff()
self.actorpt.DragableOff()
self._vtkren.AddActor(self.actorpt)
self._iren.Render()
示例8: _save_unstructured_grid
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def _save_unstructured_grid(filename, vtkUnstructGrid, directory=''):
"""Saves a VTK unstructured grid file (vtu) for an already generated
:class:`pyvista.UnstructuredGrid` object.
Parameters
----------
filename : str
path to the output vtk file or just its name if directory is specified
directory : str
directory where the UBC GIF file lives
"""
if not isinstance(vtkUnstructGrid, _vtk.vtkUnstructuredGrid):
raise RuntimeError('`_save_unstructured_grid` can only handle `vtkUnstructuredGrid` objects. `%s` is not supported.' % vtkUnstructGrid.__class__)
# Check the extension of the filename
fname = os.path.join(directory, filename)
ext = os.path.splitext(fname)[1]
if ext is '':
fname = fname + '.vtu'
elif ext not in '.vtu':
raise IOError('{:s} is an incorrect extension, has to be .vtu'.format(ext))
# Make the writer
vtuWriteFilter = _vtkUnstWriter()
if float(_vtk_version.split('.')[0]) >= 6:
vtuWriteFilter.SetInputDataObject(vtkUnstructGrid)
else:
vtuWriteFilter.SetInput(vtkUnstructGrid)
vtuWriteFilter.SetFileName(fname)
# Write the file
vtuWriteFilter.Update()
示例9: writeVTK
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def writeVTK(mesh, filename, models=None, directory=''):
"""Makes and saves a VTK object from this mesh and given models
Parameters
----------
filename : str
path to the output vtk file or just its name if directory is specified
models : dict
dictionary of numpy.array - Name('s) and array('s). Match number of cells
directory : str
directory where the UBC GIF file lives
"""
vtkObj = InterfaceVTK.to_vtk(mesh, models=models)
writers = {
'vtkUnstructuredGrid' : InterfaceVTK._save_unstructured_grid,
'vtkRectilinearGrid' : InterfaceVTK._save_rectilinear_grid,
'vtkStructuredGrid' : InterfaceVTK._save_structured_grid,
}
key = vtkObj.GetClassName()
try:
write = writers[key]
except:
raise RuntimeError('VTK data type `%s` is not currently supported.' % key)
return write(filename, vtkObj, directory=directory)
示例10: __init__
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def __init__(self, nOutputPorts=1, outputType='vtkUnstructuredGrid', **kwargs):
ubcMeshReaderBase.__init__(self,
nOutputPorts=nOutputPorts, outputType=outputType,
**kwargs)
self.__mesh = None
self.__models = []
示例11: ubc_octree_mesh
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def ubc_octree_mesh(self, FileName, pdo=None):
"""This method reads a UBC OcTree Mesh file and builds a
``vtkUnstructuredGrid`` of the data in the file. This method generates
the ``vtkUnstructuredGrid`` without any data attributes.
Args:
FileName (str): The mesh filename as an absolute path for the input
mesh file in UBC OcTree format.
pdo (vtkUnstructuredGrid): A pointer to the output data object.
Return:
vtkUnstructuredGrid:
a ``vtkUnstructuredGrid`` generated from the UBCMesh grid.
Mesh is defined by the input mesh file.
No data attributes here, simply an empty mesh. Use the
``place_model_on_octree_mesh()`` method to associate with model data.
"""
try:
self.__mesh = discretize.TreeMesh.readUBC(FileName)
except (IOError, OSError) as fe:
raise _helpers.PVGeoError(str(fe))
if pdo is None:
pdo = self.__mesh.to_vtk()
else:
pdo.DeepCopy(self.__mesh.to_vtk())
return pdo
示例12: place_model_on_octree_mesh
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def place_model_on_octree_mesh(mesh, model, data_name='Data'):
"""Places model data onto a mesh. This is for the UBC Grid data reaers
to associate model data with the mesh grid.
Args:
mesh (vtkUnstructuredGrid): The ``vtkUnstructuredGrid`` that is the
mesh to place the model data upon. Needs to have been read in by ubcOcTree
model (np.ndarray): A NumPy float array that holds all of the data
to place inside of the mesh's cells.
data_name (str): The name of the model data array once placed on the
``vtkUnstructuredGrid``.
Return:
vtkUnstructuredGrid:
The input ``vtkUnstructuredGrid`` with model data appended.
"""
if isinstance(model, dict):
for key in model.keys():
mesh = OcTreeReader.place_model_on_octree_mesh(mesh, model[key], data_name=key)
return mesh
# Make sure this model file fits the dimensions of the mesh
numCells = mesh.GetNumberOfCells()
if (numCells < len(model)):
raise _helpers.PVGeoError('This model file has more data than the given mesh has cells to hold.')
elif (numCells > len(model)):
raise _helpers.PVGeoError('This model file does not have enough data to fill the given mesh\'s cells.')
# This is absolutely crucial!
# Do not play with unless you know what you are doing!
# Also note that this assumes ``discretize`` handles addin this array
ind_reorder = nps.vtk_to_numpy(
mesh.GetCellData().GetArray('index_cell_corner'))
model = model[ind_reorder]
# Convert data to VTK data structure and append to output
c = interface.convert_array(model, name=data_name, deep=True)
# THIS IS CELL DATA! Add the model data to CELL data:
mesh.GetCellData().AddArray(c)
return mesh
示例13: __ubc_octree
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def __ubc_octree(self, filename_mesh, filename_models, output):
"""Wrapper to Read UBC GIF OcTree mesh and model file pairs. UBC OcTree
models are defined using a 2-file format. The "mesh" file describes how
the data is descritized. The "model" file lists the physical property
values for all cells in a mesh. A model file is meaningless without an
associated mesh file. This only handles OcTree formats
Args:
filename_mesh (str): The OcTree Mesh filename as an absolute path
for the input mesh file in UBC OcTree Mesh Format
filename_models (list(str)): The model filenames as absolute paths for
the input model timesteps in UBC OcTree Model Format.
output (vtkUnstructuredGrid): The output data object
Return:
vtkUnstructuredGrid:
A ``vtkUnstructuredGrid`` generated from the UBC 2D/3D Mesh grid.
Mesh is defined by the input mesh file. Cell data is defined by
the input model file.
"""
if self.need_to_readMesh():
# Construct/read the mesh
self.ubc_octree_mesh(filename_mesh, pdo=output)
self.need_to_readMesh(flag=False)
output.DeepCopy(self.__mesh.to_vtk())
if self.need_to_readModels() and self.this_has_models():
# Read the model data
self.__models = []
for f in filename_models:
# Read the model data
self.__models.append(ubcMeshReaderBase.ubc_model_3d(f))
self.need_to_readModels(flag=False)
return output
示例14: clear_mesh
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def clear_mesh(self):
"""Use to clean/rebuild the mesh.
"""
self.__mesh = vtk.vtkUnstructuredGrid()
ubcMeshReaderBase.clear_models(self)
示例15: __init__
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkUnstructuredGrid [as 别名]
def __init__(self, **kwargs):
FilterBase.__init__(self,
nInputPorts=1, inputType='vtkPointSet',
nOutputPorts=1, outputType='vtkUnstructuredGrid')
self.__dx = kwargs.get('dx', None)
self.__dy = kwargs.get('dy', None)
self.__dz = kwargs.get('dz', None)
self.__estimate_grid = kwargs.get('estimate', True)
self.__safe = kwargs.get('safe', 10.0)
self.__unique = kwargs.get('unique', True)
self.__tolerance = kwargs.get('tolerance', None)
self.__angle = kwargs.get('angle', 0.0)