VTK-based show_object - #1366
Conversation
Codecov Report
@@ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
jmwright
left a comment
There was a problem hiding this comment.
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!
|
@jmwright I tweaked it a bit based on your comments. |
|
@adam-urbanczyk Looks and works good, thanks! |
|
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 |
I see it is due to clipping range. Perhaps the |
|
How can I reproduce the issue? The call was needed to solve one glitch I've seen. |
|
I can use |
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 # camera.SetClippingRange(0.1, 100)or adding |
|
OK, latest version (with |
lorenzncode
left a comment
There was a problem hiding this comment.
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.
|
Just wanted to note that I use this feature a lot. |
|
It opens a window but with errors, then quickly closes itself.
TracebackSuccessfully 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>Codeimport 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 ListPS 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 |
|
@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. |
|
@rohit-kumar-j can you verify that your vtk installation actually works? E.g. by running an example from their docs. |
|
@adam-urbanczyk ,this looks pretty cool! |
|
@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. |
|
@rohit-kumar-j it does work. Could you check what is the result of @jmwright sure, we can change the code as you suggested. |
(2560, 1080) |
|
Ok, @rohit-kumar-j pls take a look at #1394 |
|
Tried installing with pip install git+https://github.com/CadQuery/cadquery.git@vtk-fixbut 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 |
|
Thanks for checking, not sure what else to try I'm afraid. |
|
@adam-urbanczyk thanks for checking this out.... 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 |
|
@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? |
|
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. |
|
Hi, I'm having the same problem as @rohit-kumar-j here. The error that appears in the VTK window is shown here: 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 👌 |
|
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: Adding a I'm running on X11, maybe Wayland will work? |
|
Tested on Wayland but the problem still exists. But the error consists of two parts:
To start with the second one, it's weird. When I add For the first one, I digged deeper and got to cadquery/cadquery/occ_impl/shapes.py Line 1340 in d780127 9.2.6
|



Useful for developing CQ itself, debugging and quick checking. Usage:
Can display all CQ objects and TopoDS_Shape form OCP.
