From ea8eced67dc75b90eef6f79a7134a5a447cce4d0 Mon Sep 17 00:00:00 2001 From: Miguel Xochicale Date: Fri, 5 Jul 2024 15:40:11 +0100 Subject: [PATCH 1/8] fixes #37 --- doc/00_Introduction.rst | 64 ++++--------------- requirements-dev.txt | 1 - requirements.txt | 6 +- sksurgerytutorial01/vtk_aruco_app.py | 15 +++-- sksurgerytutorial01/vtkoverlay_app.py | 15 +++-- .../vtkoverlay_with_movement_app.py | 15 +++-- tests/conftest.py | 4 +- tests/test_sksurgerytorial01.py | 7 +- 8 files changed, 54 insertions(+), 73 deletions(-) diff --git a/doc/00_Introduction.rst b/doc/00_Introduction.rst index a1c43e6..57b4f99 100644 --- a/doc/00_Introduction.rst +++ b/doc/00_Introduction.rst @@ -42,62 +42,24 @@ guide the user in creating an augmented reality application in around 70 lines o Installation ~~~~~~~~~~~~ -Step 1: -You'll need SciKit-SurgeryUtils installed on your system. Provided you have Python installed on -your system you should be able to run ... -:: - - pip install scikit-surgeryutils - -to install SciKit-SurgeryUtils and its dependencies (including SciKit-SurgeryCore). -For the third part of the tutorial you'll also need SciKit-SurgeryArUcoTracker - -:: - pip install scikit-surgeryarucotracker +Packages, other requirements, and virtual environments +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If you don't have Python installed, we -recommend downloading an installer for your platform directly from `python.org`_. - -Virtual environments +Python virtual environments ~~~~~~~~~~~~ Virtualenv, venv, conda or pyenv can be used to create virtual environments to manage python packages. -You can use conda env by installing conda for your OS (`conda_installation`_) and use the following yml file with all dependencies. +If you don't have Python installed, we recommend downloading an installer for your platform directly from `python.org`_. +For the case of conda, please create a VE using the following commands in your terminal: + :: - ## Create scikit-surgerytutorial01VE.yml in your favorite location with the following content: - ## - ## scikit-surgerytutorial01VE.yml - ## - ## Some useful commands to manage your conda env: - ## LIST CONDA ENVS: conda list -n *VE # show list of installed packages - ## UPDATE CONDA: conda update -n base -c defaults conda - ## INSTALL CONDA EV: conda env create -f *VE.yml - ## UPDATE CONDA ENV: conda env update --file *VE.yml --prune - ## ACTIVATE CONDA ENV: conda activate *VE - ## REMOVE CONDA ENV: conda remove -n *VE --all - - name: scikit-surgerytutorial01VE - channels: - - defaults - - conda-forge #vtk; tox; - - anaconda #coverage; scipy; - dependencies: - - python=3.7 - - numpy>=1.17.4 - - vtk=8.1.2 - - tox>=3.26.0 - - pytest>=7.1.2 - - pylint>=2.14.5 - - pip>=22.2.2 - - pip: - - PySide2>=5.14.2.3 - - scikit-surgerycore>=0.1.7 - - scikit-surgeryutils>=1.2.0 - - scikit-surgeryarucotracker>=0.1.1 - - opencv-python-headless - -Step 2: -You should now be able to follow the tutorial, using the code snippets contained herein. + + conda update -n base -c defaults conda + conda create -n sst01VE python=3.8 pip -c conda-forge #try3.7 + conda activate sst01VE + pip install -r requirements.txt + pip install -r requirements-dev.txt + .. _`python.org`: https://www.python.org/downloads/ .. _`SmartLiver`: https://link.springer.com/article/10.1007/s11548-018-1761-3 diff --git a/requirements-dev.txt b/requirements-dev.txt index baa086b..5cc162c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,7 +2,6 @@ # for development. # It is used by pip to manage software dependencies. It is not to be # confused with the software requirements, which are listed in -# doc/requirements.rst -r requirements.txt coverage mock diff --git a/requirements.txt b/requirements.txt index 4fc3e80..103caac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,9 @@ # confused with the software requirements, which are listed in # doc/requirements.rst numpy>=1.17.4 -PySide2 +vtk>=9.2.6 +PySide6>=6.5.1.1 +opencv-contrib-python-headless>=4.2.0.32 scikit-surgerycore>=0.1.7 scikit-surgeryutils>=1.2.0 -scikit-surgeryarucotracker>= 0.2.7 \ No newline at end of file +scikit-surgeryarucotracker>= 0.2.7 diff --git a/sksurgerytutorial01/vtk_aruco_app.py b/sksurgerytutorial01/vtk_aruco_app.py index ddd3cbe..6c90c06 100644 --- a/sksurgerytutorial01/vtk_aruco_app.py +++ b/sksurgerytutorial01/vtk_aruco_app.py @@ -1,12 +1,15 @@ -# coding=utf-8 +""" +Script to create a viewer window with a movable surface +model overlaid in a live video feed -"""Script to create a viewer window with a movable surface -model overlaid in a live video feed""" +USAGE: +python vtk_aruco_app.py +""" import sys #add an import for numpy, to manipulate arrays import numpy -from PySide2.QtWidgets import QApplication +from PySide6.QtWidgets import QApplication from sksurgeryutils.common_overlay_apps import OverlayBaseWidget from sksurgerycore.transforms.transform_manager import TransformManager from sksurgeryarucotracker.arucotracker import ArUcoTracker @@ -60,6 +63,8 @@ def update_view(self): #see what happens. self.vtk_overlay_window.set_camera_state({"ClippingRange": [10, 800]}) self.vtk_overlay_window.set_video_image(image) + self.vtk_overlay_window.Initialize() # Allows the interactor to initialize itself. + self.vtk_overlay_window.Start() # Start the event loop. self.vtk_overlay_window.Render() def _aruco_detect_and_follow(self, image): @@ -104,4 +109,4 @@ def _move_camera(self, tag2camera): viewer.show() viewer.start() - sys.exit(app.exec_()) + sys.exit(app.exec()) diff --git a/sksurgerytutorial01/vtkoverlay_app.py b/sksurgerytutorial01/vtkoverlay_app.py index 7deb70f..785d48c 100644 --- a/sksurgerytutorial01/vtkoverlay_app.py +++ b/sksurgerytutorial01/vtkoverlay_app.py @@ -1,10 +1,13 @@ -# coding=utf-8 +""" +Script to create a viewer window with a static surface +model overlaid in a live video feed -"""Script to create a viewer window with a static surface -model overlaid in a live video feed""" +USAGE: +python vtkoverlay_app.py +""" import sys -from PySide2.QtWidgets import QApplication +from PySide6.QtWidgets import QApplication from sksurgeryutils.common_overlay_apps import OverlayBaseWidget #create an OverlayApp class, that inherits from OverlayBaseApp @@ -16,6 +19,8 @@ def update_view(self): and render""" _, image = self.video_source.read() self.vtk_overlay_window.set_video_image(image) + self.vtk_overlay_window.Initialize() # Allows the interactor to initialize itself. + self.vtk_overlay_window.Start() # Start the event loop. self.vtk_overlay_window.Render() #the following line prevents the code below from running unless @@ -43,4 +48,4 @@ def update_view(self): viewer.start() #start the application - sys.exit(app.exec_()) + sys.exit(app.exec()) diff --git a/sksurgerytutorial01/vtkoverlay_with_movement_app.py b/sksurgerytutorial01/vtkoverlay_with_movement_app.py index 1e611fa..562769d 100644 --- a/sksurgerytutorial01/vtkoverlay_with_movement_app.py +++ b/sksurgerytutorial01/vtkoverlay_with_movement_app.py @@ -1,10 +1,13 @@ -# coding=utf-8 +""" +Script to create a viewer window with a moving surface +model overlaid in a live video feed -"""Script to create a viewer window with a moving surface -model overlaid in a live video feed""" +USAGE: +python vtkoverlay_with_movement_app.py +""" import sys -from PySide2.QtWidgets import QApplication +from PySide6.QtWidgets import QApplication from sksurgeryutils.common_overlay_apps import OverlayBaseWidget class OverlayApp(OverlayBaseWidget): @@ -20,6 +23,8 @@ def update_view(self): self._move_model() self.vtk_overlay_window.set_video_image(image) + self.vtk_overlay_window.Initialize() # Allows the interactor to initialize itself. + self.vtk_overlay_window.Start() # Start the event loop. self.vtk_overlay_window.Render() def _move_model(self): @@ -48,4 +53,4 @@ def _move_model(self): viewer.show() viewer.start() - sys.exit(app.exec_()) + sys.exit(app.exec()) diff --git a/tests/conftest.py b/tests/conftest.py index e87f0d5..316a666 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- import pytest -from PySide2.QtWidgets import QApplication +from PySide6.QtWidgets import QApplication @pytest.fixture(scope="session") def setup_qt(): """ Create the QT application. """ app = QApplication([]) - return app \ No newline at end of file + return app diff --git a/tests/test_sksurgerytorial01.py b/tests/test_sksurgerytorial01.py index 0c841b5..78b8274 100644 --- a/tests/test_sksurgerytorial01.py +++ b/tests/test_sksurgerytorial01.py @@ -1,6 +1,9 @@ -# coding=utf-8 +""" +sksurgerytutorial01 vtkoverlay tests -"""sksurgerytutorial01 vtkoverlay tests""" +USAGE: +python -m pytest -v -s tests +""" import pytest From 96e9fc2c7e1a77550a88d8dd99d1909f25e0eef9 Mon Sep 17 00:00:00 2001 From: Stephen Thompson Date: Thu, 25 Jul 2024 08:44:44 +0100 Subject: [PATCH 2/8] Removed pip-compile from ci --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1b1c8c..9c6ffe5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,6 @@ jobs: run: | python -m pip install --upgrade pip pip install pip-tools - pip-compile requirements.txt pip install -r requirements-dev.txt - name: Run tests using xvfb (Ubuntu) From 8f74fdafb20bda6236928dd430e7488c26afd1d1 Mon Sep 17 00:00:00 2001 From: Stephen Thompson Date: Thu, 25 Jul 2024 09:04:04 +0100 Subject: [PATCH 3/8] Updates to tests (lint, coverage, ci) #37 --- .coveragerc | 4 +-- .github/workflows/ci.yml | 4 +-- tests/pylintrc | 74 +++------------------------------------- 3 files changed, 9 insertions(+), 73 deletions(-) diff --git a/.coveragerc b/.coveragerc index 09d324b..fbc3618 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,4 @@ [run] omit = - ./snappytutorial01/_version.py - ./snappytutorial01/__init__.py + ./sksurgerytutorial01/_version.py + ./sksurgerytutorial01/__init__.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c6ffe5..027dec3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, windows-latest] python-ver: [3.7, 3.8] experimental: [false] exclude: @@ -64,7 +64,7 @@ jobs: - name: Run tests using xvfb (Ubuntu) if: startsWith(matrix.os, 'ubuntu') run: | - sudo apt-get install xvfb libxkbcommon-x11-0 + sudo apt-get install xvfb libxkbcommon-x11-0 libgl1 sudo Xvfb :1 -screen 0 1024x768x24 ?$ # else. single-line-if-stmt=y -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Maximum number of lines in a module max-module-lines=1000 @@ -278,7 +214,7 @@ ignore-mixin-members=yes # (useful for modules/projects where namespaces are manipulated during runtime # and thus existing member attributes cannot be deduced by static analysis. It # supports qualified module names, as well as Unix pattern matching. -ignored-modules=PySide2,cv2,sksurgeryvtk,numpy +ignored-modules= # List of class names for which member attributes should not be checked (useful # for classes with dynamically set attributes). This supports the use of @@ -315,7 +251,7 @@ callbacks=cb_,_cb # List of qualified module names which can have objects that can redefine # builtins. -redefining-builtins-modules=six.moves,future.builtins +redefining-builtins-modules=future.builtins [CLASSES] @@ -405,4 +341,4 @@ analyse-fallback-blocks=no # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception From dfc1a5a6ed2f1cf8612fd0bc1f5e3e3fc0f78d25 Mon Sep 17 00:00:00 2001 From: Stephen Thompson Date: Thu, 25 Jul 2024 09:11:31 +0100 Subject: [PATCH 4/8] Try with freeglut #37 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 027dec3..43444cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: - name: Run tests using xvfb (Ubuntu) if: startsWith(matrix.os, 'ubuntu') run: | - sudo apt-get install xvfb libxkbcommon-x11-0 libgl1 + sudo apt-get install xvfb libxkbcommon-x11-0 libgl1 freeglut3-dev sudo Xvfb :1 -screen 0 1024x768x24 Date: Thu, 25 Jul 2024 09:21:42 +0100 Subject: [PATCH 5/8] Updates for code style #37 --- sksurgerytutorial01/vtk_aruco_app.py | 11 ++++++----- sksurgerytutorial01/vtkoverlay_app.py | 11 ++++++----- sksurgerytutorial01/vtkoverlay_with_movement_app.py | 11 ++++++----- tests/pylintrc | 3 ++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/sksurgerytutorial01/vtk_aruco_app.py b/sksurgerytutorial01/vtk_aruco_app.py index 6c90c06..84e68b7 100644 --- a/sksurgerytutorial01/vtk_aruco_app.py +++ b/sksurgerytutorial01/vtk_aruco_app.py @@ -63,7 +63,8 @@ def update_view(self): #see what happens. self.vtk_overlay_window.set_camera_state({"ClippingRange": [10, 800]}) self.vtk_overlay_window.set_video_image(image) - self.vtk_overlay_window.Initialize() # Allows the interactor to initialize itself. + # Allows the interactor to initialize itself. + self.vtk_overlay_window.Initialize() self.vtk_overlay_window.Start() # Start the event loop. self.vtk_overlay_window.Render() @@ -100,11 +101,11 @@ def _move_camera(self, tag2camera): if __name__ == '__main__': app = QApplication([]) - video_source = 0 - viewer = OverlayApp(video_source) + VIDEO_SOURCE = 0 + viewer = OverlayApp(VIDEO_SOURCE) - model_dir = '../models' - viewer.add_vtk_models_from_dir(model_dir) + MODEL_DIR = '../models' + viewer.add_vtk_models_from_dir(MODEL_DIR) viewer.show() viewer.start() diff --git a/sksurgerytutorial01/vtkoverlay_app.py b/sksurgerytutorial01/vtkoverlay_app.py index 785d48c..774f573 100644 --- a/sksurgerytutorial01/vtkoverlay_app.py +++ b/sksurgerytutorial01/vtkoverlay_app.py @@ -19,7 +19,8 @@ def update_view(self): and render""" _, image = self.video_source.read() self.vtk_overlay_window.set_video_image(image) - self.vtk_overlay_window.Initialize() # Allows the interactor to initialize itself. + # Allows the interactor to initialize itself. + self.vtk_overlay_window.Initialize() self.vtk_overlay_window.Start() # Start the event loop. self.vtk_overlay_window.Render() @@ -34,14 +35,14 @@ def update_view(self): #is set when we create the instance. This is an index #starting at 0. If you have more than one webcam, you can #try using different numbered sources - video_source = 0 - viewer = OverlayApp(video_source) + VIDEO_SOURCE = 0 + viewer = OverlayApp(VIDEO_SOURCE) #Set a model directory containing the models you wish #to render and optionally a colours.txt defining the #colours to render in. - model_dir = '../models' - viewer.add_vtk_models_from_dir(model_dir) + MODEL_DIR = '../models' + viewer.add_vtk_models_from_dir(MODEL_DIR) #start the viewer viewer.show() diff --git a/sksurgerytutorial01/vtkoverlay_with_movement_app.py b/sksurgerytutorial01/vtkoverlay_with_movement_app.py index 562769d..7b1c8ac 100644 --- a/sksurgerytutorial01/vtkoverlay_with_movement_app.py +++ b/sksurgerytutorial01/vtkoverlay_with_movement_app.py @@ -23,7 +23,8 @@ def update_view(self): self._move_model() self.vtk_overlay_window.set_video_image(image) - self.vtk_overlay_window.Initialize() # Allows the interactor to initialize itself. + # Allows the interactor to initialize itself. + self.vtk_overlay_window.Initialize() self.vtk_overlay_window.Start() # Start the event loop. self.vtk_overlay_window.Render() @@ -44,11 +45,11 @@ def _move_model(self): if __name__ == '__main__': app = QApplication([]) - video_source = 0 - viewer = OverlayApp(video_source) + VIDEO_SOURCE = 0 + viewer = OverlayApp(VIDEO_SOURCE) - model_dir = '../models' - viewer.add_vtk_models_from_dir(model_dir) + MODEL_DIR = '../models' + viewer.add_vtk_models_from_dir(MODEL_DIR) viewer.show() viewer.start() diff --git a/tests/pylintrc b/tests/pylintrc index 9596f1c..a93fb5d 100644 --- a/tests/pylintrc +++ b/tests/pylintrc @@ -32,7 +32,8 @@ unsafe-load-any-extension=no # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code -extension-pkg-whitelist=numpy +extension-pkg-whitelist=numpy, PySide6 +extension-pkg-allow-list=PySide6 [MESSAGES CONTROL] From 89c98fc0a5ba26d7c686eb715b155c871a81ac15 Mon Sep 17 00:00:00 2001 From: Stephen Thompson Date: Thu, 25 Jul 2024 09:28:41 +0100 Subject: [PATCH 6/8] Turn off ubuntu ci #37 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43444cf..935f1e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest] + os: [windows-latest] python-ver: [3.7, 3.8] experimental: [false] exclude: From a1928c1cb7013402575d9b2143fedff8d449d84f Mon Sep 17 00:00:00 2001 From: Stephen Thompson Date: Thu, 25 Jul 2024 09:32:03 +0100 Subject: [PATCH 7/8] put comment back in requirements-dev --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 5cc162c..baa086b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,6 +2,7 @@ # for development. # It is used by pip to manage software dependencies. It is not to be # confused with the software requirements, which are listed in +# doc/requirements.rst -r requirements.txt coverage mock From 6366f3f2ad91682811180f29ceebba42e2e974f0 Mon Sep 17 00:00:00 2001 From: Stephen Thompson Date: Thu, 25 Jul 2024 09:34:49 +0100 Subject: [PATCH 8/8] Update doc/00_Introduction.rst --- doc/00_Introduction.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/00_Introduction.rst b/doc/00_Introduction.rst index 57b4f99..d6468fd 100644 --- a/doc/00_Introduction.rst +++ b/doc/00_Introduction.rst @@ -58,7 +58,6 @@ For the case of conda, please create a VE using the following commands in your t conda create -n sst01VE python=3.8 pip -c conda-forge #try3.7 conda activate sst01VE pip install -r requirements.txt - pip install -r requirements-dev.txt .. _`python.org`: https://www.python.org/downloads/