/[libvob]/libvob/lava/blob/fshape.py
ViewVC logotype

Diff of /libvob/lava/blob/fshape.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by jvk, Fri May 23 14:07:51 2003 UTC revision 1.3 by tjl, Sat May 24 14:02:11 2003 UTC
# Line 28  import os Line 28  import os
28  import sys  import sys
29  import RandomArray  import RandomArray
30    
31  length= 100  from Tkinter import *
32    
33    length= 150
34  epsilon = 0.0001  epsilon = 0.0001
35    
36  # print l  # print l
# Line 37  def A(xleft, xright, rleft, rright): Line 39  def A(xleft, xright, rleft, rright):
39      return (xright-xleft) * .5 * (rleft + rright)      return (xright-xleft) * .5 * (rleft + rright)
40    
41  def L(xleft, xright, rleft, rright):  def L(xleft, xright, rleft, rright):
42      return sqrt((xright-xleft)**2 + (rright-rleft)**2)      return sqrt((xright-xleft)**2 + yweight**2 * (rright-rleft)**2)
43    
44  def U(xleft, xright, rleft, rright):  def U(xleft, xright, rleft, rright):
45    
46      return A(xleft, xright, rleft, rright) +3* L(xleft, xright, rleft, rright)      return areaweight * A(xleft, xright, rleft, rright) +3* L(xleft, xright, rleft, rright)
47    
48    
49  def pot(x, r):  def pot(x, r):
# Line 88  geomview = os.popen("geomview -c -", "w" Line 90  geomview = os.popen("geomview -c -", "w"
90  # geomview = sys.stdout  # geomview = sys.stdout
91    
92  geomview.write("""  geomview.write("""
 (merge-baseap { appearance { texture { file noisetex.ppm apply modulate } } })  
93  (geometry example { LIST { : foo0 } { : foo1 } { : foo2 } { :foo3 } { :foo4 }})  (geometry example { LIST { : foo0 } { : foo1 } { : foo2 } { :foo3 } { :foo4 }})
94  """);  """);
95  geomview.flush()  geomview.flush()
# Line 114  class MomGrad: Line 115  class MomGrad:
115          self.mom = x * 0          self.mom = x * 0
116          self.x = x          self.x = x
117          self.step = 0.02          self.step = 0.02
118          self.brake = 0.980          self.brake = 0.990
119      def round(self):      def round(self):
120          (u, g) = self.func(self.x)          (u, g) = self.func(self.x)
121          self.u = u          self.u = u
# Line 126  class MomGrad: Line 127  class MomGrad:
127    
128  sur = []  sur = []
129  for i in range(1, 2):  for i in range(1, 2):
130      l = 3**i      l = 2**i
131      tl = l * length      tl = l * length
132      print "TL",tl      print "TL",tl
133      x = zeros(2*tl, Float)      x = zeros(2*tl, Float)
# Line 136  for i in range(1, 2): Line 137  for i in range(1, 2):
137      mi = MomGrad(minfunc, x)      mi = MomGrad(minfunc, x)
138      sur.append(mi)      sur.append(mi)
139    
140  while 1:  def slider(obj, name, var, default, from_, to, resolution=0.001):
141      for i in range(0, len(sur)):      setattr(obj, name, var)
142          for rou in range(0,50): sur[i].round()      var.set(default)
143          print "Pot:",sur[i].u      Scale(obj, label=name, orient="horizontal",
144          wmesh(i, sur[i].x[0:sur[i].x.shape[0]/2], sur[i].x[sur[i].x.shape[0]/2:])          resolution=resolution,
145            from_=from_, to=to, variable=var).pack(
146                fill="both", expand=1)
147    
148    class UI(Frame):
149        def __init__(self, master=None):
150            Frame.__init__(self, master)
151            self.pack(expand=1, fill="both")
152            Button(self, text="Start", command = self.idle).pack()
153            slider(self, "areaweight", DoubleVar(), 1, 0, 2);
154            slider(self, "yweight", DoubleVar(), 1, 0, 2);
155    
156        def idle(self):
157            print "Start idle"
158            global areaweight
159            global yweight
160            for i in range(0, len(sur)):
161                areaweight = ui.areaweight.get()
162                yweight = ui.yweight.get()
163                for rou in range(0,100): sur[i].round()
164                print "Pot:",sur[i].u
165                wmesh(i, sur[i].x[0:sur[i].x.shape[0]/2], sur[i].x[sur[i].x.shape[0]/2:])
166            self.after_idle(self.idle)
167            print "End idle"
168    
169    ui = UI()
170    ui.mainloop()
171    
172    
173    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26