本文整理汇总了Python中vtk.vtkXMLUnstructuredGridWriter函数的典型用法代码示例。如果您正苦于以下问题:Python vtkXMLUnstructuredGridWriter函数的具体用法?Python vtkXMLUnstructuredGridWriter怎么用?Python vtkXMLUnstructuredGridWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkXMLUnstructuredGridWriter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_writer
def _get_writer(filetype, filename):
import vtk
if filetype in "vtk-ascii":
logging.warning("VTK ASCII files are only meant for debugging.")
writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileTypeToASCII()
elif filetype == "vtk-binary":
writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileTypeToBinary()
elif filetype == "vtu-ascii":
logging.warning("VTU ASCII files are only meant for debugging.")
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetDataModeToAscii()
elif filetype == "vtu-binary":
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetDataModeToBinary()
elif filetype == "xdmf2":
writer = vtk.vtkXdmfWriter()
elif filetype == "xdmf3":
writer = vtk.vtkXdmf3Writer()
else:
assert filetype == "exodus", "Unknown file type '{}'.".format(filename)
writer = vtk.vtkExodusIIWriter()
# if the mesh contains vtkmodeldata information, make use of it
# and write out all time steps.
writer.WriteAllTimeStepsOn()
return writer
示例2: setup
def setup(mb,time,dt):
N = 0
X = 0.5+0.5*(numpy.random.random((N, 3))-0.5)
X[:,0] += 0.2
X[:,2] = 0
V = numpy.zeros((N,3))
V[:,0] = 1.0
SYSTEM=pm.System.get_system_from_options(block=(mb,time,dt))
PAR=pm.ParticleBase.get_parameters_from_options()[0]
writer=vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName('boundary.vtu')
writer.SetInput(SYSTEM.boundary.bnd)
writer.Write()
PB = pm.Particles.ParticleBucket(X, V, time, delta_t=0.2*dt,
system=SYSTEM,
parameters=PAR)
return PB
示例3: Slice_VTK_data_to_VTK
def Slice_VTK_data_to_VTK(inputFileName,
outputFileName,
point, normal,
resolution
):
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(inputFileName)
reader.Update()
plane = vtk.vtkPlane()
plane.SetOrigin(point)
plane.SetNormal(normal)
cutter = vtk.vtkFiltersCorePython.vtkCutter()
cutter.SetCutFunction(plane)
cutter.SetInputConnection(reader.GetOutputPort())
cutter.Update()
#Convert tht polydata structure générated by cutter into unstructured grid by triangulation
triFilter = vtk.vtkDataSetTriangleFilter()
triFilter.SetInputConnection(cutter.GetOutputPort())
triFilter.Update()
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetInputData(triFilter.GetOutput())
writer.SetFileName(outputFileName)
writer.Write()
示例4: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkXMLUnstructuredGridWriter(), 'Writing vtkXMLUnstructuredGrid.',
('vtkXMLUnstructuredGrid',), (),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例5: WriteVTKXMLMeshFile
def WriteVTKXMLMeshFile(self):
if (self.OutputFileName == ''):
self.PrintError('Error: no OutputFileName.')
self.PrintLog('Writing VTK XML mesh file.')
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetInput(self.Mesh)
writer.SetFileName(self.OutputFileName)
writer.Write()
示例6: save
def save( self, name ):
import vtk
vtkWriter = vtk.vtkXMLUnstructuredGridWriter()
vtkWriter.SetInput ( self.vtkMesh )
vtkWriter.SetFileName( os.path.join( self.path, name ) )
if self.ascii:
vtkWriter.SetDataModeToAscii()
vtkWriter.Write()
示例7: HDF5toVTKCells
def HDF5toVTKCells():
input_meshes = []
# Read input meshes.
for in_file in input_mesh_files[output]:
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(in_file)
reader.Update()
input_meshes += [reader.GetOutput()]
# Only add parent mesh for a tube (non-bifurcation)
if branches == 1:
break
for time_step in range(args.start, args.end + 1):
print("Time:", time_step)
append_filter = vtk.vtkAppendFilter()
for branch in range(branches):
mesh = vtk.vtkPolyData()
mesh.DeepCopy(input_meshes[branch])
# The base input h5 filename given the branch and from which writer it came on said branch.
h5_file_base = base_names[output] + str(time_step) + '_b_' + str(branch + 1) + '_' + 'x' + '.h5'
print("Processing file", h5_file_base)
# Group all datasets of a branch at a specific time point given
# the number of writers the data was split into.
species_array = append_datasets(writers, h5_file_base, "data")
# Loop through all attirbutes and append them to a new array in the
# correct order given the quad to task ratio.
for attribute in attributes[output]:
reordered_array = vtk.vtkDoubleArray()
reordered_array.SetName(attribute)
reordered_array.SetNumberOfValues(numCells[output][0] * numCells[output][1] * circQuads * axialQuads)
reorder_species(species_array[attribute], reordered_array, output)
mesh.GetCellData().AddArray(reordered_array)
append_filter.AddInputData(mesh)
append_filter.Update()
# Write the result.
vtu_file = base_names[output] + str(time_step) + '.vtu'
print("Writing file", os.path.abspath(vtu_file))
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName(vtu_file)
writer.SetInputData(append_filter.GetOutput())
writer.Update()
示例8: write_vtu
def write_vtu(filename, atoms, data=None):
from vtk import VTK_MAJOR_VERSION, vtkUnstructuredGrid, vtkPoints, vtkXMLUnstructuredGridWriter
from vtk.util.numpy_support import numpy_to_vtk
if isinstance(atoms, list):
if len(atoms) > 1:
raise ValueError('Can only write one configuration to a VTI file!')
atoms = atoms[0]
# Create a VTK grid of structured points
ugd = vtkUnstructuredGrid()
# add atoms as vtk Points
p = vtkPoints()
p.SetNumberOfPoints(len(atoms))
p.SetDataTypeToDouble()
for i,pos in enumerate(atoms.get_positions()):
p.InsertPoint(i,pos[0],pos[1],pos[2])
ugd.SetPoints(p)
# add atomic numbers
numbers = numpy_to_vtk(atoms.get_atomic_numbers(), deep=1)
ugd.GetPointData().AddArray(numbers)
numbers.SetName("atomic numbers")
# add tags
tags = numpy_to_vtk(atoms.get_tags(), deep=1)
ugd.GetPointData().AddArray(tags)
tags.SetName("tags")
# add covalent radii
from ase.data import covalent_radii
radii = numpy_to_vtk(np.array([covalent_radii[i] for i in atoms.get_atomic_numbers()]), deep=1)
ugd.GetPointData().AddArray(radii)
radii.SetName("radii")
# Save the UnstructuredGrid dataset to a VTK XML file.
w = vtkXMLUnstructuredGridWriter()
if fast:
w.SetDataModeToAppend()
w.EncodeAppendedDataOff()
else:
w.GetCompressor().SetCompressionLevel(0)
w.SetDataModeToAscii()
if isinstance(filename, str):
w.SetFileName(filename)
else:
w.SetFileName(filename.name)
if VTK_MAJOR_VERSION <= 5:
w.SetInput(ugd)
else:
w.SetInputData(ugd)
w.Write()
示例9: WriteVTKXMLMeshFile
def WriteVTKXMLMeshFile(self):
if (self.OutputFileName == ''):
self.PrintError('Error: no OutputFileName.')
self.PrintLog('Writing VTK XML mesh file.')
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetInput(self.Mesh)
writer.SetFileName(self.OutputFileName)
if self.Mode == "binary":
writer.SetDataModeToBinary()
elif self.Mode == "ascii":
writer.SetDataModeToAscii()
writer.Write()
示例10: write_vtu
def write_vtu(ugrid, filename, mode = 'ascii'):
writer = vtk.vtkXMLUnstructuredGridWriter()
if mode == 'ascii':
writer.SetDataModeToAscii()
elif mode == 'binary':
writer.SetDataModeToBinary()
elif mode == 'append':
writer.SetDataModetoAppend()
writer.SetFileName(filename)
writer.SetInputData(ugrid)
writer.Write()
示例11: writeVTUFile
def writeVTUFile(fileName,vtkUnstructuredGrid,compress=True):
'''Function to write vtk unstructured grid (vtu).'''
Writer = vtk.vtkXMLUnstructuredGridWriter()
if float(vtk.VTK_VERSION.split('.')[0]) >=6:
Writer.SetInputData(vtkUnstructuredGrid)
else:
Writer.SetInput(vtkUnstructuredGrid)
if not compress:
Writer.SetCompressorTypeToNone()
Writer.SetDataModeToAscii()
Writer.SetFileName(fileName)
Writer.Update()
示例12: write_vtk
def write_vtk(self,geo,filename,wells=False):
"""Writes *.vtu file for a vtkUnstructuredGrid object corresponding to the grid in 3D, with the specified filename,
for visualisation with VTK."""
from vtk import vtkXMLUnstructuredGridWriter
if wells: geo.write_well_vtk()
arrays=geo.vtk_data
grid_arrays=self.get_vtk_data(geo)
for array_type,array_dict in arrays.items():
array_dict.update(grid_arrays[array_type])
vtu=geo.get_vtk_grid(arrays)
writer=vtkXMLUnstructuredGridWriter()
writer.SetFileName(filename)
writer.SetInput(vtu)
writer.Write()
示例13: vtkbasis
def vtkbasis(mesh, etob, fname, coeffs):
''' Find the directions from a (non-uniform) plane wave basis and output a VTK-compatible file
It's possible that this needs to be updated to work with recent changes to ElementToBasis
'''
try:
import vtk
points = vtk.vtkPoints()
vectors = vtk.vtkDoubleArray()
vectors.SetNumberOfComponents(3)
scalars = vtk.vtkDoubleArray()
nc = 0
for e in range(mesh.nelements):
c = paa.origin(mesh, e)
bs = etob[e]
cc = np.zeros(3)
cc[:len(c)] = c
nondir = 0
ndir = 0
for b in bs:
if hasattr(b, "directions"):
for d in b.directions.transpose():
dd = np.zeros(3)
dd[:len(d)] = d
if coeffs is not None: dd *= abs(coeffs[nc])
points.InsertNextPoint(*cc)
vectors.InsertNextTuple3(*dd)
ndir+=1
nc+=1
else:
nondir += np.sqrt(np.sum(coeffs[nc:nc+b.n]**2))
nc += b.n
for _ in range(ndir): scalars.InsertNextValue(nondir)
g = vtk.vtkUnstructuredGrid()
g.SetPoints(points)
gpd = g.GetPointData()
gpd.SetVectors(vectors)
gpd.SetScalars(scalars)
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName(fname)
writer.SetInput(g)
writer.Write()
except ImportError as e:
print "Unable to write basis to file: ",e
示例14: SaveVTK
def SaveVTK(self, outfile="Output"):
""" Save grid in vtk structured format.
Parameters
----------
grid: vtkStructuredGrid : grid used in computation
outfile: string : output file name in system
Defaults to "Output"
Return
------
pass
save file directly on outfile location
"""
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName(outfile + ".vtu")
writer.SetInput(self.mesh)
writer.Write()
示例15: write
def write(self):
# polydata = vtk.vtkPolyData()
# polydata.SetPoints(self._points)
# polydata.SetPolys(self._hexs)
# for ptData in self._resultsPoint:
# polydata.GetPointData().AddArray(ptData)
# for cellData in self._resultsCell:
# polydata.GetCellData().AddArray(cellData)
# polydata.Modified()
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName(self._fname)
if vtk.VTK_MAJOR_VERSION <= 5:
writer.SetInput(self._hexs)
else:
writer.SetInputData(self._hexs)
writer.Write()