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

37 - Resolving QWidget issues #38

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[run]
omit =
./snappytutorial01/_version.py
./snappytutorial01/__init__.py
./sksurgerytutorial01/_version.py
./sksurgerytutorial01/__init__.py
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [windows-latest]
python-ver: [3.7, 3.8]
experimental: [false]
exclude:
Expand Down Expand Up @@ -59,13 +59,12 @@ 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)
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install xvfb libxkbcommon-x11-0
sudo apt-get install xvfb libxkbcommon-x11-0 libgl1 freeglut3-dev
sudo Xvfb :1 -screen 0 1024x768x24 </dev/null &
export DISPLAY=":1"
export LD_LIBRARY_PATH=$pythonLocation"/lib/python3.6/site-packages/PySide2/Qt/plugins/platfoms"
Expand Down
64 changes: 13 additions & 51 deletions doc/00_Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
thompson318 marked this conversation as resolved.
Show resolved Hide resolved


.. _`python.org`: https://www.python.org/downloads/
.. _`SmartLiver`: https://link.springer.com/article/10.1007/s11548-018-1761-3
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
scikit-surgeryarucotracker>= 0.2.7
24 changes: 15 additions & 9 deletions sksurgerytutorial01/vtk_aruco_app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -60,6 +63,9 @@ 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)
# 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()

def _aruco_detect_and_follow(self, image):
Expand Down Expand Up @@ -95,13 +101,13 @@ 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()

sys.exit(app.exec_())
sys.exit(app.exec())
24 changes: 15 additions & 9 deletions sksurgerytutorial01/vtkoverlay_app.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,6 +19,9 @@ def update_view(self):
and render"""
_, image = self.video_source.read()
self.vtk_overlay_window.set_video_image(image)
# 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()

#the following line prevents the code below from running unless
Expand All @@ -29,18 +35,18 @@ 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()
viewer.start()

#start the application
sys.exit(app.exec_())
sys.exit(app.exec())
24 changes: 15 additions & 9 deletions sksurgerytutorial01/vtkoverlay_with_movement_app.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -20,6 +23,9 @@ def update_view(self):
self._move_model()

self.vtk_overlay_window.set_video_image(image)
# 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()

def _move_model(self):
Expand All @@ -39,13 +45,13 @@ 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()

sys.exit(app.exec_())
sys.exit(app.exec())
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
return app
Loading
Loading