carr = cone.cellCenters()[:, 2] parr = cone.points()[:, 0] cone.addCellArray(carr, 'carr') cone.addPointArray(parr, 'parr') carr = sphere.cellCenters()[:, 2] parr = sphere.points()[:, 0] sphere.addCellArray(carr, 'carr') sphere.addPointArray(parr, 'parr') sphere.addPointArray(np.sin(sphere.points()), 'pvectors') sphere.addElevationScalars() cone.computeNormals() sphere.computeNormals() ###################################### test clone() c2 = cone.clone() print('clone()', cone.N(), c2.N()) assert cone.N() == c2.N() print('clone()', cone.NCells(), c2.NCells()) assert cone.NCells() == c2.NCells() ###################################### test merge() m = merge(sphere, cone) print('merge()', m.N(), cone.N() + sphere.N()) assert m.N() == cone.N() + sphere.N() print('merge()', m.NCells(), cone.NCells() + sphere.NCells())
def make_actor_label( atlas, actors, labels, size=300, color=None, radius=100, xoffset=0, yoffset=-500, zoffset=0, ): """ Adds a 2D text ancored to a point on the actor's mesh to label what the actor is :param kwargs: keyword 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 a gray 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. """ offset = [-yoffset, -zoffset, xoffset] default_offset = np.array([0, -200, 100]) new_actors = [] for n, (actor, label) in enumerate(zip(listify(actors), listify(labels))): # Get label color if color is None: color = [0.2, 0.2, 0.2] # Get mesh's highest point points = actor.mesh.points().copy() point = points[np.argmin(points[:, 1]), :] point += np.array(offset) + default_offset point[2] = -point[2] try: if atlas.hemisphere_from_coords(point, as_string=True) == "left": point = atlas.mirror_point_across_hemispheres(point) except IndexError: pass # Create label txt = Text3D(label, point * np.array([1, 1, -1]), s=size, c=color, depth=0.1) new_actors.append( txt.rotateX(180, locally=True).rotateY(180, locally=True)) # Mark a point on Mesh that corresponds to the label location if radius is not None: pt = actor.closestPoint(point) pt[2] = -pt[2] sphere = Sphere(pt, r=radius, c=color, res=8) sphere.ancor = pt new_actors.append(sphere) sphere.computeNormals() return new_actors