core

class trame_slicer.core.DisplayManager(view_manager: ViewManager, volume_rendering: VolumeRendering)

Bases: object

Helper class to display volume nodes in given view group

hide_volume(volume_node: vtkMRMLVolumeNode, view_group: int | None = None)
reset_views(view_group: int | None = None)
set_node_visible_in_group(node: vtkMRMLDisplayableNode, view_group: int | None = None)
show_volume(volume_node: vtkMRMLVolumeNode, view_group: int | None = None, vr_preset: str = '', do_reset_views: bool = False) None
show_volume_in_slice_background(volume_node: vtkMRMLVolumeNode | None, view_group: int | None = None)
show_volume_in_slice_foreground(volume_node: vtkMRMLVolumeNode | None, view_group: int | None = None)
class trame_slicer.core.IOManager(scene: vtkMRMLScene, app_logic: vtkMRMLApplicationLogic, segmentation_editor: SegmentationEditor)

Bases: object

Class responsible for loading files in the scene.

load_model(model_file: str | Path, do_convert_to_slicer_coord: bool = True) vtkMRMLModelNode | None
load_scene(scene_path) bool
load_segmentation(segmentation_file: str | Path, do_convert_to_slicer_coord=True) vtkMRMLSegmentationNode | None
load_volumes(volume_files: str | list[str]) list[vtkMRMLVolumeNode]
save_scene(scene_path: str | Path) bool
classmethod write_model(model_node, model_file: str | Path, do_convert_from_slicer_coord: bool = True) None
classmethod write_node(node, node_file, storage_type: type, do_convert_from_slicer_coord: bool) None
write_scene(scene_path: str | Path) bool
write_segmentation(segmentation_node, segmentation_file: str | Path)
classmethod write_volume(volume_node, volume_file: str | Path) None
class trame_slicer.core.LayoutManager(scene: vtkMRMLScene, view_manager: ViewManager, server: Server, *, virtual_node: VirtualNode | None = None, is_virtual_node_initialized: bool = False)

Bases: object

Class responsible for instantiating views depending on the layout node.
  • Creates a singleton layout node at initialization.

  • Observes layout node changes to notify observers of layout id changes.

  • Can register layouts with their associated descriptions

  • Notifies view manager of requested view on layout change

create_layout_views_if_needed(layout_id: str) None
current_layout_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

classmethod default_grid_configuration() dict[str, Layout]
get_layout(layout_id: str, default_layout: Layout | None = None) Layout
get_layout_ids() list[str]
has_layout(layout_id: str) bool
initialize_layout_grid(layout: AbstractLayout)

Initialize the LayoutGrid placeholder in the layout at the call position.

property layout_id: str | None
register_layout(layout_id: str, layout: Layout, lazy_initialization: bool = False) None

Registers the given layout id to the associated layout. Will overwrite any pre existing layout with this ID. If lazy_initialization is False, the views will not be instantiated unless the passed layout id matches the current selected layout id.

register_layout_dict(layout_dict: dict[str, Layout], lazy_initialization: bool = False) None
Parameters:
  • layout_dict – Layout dictionary to register to the layout manager

  • lazy_initialization – If True, the layout views will not be created until explicitly requested by set_layout or create_layout_views_if_needed

registered_layouts_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

set_layout(layout_id: str) None
set_layout_from_node(node: vtkMRMLScriptedModuleNode) None
class trame_slicer.core.SegmentationEditor(scene: vtkMRMLScene, logic: vtkSlicerSegmentationsModuleLogic, view_manager: ViewManager, *, builtin_effects: list[type[SegmentationEffect]] | None = None)

Bases: SignalContainer

Class responsible for editing the segmentation. Meant to be used by the application to activate / deactivate segmentation effects.

property active_effect: SegmentationEffect | None
property active_effect_name: str
active_effect_name_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

property active_segment_id: str
active_segment_id_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

