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

K3d freezes Jupyter notebook after showing a mesh #73

Open
panangam opened this issue Nov 4, 2019 · 16 comments
Open

K3d freezes Jupyter notebook after showing a mesh #73

panangam opened this issue Nov 4, 2019 · 16 comments

Comments

@panangam
Copy link

panangam commented Nov 4, 2019

I am using vtkplotter with Trimesh in Jupyter notebook, but the k3d display takes about 5 seconds to load every time I run the cell with the show command. So I want to disable the k3d display and just use the default separate window. Right now I do this by uninstalling k3d from my Python environment. Is there a better way?

@marcomusy
Copy link
Owner

@panangam
you can do it this way:

from vtkplotter import embedWindow

embedWindw(False)

it is a bit strange though that it take so long..

@panangam
Copy link
Author

panangam commented Nov 4, 2019

Thank you! Let me see if I can make a reproducible code to show the slowness.

@panangam
Copy link
Author

panangam commented Nov 5, 2019

This is all I'm doing in Jupyter

import trimesh
import vtkplotter
body_mesh = trimesh.load_mesh('censored_scan.obj')
vtkplotter.show(body_mesh)

Took about 10 seconds to display with k3d. If I use Trimesh's threejs viewer, it loaded instantly.

Here's the mesh file I'm using:
censored_scan.obj.zip

@marcomusy
Copy link
Owner

that's interesting.. on my system it only takes 0.7s to show it:
image

same if i use
vtkplotter.embedWindow('itk')

How much does it take outside jupyter e.i. a normal python script?

@panangam
Copy link
Author

panangam commented Nov 5, 2019

Interesting. I duplicated your code here, and it took about 1 second for the display to show up. However, my Jupyter screen froze for about 10 seconds after that before I could do anything else. A different notebook in a different tab froze at the same time as well.

As for running the code in normal Python console, I could instantly interact with the new window that popped up, showing my mesh.

This is probably not a vtkplotter issue, so we can close this. I'd appreciate any suggestion for what to check though.

@marcomusy
Copy link
Owner

Uhmm, I would maybe check some of the k3d standard examples to see if the problem is still there.
https://github.com/K3D-tools/K3D-jupyter/tree/master/examples

@panangam
Copy link
Author

panangam commented Nov 5, 2019

k3d examples didn't give me any trouble. In fact, doing

body_mesh = trimesh.load_mesh('censored_scan.obj')
plt = k3d.plot()
mesh = k3d.mesh(body_mesh.vertices, body_mesh.faces)
plt += mesh
plt.display()

also showed the result instantly... Weird.

@marcomusy
Copy link
Owner

that sounds weird indeed because if show() returns in 0.7 sec i cannot think of anything that would slow down the execution afterwards.
I reopen the issue in case of any further hints/ideas..

@marcomusy marcomusy reopened this Nov 5, 2019
@panangam panangam changed the title Disabling k3d, etc in Jupyter notebook K3d takes very long to load in Jupyter notebook Nov 6, 2019
@panangam panangam changed the title K3d takes very long to load in Jupyter notebook K3d freezes Jupyter notebook after showing a mesh Nov 6, 2019
@panangam
Copy link
Author

Update.

  1. I replicated the same behavior in Chrome, Safari, and Firefox on Mac OSX 10.14.5 so it's not a browser specific issue.
  2. Compared to my bare bone k3d mesh object, the vtkplotter-generated scene has a bunch of extra values associated with the mesh, along with a mysterious yellow color. Whenever I try to change any of the value, my notebook freezes up again as well. Seems like vtkplotter might generated a bunch of extra information that is being recalculated every render. Thoughts?

Also, vtkplotter scene seems to look a bit smoother. Do you use a different shader?

Screen Shot 2019-11-20 at 2 03 44 PM

Screen Shot 2019-11-20 at 2 05 06 PM

@marcomusy
Copy link
Owner

Hi @panangam I think I found the problem in the way vertices receive their color individually.
Please try
pip install vtkpotter -U

Screenshot from 2019-11-21 17-38-39

Now the color is uniform and can be changed from the dropped down menu.
To be honest I'm not sure if the problem can reappear in other cases where faces/vertices genuinely have different colors.. You may try to run the examples available in this directory.

The smoother appereance is only due to the flat_shading option shown in the 2 cases.

@panangam
Copy link
Author

This worked perfectly for me, thank you! I'm still surprised your machine could actually still run the scene smoothly with all the vertex colors. To clarify, did vtkplotter use to assume that all meshes come with a color for each vertex?

Another tangent question. Is there a way to show the plot so that Z-axis is pointing up?

@marcomusy
Copy link
Owner

This worked perfectly for me, thank you! I'm still surprised your machine could actually still run the scene smoothly with all the vertex colors. To clarify, did vtkplotter use to assume that all meshes come with a color for each vertex?

indeed that was causing the problem! the mystery is not completely solved as you say it might show up again when rendering multi colored meshes.

You may check what happens if you run any of these examples
https://github.com/marcomusy/vtkplotter/tree/master/examples/notebooks

Another tangent question. Is there a way to show the plot so that Z-axis is pointing up?

you can try with show(viewup='z') see also:
https://github.com/marcomusy/vtkplotter/blob/master/examples/notebooks/manipulate_camera.ipynb

@panangam
Copy link
Author

panangam commented Nov 25, 2019

Tried running code from sphere.ipynb and got no problem. My mesh has about 6000 vertices or so. I'm suspecting that 6000 colors are just too much to calculate.

Screen Shot 2019-11-25 at 10 05 01 AM

Also ran a similar code on my mesh with ~6000 vertices. No freezing here either.

Screen Shot 2019-11-25 at 10 13 11 AM

@marcomusy
Copy link
Owner

Cool... Thank for this useful feedback! I tried increasing the nr of triangles with res=100 and dont see any problems on my system, up to 1M triangles is still ok and relatively fast.
One thing which is probably different is the k3d version we are using (check the info tab)

image

@panangam
Copy link
Author

panangam commented Nov 26, 2019

Tried the same example above, and was fast as well. My info box says

  • Js version: 2.7.0
  • Python: 2.7.0

Are these the versions of vtkplotter or the Python it's using? I'm actually running this on Python 3.7.

@marcomusy
Copy link
Owner

I think you are using latest version of k3d whereas i'm using an older one.. not sure if this can explain the initial problem.. I'll leave the issue open in case I find a better explanation..

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

2 participants