Mask Filter from Python, How to exclude the background (for example)
-
The API of the MaskFilter algorithm does not allow un-selecting a given entity. The only way to select "everything except one" is actually to first unselect everything and then enable all the entities (except one) again.
Below is an example that does that for an anatomical model (or any other group of entities).
It uses a short helper function that returns the list of all model objects (aka entities) that are within a certain model folder (aka Entity Group). This list of objects is then passed to the MaskFilter.
import s4l_v1.analysis as analysis import s4l_v1.document as document import s4l_v1.model as model import itertools def all_entities_within_group(entity_group): '''return a list of all model entities within a given group, including all subdirectories''' if isinstance(entity_group, model.EntityGroup): return list(itertools.chain.from_iterable( all_entities_within_group(e) for e in entity_group.Entities)) else: return [entity_group] vip_group = model.AllEntities()['Duke'] entities_from_vip_model = all_entities_within_group(vip_group) # Creating the analysis pipeline # Adding a new SimulationExtractor simulation = document.AllSimulations["EM"] simulation_extractor = simulation.Results() # Adding a new EmSensorExtractor em_sensor_extractor = simulation_extractor["Overall Field"] document.AllAlgorithms.Add(em_sensor_extractor) # Adding a new FieldMaskingFilter inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]] field_masking_filter = analysis.core.FieldMaskingFilter(inputs=inputs) field_masking_filter.SetAllMaterials(False) field_masking_filter.SetEntities(entities_from_vip_model) field_masking_filter.UpdateAttributes() document.AllAlgorithms.Add(field_masking_filter)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login