property active_segment_modifier: SegmentModifier | None
property active_segmentation: Segmentation | None
property active_segmentation_display: SegmentationDisplay | None
property active_segmentation_node
property active_volume_node: vtkMRMLVolumeNode | None
add_empty_segment(*, segment_id='', segment_name='', segment_color: list[float] | None = None, segment_value: int | None = None) str
apply_labelmap(labelmap) None
apply_polydata_world(poly_world) None
builtin_effects: ClassVar[list[type[SegmentationEffect]]] = [<class 'trame_slicer.segmentation.segmentation_effect_draw.SegmentationEffectDraw'>, <class 'trame_slicer.segmentation.segmentation_effect_paint_erase.SegmentationEffectErase'>, <class 'trame_slicer.segmentation.segmentation_effect_islands.SegmentationEffectIslands'>, <class 'trame_slicer.segmentation.segmentation_effect_logical_operators.SegmentationEffectLogicalOperators'>, <class 'trame_slicer.segmentation.segmentation_effect_no_tool.SegmentationEffectNoTool'>, <class 'trame_slicer.segmentation.segmentation_effect_paint_erase.SegmentationEffectPaint'>, <class 'trame_slicer.segmentation.segmentation_effect_scissors.SegmentationEffectScissors'>, <class 'trame_slicer.segmentation.segmentation_effect_smoothing.SegmentationEffectSmoothing'>, <class 'trame_slicer.segmentation.segmentation_effect_threshold.SegmentationEffectThreshold'>, <class 'trame_slicer.segmentation.segmentation_effect_volume_intensity_mask.SegmentationEffectVolumeIntensityMask'>]
clear()
create_empty_segmentation_node() vtkMRMLSegmentationNode
create_modifier_labelmap() vtkImageData | None
create_segmentation_node_from_labelmap(labelmap_node: vtkMRMLLabelMapVolumeNode) vtkMRMLSegmentationNode
create_segmentation_node_from_model_node(model_node: vtkMRMLModelNode) vtkMRMLSegmentationNode
deactivate_effect()
property editor_logic: vtkSlicerSegmentEditorLogic
property editor_node: vtkMRMLSegmentEditorNode
editor_node_modified

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

export_segmentation_to_file(segmentation_node: vtkMRMLSegmentationNode, file_path: str) None
export_segmentation_to_labelmap(segmentation_node: vtkMRMLSegmentationNode, labelmap: vtkMRMLLabelMapVolumeNode = None) vtkMRMLLabelMapVolumeNode
export_segmentation_to_models(segmentation_node: vtkMRMLSegmentationNode, folder_item_id: int) None
export_segmentation_to_stl(segmentation_node: vtkMRMLSegmentationNode, out_folder: str, segment_ids: list[str] | None = None) None
get_active_effect_name() str
get_active_segment_id() str
get_all_segment_properties() dict[str, SegmentProperties]
get_editable_area() SegmentationEditableAreaMode
get_effect(effect_type: type[TEffect]) TEffect | None
get_effect_parameter_node(effect: SegmentationEffect | type[SegmentationEffect]) vtkMRMLScriptedModuleNode

returns segmentation effect parameter node as used by this segment editor. When passing effect types as inputs, this method will ensure the effect has been registered. If the parameter node doesn’t exist in the current scene, the parameter node will be added automatically.

get_mask_segment_id() str
get_nth_segment(i_segment: int) vtkSegment | None
get_nth_segment_id(i_segment: int) str
get_overwrite_mode() SegmentationOverwriteMode
get_segment(segment_id: str) vtkSegment | None
get_segment_ids() list[str]
get_segment_labelmap(segment_id: str, *, as_numpy_array: bool = False) vtkImageData | ndarray[tuple[Any, ...], dtype[_ScalarT]] | None
get_segment_names() list[str]
get_segment_properties(segment_id)
get_segment_visibility(segment_id) bool | None
is_3d_shown()
is_effect_type_registered(effect_type: type[SegmentationEffect]) bool
is_surface_representation_enabled() bool
load_segmentation_from_file(segmentation_file: str) vtkMRMLSegmentationNode | None
property n_segments: int
parameter_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

register_effect_type(effect_type: type[SegmentationEffect]) None

Registers the input segment editor effect type for the segmentation editor.

remove_segment(segment_id)
segmentation_display_modified

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

segmentation_modified

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

set_active_effect(effect: SegmentationEffect | None) SegmentationEffect | None
set_active_effect_name(effect_id: str) SegmentationEffect | None
set_active_effect_type(effect_type: type[SegmentationEffect]) SegmentationEffect | None
set_active_segment_id(segment_id)
set_active_segmentation(segmentation_node: vtkMRMLSegmentationNode, volume_node: vtkMRMLVolumeNode) Segmentation
set_editable_area(editable_area: SegmentationEditableAreaMode) None
set_mask_segment_id(segment_id: str)
set_overwrite_mode(overwrite_mode: SegmentationOverwriteMode) None
set_segment_properties(segment_id, segment_properties: SegmentProperties)
set_segment_visibility(segment_id, visibility: bool) None
set_surface_representation_enabled(is_enabled: bool) None
set_undo_stack(undo_stack: UndoStack)
show_3d(show_3d: bool)
show_3d_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

