-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVtkViewer.py
82 lines (64 loc) · 2.48 KB
/
VtkViewer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# ignore pylint
# pylint: disable-msg=E0611,E0602
import numpy as np
from VtkBase import VtkBase
from vtk import *
import vtk.qt
vtk.qt.QVTKRWIBase = "QGLWidget"
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
SLICE_ORIENTATION_YZ = vtk.vtkResliceImageViewer.SLICE_ORIENTATION_YZ
SLICE_ORIENTATION_XZ = vtk.vtkResliceImageViewer.SLICE_ORIENTATION_XZ
SLICE_ORIENTATION_XY = vtk.vtkResliceImageViewer.SLICE_ORIENTATION_XY
class VtkViewer(QVTKRenderWindowInteractor):
# Constructor
def __init__(self, label:str, vtkBaseClass:VtkBase):
super(VtkViewer, self).__init__()
# Properties
self.label = label
self.vtkBaseClass = vtkBaseClass
# Vtk Stuff
## Reader
self.imageReader = self.vtkBaseClass.imageReader
## Image Shift Scale
self.imageShiftScale = self.vtkBaseClass.imageShiftScale
## Image Window Level
self.imageWindowLevel = self.vtkBaseClass.imageWindowLevel
## Image Blend
self.imageBlend = self.vtkBaseClass.imageBlend
## Renderer
self.renderer = vtkRenderer()
## Render Window
self.renderWindow = self.GetRenderWindow()
self.renderWindow.SetMultiSamples(0)
self.renderWindow.AddRenderer(self.renderer)
## Interactor
self.renderWindowInteractor = self.renderWindow.GetInteractor()
## Label Text Actor
self.labelTextActor = vtkTextActor()
s = f"{self.label}"
self.labelTextActor.SetInput(s)
self.labelTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
self.labelTextActor.GetPositionCoordinate().SetValue(0.7, 0.87)
self.renderer.AddActor2D(self.labelTextActor)
# Render
self.render()
# Destructor
def closeEvent(self, QCloseEvent):
super().closeEvent(QCloseEvent)
self.renderer.FastDelete()
self.Finalize()
# Connect on data
def connect_on_data(self, path:str):
if path == "":
return
def update(self):
self.imageReader.UpdateWholeExtent()
self.imageShiftScale.UpdateWholeExtent()
self.imageWindowLevel.UpdateWholeExtent()
self.imageBlend.UpdateWholeExtent()
self.GetRenderWindow().Modified()
self.renderer.ResetCamera()
# Render
def render(self):
self.update()
self.GetRenderWindow().Render()