def scale2(self,val): """Scale a value to the range -1...1. This scales indepently in one of the intervals xmin..x0 or x0..xmax. """ if val < self.x0: return stuur(val,[self.xmin,(self.x0+self.xmin)/2,self.x0],[-1.,-0.5,0.],self.exp) else: return stuur(val,[self.x0,(self.x0+self.xmax)/2,self.xmax],[0.,0.5,1.0],1./self.exp2)
def dynazoom(self,x,y,action): """Perform dynamic zoom operation. This function processes mouse button events controlling a dynamic zoom operation. The action is one of PRESS, MOVE or RELEASE. """ if action == PRESS: self.state = [self.camera.getDist(),self.camera.area.tolist(),pf.cfg['gui/dynazoom']] elif action == MOVE: w,h = self.getSize() dx,dy = float(self.statex-x)/w, float(self.statey-y)/h for method,state,value,size in zip(self.state[2],[self.statex,self.statey],[x,y],[w,h]): #pf.debug("%s %s %s %s" % (method,state,value,size)) if method == 'area': d = float(state-value)/size f = exp(4*d) self.camera.zoomArea(f,area=asarray(self.state[1]).reshape(2,2)) elif method == 'dolly': d = utils.stuur(value,[0,state,size],[5,1,0.2],1.2) #pf.debug(d) self.camera.setDist(d*self.state[0]) self.update() elif action == RELEASE: self.update() self.camera.saveModelView()
def setFar(fld): val = fld.value()/100. cam = pf.canvas.camera res = stuur(val,[0.,0.5,1.0],[0.01*cam.dist,cam.dist,100.*cam.dist]) #print "%s = %s" % (val,res) cam.setClip(cam.near,res) pf.canvas.update()
def scale(self,val): """Scale a value to the range -1...1. If the ColorScale has only one exponent, values in the range mival..maxval are scaled to the range -1..+1. If two exponents were specified, scaling is done independently in one of the intervals minval..midval or midval..maxval resulting into resp. the interval -1..0 or 0..1. """ if self.exp2 == None: return stuur(val,[self.xmin,self.x0,self.xmax],[-1.,0.,1.],self.exp) if val < self.x0: return stuur(val,[self.xmin,(self.x0+self.xmin)/2,self.x0],[-1.,-0.5,0.],self.exp) else: return stuur(val,[self.x0,(self.x0+self.xmax)/2,self.xmax],[0.,0.5,1.0],1./self.exp2)
def setFar(fld): val = fld.value() / 100. cam = pf.canvas.camera res = stuur(val, [0., 0.5, 1.0], [0.01 * cam.dist, cam.dist, 100. * cam.dist]) #print "%s = %s" % (val,res) cam.setClip(cam.near, res) pf.canvas.update()
def dyna(self,x,y): """Perform dynamic zoom/pan/rotation functions""" w,h = self.width(),self.height() if self.dynamic == "trirotate": # set all three rotations from mouse movement # tangential movement sets twist, # but only if initial vector is big enough x0 = self.state # initial vector d = vector.length(x0) if d > h/8: x1 = [x-w/2, h/2-y, 0] # new vector a0 = math.atan2(x0[0],x0[1]) a1 = math.atan2(x1[0],x1[1]) an = (a1-a0) / math.pi * 180 ds = utils.stuur(d,[-h/4,h/8,h/4],[-1,0,1],2) twist = - an*ds #print "an,d,ds = ",an,d,ds,twist self.camera.rotate(twist,0.,0.,1.) self.state = x1 # radial movement rotates around vector in lens plane x0 = [self.statex-w/2, h/2-self.statey, 0] # initial vector dx = [x-self.statex, self.statey-y,0] # movement b = vector.projection(dx,x0) #print "x0,dx,b=",x0,dx,b if abs(b) > 5: val = utils.stuur(b,[-2*h,0,2*h],[-180,0,+180],1) rot = [ abs(val),-dx[1],dx[0],0 ] #print "val,rot=",val,rot self.camera.rotate(*rot) self.statex,self.statey = (x,y) elif self.dynamic == "pan": dist = self.camera.getDist() * 0.5 # hor movement sets x value of center # vert movement sets y value of center #panx = utils.stuur(x,[0,self.statex,w],[-dist,0.,+dist],1.0) #pany = utils.stuur(y,[0,self.statey,h],[-dist,0.,+dist],1.0) #self.camera.setCenter (self.state[0] - panx, self.state[1] + pany, self.state[2]) dx,dy = (x-self.statex,y-self.statey) panx = utils.stuur(dx,[-w,0,w],[-dist,0.,+dist],1.0) pany = utils.stuur(dy,[-h,0,h],[-dist,0.,+dist],1.0) #print dx,dy,panx,pany self.camera.translate(panx,-pany,0) self.statex,self.statey = (x,y) elif self.dynamic == "zoom": # hor movement is lens zooming f = utils.stuur(x,[0,self.statex,w],[180,self.statef,0],1.2) self.camera.setLens(f) elif self.dynamic == "combizoom": # hor movement is lens zooming f = utils.stuur(x,[0,self.statex,w],[180,self.state[1],0],1.2) #print "Lens Zooming: %s" % f self.camera.setLens(f) # vert movement is dolly zooming d = utils.stuur(y,[0,self.statey,h],[0.2,1,5],1.2) self.camera.setDist(d*self.state[0]) self.update()
def dynarot(self,x,y,action): """Perform dynamic rotation operation. This function processes mouse button events controlling a dynamic rotation operation. The action is one of PRESS, MOVE or RELEASE. """ if action == PRESS: w,h = self.getSize() self.state = [self.statex-w/2, self.statey-h/2 ] elif action == MOVE: w,h = self.getSize() # set all three rotations from mouse movement # tangential movement sets twist, # but only if initial vector is big enough x0 = self.state # initial vector d = length(x0) if d > h/8: # pf.debug(d) x1 = [x-w/2, y-h/2] # new vector a0 = math.atan2(x0[0],x0[1]) a1 = math.atan2(x1[0],x1[1]) an = (a1-a0) / math.pi * 180 ds = utils.stuur(d,[-h/4,h/8,h/4],[-1,0,1],2) twist = - an*ds self.camera.rotate(twist,0.,0.,1.) self.state = x1 # radial movement rotates around vector in lens plane x0 = [self.statex-w/2, self.statey-h/2] # initial vector if x0 == [0.,0.]: x0 = [1.,0.] dx = [x-self.statex, y-self.statey] # movement b = projection(dx,x0) if abs(b) > 5: val = utils.stuur(b,[-2*h,0,2*h],[-180,0,+180],1) rot = [ abs(val),-dx[1],dx[0],0 ] self.camera.rotate(*rot) self.statex,self.statey = (x,y) self.update() elif action == RELEASE: self.update() self.camera.saveModelView()
def scale(self, val): """Scale a value to the range -1...1. If the ColorScale has only one exponent, values in the range mival..maxval are scaled to the range -1..+1. If two exponents were specified, scaling is done independently in the intervals minval..midval and midval..maxval, mapped resp. using exp2 and exp onto the intevals -1..0 and 0..1. """ if self.exp2 == None: return stuur(val, [self.xmin, self.x0, self.xmax], [-1., 0., 1.], self.exp) if val < self.x0: return stuur(val, [self.xmin, (self.x0 + self.xmin) / 2, self.x0], [-1., -0.5, 0.], self.exp2) else: return stuur(val, [self.x0, (self.x0 + self.xmax) / 2, self.xmax], [0., 0.5, 1.0], 1. / self.exp)
def dynazoom(self,x,y,action): """Perform dynamic zoom operation. This function processes mouse button events controlling a dynamic zoom operation. The action is one of PRESS, MOVE or RELEASE. """ if action == PRESS: self.state = [self.camera.getDist(),self.camera.fovy] elif action == MOVE: w,h = self.getSize() # hor movement is lens zooming f = utils.stuur(x,[0,self.statex,w],[180,self.state[1],0],1.2) #print "Lens Zooming: %s" % f self.camera.setLens(f) # vert movement is dolly zooming d = utils.stuur(y,[0,self.statey,h],[5,1,0.2],1.2) self.camera.setDist(d*self.state[0]) self.update() elif action == RELEASE: self.update() self.camera.saveMatrix()
def dynapan(self,x,y,action): """Perform dynamic pan operation. This function processes mouse button events controlling a dynamic pan operation. The action is one of PRESS, MOVE or RELEASE. """ if action == PRESS: pass elif action == MOVE: w,h = self.getSize() dist = self.camera.getDist() * 0.5 # get distance from where button was pressed dx,dy = (x-self.statex,y-self.statey) panx = utils.stuur(dx,[-w,0,w],[-dist,0.,+dist],1.0) pany = utils.stuur(dy,[-h,0,h],[-dist,0.,+dist],1.0) # print dx,dy,panx,pany self.camera.translate(panx,pany,0) self.statex,self.statey = (x,y) self.update() elif action == RELEASE: self.update() self.camera.saveMatrix()
def scale(self,val): """Scale a value to the range -1...1.""" if self.exp2 == None: return stuur(val,[self.xmin,self.x0,self.xmax],[-1.,0.,1.],self.exp) return self.scale2(val)
def scale(self,val): """Scale a value to the range -1...1.""" return stuur(val,[self.xmin,self.x0,self.xmax],[-1.,0.,1.],1.)