trigger_all_signals()
property undo_stack: UndoStack | None
class trame_slicer.core.SlicerApp(share_directory: str | None = None)

Bases: object

Container for the core components of a Slicer application. Instantiates the scene, application logic and layout manager. Configures the default nodes present in the scene.

register_module_logic(logic: vtkSlicerModuleLogic, *, logic_name: str = '', share_sub_folder: str = '')

Configure the input module logic with the application scene, logic and share directory. Registers the logic to the application logic with the given input logic name if any, module name otherwise.

Parameters:
  • logic – instance of logic to register

  • logic_name – name of the logic in the application logic

  • share_sub_folder – sub folder of the share directory (if no sub folder, common share directory is used)

Returns:

instance of logic

class trame_slicer.core.ViewManager(scene: vtkMRMLScene, application_logic: vtkMRMLApplicationLogic)

Bases: object

Class responsible for creating views given view descriptions and factories. Create views with the first factory available which can create view spec. Provides access to created views but doesn’t hold strong ownership of the views.

create_view(view: ViewLayoutDefinition) AbstractViewChild | None

Uses the best registered factory to create the view with given id / type. Overwrites view stored if it exists. Returns created view.

filter_visible_views(views: list[AbstractViewChild]) list[AbstractViewChild]

Filter input view list by ones currently displayed in the layout.

get_current_view_ids() list[str]
get_slice_views(view_group: int | None = None) list[SliceView]
get_threed_views(view_group: int | None = None) list[ThreeDView]
get_view(view_id: str | vtkMRMLAbstractViewNode) AbstractViewChild | None

Get view associated with input view ID.

get_views(view_group: int | None = None) list[AbstractView]

Return all Slicer views matching view group in the view manager.

is_view_created(view_id: str) bool

Returns true if view id is created, false otherwise.

register_factory(view_factory: IViewFactory) None

Allows to register a factory for given view type.

remove_view(view_id: str) bool
set_current_view_ids(view_ids: list[str]) None

Set which views are currently displayed in the application. To be used by layout manager or equivalent classes.

class trame_slicer.core.VolumeRendering(slicer_app: SlicerApp)

Bases: SlicerWrapper[vtkSlicerVolumeRenderingLogic]

Simple facade for volume rendering logic.

apply_preset(display: vtkMRMLVolumeRenderingDisplayNode | None, preset_name: str)
static apply_vr_node_property(display: vtkMRMLVolumeRenderingDisplayNode, property_node: vtkMRMLVolumePropertyNode)
create_display_node(volume_node: vtkMRMLVolumeNode, preset_name: str = '') vtkMRMLVolumeRenderingDisplayNode
property crop_logic: vtkSlicerCropVolumeLogic
get_cropping_roi_node(volume_node: vtkMRMLVolumeNode | None) vtkMRMLMarkupsROINode | None

Returns the ROI node instance attached to the input volume node’s VR display node if any.

get_cropping_roi_visiblity(volume_node: vtkMRMLVolumeNode | None) bool

Returns the input volume node’s VR crop ROI node’s visibility. If the input volume node doesn’t have a ROI node, returns False.

get_preset_node(preset_name: str) vtkMRMLVolumePropertyNode | None
get_preset_property(preset_name) VolumeProperty
get_preset_vr_shift_range(preset_name: str) tuple[float, float]
get_volume_node_property(volume_node: vtkMRMLVolumeNode) VolumeProperty
get_vr_display_node(volume_node: vtkMRMLVolumeNode) vtkMRMLVolumeRenderingDisplayNode | None
get_vr_shift_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
has_vr_display_node(volume_node: vtkMRMLVolumeNode) bool
preset_names() list[str]
set_absolute_vr_shift_from_preset(volume_node: ~slicer_core.MRMLCore.vtkMRMLVolumeNode, preset_name: str | None, shift: float, shift_mode: ~trame_slicer.core.volume_property.VRShiftMode = <VRShiftMode.BOTH: 3>) None

Shift the volume rendering opacity and colors by a given value. The shift is a scalar value representing how much the preset should be moved compared to a preset default.

Which

See also:
ref:

set_relative_vr_shift

set_cropping_enabled(volume_node: vtkMRMLVolumeNode, roi_node: vtkMRMLMarkupsROINode | None, is_enabled: bool) vtkMRMLMarkupsROINode | None

Enable or disable the VR cropping for the input volume node. If the volume node doesn’t have a cropping ROI node and is_enabled is True, a new ROI node will be initialized and encompass the full volume node.

The ROI Node attached to the display node will be returned.

set_cropping_roi_node_visibile(volume_node: vtkMRMLVolumeNode | None, is_visible: bool) bool

