ThreeMfReader#

class medicalimageanalysis.read.ThreeMfReader(file, roi_name=None)[source]

Bases: object

Reader for .3mf (3D Manufacturing Format) files.

Converts one .3mf file into a decimated PyVista mesh with vertex colors, voxelizes it into a new image, and stores the mesh as an ROI on that image in the global Data registry.

Parameters:
  • file (str) – Path to the .3mf file.

  • roi_name (str, optional) – Name of the ROI that holds the mesh. Defaults to the file stem (e.g. ‘implant’ for ‘C:/Data/implant.3mf’).

file

Path to the .3mf file.

Type:

str

roi_name

ROI name used when registering the mesh (never None).

Type:

str

Examples

Load a colored tumor model and inspect the result:

>>> from medicalimageanalysis.read.mf3 import ThreeMfReader
>>> from medicalimageanalysis import Data
>>> Data.clear()
>>> reader = ThreeMfReader('C:/Data/tumor_model.3mf', roi_name='Tumor')
>>> reader.load()
>>> Data.image_list()
['CT 01']
>>> list(Data.image['CT 01'].roi.keys())
['Tumor']

The convenience wrapper does the same thing in one call:

>>> import medicalimageanalysis as mia
>>> mia.read_3mf(file='C:/Data/tumor_model.3mf', roi_name='Tumor')
load()[source]

Parse the .3mf file and register it as a new image + ROI.

Steps performed:
  1. Read 3D/3dmodel.model from the archive.

  2. Parse vertices and triangles of the first object.

  3. Resolve vertex colors (texture or basematerials).

  4. Build the PyVista mesh and store colors in mesh[‘colors’].

  5. Decimate to roughly 50k points (only if larger).

  6. Voxelize into a mask image named ‘CT NN’.

  7. Attach the mesh as an ROI and run Data.match_rois().

Return type:

None

Raises:
  • KeyError – If the archive has no 3D/3dmodel.model entry.

  • IndexError – If the model contains no <object>.

Examples

Load a mesh into an empty session:

>>> from medicalimageanalysis.read.mf3 import ThreeMfReader
>>> from medicalimageanalysis import Data
>>> Data.clear()
>>> ThreeMfReader('C:/Data/mandible.3mf', roi_name='Mandible').load()
>>> Data.image_list()
['CT 01']

The image name continues the session’s numbering, and the new ROI is added (empty) to the images already loaded:

>>> import medicalimageanalysis as mia
>>> mia.read_dicoms(folder_path='C:/Data/Patient01')
>>> ThreeMfReader('C:/Data/guide.3mf', roi_name='CuttingGuide').load()
>>> Data.image_list()
['CT 01', 'MR 02', 'CT 03']
>>> 'CuttingGuide' in Data.image['MR 02'].roi
True