Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLLayerDMScriptedPipeline.py
Go to the documentation of this file.
1from typing import Any
2
3from slicer import (
4 vtkMRMLAbstractViewNode,
5 vtkMRMLAbstractWidget,
6 vtkMRMLInteractionEventData,
7 vtkMRMLLayerDMPipeline,
8 vtkMRMLLayerDMPipelineManager,
9 vtkMRMLLayerDMScriptedPipelineBridge,
10 vtkMRMLNode,
11 vtkMRMLScene,
12)
13from vtk import vtkCamera, vtkRenderer, vtkObject
14
15
17 """Python base class for all Layer Displayable Manager pipelines."""
18
19 def __init__(self):
20 self.SetPythonObject(self)
21
22 @property
23 def viewNode(self) -> vtkMRMLAbstractViewNode:
24 """Property returning the current view node on which the pipeline is attached."""
25 return self.GetViewNode()
26
27 @property
28 def displayNode(self) -> vtkMRMLNode:
29 """Property returning the current display node for which the pipeline was created."""
30 return self.GetDisplayNode()
31
32 def CanProcessInteractionEvent(self, eventData: vtkMRMLInteractionEventData) -> tuple[bool, float]:
33 """
34 Should return true + distance2 to interaction if the pipeline can process the input event data.
35 :param eventData: The MRML event needing to be processed
36 :return: (bool, distance2) default = False, float_max
37 """
38 import sys
39
40 return False, sys.float_info.max
41
42 def GetCustomCamera(self, renderOrder: int) -> vtkCamera | None:
43 """
44 Custom pipeline camera for the input renderOrder.
45 If the returned value is not None, then the pipeline (or dedicated logic) is expected to handle its own camera
46 for the given input render order.
47 Otherwise, the pipeline will be moved in a renderer with a default camera synchronized on its view default camera.
48
49 :return: None by default
50 """
51 return None
52
53 def GetMouseCursor(self) -> int:
54 """
55 Custom mouse cursor from VTK mouse cursor enum.
56 This value is only used if the pipeline actually processes an event and is ignored otherwise.
57 :return: 0 by default.
58 """
59 return 0
60
61 def GetRenderOrder(self) -> int:
62 """
63 Arbitrary render order number where the pipeline wants to be displayed.
64 Return 0 to be at the default order (main 3D Slicer pipelines)
65 Return larger values to be rendered on top of pipelines with lower render orders.
66
67 See also: vtkMRMLLayerDMLayerManager
68 :return: default = 0
69 """
70 return 0
71
72 def GetRenderOrders(self) -> list[int]:
73 """
74 Arbitrary render orders number where the pipeline wants to be displayed.
75 Allows the pipeline to be displayed in more than one renderer (for instance in the background / foreground).
76 Return larger values to be rendered on top of pipelines with lower render orders.
77
78 :return: default = [self.GetRenderOrder()]
79 """
80 return [self.GetRenderOrder()]
81
82 def GetWidgetState(self) -> int:
83 """
84 Current widget state of the pipeline.
85 :return: default = WidgetStateIdle
86 """
87 return vtkMRMLAbstractWidget.WidgetStateIdle
88
89 def LoseFocus(self, eventData: vtkMRMLInteractionEventData | None) -> None:
90 """
91 Triggered when the pipeline had focus (processed an interaction) and loses the focus (other pipeline
92 handled the new interaction or window leave event).
93 default behavior: does nothing.
94 :param eventData: Optional event data which triggered the lose focus
95 """
96 pass
97
98 def OnDefaultCameraModified(self, camera: vtkCamera) -> None:
99 """
100 Triggered when the default camera is modified.
101 default behavior: does nothing.
102 :param camera: Instance of the default camera
103 """
104 pass
105
106 def OnReferenceToDisplayNodeAdded(self, fromNode: vtkMRMLNode | None, role: str) -> None:
107 """
108 Triggered when a reference to the display node is added
109 default behavior: does nothing.
110
111 See also: self.GetDisplayNode()
112 :param fromNode: Node which added a reference to the display node
113 :param role: Role of the added reference
114 """
115 pass
116
117 def OnReferenceToDisplayNodeRemoved(self, fromNode: vtkMRMLNode | None, role: str) -> None:
118 """
119 Triggered when a reference to the display node is removed
120 default behavior: does nothing.
121
122 See also: self.GetDisplayNode()
123 :param fromNode: Node which removed a reference to the display node
124 :param role: Role of the removed reference
125 """
126 pass
127
128 def OnRendererAdded(self, renderer: vtkRenderer | None) -> None:
129 """
130 Triggered when the pipeline is displayed on a new renderer.
131 default behavior: does nothing.
132 See also: self.GetRenderer()
133 See also: self.UpdateDisplay()
134 See also: self.RequestRender()
135
136 :param renderer: Optional instance of renderer on which the pipeline is added
137 """
138 pass
139
140 def OnRendererRemoved(self, renderer: vtkRenderer) -> None:
141 """
142 Triggered when the pipeline is removed from its previous renderer.
143 default behavior: does nothing.
144 See also: self.GetRenderer()
145
146 :param renderer: Optional instance of renderer from which the pipeline was removed
147 """
148 pass
149
150 def OnUpdate(self, obj: vtkObject, eventId: int, callData: Any | None) -> None:
151 """
152 Observer update callback.
153 Triggered when any object & events observed using UpdateObservation is triggered.
154
155 :param obj: vtkObject instance which triggered the callback
156 :param eventId: Event id which triggered the callback
157 :param callData: Optional observer call data. Use self.CastCallData(callData, vtkType) to convert to Python
158 """
159 pass
160
161 def ProcessInteractionEvent(self, eventData: vtkMRMLInteractionEventData) -> bool:
162 """
163 Triggered when the pipeline can process the interaction and is at the top of the priority list.
164 default behavior: does nothing and returns false.
165
166 :param eventData: The MRML event needing to be processed
167 :return: True if event was processed. False otherwise (default = false)
168 """
169 return False
170
171 def SetDisplayNode(self, displayNode: vtkMRMLNode) -> None:
172 """
173 Called when the display node of the pipeline has changed (initialization).
174 default behavior: Stored and display node is observed for vtkCommand::ModifiedEvent.
175 See also: self.UpdateObservation(prevObj, newObj, eventIds)
176 See also: self.OnUpdate(obj, eventId, callData)
177
178 :param displayNode: The new instance of display node for the pipeline
179 """
181
182 def SetPipelineManager(self, pipelineManager: vtkMRMLLayerDMPipelineManager) -> None:
183 """
184 Set the pipeline manager (initialization).
185 default behavior: Stores the pipeline manager to delegate request render calls (no active observer).
186
187 See also: self.GetPipelineManager()
188 See also: self.GetNodePipeline(node)
189 :param pipelineManager: The instance of pipeline manager managing the current pipeline
190 """
191 vtkMRMLLayerDMPipeline.SetPipelineManager(self, pipelineManager)
192
193 def SetScene(self, scene: vtkMRMLScene) -> None:
194 """
195 Set the pipeline scene (initialization).
196 default behavior: Stores the scene for access (no active observer).
197 """
199
200 def SetViewNode(self, viewNode: vtkMRMLAbstractViewNode) -> None:
201 """
202 Set the pipeline view node (initialization).
203 default behavior: Stored and view node is observed for vtkCommand::ModifiedEvent.
204 :param viewNode: The instance of viewNode the pipeline is attached to
205 """
207
208 def UpdateFromMRML(self) -> None:
209 """
210 Triggered by self.UpdateDisplay() calls
211 Override to update the representation of the pipeline in the different views.
212
213 See also: self.RequestRender()
214 default behavior: does nothing.
215 """
216 pass
tuple[bool, float] CanProcessInteractionEvent(self, vtkMRMLInteractionEventData eventData)
None SetPipelineManager(self, vtkMRMLLayerDMPipelineManager pipelineManager)
None OnUpdate(self, vtkObject obj, int eventId, Any|None callData)
vtkMRMLAbstractViewNode * GetViewNode() const
Returns the current view node.
virtual vtkCamera * GetCustomCamera() const
virtual void SetViewNode(vtkMRMLAbstractViewNode *viewNode)
virtual void SetScene(vtkMRMLScene *scene)
vtkMRMLNode * GetDisplayNode() const
Returns the current display node.
virtual void SetPipelineManager(vtkMRMLLayerDMPipelineManager *pipelineManager)
virtual void SetDisplayNode(vtkMRMLNode *displayNode)
Python bridge for vtkMRMLLayerDMPipeline. Delegates calls to the pipeline to its underlying python ob...
unsigned int GetRenderOrder() const override
int GetWidgetState() const override
void SetPythonObject(PyObject *object)
std::vector< unsigned int > GetRenderOrders() const override
int GetMouseCursor() const override