Closed thompson318 closed 1 year ago
Matt found these examples. Check whether they are relevant. https://kitware.github.io/vtk-examples/site/Python/Picking/HighlightWithSilhouette/ https://kitware.github.io/vtk-examples/site/Cxx/PolyData/Silhouette/
Stating this one by creating conda env to run https://scikit-surgeryvtk.readthedocs.io/en/latest/tutorials/overlay_window.html
## 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-surgeryvtkVE
channels:
- defaults
- conda-forge #vtk; tox;
- anaconda #coverage; scipy; pyserial
#- fastai #opencv-python-headless
dependencies:
- python=3.7
#- cookiecutter>=1.7.3
- numpy>=1.11
- vtk=8.1.2
# - six>=1.10
# - scipy>=1.7.3
- tox>=3.26.0
- pytest>=7.1.2
- pylint>=2.14.5
- pyserial
- jupyter
- pip>=22.2.2
- pip:
#- scikit-surgeryvtk>=1.0.6
- scikit-surgeryutils>=1.2.0
- scikit-surgerycore>=0.1.7
- scikit-surgeryimage>=0.10.1
# - ndicapi>=3.2.6
- PySide2<5.15.0
- opencv-contrib-python-headless>=4.2.0.32
import sksurgeryutils.common_overlay_apps as coa
and updating the above conda env.The kernel appears to have died. It will restart automatically.
and trying latest numpy versions but got the same error so get back to numpy>=1.11Cannot mix incompatible Qt library (version 0x50c09) with this library (version 0x50e02) Aborted (core dumped)
when running this py script:
import sksurgeryutils.common_overlay_apps as coa
from PySide2 import QtWidgets, QtCore
app = QtCore.QCoreApplication.instance() if app is None: app = QtWidgets.QApplication([])
camera_source = 0 wind = coa.OverlayOnVideoFeed(camera_source) wind.add_vtk_models_from_dir('../../tests/data/models/Liver') wind.start()
app.exec_()
Maybe try sorting https://github.com/SciKit-Surgery/scikit-surgerycalibration/issues/46 first, that might make it easier to install utils.
This seems to work for me OK, so I think we can do this quite easily, just need to tidy it up.
`from PySide6.QtWidgets import QApplication, QWidget, QMainWindow from sksurgeryvtk.widgets.vtk_overlay_window import VTKOverlayWindow from sksurgeryvtk.models.vtk_surface_model import VTKSurfaceModel
from vtkmodules.vtkFiltersHybrid import vtkPolyDataSilhouette from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, )
from vtkmodules.vtkCommonColor import vtkNamedColors
app = QApplication(['Is it working?']) window = QMainWindow() widget = QWidget() vtk_overlay = VTKOverlayWindow(offscreen=False) model=VTKSurfaceModel("weiss.stl", colour=[0.,0.384,0.490]) vtk_overlay.add_vtk_models([model])
window.setCentralWidget(vtk_overlay)
window.show()
colors = vtkNamedColors()
silhouette = vtkPolyDataSilhouette()
silhouette.SetEnableFeatureAngle(False) silhouette.SetCamera(vtk_overlay.foreground_renderer.GetActiveCamera()) allActors=vtk_overlay.foreground_renderer.GetActors() firstactor=allActors.GetLastActor() silhouette.SetInputData(firstactor.GetMapper().GetInput())
silhouetteMapper = vtkPolyDataMapper() silhouetteMapper.SetInputConnection(silhouette.GetOutputPort())
silhouetteActor = vtkActor() silhouetteActor.SetMapper(silhouetteMapper) silhouetteActor.GetProperty().SetColor(colors.GetColor3d("Tomato")) silhouetteActor.GetProperty().SetLineWidth(5) vtk_overlay.foreground_renderer.AddActor(silhouetteActor)
firstactor.GetProperty().SetOpacity(0.0) vtk_overlay.Initialize() vtk_overlay.Start()
try: app.exec() except AttributeError: app.exec_()
print("Finalizing") `
The outline rendering bit is done, so closing this issue. Follow on issues #193 and #194 raised.
What would it take to implement outline rendering, i.e. we only show the 2D outline of a given model like we used to be able to do using the Visualisation Library with NifTK. I can't find any easy way of doing this with VTK. We could go vtk window to image, contour image with OpenCV, then display image. Any other ideas @tdowrick @MattClarkson ?