0

我想使用 vtk 从 OpenFOAM 中提取 stl。贝娄是我的代码

这是示例代码。

import vtk 
from vtk.util.numpy_support import vtk_to_numpy 
filename = "case1.foam" 
reader = vtk.vtkOpenFOAMReader() 
reader.SetFileName(filename) 
reader.CreateCellToPointOn() 
reader.DecomposePolyhedraOn() 
reader.EnableAllCellArrays() 
reader.Update()

tArray =vtk_to_numpy(reader.GetTimeValues()) 
reader.UpdateTimeStep(tArray[-1])  
reader.Update() 

filter = vtk.vtkGeometryFilter() 
filter.SetInputConnection(reader.GetOutputPort()) 
filter.Update() 

surface = vtk.vtkExtractSurface()
surface.SetInputData(filter.GetOutput())
surface.Update()

writer = vtk.vtkSTLWriter()
writer.SetFileName("test.stl")
writer.SetInputConnection(surface.GetOutputPort())
writer.Write()

请告诉我该怎么办 谢谢。

4

0 回答 0