def sslice ( v1, v2, varno = 1, nslices = 1, opt_3d = None) : """This function slices a Mesh3d or a previous Slice object, and returns a new Slice object, depending on how it is called. sslice (m, plane, varno = 1) returns a plane Slice through the specified mesh m. varno is the number of the variable to be used to color the Slice (1-based). sslice (m, val, varno = 1) returns an isosurface Slice of m. varno is the number of the variable with respect to which the Slice is taken (1-based) and val is its value on the isosurface. varno can be let default to 1 if there is only one function to worry about. sslice (s, plane, nslices = 1) slices the isosurface s and returns the part in "front" of the plane if nslices == 1, or returns a pair of Slices [front, back] if nslices == 2. If s is a Surface, then this operation will produce a Slice or pair of Slices from the given Surface. N. B. If you want just the "back" surface, you can achieve this by calling sslice with - plane instead of plane. The opt_3d argument can be used to overrule defaults, which are intelligently figured out, but may not always be what you want. """ if v1.type () == Mesh3dType : if type (v1.c) != ListType : funcs = [v1.c] else : funcs = v1.c if not hasattr (v2, "type") or v2.type () != PlaneType : try : val = float (v2) except : raise _SliceError, \ "second argument is not coercible to float." plane = None else : plane = v2 val = None if opt_3d is None : if plane is not None: opt_3d = ["wm", "f4"] else : opt_3d = ["f4"] # First we build a "mesh3" if v1 does not already have one. if v1.structured : #and not hasattr (v1, "m3") : setattr (v1, "m3", mesh3 (v1.x, v1.y, v1.z, funcs = funcs)) elif not v1.structured and v1.avs == 1 : #and not hasattr (v1, "m3") : if no_of_dims (v1.x) == 3 and \ no_of_dims (v1.y) == 3 and \ no_of_dims (v1.z) == 3 : setattr (v1, "m3", mesh3 (array ( [v1.x, v1.y, v1.z], Float), funcs = funcs)) elif no_of_dims (v1.x) == 1 and \ no_of_dims (v1.y) == 1 and \ no_of_dims (v1.z) == 1 : setattr (v1, "m3", mesh3 (v1.x, v1.y, v1.z, funcs = funcs, verts = v1.get_verts_list ())) else : raise _SliceError, \ "x, y, and z must have either 1 or 3 dimensions." elif not hasattr (v1, "m3") : raise _SliceError, \ "Option not implemented." # A Yorick 'mesh3' object now exists, slice it as specified. if plane is None : # An isosurface Slice [nv, xyzv, dum] = slice3 (v1.m3, varno, None, None, value = val) return Slice (nv, xyzv, iso = val, opt_3d = opt_3d) else : # a plane Slice [nv, xyzv, val] = slice3 (v1.m3, plane.rep (), None, None, varno ) return Slice (nv, xyzv, val, plane = plane, opt_3d = opt_3d) elif v1.type () == SurfaceType : plane = v2 if not hasattr (v2, "type") or v2.type () != PlaneType : raise _SliceError, \ "Second argument is not a Plane." if v1.z_c_switch : z = v1.c c = v1.z if "s3" in v1.opt_3d : scale = v1.c_contours_scale if v1.c_contours_array is not None: contours = v1.c_contours_array else : contours = v1.number_of_c_contours elif "s4" in v1.opt_3d : scale = v1.z_contours_scale if v1.z_contours_array is not None: contours = v1.z_contours_array else : contours = v1.number_of_z_contours else : z = v1.z c = v1.c if "s3" in v1.opt_3d : scale = v1.z_contours_scale if v1.z_contours_array is not None: contours = v1.z_contours_array else : contours = v1.number_of_z_contours elif "s4" in v1.opt_3d : scale = v1.c_contours_scale if v1.c_contours_array is not None: contours = v1.c_contours_array else : contours = v1.number_of_c_contours edges = "w3" in v1.opt_3d or "w4" in v1.opt_3d or "wm" in v1.opt_3d \ or "i3" in v1.opt_3d or "i4" in v1.opt_3d if "s4" in v1.opt_3d : [nv, xyzv, col] = slice3mesh (v1.x, v1.y, z, color = c, smooth = 1) elif "f3" in v1.opt_3d : [nv, xyzv, col] = slice3mesh (v1.x, v1.y, z, color = z, smooth = 0) contours = None scale = "lin" elif "f4" in v1.opt_3d : [nv, xyzv, col] = slice3mesh (v1.x, v1.y, z, color = c, smooth = 0) contours = None scale = "lin" else : [nv, xyzv, col] = slice3mesh (v1.x, v1.y, z) contours = None scale = "lin" if nslices == 1 : [nv, xyzv, col] = slice2 (plane.rep (), nv, xyzv, col) return Slice (nv, xyzv, col, opt_3d = v1.opt_3d, mask = v1.mask, contours = contours, scale = scale, edges = edges) elif nslices == 2 : [nv, xyzv, col, nb, xyzb, valb] = slice2x (plane.rep (), nv, xyzv, col) return [Slice (nv, xyzv, col, opt_3d = v1.opt_3d, mask = v1.mask, contours = contours, scale = scale, edges = edges), Slice (nb, xyzb, valb, opt_3d = v1.opt_3d, mask = v1.mask, contours = contours, scale = scale, edges = edges)] else : raise _SliceError, "Illegal number (" + `nslices` + \ ") of slices requested." elif v1.type () == Slice3dType : plane = v2 if not hasattr (v2, "type") or v2.type () != PlaneType : raise _SliceError, \ "Second argument is not a Plane." if nslices == 1 : [nv, xyzv, val] = slice2 (plane.rep (), v1.nv, v1.xyzv, v1.val) return Slice (nv, xyzv, val, plane = v1.plane, iso = v1.iso, opt_3d = v1.opt_3d) elif nslices == 2 : [nf, xyzf, valf, nb, xyzb, valb] = slice2x (plane.rep (), v1.nv, v1.xyzv, v1.val) return [Slice (nf, xyzf, valf, plane = v1.plane, iso = v1.iso, opt_3d = v1.opt_3d), Slice (nb, xyzb, valb, plane = v1.plane, iso = v1.iso, opt_3d = v1.opt_3d)] else : raise _SliceError, "Illegal number (" + `nslices` + \ ") of slices requested." else : raise _SliceError, "Can only slice a Mesh3d or another Slice."
def run (*itest) : """run() or run(i) Run examples of use of pl3d.i, plwf.i, and slice3.i. With argument I = 1, 2, or 3, run that particular demonstration. Read the source code to understand the details of how the various effects are obtained. run (1) demonstrates the various effects which can be obtained with the plwf (plot wire frame) function. run (2) demonstrates shading effects controlled by the light3 function run (3) demonstrates the slice3, slice2, and pl3tree functions, as well as changing the orientation of the 3D object """ global making_movie if len (itest) == 0 or itest [0] == 1 : set_draw3_ (0) x = span (-1, 1, 64, 64) y = transpose (x) z = (x + y) * exp (-6.*(x*x+y*y)) limits_(square = 1) print "Plot wire frame: plwf (z, y, x)" orient3 ( ) light3 ( ) plwf (z, y, x) [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits (xmin, xmax, ymin, ymax) plt("opaque wire mesh", .30, .42) paws ( ) print 'plwf(z,y,x,shade=1,ecolor="red")' plwf(z,y,x,shade=1,ecolor="red") [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits (xmin, xmax, ymin, ymax) paws() print "plwf(z,y,x,shade=1,edges=0)" plwf(z,y,x,shade=1,edges=0) [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits (xmin, xmax, ymin, ymax) paws ( ) print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))" light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1])) [xmin, xmax, ymin, ymax] = draw3(1) limits (xmin, xmax, ymin, ymax) paws ( ) print "light3 ( diffuse=.5, specular=1., sdir=array([1,.5,1]))" light3 ( diffuse=.5, specular=1., sdir=array([1,.5,1])) [xmin, xmax, ymin, ymax] = draw3 (1) limits (xmin, xmax, ymin, ymax) paws ( ) print "light3 ( ambient=.1,diffuse=.1,specular=1.," print " sdir=array([[0,0,-1],[1,.5,1]]),spower=array([4,2]))" light3 ( ambient=.1,diffuse=.1,specular=1., sdir=array([[0,0,-1],[1,.5,1]]),spower=array([4,2])) [xmin, xmax, ymin, ymax] = draw3(1) limits (xmin, xmax, ymin, ymax) paws ( ) if len (itest) == 0 or itest [0] == 2 : set_draw3_ (0) x = span (-1, 1, 64, 64) y = transpose (x) z = (x + y) * exp (-6.*(x*x+y*y)) print "Default lighting: light3()" orient3 ( ) light3 ( ) plwf (z,y,x,shade=1,edges=0) [xmin, xmax, ymin, ymax] = draw3 (1) # not necessary interactively limits (xmin, xmax, ymin, ymax) paws( ) print "light3(diffuse=.2,specular=1)" light3(diffuse=.2,specular=1) limits_(square = 1) [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits (xmin, xmax, ymin, ymax) paws() print "movie(demo5_light, lims = [xmin, xmax, ymin, ymax])" print "demo5_light calls:" print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], Float))" making_movie = 1 movie(demo5_light, lims = [xmin, xmax, ymin, ymax]) making_movie = 0 fma() demo5_light(1) paws() light3() if len (itest) == 0 or itest [0] == 3 : nx = demo5_n [0] ny = demo5_n [1] nz = demo5_n [2] xyz = zeros ( (3, nx, ny, nz), Float) xyz [0] = multiply.outer ( span (-1, 1, nx), ones ( (ny, nz), Float)) xyz [1] = multiply.outer ( ones (nx, Float), multiply.outer ( span (-1, 1, ny), ones (nz, Float))) xyz [2] = multiply.outer ( ones ( (nx, ny), Float), span (-1, 1, nz)) r = sqrt (xyz [0] ** 2 + xyz [1] **2 + xyz [2] **2) theta = arccos (xyz [2] / r) phi = arctan2 (xyz [1] , xyz [0] + logical_not (r)) y32 = sin (theta) ** 2 * cos (theta) * cos (2 * phi) m3 = mesh3 (xyz, funcs = [r * (1. + y32)]) del r, theta, phi, xyz, y32 print " test uses " + `(nx - 1) * (ny - 1) * (nz - 1)` + " cells" elapsed = [0., 0., 0.] elapsed = timer_ (elapsed) elapsed0 = elapsed [nv, xyzv, dum] = slice3 (m3, 1, None, None, value = .50) # (inner isosurface) [nw, xyzw, dum] = slice3 (m3, 1, None, None, value = 1.) # (outer isosurface) pxy = plane3 ( array ([0, 0, 1], Float ), zeros (3, Float)) pyz = plane3 ( array ([1, 0, 0], Float ), zeros (3, Float)) [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1) # (pseudo-colored slice) [np, xyzp, vp] = slice2 (pxy, np, xyzp, vp) # (cut slice in half) [nv, xyzv, d1, nvb, xyzvb, d2] = \ slice2x (pxy, nv, xyzv, None) [nv, xyzv, d1] = \ slice2 (- pyz, nv, xyzv, None) # (...halve one of those halves) [nw, xyzw, d1, nwb, xyzwb, d2] = \ slice2x ( pxy , nw, xyzw, None) # (split outer in halves) [nw, xyzw, d1] = \ slice2 (- pyz, nw, xyzw, None) elapsed = timer_ (elapsed) timer_print ("slicing time", elapsed - elapsed0) fma () print 'Generate palette for pl3tree: split_palette ("earth.gp")' split_palette ("earth.gp") print "gnomon -- turn on gnomon" gnomon (1) print "pl3tree with 1 slicing plane, 2 isosurfaces" clear3 () # Make sure we don't draw till ready set_draw3_ (0) pl3tree (np, xyzp, vp, pyz) pl3tree (nvb, xyzvb) pl3tree (nwb, xyzwb) pl3tree (nv, xyzv) pl3tree (nw, xyzw) orient3 () light3 (diffuse = .2, specular = 1) limits () limits (square=1) demo5_light (1) paws () hcp () print "spin3 animated rotation, use rot3 or orient3 for one frame" # don't want limits to autoscale during animation lims = limits ( ) spin3 () limits ( ) # back to autoscaling demo5_light (1) paws () light3 () gnomon (0) limits (square = 1) palette ("gray.gp") # .. PR is not available. Comment out this section. # if len (itest) == 0 or itest [0] == 4 : # from PR import * # f = PR ('./bills_plot') # n_nodes = f.NumNodes # n_z = f.NodesOnZones # x = f.XNodeCoords # y = f.YNodeCoords # z = f.ZNodeCoords # c = f.ZNodeVelocity # n_zones = f.NumZones # # Put vertices in right order for Gist # n_z = transpose ( # take (transpose (n_z), array ( [0, 4, 3, 7, 1, 5, 2, 6]),axis=0)) # m3 = mesh3 (x, y, z, funcs = [c], verts = n_z ) # [0:10]) # [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) ) # pyz = plane3 ( array ([1, 0, 0], Float ), zeros (3, Float)) # pxz = plane3 ( array ([0, 1, 0], Float ), zeros (3, Float)) # # # draw a colored plane first # fma () # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1) # pl3tree (np, xyzp, vp, pyz, split = 0) # palette ("rainbow.gp") # orient3 () # demo5_light (1) # paws () # # # [nv, xyzv, d1] = \ # slice2 (- pyz, nv, xyzv, None) # [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) ) # [nw, xyzw, d1] = \ # slice2 (- pyz, nw, xyzw, None) # [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .5 * min (c) ) # [nvi, xyzvi, cvi] = \ # slice2 (- pyz, nvi, xyzvi, cvi) # [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .5 * max (c) ) # [nvj, xyzvj, cvj] = \ # slice2 (- pyz, nvj, xyzvj, cvj) # # fma () # print "gnomon -- turn on gnomon" # gnomon (1) # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # pl3tree (nv, xyzv) # , cv) # pl3tree (nw, xyzw) # , cw) # pl3tree (nvi, xyzvi) # , cvi) # pl3tree (nvj, xyzvj) # , cvi) # orient3 () # light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1]) # limits (square=1) # palette ("gray.gp") # demo5_light (1) # paws () # # print "spin3 animated rotation, use rot3 or orient3 for one frame" # # don't want limits to autoscale during animation # spin3 () # limits ( ) # back to autoscaling # demo5_light (1) # paws () # # light3 () # gnomon (0) # palette ("gray.gp") # # draw3 ( 1 ) # paws () # clear3 () # del nv, xyzv, cv, nw, xyzw, cw, nvi, xyzvi, cvi, nvj, xyzvj, cvj # # Make sure we don't draw till ready # set_draw3_ (0) # for i in range (8) : # [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) + # i * (.9 * max (c) - .9 * min (c)) / 8.) # [nv, xyzv, d1] = \ # slice2 (pxz, nv, xyzv, None) # pl3tree (nv, xyzv) # orient3 () # light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1]) # limits (square=1) # palette ("heat.gp") # demo5_light (1) # paws () # spin3 () # limits ( ) # back to autoscaling # demo5_light (1) # paws () # demo5_light (1) # paws () # # if len (itest) == 0 or itest [0] == 5 : # # Try bert's data # from PR import PR # f = PR ('./berts_plot') # nums = array ( [63, 63, 49], Int) # dxs = array ( [2.5, 2.5, 10.], Float ) # x0s = array ( [-80., -80., 0.0], Float ) # c = f.c # # m3 = mesh3 (nums, dxs, x0s, funcs = [transpose (c)]) # [nv, xyzv, dum] = slice3 (m3, 1, None, None, value = 6.5) # fma () # clear3 () # print "gnomon -- turn on gnomon" # gnomon (1) # # Make sure we don't draw till ready # set_draw3_ (0) # palette ("rainbow.gp") # pl3tree (nv, xyzv) # orient3 () # light3 (diffuse = .2, specular = 1) # limits (square=1) # demo5_light (1) # paws () # spin3 () # demo5_light (1) # paws () # if len (itest) == 0 or itest [0] == 6 : # # Try Bill's irregular mesh # from PR import PR # f = PR ("ball.s0001") # ZLss = f.ZLstruct_shapesize # ZLsc = f.ZLstruct_shapecnt # ZLsn = f.ZLstruct_nodelist # x = f.sap_mesh_coord0 # y = f.sap_mesh_coord1 # z = f.sap_mesh_coord2 # c = f.W_vel_data # # Now we need to convert this information to avs-style data # istart = 0 # beginning index into ZLstruct_nodelist # NodeError = "NodeError" # ntet = 0 # nhex = 0 # npyr = 0 # nprism = 0 # nz_tet = [] # nz_hex = [] # nz_pyr = [] # nz_prism = [] # for i in range (4) : # if ZLss [i] == 4 : # TETRAHEDRON # nz_tet = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # ntet = ZLsc [i] # istart = istart + ZLss [i] * ZLsc [i] # elif ZLss[i] == 5 : # PYRAMID # nz_pyr = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # npyr = ZLsc [i] # # Now reorder the points (bill has the apex last instead of first) # nz_pyr = transpose ( # take (transpose (nz_pyr), array ( [4, 0, 1, 2, 3]),axis=0)) # istart = istart + ZLss [i] * ZLsc [i] # elif ZLss[i] == 6 : # PRISM # nz_prism = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # nprism = ZLsc [i] # # now reorder the points (bill goes around a square face # # instead of traversing the opposite sides in the same direction. # nz_prism = transpose ( # take (transpose (nz_prism), array ( [0, 1, 3, 2, 4, 5]),axis=0)) # istart = istart + ZLss [i] * ZLsc [i] # elif ZLss[i] == 8 : # HEXAHEDRON # nz_hex = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # # now reorder the points (bill goes around a square face # # instead of traversing the opposite sides in the same direction. # nz_hex = transpose ( # take (transpose (nz_hex), array ( [0, 1, 3, 2, 4, 5, 7, 6]),axis=0)) # nhex = ZLsc [i] # istart = istart + ZLss [i] * ZLsc [i] # else : # raise NodeError, `ZLss[i]` + "is an incorrect number of nodes." # m3 = mesh3 (x, y, z, funcs = [c], verts = [nz_tet, nz_pyr, nz_prism, # nz_hex]) # [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) ) # pyz = plane3 ( array ([1, 0, 0], Float ), zeros (3, Float)) # pxz = plane3 ( array ([0, 1, 0], Float ), zeros (3, Float)) # # # draw a colored plane first # fma () # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1) # pl3tree (np, xyzp, vp, pyz, split = 0) # palette ("rainbow.gp") # orient3 () # limits (square=1) # demo5_light (1) # paws () # # [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) ) # [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .1 * min (c) ) # [nvi, xyzvi, cvi] = \ # slice2 (- pyz, nvi, xyzvi, cvi) # [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .1 * max (c) ) # [nvj, xyzvj, cvj] = \ # slice2 (- pyz, nvj, xyzvj, cvj) # [nvii, xyzvii, cvii] = slice3 (m3, 1, None, None, 1, # value = 1.e-12 * min (c) ) # [nvii, xyzvii, cvii] = \ # slice2 (- pyz, nvii, xyzvii, cvii) # [nvjj, xyzvjj, cvjj] = slice3 (m3, 1, None, None, 1, # value = 1.e-12 * max (c) ) # [nvjj, xyzvjj, cvjj] = \ # slice2 (- pyz, nvjj, xyzvjj, cvjj) # # fma () # print "gnomon -- turn on gnomon" # gnomon (1) # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # pl3tree (nv, xyzv) # , cv) # pl3tree (nw, xyzw) # , cw) # pl3tree (nvi, xyzvi) # , cvi) # pl3tree (nvj, xyzvj) # , cvj) # pl3tree (nvii, xyzvii) # , cvii) # pl3tree (nvjj, xyzvjj) # , cvjj) # orient3 () # light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1]) # limits (square=1) # palette ("gray.gp") # demo5_light (1) # paws () # palette ("heat.gp") # paws () if len (itest) == 0 or itest [0] == 7 : print "Test plwf on the sombrero function" # compute sombrero function x = arange (-20, 21, dtype = Float) y = arange (-20, 21, dtype = Float) z = zeros ( (41, 41), Float) r = sqrt (add.outer ( x ** 2, y **2)) + 1e-6 z = sin (r) / r fma () clear3 () gnomon (0) # Make sure we don't draw till ready set_draw3_ (0) palette ("rainbow.gp") limits (square=1) orient3 () light3 () plwf (z, fill = z, ecolor = "black") [xmin, xmax, ymin, ymax] = draw3 (1) limits (xmin, xmax, ymin, ymax) paws () print "Try smooth contours, log mode:" print 'plzcont (nv, xyzv, contours = 20, scale = "normal")' [nv, xyzv, dum] = slice3mesh (x, y, z) zmult = max (max (abs (x)), max (abs (y))) plzcont (nv, xyzv, contours = 20, scale = "normal") [xmin, xmax, ymin, ymax] = draw3 (1) limits (xmin, xmax, ymin, ymax) paws () print 'plzcont (nv, xyzv, contours = 20, scale = "lin", edges=1)' plzcont (nv, xyzv, contours = 20, scale = "lin", edges=1) [xmin, xmax, ymin, ymax] = draw3 (1) limits (xmin, xmax, ymin, ymax) paws () print 'plwf (z, fill = z, shade = 1, ecolor = "black")' plwf (z, fill = z, shade = 1, ecolor = "black") [xmin, xmax, ymin, ymax] = draw3 (1) limits (xmin, xmax, ymin, ymax) paws () print "plwf (z, fill = z, shade = 1, edges = 0)" plwf (z, fill = z, shade = 1, edges = 0) [xmin, xmax, ymin, ymax] = draw3 (1) limits (xmin, xmax, ymin, ymax) paws () print "light3(diffuse=.2,specular=1)" print "demo5_light calls:" print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], Float))" light3(diffuse=.2,specular=1) making_movie = 1 movie(demo5_light, lims = [xmin, xmax, ymin, ymax]) making_movie = 0 fma() demo5_light(1) paws () print "plwf (z, fill = None, shade = 1, edges = 0)" plwf (z, fill = None, shade = 1, edges = 0) [xmin, xmax, ymin, ymax] = draw3 (1) palette("gray.gp") limits (xmin, xmax, ymin, ymax) paws () if len (itest) == 0 or itest [0] == 8 : print "Test pl3surf on the sombrero function" # compute sombrero function nc1 = 100 nv1 = nc1 + 1 br = - (nc1 / 2) tr = nc1 / 2 + 1 x = arange (br, tr, dtype = Float) * 40. / nc1 y = arange (br, tr, dtype = Float) * 40. / nc1 z = zeros ( (nv1, nv1), Float) r = sqrt (add.outer ( x ** 2, y **2)) + 1e-6 z = sin (r) / r # In order to use pl3surf, we need to construct a mesh # using mesh3. The way I am going to do that is to define # a function on the 3d mesh so that the sombrero function # is its 0-isosurface. z0 = min (ravel (z)) z0 = z0 - .05 * abs (z0) maxz = max (ravel (z)) maxz = maxz + .05 * abs (maxz) zmult = max (max (abs (x)), max (abs (y))) dz = (maxz - z0) nxnynz = array ( [nc1, nc1, 1], Int) dxdydz = array ( [1.0, 1.0, zmult*dz], Float ) x0y0z0 = array ( [float (br), float (br), z0*zmult], Float ) meshf = zeros ( (nv1, nv1, 2), Float ) meshf [:, :, 0] = zmult*z - (x0y0z0 [2]) meshf [:, :, 1] = zmult*z - (x0y0z0 [2] + dxdydz [2]) m3 = mesh3 (nxnynz, dxdydz, x0y0z0, funcs = [meshf]) fma () # Make sure we don't draw till ready set_draw3_ (0) pldefault(edges=0) [nv, xyzv, col] = slice3 (m3, 1, None, None, value = 0.) orient3 () pl3surf (nv, xyzv) lim = draw3 (1) limits (lim [0], lim [1], 1.5*lim [2], 1.5*lim [3]) palette ("gray.gp") paws () print "Try new slicing function (slice3mesh) to get color graph" [nv, xyzv, col] = slice3mesh (nxnynz [0:2], dxdydz [0:2], x0y0z0 [0:2], zmult * z, color = zmult * z) pl3surf (nv, xyzv, values = col) lim = draw3 (1) dif = 0.5 * (lim [3] - lim [2]) limits (lim [0], lim [1], lim [2] - dif, lim [3] + dif) palette ("rainbow.gp") paws () print "Try plzcont -- see if smooth mode is possible" print "plzcont (nv, xyzv)" palette ("heat.gp") plzcont (nv, xyzv) draw3 (1) paws () print "plzcont (nv, xyzv, contours = 20)" plzcont (nv, xyzv, contours = 20) draw3 (1) paws () print 'plzcont (nv, xyzv, contours = 20, scale = "log")' plzcont (nv, xyzv, contours = 20, scale = "log") draw3(1) paws () print 'plzcont (nv, xyzv, contours = 20, scale = "normal")' plzcont (nv, xyzv, contours = 20, scale = "normal") draw3(1) paws () if len (itest) == 0 or itest [0] == 9 : vsf = 0. c = 1 s = 1000. kmax = 25 lmax = 35 # The following computations define an interesting 3d surface. xr = multiply.outer ( arange (1, kmax + 1, dtype = Float), ones (lmax, Float)) yr = multiply.outer ( ones (kmax, Float), arange (1, lmax + 1, dtype = Float)) zt = 5. + xr + .2 * random_sample (kmax, lmax) # ranf (xr) rt = 100. + yr + .2 * random_sample (kmax, lmax) # ranf (yr) z = s * (rt + zt) z = z + .02 * z * random_sample (kmax, lmax) # ranf (z) ut = rt/sqrt (rt ** 2 + zt ** 2) vt = zt/sqrt (rt ** 2 + zt ** 2) ireg = multiply.outer ( ones (kmax, Float), ones (lmax, Float)) ireg [0:1, 0:lmax]=0 ireg [0:kmax, 0:1]=0 ireg [1:15, 7:12]=2 ireg [1:15, 12:lmax]=3 ireg [3:7, 3:7]=0 freg=ireg + .2 * (1. - random_sample (kmax, lmax)) # ranf (ireg)) freg=array (freg, Float) #rt [4:6, 4:6] = -1.e8 z [3:10, 3:12] = z [3:10, 3:12] * .9 z [5, 5] = z [5, 5] * .9 z [17:22, 15:18] = z [17:22, 15:18] * 1.2 z [16, 16] = z [16, 16] * 1.1 orient3 () print "plwf (freg, shade = 1, edges = 0)" plwf (freg, shade = 1, edges = 0) [xmin, xmax, ymin, ymax] = draw3 (1) limits (xmin, xmax, ymin, ymax) paws () print "two slice3mesh and two pl3tree" nxny = array ( [kmax - 1, lmax - 1]) x0y0 = array ( [0., 0.]) dxdy = array ( [1., 1.]) [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg) [nw, xyzw, col] = slice3mesh (nxny, dxdy, x0y0, freg + ut) pl3tree (nv, xyzv) pl3tree (nw, xyzw) draw3 (1) limits ( ) paws () print "light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])" light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1]) demo5_light (1) paws () print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = freg)" [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = freg) pl3surf (nv, xyzv, values = col) draw3 (1) palette ("rainbow.gp") paws () print 'palette ("rainbow.gp")' [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = z) pl3surf (nv, xyzv, values = col) draw3 (1) paws () print 'palette ("stern.gp")' palette ("stern.gp") paws () print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, z, color = z)" [nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, z, color = z) pl3surf (nv, xyzv, values = col) orient3(phi=0,theta=0) draw3 (1) paws () print 'palette ("gray.gp")' print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))" set_draw3_ (0) palette ("gray.gp") light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1])) pl3surf (nv, xyzv) draw3 (1) paws () # spin3 () # paws () hcp_finish ()
def run(*itest): """run() or run(i) Run examples of use of pl3d.i, plwf.i, and slice3.i. With argument I = 1, 2, or 3, run that particular demonstration. Read the source code to understand the details of how the various effects are obtained. run (1) demonstrates the various effects which can be obtained with the plwf (plot wire frame) function. run (2) demonstrates shading effects controlled by the light3 function run (3) demonstrates the slice3, slice2, and pl3tree functions, as well as changing the orientation of the 3D object """ global making_movie if len(itest) == 0 or itest[0] == 1: set_draw3_(0) x = gistfuncs.span(-1, 1, 64, 64) y = transpose(x) z = (x + y) * exp(-6. * (x * x + y * y)) limits_(square=1) print "Plot wire frame: plwf (z, y, x)" orient3() light3() plwf(z, y, x) [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits(xmin, xmax, ymin, ymax) plt("opaque wire mesh", .30, .42) paws() print 'plwf(z,y,x,shade=1,ecolor="red")' plwf(z, y, x, shade=1, ecolor="red") [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits(xmin, xmax, ymin, ymax) paws() print "plwf(z,y,x,shade=1,edges=0)" plwf(z, y, x, shade=1, edges=0) [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits(xmin, xmax, ymin, ymax) paws() print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))" light3(diffuse=.1, specular=1., sdir=array([0, 0, -1])) [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print "light3 ( diffuse=.5, specular=1., sdir=array([1,.5,1]))" light3(diffuse=.5, specular=1., sdir=array([1, .5, 1])) [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print "light3 ( ambient=.1,diffuse=.1,specular=1.," print " sdir=array([[0,0,-1],[1,.5,1]]),spower=array([4,2]))" light3(ambient=.1, diffuse=.1, specular=1., sdir=array([[0, 0, -1], [1, .5, 1]]), spower=array([4, 2])) [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() if len(itest) == 0 or itest[0] == 2: set_draw3_(0) x = gistfuncs.span(-1, 1, 64, 64) y = transpose(x) z = (x + y) * exp(-6. * (x * x + y * y)) print "Default lighting: light3()" orient3() light3() plwf(z, y, x, shade=1, edges=0) [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits(xmin, xmax, ymin, ymax) paws() print "light3(diffuse=.2,specular=1)" light3(diffuse=.2, specular=1) limits_(square=1) [xmin, xmax, ymin, ymax] = draw3(1) # not necessary interactively limits(xmin, xmax, ymin, ymax) paws() print "movie(demo5_light, lims = [xmin, xmax, ymin, ymax])" print "demo5_light calls:" print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], float32))" making_movie = 1 movie(demo5_light, lims=[xmin, xmax, ymin, ymax]) making_movie = 0 fma() demo5_light(1) paws() light3() if len(itest) == 0 or itest[0] == 3: nx = demo5_n[0] ny = demo5_n[1] nz = demo5_n[2] xyz = zeros((3, nx, ny, nz), float32) xyz[0] = multiply.outer(gistfuncs.span(-1, 1, nx), ones((ny, nz), float32)) xyz[1] = multiply.outer( ones(nx, float32), multiply.outer(gistfuncs.span(-1, 1, ny), ones(nz, float32))) xyz[2] = multiply.outer(ones((nx, ny), float32), gistfuncs.span(-1, 1, nz)) r = sqrt(xyz[0]**2 + xyz[1]**2 + xyz[2]**2) theta = arccos(xyz[2] / r) phi = arctan2(xyz[1], xyz[0] + logical_not(r)) y32 = sin(theta)**2 * cos(theta) * cos(2 * phi) m3 = mesh3(xyz, funcs=[r * (1. + y32)]) del r, theta, phi, xyz, y32 print " test uses " + ` (nx - 1) * (ny - 1) * (nz - 1) ` + " cells" elapsed = [0., 0., 0.] elapsed = timer_(elapsed) elapsed0 = elapsed [nv, xyzv, dum] = slice3(m3, 1, None, None, value=.50) # (inner isosurface) [nw, xyzw, dum] = slice3(m3, 1, None, None, value=1.) # (outer isosurface) pxy = plane3(array([0, 0, 1], float32), zeros(3, float32)) pyz = plane3(array([1, 0, 0], float32), zeros(3, float32)) [np, xyzp, vp] = slice3(m3, pyz, None, None, 1) # (pseudo-colored slice) [np, xyzp, vp] = slice2(pxy, np, xyzp, vp) # (cut slice in half) [nv, xyzv, d1, nvb, xyzvb, d2] = \ slice2x (pxy, nv, xyzv, None) [nv, xyzv, d1] = \ slice2 (- pyz, nv, xyzv, None) # (...halve one of those halves) [nw, xyzw, d1, nwb, xyzwb, d2] = \ slice2x ( pxy , nw, xyzw, None) # (split outer in halves) [nw, xyzw, d1] = \ slice2 (- pyz, nw, xyzw, None) elapsed = timer_(elapsed) timer_print("slicing time", elapsed - elapsed0) fma() print 'Generate palette for pl3tree: split_palette ("earth.gp")' split_palette("earth.gp") print "gnomon -- turn on gnomon" gnomon(1) print "pl3tree with 1 slicing plane, 2 isosurfaces" clear3() # Make sure we don't draw till ready set_draw3_(0) pl3tree(np, xyzp, vp, pyz) pl3tree(nvb, xyzvb) pl3tree(nwb, xyzwb) pl3tree(nv, xyzv) pl3tree(nw, xyzw) orient3() light3(diffuse=.2, specular=1) limits() limits(square=1) demo5_light(1) paws() hcp() print "spin3 animated rotation, use rot3 or orient3 for one frame" # don't want limits to autoscale during animation lims = limits() spin3() limits() # back to autoscaling demo5_light(1) paws() light3() gnomon(0) limits(square=1) palette("gray.gp") # .. PR is not available. Comment out this section. # if len (itest) == 0 or itest [0] == 4 : # from PR import * # f = PR ('./bills_plot') # n_nodes = f.NumNodes # n_z = f.NodesOnZones # x = f.XNodeCoords # y = f.YNodeCoords # z = f.ZNodeCoords # c = f.ZNodeVelocity # n_zones = f.NumZones # # Put vertices in right order for Gist # n_z = transpose ( # take (transpose (n_z), array ( [0, 4, 3, 7, 1, 5, 2, 6]))) # m3 = mesh3 (x, y, z, funcs = [c], verts = n_z ) # [0:10]) # [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) ) # pyz = plane3 ( array ([1, 0, 0], float32 ), zeros (3, float32)) # pxz = plane3 ( array ([0, 1, 0], float32 ), zeros (3, float32)) # # # draw a colored plane first # fma () # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1) # pl3tree (np, xyzp, vp, pyz, split = 0) # palette ("rainbow.gp") # orient3 () # demo5_light (1) # paws () # # # [nv, xyzv, d1] = \ # slice2 (- pyz, nv, xyzv, None) # [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) ) # [nw, xyzw, d1] = \ # slice2 (- pyz, nw, xyzw, None) # [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .5 * min (c) ) # [nvi, xyzvi, cvi] = \ # slice2 (- pyz, nvi, xyzvi, cvi) # [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .5 * max (c) ) # [nvj, xyzvj, cvj] = \ # slice2 (- pyz, nvj, xyzvj, cvj) # # fma () # print "gnomon -- turn on gnomon" # gnomon (1) # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # pl3tree (nv, xyzv) # , cv) # pl3tree (nw, xyzw) # , cw) # pl3tree (nvi, xyzvi) # , cvi) # pl3tree (nvj, xyzvj) # , cvi) # orient3 () # light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1]) # limits (square=1) # palette ("gray.gp") # demo5_light (1) # paws () # # print "spin3 animated rotation, use rot3 or orient3 for one frame" # # don't want limits to autoscale during animation # spin3 () # limits ( ) # back to autoscaling # demo5_light (1) # paws () # # light3 () # gnomon (0) # palette ("gray.gp") # # draw3 ( 1 ) # paws () # clear3 () # del nv, xyzv, cv, nw, xyzw, cw, nvi, xyzvi, cvi, nvj, xyzvj, cvj # # Make sure we don't draw till ready # set_draw3_ (0) # for i in range (8) : # [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) + # i * (.9 * max (c) - .9 * min (c)) / 8.) # [nv, xyzv, d1] = \ # slice2 (pxz, nv, xyzv, None) # pl3tree (nv, xyzv) # orient3 () # light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1]) # limits (square=1) # palette ("heat.gp") # demo5_light (1) # paws () # spin3 () # limits ( ) # back to autoscaling # demo5_light (1) # paws () # demo5_light (1) # paws () # # if len (itest) == 0 or itest [0] == 5 : # # Try bert's data # from PR import PR # f = PR ('./berts_plot') # nums = array ( [63, 63, 49], int32) # dxs = array ( [2.5, 2.5, 10.], float32 ) # x0s = array ( [-80., -80., 0.0], float32 ) # c = f.c # # m3 = mesh3 (nums, dxs, x0s, funcs = [transpose (c)]) # [nv, xyzv, dum] = slice3 (m3, 1, None, None, value = 6.5) # fma () # clear3 () # print "gnomon -- turn on gnomon" # gnomon (1) # # Make sure we don't draw till ready # set_draw3_ (0) # palette ("rainbow.gp") # pl3tree (nv, xyzv) # orient3 () # light3 (diffuse = .2, specular = 1) # limits (square=1) # demo5_light (1) # paws () # spin3 () # demo5_light (1) # paws () # if len (itest) == 0 or itest [0] == 6 : # # Try Bill's irregular mesh # from PR import PR # f = PR ("ball.s0001") # ZLss = f.ZLstruct_shapesize # ZLsc = f.ZLstruct_shapecnt # ZLsn = f.ZLstruct_nodelist # x = f.sap_mesh_coord0 # y = f.sap_mesh_coord1 # z = f.sap_mesh_coord2 # c = f.W_vel_data # # Now we need to convert this information to avs-style data # istart = 0 # beginning index into ZLstruct_nodelist # NodeError = "NodeError" # ntet = 0 # nhex = 0 # npyr = 0 # nprism = 0 # nz_tet = [] # nz_hex = [] # nz_pyr = [] # nz_prism = [] # for i in range (4) : # if ZLss [i] == 4 : # TETRAHEDRON # nz_tet = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # ntet = ZLsc [i] # istart = istart + ZLss [i] * ZLsc [i] # elif ZLss[i] == 5 : # PYRAMID # nz_pyr = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # npyr = ZLsc [i] # # Now reorder the points (bill has the apex last instead of first) # nz_pyr = transpose ( # take (transpose (nz_pyr), array ( [4, 0, 1, 2, 3]))) # istart = istart + ZLss [i] * ZLsc [i] # elif ZLss[i] == 6 : # PRISM # nz_prism = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # nprism = ZLsc [i] # # now reorder the points (bill goes around a square face # # instead of traversing the opposite sides in the same direction. # nz_prism = transpose ( # take (transpose (nz_prism), array ( [0, 1, 3, 2, 4, 5]))) # istart = istart + ZLss [i] * ZLsc [i] # elif ZLss[i] == 8 : # HEXAHEDRON # nz_hex = reshape (ZLsn [istart: istart + ZLss [i] * ZLsc [i]], # (ZLsc [i], ZLss [i])) # # now reorder the points (bill goes around a square face # # instead of traversing the opposite sides in the same direction. # nz_hex = transpose ( # take (transpose (nz_hex), array ( [0, 1, 3, 2, 4, 5, 7, 6]))) # nhex = ZLsc [i] # istart = istart + ZLss [i] * ZLsc [i] # else : # raise NodeError, `ZLss[i]` + "is an incorrect number of nodes." # m3 = mesh3 (x, y, z, funcs = [c], verts = [nz_tet, nz_pyr, nz_prism, # nz_hex]) # [nv, xyzv, cv] = slice3 (m3, 1, None, None, 1, value = .9 * max (c) ) # pyz = plane3 ( array ([1, 0, 0], float32 ), zeros (3, float32)) # pxz = plane3 ( array ([0, 1, 0], float32 ), zeros (3, float32)) # # # draw a colored plane first # fma () # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # [np, xyzp, vp] = slice3 (m3, pyz, None, None, 1) # pl3tree (np, xyzp, vp, pyz, split = 0) # palette ("rainbow.gp") # orient3 () # limits (square=1) # demo5_light (1) # paws () # # [nw, xyzw, cw] = slice3 (m3, 1, None, None, 1, value = .9 * min (c) ) # [nvi, xyzvi, cvi] = slice3 (m3, 1, None, None, 1, value = .1 * min (c) ) # [nvi, xyzvi, cvi] = \ # slice2 (- pyz, nvi, xyzvi, cvi) # [nvj, xyzvj, cvj] = slice3 (m3, 1, None, None, 1, value = .1 * max (c) ) # [nvj, xyzvj, cvj] = \ # slice2 (- pyz, nvj, xyzvj, cvj) # [nvii, xyzvii, cvii] = slice3 (m3, 1, None, None, 1, # value = 1.e-12 * min (c) ) # [nvii, xyzvii, cvii] = \ # slice2 (- pyz, nvii, xyzvii, cvii) # [nvjj, xyzvjj, cvjj] = slice3 (m3, 1, None, None, 1, # value = 1.e-12 * max (c) ) # [nvjj, xyzvjj, cvjj] = \ # slice2 (- pyz, nvjj, xyzvjj, cvjj) # # fma () # print "gnomon -- turn on gnomon" # gnomon (1) # clear3 () # # Make sure we don't draw till ready # set_draw3_ (0) # pl3tree (nv, xyzv) # , cv) # pl3tree (nw, xyzw) # , cw) # pl3tree (nvi, xyzvi) # , cvi) # pl3tree (nvj, xyzvj) # , cvj) # pl3tree (nvii, xyzvii) # , cvii) # pl3tree (nvjj, xyzvjj) # , cvjj) # orient3 () # light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1]) # limits (square=1) # palette ("gray.gp") # demo5_light (1) # paws () # palette ("heat.gp") # paws () if len(itest) == 0 or itest[0] == 7: print "Test plwf on the sombrero function" # compute sombrero function x = arange(-20, 21, dtype=float32) y = arange(-20, 21, dtype=float32) z = zeros((41, 41), float32) r = sqrt(add.outer(x**2, y**2)) + 1e-6 z = sin(r) / r fma() clear3() gnomon(0) # Make sure we don't draw till ready set_draw3_(0) palette("rainbow.gp") limits(square=1) orient3() light3() plwf(z, fill=z, ecolor="black") [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print "Try smooth contours, log mode:" print 'plzcont (nv, xyzv, contours = 20, scale = "normal")' [nv, xyzv, dum] = slice3mesh(x, y, z) zmult = max(max(abs(x)), max(abs(y))) plzcont(nv, xyzv, contours=20, scale="normal") [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print 'plzcont (nv, xyzv, contours = 20, scale = "lin", edges=1)' plzcont(nv, xyzv, contours=20, scale="lin", edges=1) [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print 'plwf (z, fill = z, shade = 1, ecolor = "black")' plwf(z, fill=z, shade=1, ecolor="black") [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print "plwf (z, fill = z, shade = 1, edges = 0)" plwf(z, fill=z, shade=1, edges=0) [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print "light3(diffuse=.2,specular=1)" print "demo5_light calls:" print "light3 (sdir = array ( [cos(theta), .25, sin(theta)], float32))" light3(diffuse=.2, specular=1) making_movie = 1 movie(demo5_light, lims=[xmin, xmax, ymin, ymax]) making_movie = 0 fma() demo5_light(1) paws() print "plwf (z, fill = None, shade = 1, edges = 0)" plwf(z, fill=None, shade=1, edges=0) [xmin, xmax, ymin, ymax] = draw3(1) palette("gray.gp") limits(xmin, xmax, ymin, ymax) paws() if len(itest) == 0 or itest[0] == 8: print "Test pl3surf on the sombrero function" # compute sombrero function nc1 = 100 nv1 = nc1 + 1 br = -(nc1 / 2) tr = nc1 / 2 + 1 x = arange(br, tr, dtype=float32) * 40. / nc1 y = arange(br, tr, dtype=float32) * 40. / nc1 z = zeros((nv1, nv1), float32) r = sqrt(add.outer(x**2, y**2)) + 1e-6 z = sin(r) / r # In order to use pl3surf, we need to construct a mesh # using mesh3. The way I am going to do that is to define # a function on the 3d mesh so that the sombrero function # is its 0-isosurface. z0 = min(ravel(z)) z0 = z0 - .05 * abs(z0) maxz = max(ravel(z)) maxz = maxz + .05 * abs(maxz) zmult = max(max(abs(x)), max(abs(y))) dz = (maxz - z0) nxnynz = array([nc1, nc1, 1], int32) dxdydz = array([1.0, 1.0, zmult * dz], float32) x0y0z0 = array([float(br), float(br), z0 * zmult], float32) meshf = zeros((nv1, nv1, 2), float32) meshf[:, :, 0] = zmult * z - (x0y0z0[2]) meshf[:, :, 1] = zmult * z - (x0y0z0[2] + dxdydz[2]) m3 = mesh3(nxnynz, dxdydz, x0y0z0, funcs=[meshf]) fma() # Make sure we don't draw till ready set_draw3_(0) pldefault(edges=0) [nv, xyzv, col] = slice3(m3, 1, None, None, value=0.) orient3() pl3surf(nv, xyzv) lim = draw3(1) limits(lim[0], lim[1], 1.5 * lim[2], 1.5 * lim[3]) palette("gray.gp") paws() print "Try new slicing function (slice3mesh) to get color graph" [nv, xyzv, col] = slice3mesh(nxnynz[0:2], dxdydz[0:2], x0y0z0[0:2], zmult * z, color=zmult * z) pl3surf(nv, xyzv, values=col) lim = draw3(1) dif = 0.5 * (lim[3] - lim[2]) limits(lim[0], lim[1], lim[2] - dif, lim[3] + dif) palette("rainbow.gp") paws() print "Try plzcont -- see if smooth mode is possible" print "plzcont (nv, xyzv)" palette("heat.gp") plzcont(nv, xyzv) draw3(1) paws() print "plzcont (nv, xyzv, contours = 20)" plzcont(nv, xyzv, contours=20) draw3(1) paws() print 'plzcont (nv, xyzv, contours = 20, scale = "log")' plzcont(nv, xyzv, contours=20, scale="log") draw3(1) paws() print 'plzcont (nv, xyzv, contours = 20, scale = "normal")' plzcont(nv, xyzv, contours=20, scale="normal") draw3(1) paws() if len(itest) == 0 or itest[0] == 9: vsf = 0. c = 1 s = 1000. kmax = 25 lmax = 35 # The following computations define an interesting 3d surface. xr = multiply.outer(arange(1, kmax + 1, dtype=float32), ones(lmax, float32)) yr = multiply.outer(ones(kmax, float32), arange(1, lmax + 1, dtype=float32)) zt = 5. + xr + .2 * random_sample(kmax, lmax) # ranf (xr) rt = 100. + yr + .2 * random_sample(kmax, lmax) # ranf (yr) z = s * (rt + zt) z = z + .02 * z * random_sample(kmax, lmax) # ranf (z) ut = rt / sqrt(rt**2 + zt**2) vt = zt / sqrt(rt**2 + zt**2) ireg = multiply.outer(ones(kmax, float32), ones(lmax, float32)) ireg[0:1, 0:lmax] = 0 ireg[0:kmax, 0:1] = 0 ireg[1:15, 7:12] = 2 ireg[1:15, 12:lmax] = 3 ireg[3:7, 3:7] = 0 freg = ireg + .2 * (1. - random_sample(kmax, lmax)) # ranf (ireg)) freg = array(freg, float32) #rt [4:6, 4:6] = -1.e8 z[3:10, 3:12] = z[3:10, 3:12] * .9 z[5, 5] = z[5, 5] * .9 z[17:22, 15:18] = z[17:22, 15:18] * 1.2 z[16, 16] = z[16, 16] * 1.1 orient3() print "plwf (freg, shade = 1, edges = 0)" plwf(freg, shade=1, edges=0) [xmin, xmax, ymin, ymax] = draw3(1) limits(xmin, xmax, ymin, ymax) paws() print "two slice3mesh and two pl3tree" nxny = array([kmax - 1, lmax - 1]) x0y0 = array([0., 0.]) dxdy = array([1., 1.]) [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, freg) [nw, xyzw, col] = slice3mesh(nxny, dxdy, x0y0, freg + ut) pl3tree(nv, xyzv) pl3tree(nw, xyzw) draw3(1) limits() paws() print "light3 (ambient = 0, diffuse = .5, specular = 1, sdir = [0, 0, -1])" light3(ambient=0, diffuse=.5, specular=1, sdir=[0, 0, -1]) demo5_light(1) paws() print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, freg, color = freg)" [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, freg, color=freg) pl3surf(nv, xyzv, values=col) draw3(1) palette("rainbow.gp") paws() print 'palette ("rainbow.gp")' [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, freg, color=z) pl3surf(nv, xyzv, values=col) draw3(1) paws() print 'palette ("stern.gp")' palette("stern.gp") paws() print "[nv, xyzv, col] = slice3mesh (nxny, dxdy, x0y0, z, color = z)" [nv, xyzv, col] = slice3mesh(nxny, dxdy, x0y0, z, color=z) pl3surf(nv, xyzv, values=col) orient3(phi=0, theta=0) draw3(1) paws() print 'palette ("gray.gp")' print "light3 ( diffuse=.1, specular=1., sdir=array([0,0,-1]))" set_draw3_(0) palette("gray.gp") light3(diffuse=.1, specular=1., sdir=array([0, 0, -1])) pl3surf(nv, xyzv) draw3(1) paws() # spin3 () # paws () hcp_finish()