How to get spatial coordinate information of an anatomical structure?
CAD Modeling
2
Posts
2
Posters
207
Views
2
Watching
-
Hello,
I am using a script to place electric dipoles within specific structures in an anatomical model, such as the gastrointestinal (GI) tract (including the stomach, small intestine, etc.). The question is, how can I get the coordinates of the space occupied by the model of the GI tract, or in other words, how can I verify that the electric dipoles I place are inside the tissue of the GI tract? Thanks for your help!
-
To get the bounding box of some tissues, say
- Large_intestine_lumen
- Large_intestine_wall
and test if some points are inside these tissues you can use the
GetEntityPointDistance
API, e.g., something like this:import numpy as np import s4l_v1.model as s4l_model Vec3 = s4l_model.Vec3 def sample_box(p1: Vec3, p2: Vec3) -> list[Vec3]: xs = np.linspace(p1[0], p2[0], 10) ys = np.linspace(p1[1], p2[1], 10) zs = np.linspace(p1[2], p2[2], 10) X, Y, Z = np.meshgrid(xs, ys, zs, indexing="ij") points = np.vstack([X.ravel(), Y.ravel(), Z.ravel()]).T return [Vec3(p) for p in points] def find_entities(root_group: s4l_model.EntityGroup, names: list[str]): entities = s4l_model.CollectEntities([root_group]) entities = [e for e in entities if e.Name in names] return entities if __name__ == "__main__": model_group = s4l_model.AllEntities()["Thelonious_6y_m_v3.1b02_posable"] entities = find_entities(model_group, ["Large_intestine_lumen", "Large_intestine_wall"]) p1, p2 = s4l_model.GetBoundingBox(entities) points = sample_box(p1, p2) inside_gi_tract = np.zeros(len(points), dtype=np.uint8) for entity in entities: distance = s4l_model.GetEntityPointDistance(entity, points) for idx, dist in enumerate(distance): # note: negative distance means inside the closed surface if dist.Distance <= 0.0: inside_gi_tract[idx] = True