Skip to content

WIP: non-blocking show using trame/vtk #1786

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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft

Conversation

adam-urbanczyk
Copy link
Member

@adam-urbanczyk adam-urbanczyk commented Mar 10, 2025

Closes #1784 (?)

API:

from cadquery.fig import Figure
from cadquery.func import sphere, torus

# this starts a server and opens a browser tab
fig = Figure()

# we can use show, the API is fluent
fig.show(torus(10, 2), color='violet').show(sphere(5))

# zoom to fit
fig.fit()

# clear
fig.clear()

image

@adam-urbanczyk adam-urbanczyk marked this pull request as draft March 10, 2025 07:11
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.47%. Comparing base (471ab6f) to head (4a98f6a).

Files with missing lines Patch % Lines
cadquery/vis.py 88.88% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1786      +/-   ##
==========================================
- Coverage   95.47%   95.47%   -0.01%     
==========================================
  Files          28       28              
  Lines        7188     7187       -1     
  Branches     1080     1082       +2     
==========================================
- Hits         6863     6862       -1     
  Misses        195      195              
  Partials      130      130              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adam-urbanczyk
Copy link
Member Author

@jmwright @lorenzncode I'm not saying this is ready, but would you be able to give this a try? Just to collect some datapoints on possible issues...

@lorenzncode
Copy link
Member

I tested on linux.

  • It worked with both firefox, chrome browsers. The browser opened automatically.

  • As the output message says you can add --server to prevent launching browser:

    $ python test1.py

    App running at:

    Note that for multi-users you need to use and configure a launcher.
    And to prevent your browser from opening, add '--server' to your command line.

    $ python test1.py --server

  • I found the server exits immediately (connection closed) unless I add code to prevent it (sleep).
    I expected behavior more similar to starting a jupyter server where it runs in the foreground and you can stop the server from the terminal.

  • It does not work in a container without exposing DISPLAY
    I would like to try rendering with VTK.js in the browser in this scenario. Yesterday I tested with a python server and browser using websockets. I did not try to connect to CQ yet. I was using dummy data with VTK.js vtkXMLPolyDataReader. This isn't a requirement for this PR - I'm only wondering if I'll be able to reuse any of this if I continue with a custom VTK.js front end.

@lorenzncode
Copy link
Member

OK I forgot you probably intend this to be run from ipython. In that case the server does stay running.

@jmwright
Copy link
Member

I created a new venv for the changes and installed via pip, and it seems to work. Two corrections for your sample code at top.

from cadquery.fig import Figure()

should be...

from cadquery.fig import Figure

and

fit.clear()

should be...

fig.clear()

The server continued to run when started by entering the code into the Python REPL and all updates showed up in the 3D viewer. The mouse rotation of the scene is a little laggy, even though my laptop does not normally struggle with 3D rendering.

Debian 12, AMD64, local install via pip.

@adam-urbanczyk
Copy link
Member Author

Thanks for the feedback.

  • NB: this is a non-blocking show, not a server. It is intended to be used in a repl.
  • For vtk.js you can try vtk_widgets.VtkLocalView but it did not work well for me. I'd like to wait for WASM/VTK 9.4
  • Regarding containers/DISPLAY I thought that this is not needed and you just need to expose a port and manually connect from the host
  • Indeed the perf with remote view could be better, but it is IMHO very usable

@lorenzncode
Copy link
Member

Regarding containers/DISPLAY I thought that this is not needed and you just need to expose a port and manually connect from the host

Yes, that's correct. It works fine with cadquery.vis and cq-editor (and I expect this PR after adding a browser). I only meant that if this was a server it could be an alternative display method which might have some advantages. Sorry to get off topic. Here is how I use the container today:

 weston --xwayland -S wayland-88 --width=1400 --height=1000

Then in container run script:

podman run -it --entrypoint=/bin/bash  --userns=keep-id \
   --security-opt label=type:container_runtime_t \
   -e XDG_RUNTIME_DIR=/tmp \
   -e DISPLAY=${display} \
   -e "WAYLAND_DISPLAY=$way_display" \
   -v /run/user/$user_uid/${way_display}:/tmp/${way_display} \
   -v "$XDG_RUNTIME_DIR/${way_display}:/tmp/${way_display}" \
   -v /tmp/.X11-unix/${x_socket}:/tmp/.X11-unix/${x_socket} \
   ...

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

Successfully merging this pull request may close these issues.

Interactive show
3 participants