| 1 | # ------------------------------------------------------------------------------
|
|---|
| 2 | # Create a marker set placing a marker at each hidden vertex of a surface piece.
|
|---|
| 3 | #
|
|---|
| 4 | def mark_hidden_vertices(plist, radius = 1.0, rgba = (1,1,1,1),
|
|---|
| 5 | marker_set = None):
|
|---|
| 6 |
|
|---|
| 7 | for p in plist:
|
|---|
| 8 | m = p.triangleAndEdgeMask
|
|---|
| 9 | v,t = p.geometry
|
|---|
| 10 | hidden = hidden_vertices(t, m)
|
|---|
| 11 | if hidden:
|
|---|
| 12 | if marker_set is None:
|
|---|
| 13 | from VolumePath.markerset import Marker_Set
|
|---|
| 14 | marker_set = Marker_Set('vertices')
|
|---|
| 15 | marker_set.set_transform(p.model.openState.xform)
|
|---|
| 16 | positions = v[tuple(hidden),:]
|
|---|
| 17 | transform_points(positions, p.model.openState.xform,
|
|---|
| 18 | marker_set.transform())
|
|---|
| 19 | for xyz in positions:
|
|---|
| 20 | marker_set.place_marker(xyz, rgba, radius)
|
|---|
| 21 |
|
|---|
| 22 | # ------------------------------------------------------------------------------
|
|---|
| 23 | #
|
|---|
| 24 | def hidden_vertices(t, m):
|
|---|
| 25 | vis = set()
|
|---|
| 26 | all = set()
|
|---|
| 27 | for ti, tm in enumerate(m):
|
|---|
| 28 | if tm & 0x8:
|
|---|
| 29 | v0,v1,v2 = t[ti,:]
|
|---|
| 30 | for v in (v0,v1,v2):
|
|---|
| 31 | all.add(v)
|
|---|
| 32 | if tm & 0x5: # Edge 0-1 or 2-0 shown
|
|---|
| 33 | vis.add(v0)
|
|---|
| 34 | if tm & 0x3: # Edge 0-1 or 1-2 shown
|
|---|
| 35 | vis.add(v1)
|
|---|
| 36 | if tm & 0x6: # Edge 1-2 or 2-0 shown
|
|---|
| 37 | vis.add(v2)
|
|---|
| 38 | hidden = all.difference(vis)
|
|---|
| 39 | return hidden
|
|---|
| 40 |
|
|---|
| 41 | # ------------------------------------------------------------------------------
|
|---|
| 42 | #
|
|---|
| 43 | def transform_points(points, from_xf, to_xf):
|
|---|
| 44 |
|
|---|
| 45 | from chimera import Xform
|
|---|
| 46 | xf = Xform()
|
|---|
| 47 | xf.premultiply(from_xf)
|
|---|
| 48 | xf.premultiply(to_xf.inverse())
|
|---|
| 49 | from Matrix import xform_matrix
|
|---|
| 50 | tf = xform_matrix(xf)
|
|---|
| 51 | import _contour
|
|---|
| 52 | _contour.affine_transform_vertices(points, tf)
|
|---|
| 53 |
|
|---|
| 54 | # ------------------------------------------------------------------------------
|
|---|
| 55 | #
|
|---|
| 56 | import Surface
|
|---|
| 57 | plist = Surface.selected_surface_pieces()
|
|---|
| 58 | mark_hidden_vertices(plist)
|
|---|