def add_actor(self, *actors, name=None, br_class=None, store=None): """ Add a vtk actor to the scene :param actor: :param store: a list to store added actors """ # Parse inputs to match a name and br class to each actor actors, names, br_classes = parse_add_actors_inputs( actors, name, br_class) # Add actors to scene to_return = [] for actor, name, br_class in zip(actors, names, br_classes): for act in listify(actor): if act is None: continue try: act = Actor(act, name=name, br_class=br_class) except Exception: # doesn't work for annotations act.name = name act.br_class = br_class act._is_transformed = False if store is None: self.actors.append(act) else: store.append(act) to_return.append(act) return return_list_smart(to_return)
def add_actor_label(self, actors, labels, **kwargs): """ Prepares an actor label. Labels are only created when `Scene.render` is called. :param kwargs: key word arguments can be passed to determine text appearance and location: - size: int, text size. Default 300 - color: str, text color. A list of colors can be passed if None the actor's color is used. Default None. - xoffset, yoffset, zoffset: integers that shift the label position - radius: radius of sphere used to denote label anchor. Set to 0 or None to hide. """ for actor, label in zip(listify(actors), listify(labels)): actor._needs_label = True actor._label_str = label actor._label_kwargs = kwargs
def add_plane(self, plane, **kwargs): """ Adds one or more planes to the scene. For more details on how to build custom planes, check: brainrender/atlases/base.py -> Base.get_plane_at_point method. :param plane: either a string with the name of one of the predifined planes ['sagittal', 'coronal', 'horizontal'] or an instance of the Plane class from vedo.shapes """ if self.transform_applied: rprint( f"[b {salmon}]Warning: [/b {salmon}][{mocassin}]you're attempting to add a plane " + "after having rendered the scene at lest once, this might give unpredicable results." + "\nIt's advised to perform add all planes before the first call to `render`" ) planes = listify(plane).copy() actors = [] for plane in planes: if isinstance(plane, str): plane = self.atlas.get_plane_at_point(plane=plane, **kwargs) else: if not isinstance(plane, Plane): raise ValueError( "The plane arguments should either be a Plane actor or" + "a string with the name of predefined planes." + f" Not: {plane.__type__}") actors.append(plane) self.add_actor(*actors, name="plane", br_class="plane") return return_list_smart(actors)
def add_neurons(self, *args, **kwargs): """ Adds rendered morphological data of neurons reconstructions. Check the atlas' method to know how it works """ actors, store = self.atlas.get_neurons(*args, **kwargs) if store is not None: for n, v in store.items(): self.store[n] = v to_return = [] for act in listify(actors): if isinstance(act, dict): act = self.add_actor(list(act.values()), name="neuron", br_class="neuron") to_return.append(act) else: act = self.add_actor(list(actors), name="neuron", br_class="neuron") to_return.append(act) return to_return
def cut_actors_with_plane( self, plane, actors=None, showplane=False, returncut=False, close_actors=False, **kwargs, ): if self.transform_applied: rprint( f"[b {salmon}]Warning: [/b {salmon}][{mocassin}]you're attempting to cut actors with a plane " + "after having rendered the scene at lest once, this might give unpredicable results." + "\nIt's advised to perform all cuts before the first call to `render`" ) # Loop over each plane planes = listify(plane).copy() to_return = [] for plane in planes: # Get the plane actor if isinstance(plane, str): plane = self.atlas.get_plane_at_point(plane=plane, **kwargs) else: if not isinstance(plane, Plane): raise ValueError( "The plane arguments should either be a Plane actor or" + "a string with the name of predefined planes." + f" Not: {plane.__type__}") # Show plane if showplane: self.add_actor(plane) # Cut actors if actors is None: actors = self.actors.copy() for actor in listify(actors): if actor is None: continue try: actor.mesh = actor.mesh.cutWithPlane( origin=plane.center, normal=plane.normal, returnCut=returncut, ) except AttributeError: # some rendered objects can't be cut (e.g.text 2d) continue if returncut: to_return.append(actor) if close_actors: actor.cap() if len(to_return) == 1: return to_return[0] else: return to_return