Scripts: edgeband.py

File edgeband.py, 1.2 KB (added by goddard, 10 years ago)
Line 
1# Show colored bands at the edge of a surface zone.
2
3def make_edge_bands(surf_piece):
4 p = surf_piece
5 from numpy import array, bool, zeros, logical_or, logical_and, logical_not
6 # Find mask of shown triangles.
7 t = array(p.triangleAndEdgeMask & 0x8, bool)
8 va, ta = p.geometry
9 # Compute mask of shown vertices
10 vs = zeros((len(va),), bool)
11 for a in (0,1,2):
12 vs[ta[t,a]] = 1
13 # Find mask of triangles that have a shown vertex
14 ts = logical_or(vs[ta[:,0]], vs[ta[:,1]])
15 logical_or(ts, vs[ta[:,2]], ts)
16 # Find mask of unshown triangles having a shown vertex
17 logical_and(ts, logical_not(t), ts)
18 # Copy these triangles to a new surface piece
19 if ts.sum() == 0:
20 return None
21 # Put bands in a new surface model so zone does not apply to them.
22 from _surface import SurfaceModel
23 s = SurfaceModel()
24 s.name = p.model.name + ' bands'
25 bp = s.newPiece()
26 bp.geometry = va, ta[ts,:]
27 bp.normals = p.normals
28 bp.color = (0,1,0,1) # Green
29 from chimera import openModels
30 openModels.add([s])
31 s.openState.xform = p.model.openState.xform
32 return s
33
34import Surface
35for p in Surface.selected_surface_pieces():
36 make_edge_bands(p)