Workbench
Workbench handle — primary entry point for controlling a MITK Workbench instance.
- class mitk_workbench_remote.workbench.WorkbenchInfo(name, api_version, mitk_version, url)
Bases:
objectMetadata about a MITK Workbench instance.
- Variables:
name – Human-readable server name.
api_version – REST API version string (e.g.
"v1").mitk_version – Underlying MITK framework version string.
url – Base URL of the Workbench REST server.
- class mitk_workbench_remote.workbench.PositionBounds(min_position, max_position)
Bases:
objectWorld-space axis-aligned bounding box of the scene.
- Variables:
min_position – Minimum corner
[x, y, z], orNoneif no geometry is loaded.max_position – Maximum corner
[x, y, z], orNoneif no geometry is loaded.
- class mitk_workbench_remote.workbench.SelectedPosition(position, bounds)
Bases:
objectCurrent crosshair position and scene bounds.
- Variables:
position – Crosshair position in world coordinates
[x, y, z].bounds – Scene bounding box.
- bounds: PositionBounds
- class mitk_workbench_remote.workbench.TimeBounds(min_timepoint_ms, max_timepoint_ms, steps)
Bases:
objectTime geometry bounds.
- Variables:
min_timepoint_ms – Start of the time range in milliseconds.
max_timepoint_ms – End of the time range in milliseconds.
steps – Total number of time steps.
- class mitk_workbench_remote.workbench.SelectedTime(timepoint_ms, timestep, bounds)
Bases:
objectCurrent time navigation state.
- Variables:
timepoint_ms – Selected time point in milliseconds.
timestep – Selected time step index (zero-based).
bounds – Time geometry bounds.
- bounds: TimeBounds
- class mitk_workbench_remote.workbench.ReinitMode(*values)
-
Controls automatic reinit behavior after show().
- Variables:
ALL_VISIBLE – Global reinit – fit all views to all visible data.
NODE – Node reinit – fit views to the newly shown node only.
NONE – Skip reinit entirely.
- ALL_VISIBLE = 'all'
- NODE = 'node'
- NONE = 'none'
- class mitk_workbench_remote.workbench.RenderWindows(*values)
-
Which render windows to update.
- Variables:
ALL – Update all render windows.
TWO_D – Update only 2-D render windows.
THREE_D – Update only the 3-D render window.
- ALL = 'all'
- TWO_D = '2d'
- THREE_D = '3d'
- class mitk_workbench_remote.workbench.ScreenshotFormat(*values)
-
Image encoding format for screenshots.
- Variables:
PNG – Lossless PNG encoding.
JPEG – Lossy JPEG encoding.
- PNG = 'png'
- JPEG = 'jpeg'
- class mitk_workbench_remote.workbench.Workbench(transport, *, process=None, stderr_log_path=None)
Bases:
objectHandle to a running MITK Workbench instance.
Do not instantiate directly — use
connect()orlaunch().- Parameters:
transport (
RestTransport) – Configured REST transport for the target instance.process (
Popen[bytes] |None(default:None)) – Optional subprocess handle when the instance was started vialaunch().stderr_log_path (
str|None(default:None)) – Optional path to the temp file capturing the launched child’s stderr. Removed best-effort onshutdown().
- property is_launched_remotely: bool
Returns if the workbench was launched remotely (true) or was just connected to but is independent (false).
- property info: WorkbenchInfo
Metadata about the connected Workbench instance.
Fetched lazily from
GET /api/v1/infoon first access and cached thereafter.
- property storage: DataStorage
The DataStorage for this Workbench instance. Lazy and cached.
- property std_multi: StdMultiEditor
Handle to the StdMultiWidget editor. Lazy and cached.
The handle holds only the transport — every state read goes to the network. Use
is_activeon the returned handle (oreditors()) to check whether the editor is currently open.
- editor(alias)
Return an editor handle by alias.
Accepts either a raw alias string (
"stdmulti","mxn") or anEditorAliasmember. For the well-known aliases this returns the same instance as the named property (std_multi/mxn). Unknown aliases raiseValueError.- Return type:
- editors()
List all known editors with their current activity state.
Sends
GET /rendering/editors. Always live — the active state of an editor changes at runtime as the user opens or closes it.- Return type:
- ping()
Check whether the Workbench is reachable.
Sends a
GET /healthrequest. ReturnsFalsefor any failure — network errors, HTTP errors, or unexpected exceptions — without raising.- Return type:
- Returns:
Trueif the server responded with a 2xx status,Falseotherwise.
- show(data, *, name=None, visible=True, opacity=None, color=None, parent=None, hide_others=False, reinit=ReinitMode.ALL_VISIBLE)
One-liner to load data into the Workbench and display it.
Creates a new node, uploads the data, sets display properties, and optionally reinitializes the render views.
- Parameters:
data (
Any) – Data to show. Accepts file paths (str/Path),Image,MultiLabelSegmentation, numpy arrays, or any type handled by the converter registry.name (
str|None(default:None)) – Node display name. Inferred fromdatawhenNone.visible (
bool(default:True)) – Whether the node is visible after showing.opacity (
float|None(default:None)) – Node opacity (0.0 - 1.0).Nonekeeps the server default.color (
tuple[float,float,float] |None(default:None)) – Node color as(r, g, b).Nonekeeps the server default.parent (
DataNode|str|None(default:None)) – Parent node (instance or UID string).Nonefor top-level.hide_others (
bool(default:False)) – WhenTrue, hide all existing nodes before showing.reinit (
ReinitMode(default:<ReinitMode.ALL_VISIBLE: 'all'>)) – Auto-reinit mode after showing the data.
- Return type:
- Returns:
The newly created
DataNode.
- update(*, windows=RenderWindows.ALL)
Request all render windows to redraw.
Use after batching data or property changes to make them visible without per-change flicker.
- Parameters:
windows (
RenderWindows|str(default:<RenderWindows.ALL: 'all'>)) – Which render windows to update:"all"(default),"2d", or"3d".- Raises:
RenderingError – If the rendering framework reports a failure.
- Return type:
- reinit(nodes=None)
Fit render window cameras to the bounding geometry of nodes.
Three modes:
nodes=None— global reinit: fits all views to all visible data (equivalent to clicking the global reinit button in the Workbench).single element list — fits views to that node’s geometry.
multi-element list — fits views to the combined bounding geometry.
- Parameters:
nodes (
list[DataNode|str] |None(default:None)) – Nodes to reinit to. AcceptsDataNodeinstances or UID strings.Noneperforms a global reinit.- Raises:
ValueError – If
nodesis an empty list (useNonefor global reinit).NodeNotFoundError – If any listed node does not exist.
ApiError – If a node has no data (code
NO_DATA) or no usable geometry (codeNO_GEOMETRY).RenderingError – If the rendering framework reports a failure.
- Return type:
- get_position()
Get the current crosshair position and scene bounds.
- Return type:
- Returns:
A
SelectedPositionwith the crosshair coordinates and the world-space bounding box.- Raises:
RenderingError – If no render window is available.
- set_position(position)
Move the crosshair to the given world position.
- Parameters:
position (
tuple[float,float,float] |list[float]) – Target position[x, y, z]in world coordinates.- Raises:
ValueError – If position does not have exactly 3 elements.
RenderingError – If no render window is available.
- Return type:
- get_time()
Get the current time navigation state.
- Return type:
- Returns:
A
SelectedTimewith the active time point, step, and bounds.- Raises:
RenderingError – If no render window is available.
- set_timepoint(timepoint_ms)
Set the active time point.
- Parameters:
timepoint_ms (
float) – Target time point in milliseconds.- Raises:
RenderingError – If no render window is available.
- Return type:
- set_timestep(timestep)
Set the active time step.
- Parameters:
timestep (
int) – Target time step index (zero-based).- Raises:
RenderingError – If no render window is available.
- Return type:
- screenshot(*, fmt=ScreenshotFormat.PNG, width=None, height=None, path=None)
Capture a screenshot of the active application window.
- Parameters:
fmt (
ScreenshotFormat|str(default:<ScreenshotFormat.PNG: 'png'>)) – Image encoding format ("png"or"jpeg").width (
int|None(default:None)) – Output width in pixels. Must be given together withheight.height (
int|None(default:None)) – Output height in pixels. Must be given together withwidth.path (
str|Path|None(default:None)) – If given, save the screenshot to this file path.
- Return type:
- Returns:
Raw image bytes.
- Raises:
ValueError – If only one of
width/heightis given.RenderingError – If no render window is available.
- shutdown()
Terminate the subprocess started by
launch().On Windows the MITK executable is often a batch-script wrapper, so the
Popenhandle points tocmd.exe— not the realMitkWorkbench.exe. Killing the wrapper (or its tree) may leave the actual Workbench running. We therefore look up the process that owns the REST port vianetstatand kill that.On Unix, sends
SIGTERMto the subprocess and falls back toSIGKILLafter 10 seconds.Removes the launch stderr temp file (if any) best-effort and closes the underlying transport session.