Importing anatomical models in the python script
-
Hi,
It seems overly straight forward to import, e.g. the Duke to a model:
model.Import(r"C:\...\Sim4life\model\Duke (Posable) 3.1.1b02\Duke_34y_m_v3.1.1_b02_posable.sab") subject = model.AllEntities()["Duke_34y_m_v3.1.1b02_posable"]
But importing the Duke to the simulation is causing trouble at the voxeling stage. Can anyone help?
I currently have this
def add_duke_to_EM_sim(simulation): duke_group = model.AllEntities()["Duke_34y_m_v3.1.1b02_posable"] components = list(duke_group.Entities) material_settings = fdtd.MaterialSettings() automatic_voxeler_settings = fdtd.AutomaticVoxelerSettings() voxeler = automatic_voxeler_settings voxeler.Name = "Duke EM Voxels" simulation.Add(voxeler, components) simulation.Add(material_settings, components) simulation.UpdateAllMaterials()
-
What does it mean "causing trouble"? Do you get an error message, or it generates unexpected results?
-
You probably already know, but you can generate a script by setting up the simulation in the GUI, selecting it and running "To Python" in the context menu.
-
Your script is incorrect. You use only one material settings for all tissues in Duke. However, different tissues (fat, muscle, bone, blood, lung, etc.) have very different properties. To replicate what the GUI does, you probably would want to group all entities with the same material tag (
entity.MaterialName
), get the material from the database, and create linked material settings:
material_settings = emfdtd.MaterialSettings() components = [e for e in xcm.CollectEntities(duke_group.Entities) if e.MaterialName == "Muscle"] mat = database["IT'IS 4.2"]["Muscle"] simulation.LinkMaterialWithDatabase(material_settings, mat) simulation.Add(material_settings, components)
- Your script may also be wrong, because duke_group.Entities contains a sub-group "Bones". To recursively collect all entities in duke use
CollectEntities
:
import XCoreModeling as xcm duke_all_entities = xcm.CollectEntities(duke_group.Entities)
- You also want to create ManualGridSettings (with specified grid spacing), or AutomaticGridSettings, and assign the entities. You can then run
UpdateGrid
simulation.UpdateAllMaterials() simulation.UpdateGrid() simulation.CreateVoxels()
-
-
B bryn referenced this topic
-
I ended up creating my Duke model in a separate script, where I first cloned him as static. Then I removed part of the body not relevant to me by boolean subtraction (entity by entity) and finally export the remain static model to a sab file, which I load in my main script instead of the entire Duke. It has been this confusion about entities and groups and what not disturbing the flow. Thanks for your suggestions bryn