Sets the inputs volume node’s VR cropping ROI visible. If the input volume node doesn’t have a cropping node, does nothgin.

:return visibility state of the ROI node

set_relative_vr_shift(volume_node: ~slicer_core.MRMLCore.vtkMRMLVolumeNode, shift: float, shift_mode: ~trame_slicer.core.volume_property.VRShiftMode = <VRShiftMode.BOTH: 3>) None

Shift the volume rendering opacity and colors by a given value for the current scalar/opacity values.

See also:
ref:

set_absolute_vr_shift_from_preset

set_volume_node_property(volume_node: vtkMRMLVolumeNode, property_node: vtkMRMLVolumePropertyNode)
set_vr_opacity(volume_node: vtkMRMLVolumeNode, opacity: float, gradient_threshold_hu: float = 0)

Update volume node gradient opacity function applied on RBG value. Copied from: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#show-volume-rendering-making-soft-tissues-transparent

Updates the Volume property node gradient opacity with 0 opacity below a given HU value and the updated slider position opacity value above.

By default, the gradient threshold is set to around water HU value https://www.sciencedirect.com/topics/medicine-and-dentistry/hounsfield-scale

Parameters:
  • volume_node – volume node on which the VR opacity will be applied

  • opacity – Opacity value between [0, 1]. 1 = fully opaque, 0 = fully transparent.

  • gradient_threshold_hu – Cut off for opacity gradient.

toggle_cropping_visibility(volume_node: vtkMRMLVolumeNode | None) bool

Toggle input volume node cropping visibility. Toggling the visibility will activate and initialize the cropping ROI Node if needed.

Returns:

New visibility state of the Cropping ROI Node

class trame_slicer.core.VolumeWindowLevel

Bases: object

Collection of helper functions to update a volume’s window / level

classmethod get_volume_auto_min_max_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
classmethod get_volume_display_node(volume_node: vtkMRMLVolumeNode) vtkMRMLVolumeDisplayNode
classmethod get_volume_display_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
classmethod get_volume_scalar_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
classmethod min_max_to_window_level(min_value: float, max_value: float) tuple[float, float]
classmethod set_volume_node_display_min_max_range(volume_node: vtkMRMLVolumeNode, min_value: float, max_value: float) None
classmethod set_volume_node_window_level(volume_node: vtkMRMLVolumeNode, window: float, level: float) None
classmethod window_level_to_min_max(window: float, level: float) tuple[float, float]
class trame_slicer.core.VolumesReader

Bases: object

Adapted from Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py

classmethod contains_dcm_volume(volume_files: list[str]) bool
dcm_read_lru_cache_size = 5000
classmethod is_dcm_file(file_name: str) bool
classmethod load_dcm_volumes(scene: vtkMRMLScene, volume_files: list[vtkMRMLVolumeNode | None])
classmethod load_single_dcm_volume(scene: vtkMRMLScene, volume_files: list[str]) vtkMRMLVolumeNode | None
classmethod load_single_file_volume(scene: vtkMRMLScene, app_logic: vtkMRMLApplicationLogic, volume_file: str) vtkMRMLVolumeNode | None
classmethod load_volumes(scene: vtkMRMLScene, app_logic: vtkMRMLApplicationLogic, volume_files: list[str] | str) list[vtkMRMLVolumeNode]
classmethod split_volumes(volume_files: list[str]) list[list[str]]
classmethod tag_value_to_vector(value)

trame_slicer.core.display_manager module

class trame_slicer.core.display_manager.DisplayManager(view_manager: ViewManager, volume_rendering: VolumeRendering)

Bases: object

Helper class to display volume nodes in given view group

show_volume(volume_node: vtkMRMLVolumeNode, view_group: int | None = None, vr_preset: str = '', do_reset_views: bool = False) None
hide_volume(volume_node: vtkMRMLVolumeNode, view_group: int | None = None)
reset_views(view_group: int | None = None)
show_volume_in_slice_background(volume_node: vtkMRMLVolumeNode | None, view_group: int | None = None)
show_volume_in_slice_foreground(volume_node: vtkMRMLVolumeNode | None, view_group: int | None = None)
set_node_visible_in_group(node: vtkMRMLDisplayableNode, view_group: int | None = None)

trame_slicer.core.io_manager module

class trame_slicer.core.io_manager.IOManager(scene: vtkMRMLScene, app_logic: vtkMRMLApplicationLogic, segmentation_editor: SegmentationEditor)

Bases: object

Class responsible for loading files in the scene.

