Skip to main content

bone-cutting-plane-visualization

Standalone data contracts and VTK visualization for bone-tumor cutting-plane plans. The package is independent of any planning or optimization repository.

All persisted inputs use the .ubd.npz format from ct-mri-dicom-nii-reader. Volumes are interpreted in (Left, Posterior, Superior) axis order. Standard UBD files can be used for the bone/tumor and convex-hull views; a compatible, namespaced extension stores a complete resection plan in one UBD archive.

Installation

python -m pip install -e ".[all]"

The mandatory runtime dependency on ct-mri-dicom-nii-reader provides the UBD loader and BodyData contract. VTK remains optional so data inspection and scene preparation work on headless systems:

python -m pip install -e .
python -m pip install -e ".[viz]"

Data contracts

The public plan consists of five explicit classes:

  • LabeledVolume: -1 normal bone, 0 other, 1 tumor.
  • SelectedCuttingPlanes: ordered index-space rows [a, b, c, d].
  • RegionClassificationVolume: negative retained bone and 2 resected bone.
  • VolumeGeometry: spacing, LPS origin, and index-to-LPS direction.
  • TumorSafetyMarginData: optional planning volume, protected mask, danger-bone mask, and physical margin.

ResectionPlanData combines them and validates shapes, labels, plane references, and safety-margin clearance.

import numpy as np

from bone_cutting_plane_visualization import (
    ResectionPlanData,
    SelectedCuttingPlanes,
    classify_regions,
    load_labeled_volume,
    save_resection_plan,
)

volume, geometry = load_labeled_volume("case-labels.ubd.npz")
planes = SelectedCuttingPlanes(
    np.asarray([[1.0, 0.0, 0.0, -42.5]], dtype=np.float64)
)
classification = classify_regions(volume, planes)
plan = ResectionPlanData(volume, planes, classification, geometry)
save_resection_plan(plan, "case-plan.ubd.npz")

Arrays are copied, normalized to stable dtypes, and exposed read-only.

Callers migrating from NumPy-based APIs can use compatibility.plan_from_arrays, compatibility.visualize_resection_arrays, compatibility.visualize_volume, and compatibility.visualize_solution. These adapters depend only on this package; they never import a planning repository.

UBD plan extension

Every plan archive retains the standard UBD v1 fields:

format_version, body_data, image_type, mmpd

It adds the following bcv_ fields:

bcv_schema_version
bcv_cutting_planes
bcv_region_classification
bcv_spacing_mm
bcv_origin_lps_mm
bcv_direction_index_to_lps
bcv_has_safety_margin
bcv_safety_planning_volume       # present when enabled
bcv_safety_protected_mask        # present when enabled
bcv_safety_danger_bone_mask      # present when enabled
bcv_safety_margin_mm             # present when enabled

Unknown fields are ignored by UnifiedBodyDataLoader, so a plan archive remains readable as an ordinary mask UBD file. The package verifies that compatibility after every save. Because UBD stores one scalar mmpd, persisted plans require isotropic spacing. Direct in-memory visualization still supports arbitrary valid VolumeGeometry values.

Visualization

from bone_cutting_plane_visualization import load_resection_plan, visualize_resection

plan = load_resection_plan("case-plan.ubd.npz")
visualize_resection(plan)

The final view includes retained normal bone, resected normal bone, tumor, optional safety-margin bone, bounded cutting-plane polygons, legend, retention rate, and the same camera and visual styling as the source implementation. Every VTK scene also includes a compact black orientation cube with white edges and L/R, P/A, and S/i face labels. It is scaled from the physical volume bounds and placed beyond the negative X/Y side of the LPS bounds, outside the clinical geometry and business legend.

The CLI accepts only .ubd.npz inputs:

bone-cutting-plane-viz view case-labels.ubd.npz
bone-cutting-plane-viz hull case-labels.ubd.npz
bone-cutting-plane-viz plan case-plan.ubd.npz
bone-cutting-plane-viz plan case-plan.ubd.npz --view resected
bone-cutting-plane-viz plan case-plan.ubd.npz --offscreen --screenshot plan.png
bone-cutting-plane-viz inspect case-plan.ubd.npz

Development

python -m pytest
ruff check src tests

Metadata

Release files for bone-cutting-plane-visualization 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bone-cutting-plane-visualization 0.1.1
File Size Uploaded
bone_cutting_plane_visualization-0.1.1.tar.gz 27.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bone-cutting-plane-visualization 0.1.1
File Interpreter ABI Platform
bone_cutting_plane_visualization-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 52.2 kB

Release files / bone_cutting_plane_visualization-0.1.1.tar.gz

Download URL bone_cutting_plane_visualization-0.1.1.tar.gz
Size 27.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a28c19e02d52019b53ac145df86fc60917fed0942d1cf20d2ed871b0b487dd42
BLAKE2b-256 checksum
How to use checksums
e8add20e215bbf64e968f05769bd072f82201df2565202f3e4cae57830048b91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Windows/11

Release files / bone_cutting_plane_visualization-0.1.1-py3-none-any.whl

Download URL bone_cutting_plane_visualization-0.1.1-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa4ae7b4d14be09143e4e244f7a06a065c5b1632db97c2cd22daf4bb2ffa3ff7
BLAKE2b-256 checksum
How to use checksums
91a0dd8832b2858c35b222c30677b8bcb521ba3fa99773a3b34187073f2aba81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Windows/11

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page