utils

class trame_slicer.utils.ClosestToCameraPicker

Bases: object

pick(display_position: tuple[int, int], poked_renderer: vtkRenderer, camera: vtkCamera) list[float] | None
class trame_slicer.utils.SlicerWrapper(slicer_obj: T | None = None)

Bases: Generic[T]

This class provides automatic conversion of snake_case attributes to CamelCase if the original attribute is not found in any slicer object. If neither form exists, raises AttributeError is raised.

Delegates calls to the wrapped object.

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_wrapped_obj(slicer_obj: object | None)
trame_slicer.utils.as_rgba_hex(hex_channels: str) str

Pads input hex string to RGBA (8 characters) by adding FF values.

trame_slicer.utils.create_scripted_module_dataclass_proxy(dataclass_type: type[T], node: vtkMRMLScriptedModuleNode, scene: vtkMRMLScene, encoders: list[IStateEncoderDecoder] | None = None) T
trame_slicer.utils.create_scripted_module_dataclass_proxy_name(dataclass_type: type[T]) T
trame_slicer.utils.ensure_node_in_scene(node: T | None, scene: vtkMRMLScene) T | None

Ensure that the input node is properly registered in the scene.

trame_slicer.utils.float_channels_to_hex(float_channels: list[float]) str

Converts a list of input color channels to hex format. Supports arbitrary length of color components (e.g., RGB, RG, RGBA).

trame_slicer.utils.hex_to_float_channels(hex_channels: str) list[float]

Converts a list of input hex colors channels prefixed by # to the equivalent float color channels. Supports arbitrary length of color hex channels (e.g., RGB, RG, RGBA).

trame_slicer.utils.hex_to_rgb_float(color_hex: str) list[float]
trame_slicer.utils.is_scripted_module_dataclass(instance: T)
trame_slicer.utils.rgb_float_to_hex(rgb_float: list[float]) str
trame_slicer.utils.scripted_proxy_from_dataclass(instance: T, dataclass_obj: T) T
trame_slicer.utils.scripted_proxy_to_dataclass(instance: T) T
trame_slicer.utils.to_camel_case(attr: str) str

Copied from https://github.com/jpvanhal/inflection/blob/master/inflection/__init__.py Also capitalizes letters that follow digits.

trame_slicer.utils.to_snake_case(attr: str) str

Copied from https://github.com/jpvanhal/inflection/blob/master/inflection/__init__.py Preserves digit-letter sequences like ‘3D’ as single tokens.

trame_slicer.utils.vtk_image_to_np(image: vtkImageData) ndarray[tuple[Any, ...], dtype[_ScalarT]]
trame_slicer.utils.wrap(obj)
trame_slicer.utils.write_client_files_to_dir(client_file_dicts: list[dict], dest_dir: str | Path) list[str]

Helper method to copy files from client to a local server dir

trame_slicer.utils.closest_to_camera_picker module

class trame_slicer.utils.closest_to_camera_picker.ClosestToCameraPicker

Bases: object

pick(display_position: tuple[int, int], poked_renderer: vtkRenderer, camera: vtkCamera) list[float] | None

trame_slicer.utils.convert_colors module

trame_slicer.utils.convert_colors.as_rgba_hex(hex_channels: str) str

Pads input hex string to RGBA (8 characters) by adding FF values.

trame_slicer.utils.convert_colors.float_channels_to_hex(float_channels: list[float]) str

Converts a list of input color channels to hex format. Supports arbitrary length of color components (e.g., RGB, RG, RGBA).

trame_slicer.utils.convert_colors.hex_to_float_channels(hex_channels: str) list[float]

Converts a list of input hex colors channels prefixed by # to the equivalent float color channels. Supports arbitrary length of color hex channels (e.g., RGB, RG, RGBA).

trame_slicer.utils.convert_colors.rgb_float_to_hex(rgb_float: list[float]) str
trame_slicer.utils.convert_colors.hex_to_rgb_float(color_hex: str) list[float]

trame_slicer.utils.ensure_node_in_scene module

trame_slicer.utils.ensure_node_in_scene.ensure_node_in_scene(node: T | None, scene: vtkMRMLScene) T | None

Ensure that the input node is properly registered in the scene.

trame_slicer.utils.file_access module

trame_slicer.utils.file_access.write_client_files_to_dir(client_file_dicts: list[dict], dest_dir: str | Path) list[str]

Helper method to copy files from client to a local server dir

trame_slicer.utils.scripted_module_node_dataclass_proxy module

class trame_slicer.utils.scripted_module_node_dataclass_proxy.DefaultScriptedModuleEncoderDecoder(scene: vtkMRMLScene)

Bases: IStateEncoderDecoder

Default primitive type encoding/decoding for scripted field.

encode(obj) str
decode(obj: str, obj_type: type)
trame_slicer.utils.scripted_module_node_dataclass_proxy.create_scripted_module_dataclass_proxy(dataclass_type: type[T], node: vtkMRMLScriptedModuleNode, scene: vtkMRMLScene, encoders: list[IStateEncoderDecoder] | None = None) T
trame_slicer.utils.scripted_module_node_dataclass_proxy.create_scripted_module_dataclass_proxy_name(dataclass_type: type[T]) T
trame_slicer.utils.scripted_module_node_dataclass_proxy.is_scripted_module_dataclass(instance: T)
trame_slicer.utils.scripted_module_node_dataclass_proxy.raise_if_not_scripted_proxy(instance: T)
trame_slicer.utils.scripted_module_node_dataclass_proxy.scripted_proxy_from_dataclass(instance: T, dataclass_obj: T) T
trame_slicer.utils.scripted_module_node_dataclass_proxy.scripted_proxy_to_dataclass(instance: T) T

trame_slicer.utils.slicer_wrapper module

trame_slicer.utils.slicer_wrapper.to_camel_case(attr: str) str

Copied from https://github.com/jpvanhal/inflection/blob/master/inflection/__init__.py Also capitalizes letters that follow digits.

trame_slicer.utils.slicer_wrapper.to_snake_case(attr: str) str

Copied from https://github.com/jpvanhal/inflection/blob/master/inflection/__init__.py Preserves digit-letter sequences like ‘3D’ as single tokens.

exception trame_slicer.utils.slicer_wrapper.SlicerWrappingAttributeError

Bases: AttributeError

class trame_slicer.utils.slicer_wrapper.SlicerWrapper(slicer_obj: T | None = None)

Bases: Generic[T]

This class provides automatic conversion of snake_case attributes to CamelCase if the original attribute is not found in any slicer object. If neither form exists, raises AttributeError is raised.

Delegates calls to the wrapped object.

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_wrapped_obj(slicer_obj: object | None)
trame_slicer.utils.slicer_wrapper.wrap(obj)

trame_slicer.utils.vtk_numpy module

trame_slicer.utils.vtk_numpy.vtk_image_to_np(image: vtkImageData) ndarray[tuple[Any, ...], dtype[_ScalarT]]