~ubuntu-branches/ubuntu/raring/python-scipy/raring-proposed

« back to all changes in this revision

Viewing changes to Lib/sandbox/xplt/gisttest3d.py~

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-07 14:12:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070107141212-mm0ebkh5b37hcpzn
* Remove build dependency on python-numpy-dev.
* python-scipy: Depend on python-numpy instead of python-numpy-dev.
* Package builds on other archs than i386. Closes: #402783.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## Automatically adapted for scipy Oct 31, 2005 by 
 
2
 
 
3
# Copyright (c) 1996, 1997, The Regents of the University of California.
 
4
# All rights reserved.  See Legal.htm for full text and disclaimer.
 
5
 
 
6
from graph3d import *
 
7
from mesh3d import *
 
8
from surface import *
 
9
 
 
10
from scipy import *
 
11
from numpy.core.umath import *
 
12
 
 
13
from arrayfns import *
 
14
 
 
15
def paws ( ) :
 
16
    i = raw_input ("Type in any string to continue; ^C to return to prompt. ")
 
17
    return
 
18
 
 
19
def demo (*i) :
 
20
   x = span (-1, 1, 64, 64)
 
21
   y = transpose (x)
 
22
   z = (x + y) * exp (-6.*(x*x+y*y))
 
23
 
 
24
   if len (i) == 0 or i [0] == 1 :
 
25
      s1 = Surface (z = z, opt_3d = "wm", mask = "sort")
 
26
 
 
27
      g1 = Graph3d (s1, color_card = "gray.gp", titles = "opaque wire mesh", y_factor = 2.)
 
28
 
 
29
      g1.plot ()
 
30
 
 
31
      paws ()
 
32
 
 
33
      s1.set (mask = "none")
 
34
 
 
35
      g1.change (titles = "transparent wire mesh")
 
36
      g1.plot ()
 
37
      paws ()
 
38
 
 
39
      s1.set (ecolor = "red")
 
40
      g1.change (titles = "transparent wire mesh in red")
 
41
      g1.plot ()
 
42
      paws ()
 
43
 
 
44
      s1.set (mask = "sort", shade = 1)
 
45
      g1.change (titles = "opaque shaded mesh with red lines")
 
46
      g1.plot ()
 
47
      paws ()
 
48
 
 
49
      s1.set (opt_3d = "none")
 
50
      g1.change (titles = "opaque shaded mesh with no lines")
 
51
      g1.plot ()
 
52
      paws ()
 
53
 
 
54
      g1.change (titles = "same with different lighting")
 
55
      g1.quick_plot (diffuse=.1, specular = 1., sdir=array([0,0,-1]))
 
56
      paws ()
 
57
   
 
58
      s1.set (c = z - min (ravel (z)), opt_3d = "s4", shade = 0)
 
59
      g1.change (color_card = "rainbow.gp",
 
60
         titles = "surface shaded according to height")
 
61
      g1.plot ()
 
62
      paws ()
 
63
 
 
64
   if len (i) == 0 or i [0] == 2 :
 
65
      s1 = Surface (z = z, opt_3d = "none", mask = "sort", shade = 1)
 
66
 
 
67
      # The purpose of the try clause is to prevent creation of a new Graph
 
68
      # object if g1 already exists. Creation of a new one forces the
 
69
      # current Plotter(s) to close and new one(s) to open. When working
 
70
      # with Xwindows, this leads to annoying popping of windows in and
 
71
      # out of existence.
 
72
      try:
 
73
         g1 = g1
 
74
      except:
 
75
         g1 = Graph3d (s1, ambient = 0.2, diffuse = .2, specular = 1.,
 
76
            color_card = "gray.gp", titles = "backlit surface", y_factor = 2.)
 
77
      else:
 
78
         g1.new (s1, ambient = 0.2, diffuse = .2, specular = 1.,
 
79
            color_card = "gray.gp", titles = "backlit surface", y_factor = 2.)
 
