Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kemo993 opened this issue Mar 3, 2020 · 6 comments
Open

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

kemo993 opened this issue Mar 3, 2020 · 6 comments

Comments

@kemo993
Copy link

kemo993 commented Mar 3, 2020

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!

@marcomusy
Copy link
Owner

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())

@kemo993
Copy link
Author

kemo993 commented Mar 3, 2020

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

@ahinoampollack
Copy link

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

@marcomusy
Copy link
Owner

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

@ahinoampollack
Copy link

ahinoampollack commented Apr 29, 2020

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.

@marcomusy
Copy link
Owner

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').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants