From: Bruce P. <bap...@te...> - 2002-12-03 17:24:51
|
I've recently been developing an app for data animation using Python/Vpython. After reading all the hits on Python about performance (due to no compilation) my thought was that I would develop a prototype and then replace slow routines with C modules. I suspected that Vpython might be one of those. I've gotten far enough to do some performance testing -- and it looks like my major bottleneck is my video card! Vpython has next to no overhead for static display (e.g. lots (thousands) of objects in a scene but just spin and zoom operations using the mouse). The updating of moving objects could be a bottleneck but on my machine (2.2 Ghz Xeon with 512 meg ram, NVidia Quadro 2 VDI, Windows XP) the practical limit for objects (over 100 or so on screen and you can't really follow anything anyway) is reached before the updating function causes a noticeable delay. The bottom line is I can get 20 fps at virtually any scene complexity and if I want more speed I'll probably have upgrade the hardware. The only thing leading me to replace Vpython is its' lack of translucency for objects. Anyone else have experience with Vpython performance? Bruce Peterson Terastat, Inc Information Access Systems Voice (425) 466 7344 Fax (206) 350 3685 |
From: Andrew W. <an...@ph...> - 2002-12-03 17:48:49
|
On Tue, 03 Dec 2002 09:24:31 -0800, Bruce Peterson wrote: >looks like my major bottleneck is my video card! Vpython has next to no >overhead for static display (e.g. lots (thousands) of objects in a scene >but just spin and zoom operations using the mouse). The updating of moving >Anyone else have experience with Vpython performance? I've done something that sounds similar - displaying the nearest 2367 galaxies (from the 'Tully Nearby Galaxy Catalog') so you can zoom and spin. Perfectly smooth on both my desktop machine (fairly high end) and my laptop, a 1GHz PIII with a GeForce 2, but I haven't checked the frame rate. The code and data file a at: http://www.physics.uwa.edu.au/Courses/First_Year/OurUniverse/software/tu llys.py and http://www.physics.uwa.edu.au/Courses/First_Year/OurUniverse/software/tu lly.csv Galaxies are displayed as short cylinders for spirals or spheres for ellipticals. The orientations are sadly random, not real, in this version, and the sizes are scaled up by a factor of 10 to make it look better. Left clicking on a galaxy shows the name in a popup label. Andrew |
From: Patrick K. <pa...@ke...> - 2002-12-04 05:06:13
|
As you probably know, if you just close a Vpython display which was started from a program running under Pythonwin, it causes Pythonwin to die, even after the program terminates. So I had to "invent" a method of gracefully terminating a Vpython program. Not too difficult I know, but having done so, I thought I might as well share it. So here is a function (a histogram plotter), with this capability. #!/usr/bin/python # # Histo - plot a histogram of stacked cylinders using Vpython # # Author Patrick Keogh # from visual import * def histo(stacked, data): """ The second parameter which is passed is assumed to be a sequence, which has: - The first element is a sequence of category labels - The second element is a sequence of data series labels. - The third element is a sequence of sequences of the data values """ # # This try/except figures out if there is already a scene. If not, it creates it. # try: type(scene) except: scene = display() scene.show() max_entries = len(data[0]) col = (color.red,color.blue,color.green,color.yellow) data_array = [] for i in data[2]: max_entries = max((max_entries, len(i))) arrow(axis=(max_entries+1,0,0), shaftwidth=0.1, fixedwidth=1) max_height = 0.0 for i in range(max_entries): data_array.append([]) for j in range(len(data[2])): data_array[i].append(data[2][j][i]) max_height=max((max_height,sum(data_array[i]))) arrow(axis=(0,10,0), shaftwidth=0.1, fixedwidth=1) for j in range(len(data_array[0])): label(pos=(-5,j*2,j*2),text=data[1][j],color=col[j],opacity=0,box=0,border=0 ) for i in range(len(data_array)): base = 0 for j in range(len(data_array[i])): cyl_height = data_array[i][j]*10.0/max_height if stacked: pos = (i+1,base,0) base = base + cyl_height else: pos = (i+1,0,j*2) axis = (0,cyl_height,0) c = cylinder(pos=pos,axis=axis,radius=0.3,color=col[j]) c.label = "(" + data[0][i] + "," + repr(data_array[i][j]) + ")" scene.center = (len(data_array)/2,5,0) again = 1 prev = None # # Apart from the standard zoom and rotate capabilities, we will add # # Left click = Set a new center # Ctrl-C = Exit # Move over a bar = Display the (x,y) label for the histogram bar # Note the "hack" of inserting the label as an attribute of the cylinder # while again: while scene.mouse.events: if scene.mouse.clicked: scene.center = scene.mouse.getclick().pos if scene.kb.keys: if scene.kb.getkey() == 'ctrl+c': again = 0 if scene.mouse.pick <> None: if prev <> scene.mouse.pick: try: l.visible = 0 except: pass prev = scene.mouse.pick if prev.__class__ == cylinder: l = label(pos=scene.mouse.pos, text=prev.label, box=0) # # If a control-c was entered, then the while loop exits, and we close down the display and exit # scene.hide() del(scene) |
From: David S. <da...@vi...> - 2002-12-04 13:58:16
|
I think you are looking for scene.exit = 0 while scene.visible: # do something print "Scene was closed by user" Closing the program is the default behavior for the "close" button, but it can easily be overridden with this method. Setting scene.visible = 0 is the preferred way of closing a display programmatically. Also, in writing functions such as histo, where you want the option to use a specific existing display, I would recommend the following method for dealing with displays: def histo(stacked, data, scene=None): if scene is None: scene = display() # Do plotting with scene # Do user interface loop histo() will use its own display unless the user specifically provides one. Dave > -----Original Message----- > From: vis...@li... > [mailto:vis...@li...] On > Behalf Of Patrick Keogh > Sent: Wednesday, December 04, 2002 12:05 AM > To: vis...@li... > Subject: [Visualpython-users] Starting and stopping Vpython > programs from Pythonwin > > > As you probably know, if you just close a Vpython display > which was started from a program running under Pythonwin, it > causes Pythonwin to die, even after the program terminates. > > So I had to "invent" a method of gracefully terminating a > Vpython program. Not too difficult I know, but having done > so, I thought I might as well share it. So here is a function > (a histogram plotter), with this capability. > > #!/usr/bin/python > # > # Histo - plot a histogram of stacked cylinders using Vpython > # > # Author Patrick Keogh > # > from visual import * > > def histo(stacked, data): > """ The second parameter which is passed is assumed to be > a sequence, > which has: > - The first element is a sequence of category labels > - The second element is a sequence of data series labels. > - The third element is a sequence of sequences of the > data values > """ > # > # This try/except figures out if there is already a scene. If > not, it creates it. # > try: > type(scene) > except: > scene = display() > scene.show() > max_entries = len(data[0]) > col = (color.red,color.blue,color.green,color.yellow) > data_array = [] > for i in data[2]: > max_entries = max((max_entries, len(i))) > arrow(axis=(max_entries+1,0,0), shaftwidth=0.1, fixedwidth=1) > max_height = 0.0 > for i in range(max_entries): > data_array.append([]) > for j in range(len(data[2])): > data_array[i].append(data[2][j][i]) > max_height=max((max_height,sum(data_array[i]))) > arrow(axis=(0,10,0), shaftwidth=0.1, fixedwidth=1) > for j in range(len(data_array[0])): > > label(pos=(-5,j*2,j*2),text=data[1][j],color=col[j],opacity=0, > box=0,border=0 > ) > for i in range(len(data_array)): > base = 0 > for j in range(len(data_array[i])): > cyl_height = data_array[i][j]*10.0/max_height > if stacked: > pos = (i+1,base,0) > base = base + cyl_height > else: > pos = (i+1,0,j*2) > axis = (0,cyl_height,0) > c = cylinder(pos=pos,axis=axis,radius=0.3,color=col[j]) > c.label = "(" + data[0][i] + "," + > repr(data_array[i][j]) + ")" > scene.center = (len(data_array)/2,5,0) > again = 1 > prev = None > # > # Apart from the standard zoom and rotate capabilities, we will add # > # Left click = Set a new center > # Ctrl-C = Exit > # Move over a bar = Display the (x,y) label for the histogram bar > # Note the "hack" of inserting > the label as an attribute of the > cylinder > # > while again: > while scene.mouse.events: > if scene.mouse.clicked: > scene.center = scene.mouse.getclick().pos > if scene.kb.keys: > if scene.kb.getkey() == 'ctrl+c': > again = 0 > if scene.mouse.pick <> None: > if prev <> scene.mouse.pick: > try: > l.visible = 0 > except: > pass > prev = scene.mouse.pick > if prev.__class__ == cylinder: > l = label(pos=scene.mouse.pos, > text=prev.label, box=0) # # If a control-c was entered, then > the while loop exits, and we close down the display and exit # > scene.hide() > del(scene) > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Microsoft Visual Studio.NET > comprehensive development tool, built to increase your > productivity. Try a free online hosted session at: http://ads.sourceforge.net/cgi-bin/redirect.pl?micr0003en _______________________________________________ Visualpython-users mailing list Vis...@li... https://lists.sourceforge.net/lists/listinfo/visualpython-users |