def add(self, *items, names=None, classes=None, **kwargs): """ General method to add Actors to the scene. :param items: vedo.Mesh, Actor, (str, Path). If str/path it should be a path to a .obj or .stl file. Whatever the input it's turned into an instance of Actor before adding it to the scne :param names: names to be assigned to the Actors :param classs: br_classes to be assigned to the Actors :param **kwargs: parameters to be passed to the individual loading functions (e.g. to load from file and specify the color) """ names = names or [None for a in items] classes = classes or [None for a in items] # turn items into Actors actors = [] for item, name, _class in zip(items, listify(names), listify(classes)): if item is None: continue if isinstance(item, (Mesh, Assembly)): actors.append(Actor(item, name=name, br_class=_class)) elif pi.utils._class_name(item) == "vtkCornerAnnotation": # Mark text actors differently because they don't behave like # other 3d actors actors.append( Actor( item, name=name, br_class=_class, is_text=True, **kwargs, )) elif pi.utils._class_name(item) == "Volume" and not isinstance( item, Volume): actors.append( Volume(item, name=name, br_class=_class, **kwargs)) elif isinstance(item, Actor): actors.append(item) elif isinstance(item, (str, Path)): mesh = load_mesh_from_file(item, **kwargs) name = name or Path(item).name _class = _class or "from file" actors.append(Actor(mesh, name=name, br_class=_class)) else: raise ValueError( f"Unrecognized argument: {item} [{pi.utils._class_name(item)}]" ) # Add to the lists actors self.actors.extend(actors) return return_list_smart(actors)
def get_region(self, *regions, alpha=1, color=None): """ Get brain regions meshes as Actors :param regions: str with names of brain regions in the atlas :param alpha: float :param color: str """ if not regions: return None _color = color actors = [] for region in regions: if ( region not in self.lookup_df.acronym.values and region not in self.lookup_df["id"].values ): print( f"The region {region} doesn't seem to belong to the atlas being used: {self.atlas_name}. Skipping" ) continue # Get mesh obj_file = str(self.meshfile_from_structure(region)) mesh = load_mesh_from_file(obj_file, color=color, alpha=alpha) # Get color if color is None: color = [ x / 255 for x in self._get_from_structure(region, "rgb_triplet") ] # Make actor actor = Actor(mesh, name=region, br_class="brain region") actor.c(color).alpha(alpha) actors.append(actor) # reset color to input color = _color return return_list_smart(actors)