80
 
 
81
      g1.plot ()
 
82
      paws ()
 
83
      g1.change (titles = "moving light source")
 
84
      g1.move_light_source ()
 
85
      paws ()
 
86
 
 
87
   if len (i) == 0 or i [0] == 3 :
 
88
      nx = 20
 
89
      ny = 20
 
90
      nz = 20
 
91
      xyz = zeros ( (3, nx, ny, nz), Float)
 
92
      xyz [0] = multiply.outer ( span (-1, 1, nx), ones ( (ny, nz), Float))
 
93
      xyz [1] = multiply.outer ( ones (nx, Float),
 
94
         multiply.outer ( span (-1, 1, ny), ones (nz, Float)))
 
95
      xyz [2] = multiply.outer ( ones ( (nx, ny), Float), span (-1, 1, nz))
 
96
      r = sqrt (xyz [0] ** 2 + xyz [1] **2 + xyz [2] **2)
 
97
      theta = arccos (xyz [2] / r)
 
98
      phi = arctan2 (xyz [1] , xyz [0] + logical_not (r))
 
99
      y32 = sin (theta) ** 2 * cos (theta) * cos (2 * phi)
 
100
 
 
101
      m1 = Mesh3d (x = span (-1, 1, nx),
 
102
                   y = span (-1, 1, ny),
 
103
                   z = span (-1, 1, nz),
 
104
                   c = r * (1. + y32))
 
105
      del r, theta, phi, xyz, y32
 
106
 
 
107
      s1 = sslice (m1, .50, varno = 1) # , opt_3d = "f3") # (inner isosurface)
 
108
      s2 = sslice (m1, 1.0, varno = 1) # , opt_3d = "f3") # (outer isosurface)
 
109
 
 
110
      pxy = Plane (array ([0., 0., 1.], Float ), zeros (3, Float))
 
111
      pyz = Plane (array ([1., 0., 0.], Float ), zeros (3, Float))
 
112
 
 
113
      # pseudo-colored plane slice, then cut it in half and save
 
114
      # only the front half
 
115
      s3 = sslice (m1, pyz, opt_3d = ["wm", "f4"])
 
116
      s3 = sslice (s3, pxy, nslices = 1, opt_3d = ["wm", "f4"])
 
117
 
 
118
      # cut the inner isosurface in half so that we can slice the
 
119
      # top off one of the halves:
 
120
      [s1, s4] = sslice (s1, pxy, nslices = 2) #, opt_3d = "f3")
 
121
      s1 = sslice (s1, - pyz) #, opt_3d = "f3")
 
122
 
 
123
      # do the same with the outer isosurface:
 
124
      [s2, s5] = sslice (s2, pxy, nslices = 2) #, opt_3d = "f3")
 
125
      s2 = sslice (s2, - pyz) #, opt_3d = "f3")
 
126
     
 
127
      # The purpose of the try clause is to prevent creation of a new Graph
 
128
      # object if g1 already exists. Creation of a new one forces the
 
129
      # current Plotter(s) to close and new one(s) to open. When working
 
130
      # with Xwindows, this leads to annoying popping of windows in and
 
131
      # out of existence.
 
132
      try:
 
133
         g1 = g1
 
134
      except:
 
135
         g1 = Graph3d ([s3, s1, s4, s2, s5], gnomon = 1, color_card =
 
136
            "rainbowhls", diffuse = .2, specular = 1,
 
137
            mask = "min", split = 1) # opt_3d = ["f4"],
 
138
      else:
 
139
         g1.new ([s3, s1, s4, s2, s5], gnomon = 1, color_card =
 
140
            "rainbowhls", diffuse = .2, specular = 1,
 
141
            mask = "min", split = 1) 
 
142
 
 
143
      paws ()
 
144
      g1.plot ()
 
145
      paws ()
 
146
      g1.change (x_factor = 2., y_factor = 2.)
 
147
      g1.rotate ()