Many workflows require the use of multiple tools from Mimics and 3-matic and the transfer of data between both products. With scripting is possible to automate such workflows and use tools from both software packages.
This tutorial shows how to continue the workflow in 3-matic while working in Mimics. Emphasis is put to the metadata that are attached to objects in Mimics and they are kept in 3-matic. More metadata are added in 3-matic. For this tutorial a single-file script approach is selected. The Mimics project Heart.mcs from C:\MedData\DemoFiles
is used. An empty 3-matic project is used and the Mimics project is imported.
# import required modules
from collections import OrderedDict as od
import os
import sys
import subprocess
TEMPLATE = od([
("Patient" , ""),
("Study" , ""),
("Mimics notes","")
])
TEMPLATE_3_MATIC = od([
("Processed" , "False"),
("3-matic notes","")
])
################################
PATIENT_A = od([
("Patient" , "Mat patient"),
("Study" , "CT Heart scan"),
("Mimics notes","")
])
################################
MIMICS_FILE_PATH = r"C:\MedData\DemoFiles"
MIMICS_FILE_NAME = "Heart.mcs"
PARTS_OF_INTEREST = ["LA", "LV", "Aorta"]
################################
# One script is used for the metadata tutorial for both Mimics and 3-matic.
# For that reason we have to check if we are in Mimics or in 3-matic
in_mimics = False
try:
import mimics
if mimics.get_version():
in_mimics = True
except:
pass
# Mimics part
if in_mimics:
parts = []
# Open Mimics project
mimics.file.open_project(os.path.join(MIMICS_FILE_PATH, MIMICS_FILE_NAME))
# For this exercise we will remove all the metadata from the Mimics project
for p in mimics.data.parts:
for md in p.metadata:
p.metadata.delete(md.name)
# Group the required parts
mdp = mimics.data.parts
for p in PARTS_OF_INTEREST:
parts.append(mdp[p])
# Assign the template as metadata to all the parts of interest
l = list(TEMPLATE.items())
for p in parts:
for i in range(len(TEMPLATE)):
p.metadata.create(l[i][0],l[i][1])
# Fill the metadata template
patient_a = list(PATIENT_A.items())
for p in parts:
for i in range(len(PATIENT_A)):
p.metadata[l[i][0]].value = patient_a[i][1]
# Save Mimics project
mimics.file.save_project()
#Prepare to run 3-matic
trimatic = mimics.file.get_path_to_3matic()
command = trimatic
args = ("-run_script", __file__)
process = subprocess.Popen((command,) + args, shell=False, stdout=subprocess.PIPE)
else:
parts = []
trimatic.import_project(os.path.join(MIMICS_FILE_PATH, MIMICS_FILE_NAME))
# Group the required parts
tp = trimatic.get_parts()
for p in tp:
if p.name in PARTS_OF_INTEREST:
parts.append(p)
# Assign the template as metadata elements to all the parts of interest
l3m = list(TEMPLATE_3_MATIC.items())
for p in parts:
mdata = p.get_metadata()
mdata.create_multi(tuple(TEMPLATE_3_MATIC.items()))
# Smooth all the imported parts
trimatic.smooth(entities = parts)
# Add the info that the parts are smoothed and processed
l = list(TEMPLATE.items())
for p in parts:
mdata = p.get_metadata()
notes = mdata.find(l[2][0],l[2][1])
if notes:
notes.value = "Part is smoothed with default values"
processed = mdata.find(l3m[0][0],l3m[0][1])
if processed:
processed.value = "True"