load_volumes(volume_files: str | list[str]) list[vtkMRMLVolumeNode]
classmethod write_volume(volume_node, volume_file: str | Path) None
load_model(model_file: str | Path, do_convert_to_slicer_coord: bool = True) vtkMRMLModelNode | None
classmethod write_model(model_node, model_file: str | Path, do_convert_from_slicer_coord: bool = True) None
load_segmentation(segmentation_file: str | Path, do_convert_to_slicer_coord=True) vtkMRMLSegmentationNode | None
write_segmentation(segmentation_node, segmentation_file: str | Path)
classmethod write_node(node, node_file, storage_type: type, do_convert_from_slicer_coord: bool) None
load_scene(scene_path) bool
write_scene(scene_path: str | Path) bool
save_scene(scene_path: str | Path) bool

trame_slicer.core.layout_manager module

class trame_slicer.core.layout_manager.LayoutManager(scene: vtkMRMLScene, view_manager: ViewManager, server: Server, *, virtual_node: VirtualNode | None = None, is_virtual_node_initialized: bool = False)

Bases: object

Class responsible for instantiating views depending on the layout node.
  • Creates a singleton layout node at initialization.

  • Observes layout node changes to notify observers of layout id changes.

  • Can register layouts with their associated descriptions

  • Notifies view manager of requested view on layout change

registered_layouts_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

current_layout_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

property layout_id: str | None
get_layout_ids() list[str]
register_layout(layout_id: str, layout: Layout, lazy_initialization: bool = False) None

Registers the given layout id to the associated layout. Will overwrite any pre existing layout with this ID. If lazy_initialization is False, the views will not be instantiated unless the passed layout id matches the current selected layout id.

set_layout(layout_id: str) None
create_layout_views_if_needed(layout_id: str) None
set_layout_from_node(node: vtkMRMLScriptedModuleNode) None
has_layout(layout_id: str) bool
get_layout(layout_id: str, default_layout: Layout | None = None) Layout
register_layout_dict(layout_dict: dict[str, Layout], lazy_initialization: bool = False) None
Parameters:
  • layout_dict – Layout dictionary to register to the layout manager

  • lazy_initialization – If True, the layout views will not be created until explicitly requested by set_layout or create_layout_views_if_needed

classmethod default_grid_configuration() dict[str, Layout]
initialize_layout_grid(layout: AbstractLayout)

Initialize the LayoutGrid placeholder in the layout at the call position.

trame_slicer.core.markups_logic module

class trame_slicer.core.markups_logic.MarkupsLogic(slicer_app: SlicerApp)

Bases: SlicerWrapper[vtkSlicerMarkupsLogic]

Thin wrapper around vtkSlicerMarkupsLogic

property interaction_node: vtkMRMLInteractionNode | None
place_node(node: vtkMRMLMarkupsNode, persistent: bool = False)
disable_place_mode()

trame_slicer.core.segmentation_editor module

class trame_slicer.core.segmentation_editor.SegmentationEditor(scene: vtkMRMLScene, logic: vtkSlicerSegmentationsModuleLogic, view_manager: ViewManager, *, builtin_effects: list[type[SegmentationEffect]] | None = None)

Bases: SignalContainer

Class responsible for editing the segmentation. Meant to be used by the application to activate / deactivate segmentation effects.

builtin_effects: ClassVar[list[type[SegmentationEffect]]] = [<class 'trame_slicer.segmentation.segmentation_effect_draw.SegmentationEffectDraw'>, <class 'trame_slicer.segmentation.segmentation_effect_paint_erase.SegmentationEffectErase'>, <class 'trame_slicer.segmentation.segmentation_effect_islands.SegmentationEffectIslands'>, <class 'trame_slicer.segmentation.segmentation_effect_logical_operators.SegmentationEffectLogicalOperators'>, <class 'trame_slicer.segmentation.segmentation_effect_no_tool.SegmentationEffectNoTool'>, <class 'trame_slicer.segmentation.segmentation_effect_paint_erase.SegmentationEffectPaint'>, <class 'trame_slicer.segmentation.segmentation_effect_scissors.SegmentationEffectScissors'>, <class 'trame_slicer.segmentation.segmentation_effect_smoothing.SegmentationEffectSmoothing'>, <class 'trame_slicer.segmentation.segmentation_effect_threshold.SegmentationEffectThreshold'>, <class 'trame_slicer.segmentation.segmentation_effect_volume_intensity_mask.SegmentationEffectVolumeIntensityMask'>]
segmentation_modified

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

segmentation_display_modified

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

active_segment_id_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

active_effect_name_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

show_3d_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

parameter_changed

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

editor_node_modified

