本文整理汇总了Python中vtk.vtkXMLUnstructuredGridReader方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkXMLUnstructuredGridReader方法的具体用法?Python vtk.vtkXMLUnstructuredGridReader怎么用?Python vtk.vtkXMLUnstructuredGridReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vtk
的用法示例。
在下文中一共展示了vtk.vtkXMLUnstructuredGridReader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_vtk_file
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkXMLUnstructuredGridReader [as 别名]
def convert_vtk_file(vtk_file, plt_file, strand=None, solution_time=None):
reader = None
if vtk_file.endswith(".vtu"):
reader = vtk.vtkXMLUnstructuredGridReader()
elif vtk_file.endswith(".vtp"):
reader = vtk.vtkXMLPolyDataReader()
elif vtk_file.endswith(".vts"):
reader = vtk.vtkXMLStructuredGridReader()
elif vtk_file.endswith(".vti"):
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName(vtk_file)
reader.Update()
vtk_dataset = reader.GetOutput()
tp.new_layout()
tecplot_dataset = tp.active_frame().dataset
add_vtk_dataset(vtk_dataset, tecplot_dataset)
for z in tecplot_dataset.zones():
z.name = os.path.basename(vtk_file)
if strand and solution_time:
z.strand = strand
z.solution_time = solution_time
tp.data.save_tecplot_plt(plt_file, dataset=tecplot_dataset)
示例2: add_scalar
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkXMLUnstructuredGridReader [as 别名]
def add_scalar(var, timestamp):
vtkFile = vtk.vtkXMLUnstructuredGridReader()
vtkFile.SetFileName('cosipy.vtu')
vtkFile.Update()
# Find cellId by coordinates
pointLocator = vtk.vtkPointLocator()
pointLocator.SetDataSet(vtkFile.GetOutput())
pointLocator.BuildLocator()
ds = xr.open_dataset('../data/output/Peru_20160601-20180530_comp4.nc')
ds = ds.sel(time=timestamp)
ds_sub = ds[var].stack(x=['south_north','west_east'])
ds_sub = ds_sub.dropna(dim='x')
lats = ds_sub.x.lat.values
lons = ds_sub.x.lon.values
data = ds_sub.values
print(lats)
numPoints = vtkFile.GetOutput().GetNumberOfPoints()
scalar = np.empty(numPoints)
scalar[:] = np.nan
interpField = numpy_support.numpy_to_vtk(scalar)
interpField.SetName(var)
vtkFile.GetOutput().GetPointData().AddArray(interpField)
vtkFile.Update()
print('Write points \n')
for i in np.arange(len(data)):
# Get height
alt = ds.HGT.sel(lat=lats[i],lon=lons[i]).values/6370000.0
pointId = vtk.mutable(0)
Id = vtk.vtkIdList()
pointId = pointLocator.FindClosestPoint([lons[i],lats[i],alt])
vtkFile.GetOutput().GetPointData().GetArray(var).InsertTuple1(pointId,data[i])
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName('cosipy.vtu')
writer.SetInputData(vtkFile.GetOutput())
writer.Write()
#plotSurface(vtkFile)