fixing manip display. Now it seems to work...
This commit is contained in:
@@ -165,7 +165,7 @@ class HelicalScanGui():
|
||||
self.manip : True: moves the origin cross, False moves the Cristal
|
||||
'''
|
||||
param=self.helScn.param
|
||||
self.fig=fig=plt.figure()
|
||||
self.fig=fig=plt.figure();fig.canvas.set_window_title('interactive_cx_cz_w_fy'+(' manip' if manip else ''))
|
||||
self.manip=manip
|
||||
self.ax=ax=plt3d.Axes3D(fig,[0.02, 0.15, 0.96, 0.83])
|
||||
ax.set_xlabel('Z');ax.set_ylabel('X');ax.set_zlabel('Y')
|
||||
@@ -216,30 +216,27 @@ class HelicalScanGui():
|
||||
cz = self.sldCz.val
|
||||
w = self.sldW.val
|
||||
fy = self.sldFy.val
|
||||
w=w*d2r
|
||||
if self.manip:
|
||||
param = self.helScn.param
|
||||
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
p = np.ndarray((param.shape[0], 3))
|
||||
for i in range(2):
|
||||
(z_i, y_i, x_i, r_i, phi_i) = param[i]
|
||||
p[i, 0] = x_i + r_i * np.sin(phi_i) # x= x_i+r_i*cos(phi_i+w)+cx
|
||||
p[i, 1] = y_i # y= y_i
|
||||
p[i, 2] = z_i + r_i * np.cos(phi_i) # z= z_i+r_i*sin(phi_i*w)
|
||||
m = Trf.trans(cx,fy,cz)
|
||||
m= m.dot(Trf.rotY(w*d2r))
|
||||
#TODO: THE MODES WITH manip=True are totally wrong...
|
||||
#m=Trf.rotY(w*d2r)
|
||||
#m=m.dot(Trf.trans(cx,fy,cz))
|
||||
#rx=param[:,2].mean();rz=param[:,0].mean()
|
||||
#precise caldulation of rotation center dependent of y
|
||||
(z0, y0, x0, r0, phi0)=param[0]
|
||||
(z1, y1, x1, r1, phi1)=param[1]
|
||||
rx = x0+(x1-x0)/(y1-y0)*(fy-y0)
|
||||
rz = z0+(z1-z0)/(y1-y0)*(fy-y0)
|
||||
m=Trf.trans(rx,fy,rz).dot(Trf.rotY(-w).dot(Trf.trans(cx-rx,0,cz-rz)))
|
||||
self.pltOrig(m)
|
||||
else:
|
||||
w=w*d2r
|
||||
self.pltCrist(-cx, -cz, -w, -fy)
|
||||
self.pltCrist(-cx, -cz, w, -fy)
|
||||
#self.pltCrist(cx,cz,w*d2r,fy)
|
||||
self.fig.canvas.draw_idle()
|
||||
|
||||
def interactive_dx_dz_w_y(self):
|
||||
def interactive_dx_dz_w_y(self,manip=False):
|
||||
param=self.helScn.param
|
||||
self.fig=fig=plt.figure()
|
||||
self.fig=fig=plt.figure();fig.canvas.set_window_title('interactive_dx_dz_w_y'+(' manip' if manip else ''))
|
||||
self.manip=manip
|
||||
self.ax=ax=plt3d.Axes3D(fig,[0.02, 0.15, 0.96, 0.83])
|
||||
ax.set_xlabel('Z');ax.set_ylabel('X');ax.set_zlabel('Y')
|
||||
ax.view_init(elev=10, azim=-170)
|
||||
@@ -247,16 +244,27 @@ class HelicalScanGui():
|
||||
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
l=max(2*param[:,3].max(),param[:,1].ptp()) #max of diameter and y peaktopeak
|
||||
self.scale=l #scale is the length of a cube were the pltCrist object fits into
|
||||
self.axSetCenter((0,0,0),l)
|
||||
|
||||
axDx=plt.axes([0.1, 0.01, 0.8, 0.02])
|
||||
axDz=plt.axes([0.1, 0.04, 0.8, 0.02])
|
||||
axW =plt.axes([0.1, 0.07, 0.8, 0.02])
|
||||
axY =plt.axes([0.1, 0.10, 0.8, 0.02])
|
||||
if manip:
|
||||
y0=param[:, 1].mean()
|
||||
ly=sorted(param[:,1])
|
||||
x0=param[:, 2].mean()
|
||||
lx=(-l/2,l/2)
|
||||
z0=param[:, 0].mean()
|
||||
lz=(-l/2,l/2)
|
||||
self.axSetCenter((x0,y0,z0),l)
|
||||
else:
|
||||
self.axSetCenter((0, 0, 0), l)
|
||||
ly=sorted(param[:,1])
|
||||
x0=param[:, 2].mean()
|
||||
lx=(-l/2,l/2)
|
||||
z0=param[:, 0].mean()
|
||||
lz=(-l/2,l/2)
|
||||
|
||||
lz=ax.get_xlim()
|
||||
lx=ax.get_ylim()
|
||||
ly=sorted(param[:,1])
|
||||
self.sldDx=sDx=Slider(axDx, 'dx', lx[0], lx[1], valinit=(lx[0]+lx[1])/2.)
|
||||
self.sldDz=sDz=Slider(axDz, 'dz', lz[0], lz[1], valinit=(lz[0]+lz[1])/2.)
|
||||
self.sldW =sW =Slider(axW, 'ang', -180., 180.0, valinit=0)
|
||||
@@ -266,24 +274,13 @@ class HelicalScanGui():
|
||||
sW.on_changed(self.update_dx_dz_w_y)
|
||||
sY.on_changed(self.update_dx_dz_w_y)
|
||||
|
||||
self.pltOrig(Trf.trans(0, 0, 0))
|
||||
if manip:
|
||||
self.pltCrist(0,0,0,0)
|
||||
else:
|
||||
self.pltOrig(Trf.trans(0, 0, 0))
|
||||
self.update_dx_dz_w_y()
|
||||
plt.show()
|
||||
|
||||
# # param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
# p=np.ndarray((param.shape[0], 3))
|
||||
# for i in range(2):
|
||||
# (z_i, y_i, x_i, r_i, phi_i)=param[i]
|
||||
# p[i,0]=x_i+r_i*np.sin(phi_i) # x= x_i+r_i*cos(phi_i+w)+cx
|
||||
# p[i,1]=y_i # y= y_i
|
||||
# p[i,2]=z_i+r_i*np.cos(phi_i) # z= z_i+r_i*sin(phi_i*w)
|
||||
# ofs=(p[1]+p[0])/2. # = center of the cristal
|
||||
# print('p, ofs',p,ofs)
|
||||
#
|
||||
# m=Trf.trans(0,0,0); self.pltOrig(m)
|
||||
# self.pltCrist(cx=-ofs[0],cz=-ofs[2],w=0,fy=-ofs[1])
|
||||
#plt.show()
|
||||
|
||||
def update_dx_dz_w_y(self,val=None):
|
||||
helScn=self.helScn
|
||||
dx = self.sldDx.val
|
||||
@@ -292,13 +289,25 @@ class HelicalScanGui():
|
||||
y = self.sldY.val
|
||||
w=w*d2r
|
||||
(cx,cz,w,fy)=helScn.inv_transform(dx,dz,w,y)
|
||||
self.pltCrist(-cx,-cz,w,-fy)
|
||||
if self.manip:
|
||||
param = self.helScn.param
|
||||
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
#precise caldulation of rotation center dependent of y
|
||||
(z0, y0, x0, r0, phi0)=param[0]
|
||||
(z1, y1, x1, r1, phi1)=param[1]
|
||||
rx = x0+(x1-x0)/(y1-y0)*(fy-y0)
|
||||
rz = z0+(z1-z0)/(y1-y0)*(fy-y0)
|
||||
m=Trf.trans(rx,fy,rz).dot(Trf.rotY(-w).dot(Trf.trans(cx-rx,0,cz-rz)))
|
||||
self.pltOrig(m)
|
||||
else:
|
||||
self.pltCrist(-cx,-cz,w,-fy)
|
||||
self.fig.canvas.draw_idle()
|
||||
|
||||
def interactive_anim(self):
|
||||
def interactive_anim(self,manip=False):
|
||||
param=self.helScn.param
|
||||
rec=self.helScn.rec
|
||||
fig = plt.figure()
|
||||
fig = plt.figure();fig.canvas.set_window_title('interactive_anim'+(' manip' if manip else ''))
|
||||
self.manip=manip
|
||||
self.ax=ax=plt3d.Axes3D(fig,[0.02, 0.15, 0.96, 0.83])
|
||||
ax.set_xlabel('Z');ax.set_ylabel('X');ax.set_zlabel('Y')
|
||||
ax.view_init(elev=10, azim=-170)
|
||||
@@ -306,32 +315,45 @@ class HelicalScanGui():
|
||||
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
l=max(2*param[:,3].max(),param[:,1].ptp()) #max of diameter and y peaktopeak
|
||||
self.scale=l #scale is the length of a cube were the pltCrist object fits into
|
||||
self.axSetCenter((0,0,0),l)
|
||||
|
||||
axFrm=plt.axes([0.1, 0.01, 0.8, 0.02])
|
||||
if manip:
|
||||
y0=param[:, 1].mean()
|
||||
x0=param[:, 2].mean()
|
||||
z0=param[:, 0].mean()
|
||||
self.axSetCenter((x0,y0,z0),l)
|
||||
else:
|
||||
self.axSetCenter((0, 0, 0), l)
|
||||
|
||||
lx=[-1,1];ly=[0,1];lz=[-1,1]
|
||||
ly = param[:,1]
|
||||
self.sldFrm=sFrm=Slider(axFrm, 'frm', 0, rec.shape[0]-1, valinit=0)
|
||||
sFrm.on_changed(self.update_anim)
|
||||
self.fig=fig
|
||||
|
||||
self.pltOrig(Trf.trans(0,0,0))
|
||||
if manip:
|
||||
self.pltCrist(0,0,0,0)
|
||||
else:
|
||||
self.pltOrig(Trf.trans(0, 0, 0))
|
||||
self.update_anim(0)
|
||||
|
||||
#following lines make an animation
|
||||
#animCnt=100
|
||||
#self.step=rec.shape[0]/animCnt
|
||||
#a = anim.FuncAnimation(fig, self.anim_gather_data, animCnt, fargs=(), interval=20, repeat=False, blit=False)
|
||||
plt.show()
|
||||
pass
|
||||
|
||||
def update_anim(self,frm):
|
||||
rec=self.helScn.rec
|
||||
(cx, cz, w, fy)=rec[int(frm),:]
|
||||
#data/=. #scale from um to mm
|
||||
w*=d2r/1000 # scale from deg to rad
|
||||
self.pltCrist(-cx,-cz,w,-fy)
|
||||
if self.manip:
|
||||
param = self.helScn.param
|
||||
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
#rx=param[:,2].mean();rz=param[:,0].mean()
|
||||
#precise caldulation of rotation center dependent of y
|
||||
(z0, y0, x0, r0, phi0)=param[0]
|
||||
(z1, y1, x1, r1, phi1)=param[1]
|
||||
rx = x0+(x1-x0)/(y1-y0)*(fy-y0)
|
||||
rz = z0+(z1-z0)/(y1-y0)*(fy-y0)
|
||||
m=Trf.trans(rx,fy,rz).dot(Trf.rotY(-w).dot(Trf.trans(cx-rx,0,cz-rz)))
|
||||
self.pltOrig(m)
|
||||
else:
|
||||
self.pltCrist(-cx,-cz,w,-fy)
|
||||
self.fig.canvas.draw_idle()
|
||||
|
||||
def anim_gather_data(self,idx):
|
||||
@@ -1073,20 +1095,22 @@ if __name__=='__main__':
|
||||
fn='/tmp/helicalscan'
|
||||
hs.load_rec(fn+'.npz')
|
||||
hs.param[:4]+=np.pi/2.#add 90 deg
|
||||
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_anim()
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_anim(manip=True)
|
||||
#while True:hsg.update_anim(0)
|
||||
#hs.param = np.ndarray((2,5))
|
||||
#hs.param[0]=(15,2,0,3,0)#(z_i, y_i, x_i, r_i,phi_i)
|
||||
#hs.param[1]=(15,4,0,2,np.pi/4)#(z_i, y_i, x_i, r_i,phi_i)
|
||||
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy()
|
||||
#hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy(manip=True)
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy(manip=True)
|
||||
#while True: hsg.update_cx_cz_w_fy() #for debug purpose
|
||||
|
||||
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_dx_dz_w_y()
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_dx_dz_w_y(manip=True)
|
||||
#while True: hsg.update_dx_dz_w_y() #for debug purpose
|
||||
|
||||
#return
|
||||
|
||||
#TODO: FE Digitizers PBPS117 timing not working!
|
||||
|
||||
Reference in New Issue
Block a user