Changeset 9ec9c67 in sasmodels


Ignore:
Timestamp:
Feb 6, 2019 3:09:52 PM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3d7f364
Parents:
b1c49601
Message:

note techniques for smooth rotation and transparency in ipyvolume jitter viewer code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/jitter.py

    rb1c49601 r9ec9c67  
    11101110} 
    11111111def ipv_fix_color(kw): 
    1112     kw.pop('alpha', None) 
     1112    alpha = kw.pop('alpha', None) 
    11131113    color = kw.get('color', None) 
    11141114    if isinstance(color, str): 
    11151115        color = _IPV_COLORS.get(color, color) 
    11161116        kw['color'] = color 
     1117    if alpha is not None: 
     1118        color = kw['color'] 
     1119        #TODO: convert color to [r, g, b, a] if not already 
     1120        if isinstance(color, np.ndarray) and color.shape[-1] == 4: 
     1121            color[..., 3] = alpha 
     1122            kw['color'] = color 
     1123 
     1124def ipv_set_transparency(kw, obj): 
     1125    color = kw.get('color', None) 
     1126    if (isinstance(color, np.ndarray) 
     1127            and color.shape[-1] == 4 
     1128            and (color[..., 3] != 1.0).any()): 
     1129        obj.material.transparent = True 
     1130        obj.material.side = "FrontSide" 
    11171131 
    11181132def ipv_axes(): 
     
    11201134 
    11211135    class Plotter: 
     1136        # transparency can be achieved by setting the following: 
     1137        #    mesh.color = [r, g, b, alpha] 
     1138        #    mesh.material.transparent = True 
     1139        #    mesh.material.side = "FrontSide" 
     1140        # smooth(ish) rotation can be achieved by setting: 
     1141        #    slide.continuous_update = True 
     1142        #    figure.animation = 0. 
     1143        #    mesh.material.x = x 
     1144        #    mesh.material.y = y 
     1145        #    mesh.material.z = z 
     1146        # maybe need to synchronize update of x/y/z to avoid shimmy when moving 
    11221147        def plot(self, x, y, z, **kw): 
    11231148            ipv_fix_color(kw) 
     
    11301155            ipv_fix_color(kw) 
    11311156            x, y, z = make_vec(x, y, z) 
    1132             ipv.plot_surface(x, y, z, **kw) 
     1157            h = ipv.plot_surface(x, y, z, **kw) 
     1158            ipv_set_transparency(kw, h) 
     1159            return h 
    11331160        def plot_trisurf(self, x, y, triangles=None, Z=None, **kw): 
    11341161            ipv_fix_color(kw) 
     
    11361163            if triangles is not None: 
    11371164                triangles = np.asarray(triangles) 
    1138             ipv.plot_trisurf(x, y, z, triangles=triangles, **kw) 
     1165            h = ipv.plot_trisurf(x, y, z, triangles=triangles, **kw) 
     1166            ipv_set_transparency(kw, h) 
     1167            return h 
    11391168        def scatter(self, x, y, z, **kw): 
    11401169            x, y, z = make_vec(x, y, z) 
     
    11421171            marker = kw.get('marker', None) 
    11431172            kw['marker'] = _IPV_MARKERS.get(marker, marker) 
    1144             ipv.scatter(x, y, z, **kw) 
     1173            h = ipv.scatter(x, y, z, **kw) 
     1174            ipv_set_transparency(kw, h) 
     1175            return h 
    11451176        def contourf(self, x, y, v, zdir='z', offset=0, levels=None, **kw): 
    11461177            # Don't use contour for now (although we might want to later) 
     
    11561187            u = np.array([[0., 1], [0, 1]]) 
    11571188            v = np.array([[0., 0], [1, 1]]) 
    1158             ipv.plot_mesh(x, y, z, u=u, v=v, texture=image, wireframe=False) 
     1189            h = ipv.plot_mesh(x, y, z, u=u, v=v, texture=image, wireframe=False) 
     1190            ipv_set_transparency(kw, h) 
     1191            return h 
    11591192        def text(self, *args, **kw): 
    11601193            pass 
     
    11811214        #print(ipv.gcf().__dict__.keys()) 
    11821215        #print(dir(ipv.gcf())) 
    1183         ipv.figure() 
     1216        ipv.figure(animation=0.)  # no animation when updating object mesh 
    11841217 
    11851218        # set small jitter as 0 if multiple pd dims 
     
    12351268            description=name, 
    12361269            disabled=False, 
     1270            #continuous_update=True, 
    12371271            continuous_update=False, 
    12381272            orientation='horizontal', 
Note: See TracChangeset for help on using the changeset viewer.