Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
ModelGlowDM.ModelGlowDMPipeline Class Reference
Inheritance diagram for ModelGlowDM.ModelGlowDMPipeline:
Collaboration diagram for ModelGlowDM.ModelGlowDMPipeline:

Public Member Functions

 __init__ (self)
 
tuple[bool, float] CanProcessInteractionEvent (self, vtkMRMLInteractionEventData eventData)
 
 CreateGlowNode (cls, vtkMRMLModelNode modelNode, vtkMRMLScene scene)
 
int GetRenderOrder (self)
 
None LoseFocus (self, vtkMRMLInteractionEventData|None eventData)
 
None OnRendererAdded (self, vtkRenderer renderer)
 
None OnRendererRemoved (self, vtkRenderer renderer)
 
 OnUpdate (self, obj, eventId, callData)
 
bool ProcessInteractionEvent (self, vtkMRMLInteractionEventData eventData)
 
 RemoveGlowNode (cls, vtkMRMLModelNode modelNode, vtkMRMLScene scene)
 
 SetDisplayNode (self, node)
 
 UpdateFromMRML (self)
 
- Public Member Functions inherited from ModelGlowDM._Pipeline
 IsPipelineNode (cls, node)
 
vtkMRMLLayerDMScriptedPipeline|None TryCreatePipeline (cls, vtkMRMLAbstractViewNode viewNode, vtkMRMLNode node)
 

Protected Member Functions

vtkMRMLModelNode|None _GetModelNode (self)
 
 _GetModelNodeID (cls, node)
 
bool _IsModelVisible (self)
 
 _ObserveModelNode (self)
 
 _ObserveModelTransformNode (self)
 
 _TransformPolyData (self, polyData)
 
 _UpdateActorVisibility (self)
 
 _UpdateMapperConnection (self)
 
- Protected Member Functions inherited from ModelGlowDM._Pipeline
vtkMRMLScriptedModuleNode _CreatePipelineNode (cls)
 
str _GetClassName (cls)
 

Protected Attributes

 _glowActor = vtkActor()
 
 _glowMapper = vtkPolyDataMapper()
 
vtkMRMLModelNode|None _modelNode = None
 
 _modelTransform = None
 
 _polyData = None
 

Detailed Description

The ModelGlowDMPipeline is responsible for the actual creation of actors (and mappers) that will be rendered
in the glow pass renderer.

In this pipeline, we do three things:
    - Configure the rendering pipeline
    - connect the pipeline reactivity to the scene observers
    - connect the interaction events to make our model glow when the interaction is within the model's bounding box

Creation of the pipeline will be handled by our _Pipeline.TryCreatePipeline base methods and connected to the
factory in the registerPipeline method that we connected to the application load event.

Definition at line 295 of file ModelGlowDM.py.

Constructor & Destructor Documentation

◆ __init__()

ModelGlowDM.ModelGlowDMPipeline.__init__ ( self)
In the pipeline creation, we create the different VTK objects.
Here, the mapper properties are static, but they could be set in the data node and be reactive.

Definition at line 309 of file ModelGlowDM.py.

Member Function Documentation

◆ _GetModelNode()

vtkMRMLModelNode | None ModelGlowDM.ModelGlowDMPipeline._GetModelNode ( self)
protected
Convenience method to get the model node associated with the pipeline's data node.

Here, we use the following APIs:
    - GetScene: This will return the scene on which the pipeline is attached
    - GetDisplayNode: This will return the pipeline's data node instance

Definition at line 557 of file ModelGlowDM.py.

◆ _GetModelNodeID()

ModelGlowDM.ModelGlowDMPipeline._GetModelNodeID ( cls,
node )
protected
Convenience method to get the model node ID attached to the input MRML node.

Definition at line 609 of file ModelGlowDM.py.

◆ _IsModelVisible()

bool ModelGlowDM.ModelGlowDMPipeline._IsModelVisible ( self)
protected
Convenience method to check if the pipeline's model node is visible.

Definition at line 550 of file ModelGlowDM.py.

◆ _ObserveModelNode()

ModelGlowDM.ModelGlowDMPipeline._ObserveModelNode ( self)
protected
Convenience method to update the model and the model's transform node observers.

