The overall construct is an FastAPI Webserver to which a GemPy Model is send. This is then plotted as a 3D Model. From this I can extract the Layers as PyVista/VTK PolyData Objects. Until this point is works fine, however these Objects should idealy send back to the client as a useable file which isn´t just practicle in PYthon (e.g. .glb/.vtk/.ply). I know technically how to do that, however for the Server side i tried to save the file into a buffer, which seems impossible to implement with pyvista.PolyData.save() or vtk.vtkWriter.
My Code looks like this
# this just creates an object from which the layers can be extracted as polydata
gpv = gp.plot_3d(geo_model)
# here an examples how to get polydata or an unstructuredgrid
poly = gpv.surface_poly['Sandstone_2']
grid = pv.UnstructuredGrid(poly)
from this i´d like to ether save it with pyvista
poly.save("filename.ply")
or alternativley with vtk
def write_grid_to_vtk(grid, filename):
writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileName(filename)
writer.SetInputData(grid)
#writer.SetFileTypeToBinary()
writer.Write()
buf = io.BytesIO()
write_grid_to_vtk(grid, buf)
buf.close()
in the vtk example you can see, how i tried to implement the buffer. This Throws an TypeError: SetFileName argument %Id: %V
Does anyone know how to implement this ?