-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
22 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Add Text to VTKOverlayWindow | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Classes are provided that can add persistent text to a VTKOverlayWindow as: | ||
|
||
* Corner annotations | ||
* Large centered text | ||
* Generic text anywhere in the window | ||
|
||
.. image:: text_overlay.png | ||
|
||
First, we need to import relevant modules, setup a Qt Application, and create a VTKOverlayWindow. | ||
|
||
.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py | ||
:language: python | ||
:start-after: #Tutorial-start | ||
:end-before: #Tutorial-section1 | ||
|
||
We can now create a corner annotations: | ||
|
||
.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py | ||
:language: python | ||
:start-after: #Tutorial-section1 | ||
:end-before: #Tutorial-section2 | ||
|
||
centred text: | ||
|
||
.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py | ||
:language: python | ||
:start-after: #Tutorial-section2 | ||
:end-before: #Tutorial-section3 | ||
|
||
and place some text at given co-ordinates in the window: | ||
|
||
.. literalinclude:: ../../tests/tutorials/test_text_overlay_tutorial.py | ||
:language: python | ||
:start-after: #Tutorial-section3 | ||
:end-before: #Tutorial-end | ||
|
||
`layer=2` is typically used for text overlay (layer 0 is the background image and layer 1 is used for VTK models). | ||
Finally, we execute the Qt app to show the window: | ||
|
||
.. code-block:: python | ||
overlay_window.show() | ||
sys.exit(app.exec_()) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
#Tutorial-start | ||
import sys | ||
import cv2 | ||
from PySide2 import QtWidgets | ||
from sksurgeryvtk.widgets import vtk_overlay_window | ||
from sksurgeryvtk.text import text_overlay | ||
|
||
def test_text(): | ||
app = QtWidgets.QApplication([]) | ||
|
||
background = cv2.imread('tests/data/rendering/background-960-x-540.png') | ||
overlay_window = vtk_overlay_window.VTKOverlayWindow() | ||
overlay_window.set_video_image(background) | ||
|
||
corner_annotation = text_overlay.VTKCornerAnnotation() | ||
corner_annotation.set_text(["1", "2", "3", "4"]) | ||
overlay_window.add_vtk_actor(corner_annotation.text_actor, layer=2) | ||
|
||
large_text = text_overlay.VTKLargeTextCentreOfScreen("Central Text") | ||
large_text.set_colour(1.0, 0.0, 0.0) | ||
large_text.set_parent_window(overlay_window) | ||
overlay_window.add_vtk_actor(large_text.text_actor, layer=2) | ||
|
||
more_text = text_overlay.VTKText("More text", x=50, y=100) | ||
more_text.set_colour(0.0, 1.0, 0.0) | ||
overlay_window.add_vtk_actor(more_text.text_actor, layer=2) | ||
|
||
overlay_window.show() | ||
#sys.exit(app.exec_()) | ||
app = QtWidgets.QApplication([]) | ||
|
||
background = cv2.imread('tests/data/rendering/background-960-x-540.png') | ||
overlay_window = vtk_overlay_window.VTKOverlayWindow() | ||
overlay_window.set_video_image(background) | ||
#Tutorial-section1 | ||
corner_annotation = text_overlay.VTKCornerAnnotation() | ||
corner_annotation.set_text(["1", "2", "3", "4"]) | ||
overlay_window.add_vtk_actor(corner_annotation.text_actor, layer=2) | ||
#Tutorial-section2 | ||
arge_text = text_overlay.VTKLargeTextCentreOfScreen("Central Text") | ||
large_text.set_colour(1.0, 0.0, 0.0) | ||
large_text.set_parent_window(overlay_window) | ||
overlay_window.add_vtk_actor(large_text.text_actor, layer=2) | ||
#Tutorial-section3 | ||
more_text = text_overlay.VTKText("More text", x=50, y=100) | ||
more_text.set_colour(0.0, 1.0, 0.0) | ||
overlay_window.add_vtk_actor(more_text.text_actor, layer=2) | ||
#Tutorial-end | ||
|
||
overlay_window.show() | ||
|
||
#sys.exit(app.exec_()) | ||
|
||
|