本文整理匯總了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)