ThreeMfReader#
- class medicalimageanalysis.read.ThreeMfReader(file, roi_name=None)[source]
Bases:
objectReader 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
Path to the .3mf file.
- Type:
- roi_name
ROI name used when registering the mesh (never None).
- Type:
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:
Read 3D/3dmodel.model from the archive.
Parse vertices and triangles of the first object.
Resolve vertex colors (texture or basematerials).
Build the PyVista mesh and store colors in mesh[‘colors’].
Decimate to roughly 50k points (only if larger).
Voxelize into a mask image named ‘CT NN’.
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