Signal implementation. Can be connected to one or more callables. When called, will call associated callables with the provided args and kwargs.

Provides utility methods and contextmanager to control signal execution. Can be used both as class property and instance.

Parameters:

type_info – Types of arguments expected by the signal.

property editor_logic: vtkSlicerSegmentEditorLogic
property editor_node: vtkMRMLSegmentEditorNode
is_effect_type_registered(effect_type: type[SegmentationEffect]) bool
register_effect_type(effect_type: type[SegmentationEffect]) None

Registers the input segment editor effect type for the segmentation editor.

set_undo_stack(undo_stack: UndoStack)
property undo_stack: UndoStack | None
property active_segmentation: Segmentation | None
property active_segmentation_display: SegmentationDisplay | None
property active_segmentation_node
property active_volume_node: vtkMRMLVolumeNode | None
property active_segment_modifier: SegmentModifier | None
property active_effect: SegmentationEffect | None
set_active_segmentation(segmentation_node: vtkMRMLSegmentationNode, volume_node: vtkMRMLVolumeNode) Segmentation
create_segmentation_node_from_model_node(model_node: vtkMRMLModelNode) vtkMRMLSegmentationNode
create_segmentation_node_from_labelmap(labelmap_node: vtkMRMLLabelMapVolumeNode) vtkMRMLSegmentationNode
create_empty_segmentation_node() vtkMRMLSegmentationNode
set_active_effect_type(effect_type: type[SegmentationEffect]) SegmentationEffect | None
set_active_effect_name(effect_id: str) SegmentationEffect | None
set_active_effect(effect: SegmentationEffect | None) SegmentationEffect | None
property active_effect_name: str
get_active_effect_name() str
deactivate_effect()
get_segment_ids() list[str]
get_segment_names() list[str]
get_all_segment_properties() dict[str, SegmentProperties]
get_segment_properties(segment_id)
set_segment_properties(segment_id, segment_properties: SegmentProperties)
property n_segments: int
get_nth_segment(i_segment: int) vtkSegment | None
get_nth_segment_id(i_segment: int) str
get_segment(segment_id: str) vtkSegment | None
add_empty_segment(*, segment_id='', segment_name='', segment_color: list[float] | None = None, segment_value: int | None = None) str
remove_segment(segment_id)
get_active_segment_id() str
set_active_segment_id(segment_id)
property active_segment_id: str
get_segment_labelmap(segment_id: str, *, as_numpy_array: bool = False) vtkImageData | ndarray[tuple[Any, ...], dtype[_ScalarT]] | None
export_segmentation_to_labelmap(segmentation_node: vtkMRMLSegmentationNode, labelmap: vtkMRMLLabelMapVolumeNode = None) vtkMRMLLabelMapVolumeNode
export_segmentation_to_file(segmentation_node: vtkMRMLSegmentationNode, file_path: str) None
export_segmentation_to_models(segmentation_node: vtkMRMLSegmentationNode, folder_item_id: int) None
export_segmentation_to_stl(segmentation_node: vtkMRMLSegmentationNode, out_folder: str, segment_ids: list[str] | None = None) None
load_segmentation_from_file(segmentation_file: str) vtkMRMLSegmentationNode | None
set_surface_representation_enabled(is_enabled: bool) None
is_surface_representation_enabled() bool
show_3d(show_3d: bool)
is_3d_shown()
create_modifier_labelmap() vtkImageData | None
apply_labelmap(labelmap) None
apply_polydata_world(poly_world) None
trigger_all_signals()
set_segment_visibility(segment_id, visibility: bool) None
get_segment_visibility(segment_id) bool | None
set_editable_area(editable_area: SegmentationEditableAreaMode) None
get_editable_area() SegmentationEditableAreaMode
set_mask_segment_id(segment_id: str)
get_mask_segment_id() str
set_overwrite_mode(overwrite_mode: SegmentationOverwriteMode) None
get_overwrite_mode() SegmentationOverwriteMode
get_effect_parameter_node(effect: SegmentationEffect | type[SegmentationEffect]) vtkMRMLScriptedModuleNode

returns segmentation effect parameter node as used by this segment editor. When passing effect types as inputs, this method will ensure the effect has been registered. If the parameter node doesn’t exist in the current scene, the parameter node will be added automatically.

get_effect(effect_type: type[TEffect]) TEffect | None
clear()

trame_slicer.core.slicer_app module

class trame_slicer.core.slicer_app.SlicerApp(share_directory: str | None = None)

Bases: object

Container for the core components of a Slicer application. Instantiates the scene, application logic and layout manager. Configures the default nodes present in the scene.

