SciKit-Surgery / scikit-surgeryvtk

image fusion or overlay, for augmented reality apps, using VTK and OpenCV for a calibrated overlay.
https://scikit-surgeryvtk.readthedocs.io/en/latest/
Other
21 stars 5 forks source link

Can we implement outline rendering #177

Closed thompson318 closed 1 year ago

thompson318 commented 2 years ago

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 ?

thompson318 commented 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/

mxochicale commented 1 year ago

Stating this one by creating conda env to run https://scikit-surgeryvtk.readthedocs.io/en/latest/tutorials/overlay_window.html

conda env

## 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

errors

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_()

thompson318 commented 1 year ago

Maybe try sorting https://github.com/SciKit-Surgery/scikit-surgerycalibration/issues/46 first, that might make it easier to install utils.

thompson318 commented 1 year ago

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)

vtk_overlay.setParent(app)

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()

widget.show()

try: app.exec() except AttributeError: app.exec_()

print("Finalizing") `

thompson318 commented 1 year ago

The outline rendering bit is done, so closing this issue. Follow on issues #193 and #194 raised.