def _show_prickles(surface, length=1, color=None, prickles_model=None, children=True): va, na, ta = surface.vertices, surface.normals, surface.triangles if not va is None and not na is None: n = len(va) from numpy import empty, float32, int32, arange van = empty((2 * n, 3), float32) van[:n, :] = va for a in range(3): van[n:, a] = va[:, a] + length * na[:, a] tan = empty((n, 2), int32) tan[:, 0] = arange(n) tan[:, 1] = tan[:, 0] + n from chimerax.core.models import Model pm = Model('prickles', surface.session) pm.set_geometry(van, None, tan) pm.display_style = pm.Mesh pm.color = color.uint8x4() if color else (0, 255, 0, 255) pm.use_lighting = False if prickles_model: p = prickles_model pp, sp = prickles_model.scene_position, surface.position if not pp.is_identity() or not sp.is_identity(): (pp.inverse() * sp).transform_points(van, in_place=True) else: p = surface p = prickles_model if prickles_model else surface p.add([pm]) if children: for d in drawing.child_drawings(): show_prickles(d, length, color, prickles_model)
def lines_model(session, points, line_segments, name='vtk lines', color=(255, 255, 255, 255)): from chimerax.core.models import Model m = Model(name, session) m.set_geometry(points, None, line_segments) m.display_style = m.Mesh m.color = color return m
def smoothlines(session, models, step_factor=0.1, iterations=10, replace=False): ''' Smooth surface models consisting of lines. Each vertex is moved the fraction step_factor towards the average position of it and its connected neighbors. This is repeated for the specified number of iterations. A new model is created unless the replace option is given in which case the current model is changed. Parameters ---------- models : list Surface The surfaces must consist of line segments. step_factor : float Fraction of distance to move each vertex toward average of itself and connected neighbors. Default 0.1 iterations : integer Number of times to repeat smoothing. Default 10. replace : bool Whether to replace the lines in the existing model, or make a new model. ''' if len(models) == 0: from chimerax.core.errors import UserError raise UserError( 'smoothlines: No surface models specified. Only operates on mesh lines.' ) for model in models: ta = model.triangles if ta is None or ta.shape[1] != 2: from chimerax.core.errors import UserError raise UserError('Surface model %s does not consist of lines' % model.name) va = model.vertices sva = smoothed_vertices(va, ta, step_factor, iterations) if replace: model.set_geometry(sva, model.normals, model.triangles) else: from chimerax.core.models import Model m = Model('%s smoothed' % model.name, session) m.set_geometry(sva, model.normals, ta) m.display_style = m.Mesh m.color = model.color session.models.add([m]) model.display = False