register_module_logic(logic: vtkSlicerModuleLogic, *, logic_name: str = '', share_sub_folder: str = '')

Configure the input module logic with the application scene, logic and share directory. Registers the logic to the application logic with the given input logic name if any, module name otherwise.

Parameters:
  • logic – instance of logic to register

  • logic_name – name of the logic in the application logic

  • share_sub_folder – sub folder of the share directory (if no sub folder, common share directory is used)

Returns:

instance of logic

trame_slicer.core.view_manager module

class trame_slicer.core.view_manager.ViewManager(scene: vtkMRMLScene, application_logic: vtkMRMLApplicationLogic)

Bases: object

Class responsible for creating views given view descriptions and factories. Create views with the first factory available which can create view spec. Provides access to created views but doesn’t hold strong ownership of the views.

set_current_view_ids(view_ids: list[str]) None

Set which views are currently displayed in the application. To be used by layout manager or equivalent classes.

get_current_view_ids() list[str]
register_factory(view_factory: IViewFactory) None

Allows to register a factory for given view type.

get_view(view_id: str | vtkMRMLAbstractViewNode) AbstractViewChild | None

Get view associated with input view ID.

remove_view(view_id: str) bool
create_view(view: ViewLayoutDefinition) AbstractViewChild | None

Uses the best registered factory to create the view with given id / type. Overwrites view stored if it exists. Returns created view.

is_view_created(view_id: str) bool

Returns true if view id is created, false otherwise.

get_views(view_group: int | None = None) list[AbstractView]

Return all Slicer views matching view group in the view manager.

get_slice_views(view_group: int | None = None) list[SliceView]
get_threed_views(view_group: int | None = None) list[ThreeDView]
filter_visible_views(views: list[AbstractViewChild]) list[AbstractViewChild]

Filter input view list by ones currently displayed in the layout.

trame_slicer.core.volume_property module

class trame_slicer.core.volume_property.VRShiftMode(*values)

Bases: Flag

OPACITY = 1
COLOR = 2
BOTH = 3
class trame_slicer.core.volume_property.VolumeProperty(volume_property_node: vtkMRMLVolumePropertyNode | None)

Bases: SlicerWrapper[vtkMRMLVolumePropertyNode]

Thin facade for volume property node. Allows more pythonic access to the scalar / opacity properties of a volume rendering display node.

property volume_property: vtkVolumeProperty
property property_node: vtkMRMLVolumePropertyNode
property opacity_map: vtkPiecewiseFunction
property color_map: vtkColorTransferFunction
get_color_map_values() list[list[float]]
get_opacity_map_values() list[list[float]]
set_color_map_values(values: list[list[float]])
set_opacity_values(values: list[list[float]])
shift_color_map(shift: float) None
shift_opacity_map(shift: float) None
get_effective_range() tuple[float, float]
static shift_values(values, shift)
set_vr_shift(shift: float, shift_mode: VRShiftMode, ref_prop: VolumeProperty | None = None)

trame_slicer.core.volume_rendering module

class trame_slicer.core.volume_rendering.VolumeRendering(slicer_app: SlicerApp)

Bases: SlicerWrapper[vtkSlicerVolumeRenderingLogic]

Simple facade for volume rendering logic.

property crop_logic: vtkSlicerCropVolumeLogic
create_display_node(volume_node: vtkMRMLVolumeNode, preset_name: str = '') vtkMRMLVolumeRenderingDisplayNode
apply_preset(display: vtkMRMLVolumeRenderingDisplayNode | None, preset_name: str)
set_volume_node_property(volume_node: vtkMRMLVolumeNode, property_node: vtkMRMLVolumePropertyNode)
static apply_vr_node_property(display: vtkMRMLVolumeRenderingDisplayNode, property_node: vtkMRMLVolumePropertyNode)
get_preset_property(preset_name) VolumeProperty
get_vr_display_node(volume_node: vtkMRMLVolumeNode) vtkMRMLVolumeRenderingDisplayNode | None
has_vr_display_node(volume_node: vtkMRMLVolumeNode) bool
preset_names() list[str]
get_preset_node(preset_name: str) vtkMRMLVolumePropertyNode | None
set_absolute_vr_shift_from_preset(volume_node: ~slicer_core.MRMLCore.vtkMRMLVolumeNode, preset_name: str | None, shift: float, shift_mode: ~trame_slicer.core.volume_property.VRShiftMode = <VRShiftMode.BOTH: 3>) None

Shift the volume rendering opacity and colors by a given value. The shift is a scalar value representing how much the preset should be moved compared to a preset default.

Which

See also:
ref:

set_relative_vr_shift

