Skip to content

VTK-based show_object - #1366

Merged
adam-urbanczyk merged 6 commits into
masterfrom
vtk-show
Jul 10, 2023
Merged

VTK-based show_object#1366
adam-urbanczyk merged 6 commits into
masterfrom
vtk-show

Conversation

@adam-urbanczyk

Copy link
Copy Markdown
Member

Useful for developing CQ itself, debugging and quick checking. Usage:

from cadquery.vis import show

show(cq.Workplane().box(1,1,1)

Can display all CQ objects and TopoDS_Shape form OCP.
afbeelding

@codecov

codecov Bot commented Jul 6, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1366 (70e7d1d) into master (44ae035) will decrease coverage by 0.03%.
The diff coverage is 96.82%.

❗ Current head 70e7d1d differs from pull request most recent head 4f303a7. Consider uploading reports for the commit 4f303a7 to get more accurate results

@@            Coverage Diff             @@
##           master    #1366      +/-   ##
==========================================
- Coverage   94.15%   94.12%   -0.03%     
==========================================
  Files          26       27       +1     
  Lines        5611     5671      +60     
  Branches      956      961       +5     
==========================================
+ Hits         5283     5338      +55     
- Misses        195      199       +4     
- Partials      133      134       +1     
Impacted Files Coverage Δ
cadquery/vis.py 96.55% <96.55%> (ø)
cadquery/cqgi.py 79.67% <100.00%> (-1.07%) ⬇️
cadquery/occ_impl/assembly.py 97.27% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@adam-urbanczyk adam-urbanczyk added the enhancement New feature or request label Jul 6, 2023

@jmwright jmwright left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well for me, even with assemblies. It would be nice to be able to change the background color and maybe the camera view/direction, but those are just nice-to-haves. The lighting is not quite as good as it is now in CQ-editor, but I'm not sure what's different.

Seems like a nice, light-weight viewer tool. Thanks!

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

@jmwright I tweaked it a bit based on your comments.
afbeelding

@jmwright

jmwright commented Jul 7, 2023

Copy link
Copy Markdown
Member

@adam-urbanczyk Looks and works good, thanks!

@lorenzncode

Copy link
Copy Markdown
Member

Thanks - very useful to have this standalone viewer!

An issue I find is that with a larger model, the view is initially empty. For example with:

cq.Workplane().box(100, 100, 100)

I think the keyboard shortcuts are here (using 'r' to reset view, and 'e' for exit currently) : https://vtk.org/doc/nightly/html/classvtkInteractorStyle.html

The model is visible after I enter the r key. Could the view be fit automatically?

@lorenzncode

Copy link
Copy Markdown
Member

the view is initially empty.

I see it is due to clipping range. Perhaps the camera.SetClippingRange call can be removed?

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

How can I reproduce the issue? The call was needed to solve one glitch I've seen.

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

I can use ResetCamera() to solve my problem. Maybe it also works for your model.

@lorenzncode

Copy link
Copy Markdown
Member

I can use ResetCamera() to solve my problem. Maybe it also works for your model.

Yes it does work.

Previously I had reproduced the empty window with the following:

import cadquery as cq
from cadquery.vis import show

#d = 10  # box is visible as expected
d = 100  # empty window displayed; after 'r' key or zoom with middle mouse the box is displayed

result = cq.Workplane().box(d, d, d)

show(result)

Commenting out this show function line, the box is displayed (no issue):

#    camera.SetClippingRange(0.1, 100)

or adding ResetCamera() also works.

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

OK, latest version (with ResetCamera()) does work in both cases. Is it good to be merged?

@lorenzncode lorenzncode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good to be merged?

Yes, good for me. I did not find any other issue. Thanks @adam-urbanczyk!

I experimented with setting window size and position. I like that cq-editor, through the Qt configuration file, remembers window size and position. I thought I would miss that feature more, but the VTK-based show works well to view the model, and I can use the 'e' key to quickly close the viewer, edit code, invoke the viewer again. Perhaps some control over size and position could be exposed later either through show function options or a cadquery config/preferences file.

@adam-urbanczyk
adam-urbanczyk merged commit 76dbeef into master Jul 10, 2023
@jmwright

jmwright commented Aug 7, 2023

Copy link
Copy Markdown
Member

Just wanted to note that I use this feature a lot.

@rohit-kumar-j

rohit-kumar-j commented Aug 27, 2023

Copy link
Copy Markdown

It opens a window but with errors, then quickly closes itself.

  • Python 3.11.4
  • Windows 10
Traceback
Successfully installed cadquery-2.4.0.dev0
PS C:\Koala\python\cadquery> python .\quick_window.py
2023-08-28 00:52:13.855 (  10.266s) [                ]vtkDemandDrivenPipeline:663    ERR| vtkCompositeDataPipeline (000001EF59A41FA0): Input port 0 of algorithm vtkTriangleFilter (000001EF5A129C40) has 0 connections but is not optional.
Traceback (most recent call last):
  File "C:\Koala\python\cadquery\quick_window.py", line 9, in <module>
    show(result)
  File "C:\Users\jsk71\AppData\Local\Programs\Python\Python311\Lib\site-packages\cadquery\vis.py", line 82, in show
    win.SetSize(*win.GetScreenSize())
TypeError: vtkRenderWindow.SetSize() argument after * must be an iterable, not NoneType
PS C:\Koala\python\cadquery>

Code

import cadquery as cq
from cadquery.vis import show

d = 10  # box is visible as expected
# d = 100  # empty window displayed; after 'r' key or zoom with middle mouse the box is displayed

result = cq.Workplane().box(d, d, d)

show(result)
Pip List
PS C:\Koala\python\cadquery> pip list
Package                   Version
------------------------- -----------
anyio                     3.7.1
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.2.3
asttokens                 2.2.1
attrs                     23.1.0
backcall                  0.2.0
beautifulsoup4            4.12.2
bleach                    6.0.0
cadquery                  2.4.0.dev0
cadquery-ocp              7.7.1
cadqueryhelper            0.1.3
casadi                    3.6.3
certifi                   2023.7.22
cffi                      1.15.1
charset-normalizer        3.2.0
colorama                  0.4.6
comm                      0.1.4
contourpy                 1.1.0
cq-warehouse              0.8.0
cqkit                     0.5.1
cqmore                    0.1
cycler                    0.11.0
dearpygui                 1.9.1
debugpy                   1.6.7.post1
decorator                 5.1.1
defusedxml                0.7.1
discretisedfield          0.11.1
entrypoints               0.4
executing                 1.2.0
ezdxf                     1.0.3
fastjsonschema            2.18.0
fonttools                 4.42.1
fqdn                      1.5.1
greenlet                  2.0.2
h5py                      3.9.0
idna                      3.4
iniconfig                 2.0.0
ipykernel                 6.25.1
ipython                   8.14.0
ipython-genutils          0.2.0
ipywidgets                8.1.0
isoduration               20.11.0
jedi                      0.19.0
Jinja2                    3.1.2
json5                     0.9.14
jsonpointer               2.4
jsonschema                4.19.0
jsonschema-specifications 2023.7.1
jupyter_client            7.4.9
jupyter_core              5.3.1
jupyter-events            0.7.0
jupyter_server            2.7.2
jupyter_server_terminals  0.4.4
jupyterlab                2.2.0
jupyterlab-pygments       0.2.2
jupyterlab-server         1.2.0
jupyterlab-widgets        3.0.8
k3d                       2.16.0
kiwisolver                1.4.5
MarkupSafe                2.1.3
matplotlib                3.7.2
matplotlib-inline         0.1.6
mistune                   3.0.1
msgpack                   1.0.5
multimethod               1.9.1
nbclassic                 1.0.0
nbclient                  0.8.0
nbconvert                 7.7.4
nbformat                  5.9.2
nest-asyncio              1.5.7
nlopt                     2.7.1
notebook                  6.5.5
notebook_shim             0.2.3
nptyping                  2.0.1
numpy                     1.25.2
overrides                 7.4.0
packaging                 23.1
pandas                    2.0.3
pandocfilters             1.5.0
parso                     0.8.3
path                      16.7.1
pickleshare               0.7.5
Pillow                    10.0.0
pip                       23.2.1
platformdirs              3.10.0
pluggy                    1.3.0
prometheus-client         0.17.1
prompt-toolkit            3.0.39
psutil                    5.9.5
pure-eval                 0.2.2
pycparser                 2.21
Pygments                  2.16.1
pynvim                    0.4.3
pyparsing                 3.0.9
pytest                    7.4.0
python-dateutil           2.8.2
python-json-logger        2.0.7
pytz                      2023.3
pywin32                   306
pywinpty                  2.0.11
PyYAML                    6.0.1
pyzmq                     24.0.1
referencing               0.30.2
requests                  2.31.0
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rpds-py                   0.9.2
scipy                     1.11.2
Send2Trash                1.8.2
setuptools                65.5.0
six                       1.16.0
sniffio                   1.3.0
soupsieve                 2.4.1
stack-data                0.6.2
terminado                 0.17.1
tinycss2                  1.2.1
tornado                   6.3.3
traitlets                 5.9.0
traittypes                0.2.1
typing_extensions         4.7.1
typish                    1.9.3
tzdata                    2023.3
ubermagutil               0.4.1
uri-template              1.3.0
urllib3                   2.0.4
vtk                       9.2.6
vtk-module                0.0.1
wcwidth                   0.2.6
webcolors                 1.13
webencodings              0.5.1
websocket-client          1.6.2
widgetsnbextension        4.0.8

@jmwright

Copy link
Copy Markdown
Member

@rohit-kumar-j I'm wondering if the work-around posted here would help. I cannot reproduce your problem so I cannot test that solution. Basically this line and probably the one below it would be placed below this line.

If you're comfortable doing a development installation of CadQuery, you could try this.

It probably won't help, but another thing you could try is running your code using Python 3.10.

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

@rohit-kumar-j can you verify that your vtk installation actually works? E.g. by running an example from their docs.

@rohit-kumar-j

Copy link
Copy Markdown

@adam-urbanczyk ,this looks pretty cool!

image

@jmwright

Copy link
Copy Markdown
Member

@adam-urbanczyk I cannot reproduce the issue @rohit-kumar-j is having on Windows 11 Home 22H2, Build 22621.521. However, I did not get any new errors when rearranging the lines as I suggested above to avoid any issues like a race condition.

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

@rohit-kumar-j it does work. Could you check what is the result of renderWindow.GetScreenSize() in the example code?

@jmwright sure, we can change the code as you suggested.

@rohit-kumar-j

Copy link
Copy Markdown

@rohit-kumar-j it does work. Could you check what is the result of renderWindow.GetScreenSize() in the example code?

(2560, 1080)

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

Ok, @rohit-kumar-j pls take a look at #1394

@rohit-kumar-j

Copy link
Copy Markdown

Tried installing with

 pip install git+https://github.com/CadQuery/cadquery.git@vtk-fix

but I get the error remains the same:

2023-08-31 21:26:40.465 (   2.399s) [                ]vtkDemandDrivenPipeline:663    ERR| vtkCompositeDataPipeline (0000024FA7B8FC00): Input port 0 of algorithm vtkTriangleFilter (0000024FAB1511C0) has 0 connections but is not optional.
Traceback (most recent call last):
  File "C:\Users\jsk71\AppData\Local\nvim\tmp2.py", line 10, in <module>
    show(result)
  File "C:\Users\jsk71\AppData\Local\Programs\Python\Python311\Lib\site-packages\cadquery\vis.py", line 89, in show
    win.SetSize(*win.GetScreenSize())
TypeError: vtkRenderWindow.SetSize() argument after * must be an iterable, not NoneType

@adam-urbanczyk

Copy link
Copy Markdown
Member Author

Thanks for checking, not sure what else to try I'm afraid.

@rohit-kumar-j

Copy link
Copy Markdown

@adam-urbanczyk thanks for checking this out....
I'm not sure if there is some mismatch in OS version which is the reason for the failures.

Spec:

Device name	DESKTOP-J4C55R4
Processor	Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz   2.40 GHz
Installed RAM	8.00 GB
System type	64-bit operating system, x64-based processor
Pen and touch	No pen or touch input is available for this display

Edition	Windows 10 Home
Version	22H2
Installed on	‎15-‎11-‎2022
OS build	19045.3324
Experience	Windows Feature Experience Pack 1000.19041.1000.0

@jmwright

jmwright commented Sep 6, 2023

Copy link
Copy Markdown
Member

@rohit-kumar-j Just to confirm, the VTK example runs fine on your system, but our VTK-based show window will not. Is that correct?

@rohit-kumar-j

rohit-kumar-j commented Sep 6, 2023

Copy link
Copy Markdown

Yes

Also, I updated my windows to the latest windows 10 (ithink 2202.2 or something) and then tested it out as well. Yet, the example works, but not CadQuery script.

@joaotcarvalho

joaotcarvalho commented Sep 12, 2023

Copy link
Copy Markdown

Hi, I'm having the same problem as @rohit-kumar-j here. The error that appears in the VTK window is shown here:

image

Tried updating cadquery/vis.py as suggested in #1394 , but I'm still getting the same error

@rohit-kumar-j

Copy link
Copy Markdown

Hi, I'm having the same problem as @rohit-kumar-j here. The error that appears in the VTK window is shown here:

image

Tried updating cadquery/vis.py as suggested in #1394 , but I'm still getting the same error

Yup, this happens for me as well, but the window immediately closes, so i could not capture the output like you did 👌

@Jopie01

Jopie01 commented Oct 2, 2023

Copy link
Copy Markdown

If it helps, I get the same on Fedora 38 kind of error with CadQuery installed in a Python 3.11 virtual environment. Using the following code:

import cadquery as cq
from cadquery.vis import show

#d = 10  # box is visible as expected
d = 100  # empty window displayed; after 'r' key or zoom with middle mouse the box is displayed

result = cq.Workplane().box(d, d, d)

show(result)

With the #1394 branch I also got:

2023-10-02 23:51:41.837 (   0.491s) [        4D584740]vtkDemandDrivenPipeline:661    ERR| vtkCompositeDataPipeline (0x56454faba5e0): Input port 0 of algorithm vtkTriangleFilter (0x56454ff2f010) has 0 connections but is not optional.
Traceback (most recent call last):
  File "/home/Projects/cadquery/cadquery_vis.py", line 9, in <module>
    show(result)
  File "/home/Projects/cadquery/lib64/python3.11/site-packages/cadquery/vis.py", line 82, in show
    win.SetSize(*win.GetScreenSize())
TypeError: vtkRenderWindow.SetSize() argument after * must be an iterable, not NoneType

Adding a print statement for win.GetScreenSize() and it returns None. The workaround from #1366 (comment) results in:

2023-10-03 00:08:51.661 (   0.487s) [        55B74740]vtkDemandDrivenPipeline:661    ERR| vtkCompositeDataPipeline (0x5618c5e38540): Input port 0 of algorithm vtkTriangleFilter (0x5618c6028e70) has 0 connections but is not optional.
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  3 (X_GetWindowAttributes)
  Resource id in failed request:  0x0
  Serial number of failed request:  8
  Current serial number in output stream:  9

I'm running on X11, maybe Wayland will work?

@Jopie01

Jopie01 commented Oct 3, 2023

Copy link
Copy Markdown

Tested on Wayland but the problem still exists.

But the error consists of two parts:

  1. error about the vtkTriangleFilter
  2. error about the vtkRenderWindow

To start with the second one, it's weird. When I add import vtk at the top of the vis.py the error is gone and a window pops up but without any 3D model.

For the first one, I digged deeper and got to

t_filter.Update()
which is throwing the error. Commenting this one out, will stop the error but nothing is shown. So it seems to come down to the VTK version? I have 9.2.6

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants