vedo icon indicating copy to clipboard operation
vedo copied to clipboard

exportWindow() with volumetric data doesn't work as expected?

Open kemo993 opened this issue 6 years ago • 6 comments

Hello,

I'm trying to export the vtkplotter scene to .x3d file to inspect in the browser, in the way similar to the export_x3d.py example: https://github.com/marcomusy/vtkplotter-examples/blob/master/vtkplotter_examples/other/export_x3d.py

However, seems like it is not working as expected while trying to export the scene with volumetric data (e.g. MIP rendering style). Here is the code snippet inspired by export_x3d.py:

from vtkplotter import *

e = load(datadir+'embryo.tif')
e.mode(1)
e.color("gray")

t = Text(__doc__, pos=[3000., 2000., 4723], s=150, c='w', depth=0.1)
show(t, e)

exportWindow('embryo.x3d')

Volumetric data is properly visualized in vtkplotter window, but it seems like there is only a text in embryo.x3d file after opening embryo.html file in the browser. Moreover, while trying to visualize and export volumetric data only (i.e. show(e) instead of show(t, e)) the following error occurs:

ERROR: In /work/standalone-x64-build/VTK-source/IO/Export/vtkX3DExporter.cxx, line 138
vtkX3DExporter (0x33fb5d0): no actors found for writing X3D file.

Any help is appreciated. Thanks!

kemo993 avatar Mar 03 '20 14:03 kemo993

Hi, I strongly suspect that the underlying vtkX3DExporter class is not able to export volumes. One possibility is to exploit k3d interoperability and do something like this, which generates a html document:

import k3d
import numpy as np
from vtkplotter import load, datadir

vol = load(datadir+'embryo.tif')

kx, ky, kz = vol.dimensions()
arr = vol.getPointArray()
kimage = arr.reshape(-1, ky, kx).astype(np.float32)

plot = k3d.plot()
kvol = k3d.volume(kimage, alpha_coef=20, bounds=vol.bounds())
plot += kvol
with open('page.html','w') as fp:
    fp.write(plot.get_snapshot())

marcomusy avatar Mar 03 '20 15:03 marcomusy

Thank you @marcomusy -- this really helped me navigate the alternatives.

kemo993 avatar Mar 03 '20 17:03 kemo993

Hi,

I would like to follow up on this closed issue. I'm running the example https://github.com/marcomusy/vtkplotter-examples/blob/master/vtkplotter_examples/other/export_x3d.py and getting the following error shown in the picture:

image

I'm looking to export my model to either vtk, x3d, stl, or any other widely used format. Should I try to use the meshio package? or is there a way to do it inside VTKPlotter?

Thank you for your assistance!

Noe

ahinoampollack avatar Apr 29 '20 05:04 ahinoampollack

Hi Noe, If you need to export a single mesh you can use mesh.write('myfile.stl') # or vtk, obj etc

From inside notebooks you cannot export a window because ...there's a bug! I'll fix it for the next release, thanks for reporting it. Marco

marcomusy avatar Apr 29 '20 10:04 marcomusy

Hi Marco!

Thanks so much. I got the x3d export to work in python. Unfortunately, blender didn't accept this version of x3d format. So I thought to try to export to obj. As follows:

exportWindow('this.obj')

and then I get this error:

Traceback (most recent call last):

  File "C:\Users\ahino\Downloads\exportwindowpractice.py", line 98, in <module>
    exportWindow('this.obj')

  File "C:\Users\ahino\anaconda3\lib\site-packages\vtkplotter\vtkio.py", line 1186, in exportWindow
    w.SetInputData(settings.plotter_instance.window)

AttributeError: 'vtkIOExportPython.vtkOBJExporter' object has no attribute `'SetInputData'`

I'm guessing this is not a priority and that's fine. Just thought to write this.

ahinoampollack avatar Apr 29 '20 15:04 ahinoampollack

Hi Noe, yes - exporting the rendering scene to obj is not ready yet (i understand it will in vtk9), you can still save individual meshes as obj files with mesh.write('file.obj').

marcomusy avatar Apr 29 '20 17:04 marcomusy