set_relative_vr_shift(volume_node: ~slicer_core.MRMLCore.vtkMRMLVolumeNode, shift: float, shift_mode: ~trame_slicer.core.volume_property.VRShiftMode = <VRShiftMode.BOTH: 3>) None

Shift the volume rendering opacity and colors by a given value for the current scalar/opacity values.

See also:
ref:

set_absolute_vr_shift_from_preset

get_vr_shift_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
get_preset_vr_shift_range(preset_name: str) tuple[float, float]
get_volume_node_property(volume_node: vtkMRMLVolumeNode) VolumeProperty
set_cropping_enabled(volume_node: vtkMRMLVolumeNode, roi_node: vtkMRMLMarkupsROINode | None, is_enabled: bool) vtkMRMLMarkupsROINode | None

Enable or disable the VR cropping for the input volume node. If the volume node doesn’t have a cropping ROI node and is_enabled is True, a new ROI node will be initialized and encompass the full volume node.

The ROI Node attached to the display node will be returned.

get_cropping_roi_node(volume_node: vtkMRMLVolumeNode | None) vtkMRMLMarkupsROINode | None

Returns the ROI node instance attached to the input volume node’s VR display node if any.

get_cropping_roi_visiblity(volume_node: vtkMRMLVolumeNode | None) bool

Returns the input volume node’s VR crop ROI node’s visibility. If the input volume node doesn’t have a ROI node, returns False.

set_cropping_roi_node_visibile(volume_node: vtkMRMLVolumeNode | None, is_visible: bool) bool

Sets the inputs volume node’s VR cropping ROI visible. If the input volume node doesn’t have a cropping node, does nothgin.

:return visibility state of the ROI node

toggle_cropping_visibility(volume_node: vtkMRMLVolumeNode | None) bool

Toggle input volume node cropping visibility. Toggling the visibility will activate and initialize the cropping ROI Node if needed.

Returns:

New visibility state of the Cropping ROI Node

set_vr_opacity(volume_node: vtkMRMLVolumeNode, opacity: float, gradient_threshold_hu: float = 0)

Update volume node gradient opacity function applied on RBG value. Copied from: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#show-volume-rendering-making-soft-tissues-transparent

Updates the Volume property node gradient opacity with 0 opacity below a given HU value and the updated slider position opacity value above.

By default, the gradient threshold is set to around water HU value https://www.sciencedirect.com/topics/medicine-and-dentistry/hounsfield-scale

Parameters:
  • volume_node – volume node on which the VR opacity will be applied

  • opacity – Opacity value between [0, 1]. 1 = fully opaque, 0 = fully transparent.

  • gradient_threshold_hu – Cut off for opacity gradient.

trame_slicer.core.volume_window_level module

class trame_slicer.core.volume_window_level.VolumeWindowLevel

Bases: object

Collection of helper functions to update a volume’s window / level

classmethod get_volume_auto_min_max_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
classmethod get_volume_scalar_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
classmethod set_volume_node_window_level(volume_node: vtkMRMLVolumeNode, window: float, level: float) None
classmethod set_volume_node_display_min_max_range(volume_node: vtkMRMLVolumeNode, min_value: float, max_value: float) None
classmethod get_volume_display_range(volume_node: vtkMRMLVolumeNode) tuple[float, float]
classmethod window_level_to_min_max(window: float, level: float) tuple[float, float]
classmethod min_max_to_window_level(min_value: float, max_value: float) tuple[float, float]
classmethod get_volume_display_node(volume_node: vtkMRMLVolumeNode) vtkMRMLVolumeDisplayNode

trame_slicer.core.volumes_reader module

class trame_slicer.core.volumes_reader.VolumesReader

Bases: object

Adapted from Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py

dcm_read_lru_cache_size = 5000
classmethod load_volumes(scene: vtkMRMLScene, app_logic: vtkMRMLApplicationLogic, volume_files: list[str] | str) list[vtkMRMLVolumeNode]
classmethod load_single_file_volume(scene: vtkMRMLScene, app_logic: vtkMRMLApplicationLogic, volume_file: str) vtkMRMLVolumeNode | None
classmethod contains_dcm_volume(volume_files: list[str]) bool
classmethod is_dcm_file(file_name: str) bool
classmethod load_dcm_volumes(scene: vtkMRMLScene, volume_files: list[vtkMRMLVolumeNode | None])
classmethod split_volumes(volume_files: list[str]) list[list[str]]
classmethod tag_value_to_vector(value)
classmethod load_single_dcm_volume(scene: vtkMRMLScene, volume_files: list[str]) vtkMRMLVolumeNode | None