Here, we use the UpdateObservation method:
    - UpdateObservation(vtkObject* prevObj, vtkObject* obj, const std::vector<unsigned long>& events) -> bool
    - UpdateObservation(vtkObject* prevObj, vtkObject* obj, unsigned long event = vtkCommand::ModifiedEvent) -> bool

This method should be used to add an observer on VTK object.
By default, the object's modified event will be observed.
The method also supports lists of events.

On modify event, the class's self.OnUpdate method will be called.

Warning: prevObj is not mutated by this call. To update the pointer, a manual set is required after update.

See also: self.OnUpdate

Definition at line 567 of file ModelGlowDM.py.

◆ _ObserveModelTransformNode()

ModelGlowDM.ModelGlowDMPipeline._ObserveModelTransformNode ( self)
protected
Convenience method to update the model's transform node observer.

Note: Here we explicitly observe the transform modified event as modifying the transform doesn't trigger
its modified event.

See also: self._ObserveModelNode

Definition at line 592 of file ModelGlowDM.py.

◆ _TransformPolyData()

ModelGlowDM.ModelGlowDMPipeline._TransformPolyData ( self,
polyData )
protected
Convenience method to update the transformed displayed polydata based on the current transform node.

Definition at line 496 of file ModelGlowDM.py.

◆ _UpdateActorVisibility()

ModelGlowDM.ModelGlowDMPipeline._UpdateActorVisibility ( self)
protected
Convenience method to update the actor based on the model's visibility and the selection.

Definition at line 509 of file ModelGlowDM.py.

◆ _UpdateMapperConnection()

ModelGlowDM.ModelGlowDMPipeline._UpdateMapperConnection ( self)
protected
Convenience method to update the mapper connection.
Note: We apply the polydata transform manually here, but we could configure a transform pipeline and use
    the model's polydata connection instead for a cleaner VTK implementation.

Definition at line 486 of file ModelGlowDM.py.

◆ CanProcessInteractionEvent()

tuple[bool, float] ModelGlowDM.ModelGlowDMPipeline.CanProcessInteractionEvent ( self,
vtkMRMLInteractionEventData eventData )
Should return true + distance2 to interaction if the pipeline can process the input event data.
:param eventData: The MRML event needing to be processed
:return: (bool, distance2) default = False, float_max

Here, we check if the event interaction is within the glow pass actor bounds and return the distance to it.

To avoid blocking camera interaction, we will also process mouse move events.
Of course we could also check for left click to go further with this widget.

Note: This is not an efficient way to check for interactions. A better way would be to delegate to the model
    display node for picking events.

Definition at line 424 of file ModelGlowDM.py.

◆ CreateGlowNode()

ModelGlowDM.ModelGlowDMPipeline.CreateGlowNode ( cls,
vtkMRMLModelNode modelNode,
vtkMRMLScene scene )
Convenience static method to create and add a new glow data node pointing to a model node and add it to the
scene.

Note: Here, we could add our new data node as a reference node for the modelNode instead of keeping each
    separate. This would allow to iterate over the modelNode's references and find it instead of having
    to iterate on the scene.

Definition at line 517 of file ModelGlowDM.py.

◆ GetRenderOrder()

int ModelGlowDM.ModelGlowDMPipeline.GetRenderOrder ( self)
Arbitrary render order number where the pipeline wants to be displayed.
Here, we use the glow pass's render order to be in the same renderer (although we don't know which it will be)

Definition at line 368 of file ModelGlowDM.py.

◆ LoseFocus()

None ModelGlowDM.ModelGlowDMPipeline.LoseFocus ( self,
vtkMRMLInteractionEventData | None eventData )
Triggered when the pipeline had focus (processed an interaction) and loses the focus (other pipeline
handled the new interaction or window leave event).
default behavior: does nothing.
:param eventData: Optional event data which triggered the lose focus

Here, the pipeline lost the previous interaction.
We make sure to restore the selection state.

Definition at line 471 of file ModelGlowDM.py.

◆ OnRendererAdded()

None ModelGlowDM.ModelGlowDMPipeline.OnRendererAdded ( self,
vtkRenderer renderer )
Triggered when the pipeline is displayed on a new renderer.
default behavior: does nothing.

Here, we add our actor to the input renderer.
If the pipeline renderer has changed, the pipeline's UpdateDisplay method will be triggered and in turn its
UpdateFromMRML method will be triggered.

Since we don't control the actual renderer used by the pipeline, this should be used systematically.
See also: self.GetRenderer()

