Hi Ben, could you send me an associated test patch? Also, calling your class array might not be a good idea, as you also imported numarray.array as array.
best, Thomas
B. Bogart schrieb:
Funny you mention that Frank,
I'm currently hacking away at a py/numarray external storing control points for a Gem object.
All is great until I try and make multiple instances of the py object, things get funny. All of a sudden some methods are no longer accepted: I get an "unhandled" message, while others work fine.
Anyhow for the python hackers out there here is my current code:
(obviously some things are inefficient but I'd like to get it to work before I worry about elegance! Why might this not work when I create a second instance?)
import pyext import sys from numarray import *
class array(pyext._class):
# number of inlets and outlets _inlets=1 _outlets=1
# Vars width = 0 height = 0 points = array()
print "curve3d scripts init"
# Definitions def send_array(self):
for i in xrange(self.width): for j in xrange(self.height): self._outlet(1,"set",(i,j)+tuple(self.points[i,j]))
# Generates Array of Control points def generate_array(self,w,h,w_lower,w_upper,h_lower,h_upper):
# Set values self.width = w self.height = h # Create Array self.points=zeros((w,h,3),Float32) # Calculate Size w_range = w_upper-w_lower h_range = h_upper-h_lower z=0 for i in xrange(w): for j in xrange(h): x=i*(w_range/(w-1.0))+w_lower y=j*(h_range/(h-1.0))+h_lower self.points[i,j] = [x,y,z]
# if the point matches then subtract 0.1 def change_(self,n,*args): if len(args) == 5: x = args[0] y = args[1] test_width = args[2] test_height = args[3] z = args[4] for i in xrange(self.width): for j in xrange(self.height): if x < self.points[i,j,0]+test_width: if x > self.points[i,j,0]-test_width: if y < self.points[i,j,1]+test_height: if y > self.points[i,j,1]-test_height: # Note multiple matches are possible here self.points[i,j,2] -= z #print "X: "+str(x)+" Y: "+str(y)+" Z: "+str(points[i,j,2])+" I: "+str(i)+" J: "+str(j) self.send_array() else: print "Change requires 5 arguments: 'change <X> <Y> <test-width> <test-height> <z>'"
# methods for first inlet def generate_(self,n,*args): if len(args) == 6:
self.generate_array(*args) self.send_array() else: print "generate_array requires 6 arguments: <width> <height>
<width lower> <width upper> <height lower> <height upper>"
Thanks all.
b>
Frank Barknecht wrote:
Hallo, Georg Holzmann hat gesagt: // Georg Holzmann wrote:
I guess the iem matrix objects count from 1 because matlab/octave also counts from 1 :)
Well, there's always numarray. ;)
Ciao
PD-dev mailing list PD-dev@iem.at http://lists.puredata.info/listinfo/pd-dev