Definition at line 334 of file ModelGlowDM.py.

◆ OnRendererRemoved()

None ModelGlowDM.ModelGlowDMPipeline.OnRendererRemoved ( self,
vtkRenderer renderer )
Triggered when the pipeline is removed from its previous renderer.
default behavior: does nothing.

Here, we add our actor to the input renderer.
If the pipeline renderer has changed, the pipeline's UpdateDisplay method will be triggered and in turn its
UpdateFromMRML method will be triggered.

Since we don't control the actual renderer used by the pipeline, this should be used systematically.
See also: self.GetRenderer()

Definition at line 351 of file ModelGlowDM.py.

◆ OnUpdate()

ModelGlowDM.ModelGlowDMPipeline.OnUpdate ( self,
obj,
eventId,
callData )
Observer update callback.
Triggered when any object & events observed using UpdateObservation is triggered.

:param obj: vtkObject instance which triggered the callback
:param eventId: Event id which triggered the callback
:param callData: Optional observer call data. Use self.CastCallData(callData, vtkType) to convert to Python

Here, we want to update our model transform node observer if it has changed and trigger the pipeline's display
when either the view has changed (observed by default), the data node has changed (observed by default), or
our modelNode / transform nodes have changed (manually observed).

Definition at line 393 of file ModelGlowDM.py.

◆ ProcessInteractionEvent()

bool ModelGlowDM.ModelGlowDMPipeline.ProcessInteractionEvent ( self,
vtkMRMLInteractionEventData eventData )
Triggered when the pipeline can process the interaction and is at the top of the priority list.
default behavior: does nothing and returns false.

:param eventData: The MRML event needing to be processed
:return: True if event was processed. False otherwise (default = false)

Here, the pipeline is the closest to the interaction. We modify our display property which will trigger the
rendering update.

Definition at line 454 of file ModelGlowDM.py.

◆ RemoveGlowNode()

ModelGlowDM.ModelGlowDMPipeline.RemoveGlowNode ( cls,
vtkMRMLModelNode modelNode,
vtkMRMLScene scene )
Convenience static method to remove a glow node set on a given modelNode.
See also: CreateGlowNode

Note: This logic can be simplified if we attach our pipeline to the model node directly.
    We would then iterate over node references to check if we have our pipeline node.

Definition at line 538 of file ModelGlowDM.py.

◆ SetDisplayNode()

ModelGlowDM.ModelGlowDMPipeline.SetDisplayNode ( self,
node )
Set the display node for the pipeline has changed (initialization).
default behavior: Stored and display node is observed for vtkCommand::ModifiedEvent.
See also: self.UpdateObservation(prevObj, newObj, eventIds)
See also: self.OnUpdate(obj, eventId, callData)

:param node: The new instance of display node for the pipeline

Definition at line 412 of file ModelGlowDM.py.

◆ UpdateFromMRML()

ModelGlowDM.ModelGlowDMPipeline.UpdateFromMRML ( self)
Triggered by self.UpdateDisplay() calls:
    - Called automatically at pipeline creation / add to the render window
    - Called automatically when switching renderer
Override to update the representation of the pipeline in the different views.

See also: self.RequestRender()
default behavior: does nothing.

Here, we update the mapper connection to our modelNode PolyData and update the actor visibility to follow
the model's visibility.
Finally we ask for a rendering refresh.

Definition at line 375 of file ModelGlowDM.py.

Member Data Documentation

◆ _glowActor

ModelGlowDM.ModelGlowDMPipeline._glowActor = vtkActor()
protected

Definition at line 318 of file ModelGlowDM.py.

◆ _glowMapper

ModelGlowDM.ModelGlowDMPipeline._glowMapper = vtkPolyDataMapper()
protected

Definition at line 317 of file ModelGlowDM.py.

◆ _modelNode

ModelGlowDM.ModelGlowDMPipeline._modelNode = None
protected

Definition at line 327 of file ModelGlowDM.py.

◆ _modelTransform

ModelGlowDM.ModelGlowDMPipeline._modelTransform = None
protected

Definition at line 328 of file ModelGlowDM.py.

◆ _polyData

ModelGlowDM.ModelGlowDMPipeline._polyData = None
protected

Definition at line 332 of file ModelGlowDM.py.


The documentation for this class was generated from the following file: