wip
This commit is contained in:
19
geometry.py
19
geometry.py
@@ -384,6 +384,23 @@ if __name__=="__main__":
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib as mpl
|
import matplotlib as mpl
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
|
||||||
|
class MyJsonEncoder(json.JSONEncoder):
|
||||||
|
""" Special json encoder for numpy types """
|
||||||
|
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, np.integer):
|
||||||
|
return int(obj)
|
||||||
|
elif isinstance(obj, np.floating):
|
||||||
|
return float(obj)
|
||||||
|
elif isinstance(obj, np.ndarray):
|
||||||
|
return obj.tolist()
|
||||||
|
elif type(obj) not in (dict, list, str, int):
|
||||||
|
_log.error('dont know how to json')
|
||||||
|
return repr(obj)
|
||||||
|
return json.JSONEncoder.default(self, obj)
|
||||||
|
|
||||||
|
|
||||||
np.set_printoptions(suppress=True)
|
np.set_printoptions(suppress=True)
|
||||||
np.set_printoptions(linewidth=196)
|
np.set_printoptions(linewidth=196)
|
||||||
@@ -444,6 +461,8 @@ if __name__=="__main__":
|
|||||||
|
|
||||||
|
|
||||||
obj.update_pix2pos(measure)
|
obj.update_pix2pos(measure)
|
||||||
|
print(json.dumps(obj._lut_pix2pos, cls=MyJsonEncoder))
|
||||||
|
|
||||||
obj.interp_zoom(1)
|
obj.interp_zoom(1)
|
||||||
print(obj._pix2pos)
|
print(obj._pix2pos)
|
||||||
print(obj._pix2pos.I)
|
print(obj._pix2pos.I)
|
||||||
|
|||||||
@@ -105,12 +105,12 @@ class Marker(pg.ROI):
|
|||||||
f.setPixelSize(10)
|
f.setPixelSize(10)
|
||||||
p.setFont(f)
|
p.setFont(f)
|
||||||
p.drawText(ofx+24, ofy+20, 'beam marker')
|
p.drawText(ofx+24, ofy+20, 'beam marker')
|
||||||
ctr=tuple(self.pos()+self.size()/2)
|
ctr=tuple((self.pos()+self.size()/2)*1000)
|
||||||
sz=tuple(self.size())
|
sz=tuple(self.size()*1000)
|
||||||
p.drawText(ofx+5, ofy+45, '{:.1f}x{:.1f}'.format(*sz))
|
p.drawText(ofx+5, ofy+45, '{:.1f}x{:.1f} um'.format(*sz))
|
||||||
#p.drawText(5, -35, '{:.1f}'.format(ctr[0]))
|
#p.drawText(5, -35, '{:.1f}'.format(ctr[0]))
|
||||||
p.drawText(ofx+5, ofy+55,42,30,Qt.AlignRight, '{:.1f}'.format(ctr[0]))
|
p.drawText(ofx+5, ofy+55,42,30,Qt.AlignRight, '{:.1f}'.format(ctr[0]))
|
||||||
p.drawText(ofx+55, ofy+65, '{:.1f}'.format(ctr[1]))
|
p.drawText(ofx+55, ofy+65, '{:.1f} um'.format(ctr[1]))
|
||||||
|
|
||||||
elif m==1:
|
elif m==1:
|
||||||
p.drawEllipse(20,20,60,60)
|
p.drawEllipse(20,20,60,60)
|
||||||
|
|||||||
88
swissmx.py
88
swissmx.py
@@ -108,6 +108,7 @@ ts.log('Import part 5/8:')
|
|||||||
import matplotlib as mpl
|
import matplotlib as mpl
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
np.set_printoptions(suppress=True,linewidth=196)
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import pyqtgraph.exporters
|
import pyqtgraph.exporters
|
||||||
# use antialias for draw lines, interpret image data as row-major instead of col-major
|
# use antialias for draw lines, interpret image data as row-major instead of col-major
|
||||||
@@ -378,6 +379,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
def init_graphics(self):
|
def init_graphics(self):
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
cfg = app._cfg
|
cfg = app._cfg
|
||||||
|
geo = app._geometry
|
||||||
self.glw = pg.GraphicsLayoutWidget()
|
self.glw = pg.GraphicsLayoutWidget()
|
||||||
self.microscope_page.setLayout(QVBoxLayout())
|
self.microscope_page.setLayout(QVBoxLayout())
|
||||||
self.microscope_page.layout().addWidget(self.glw)
|
self.microscope_page.layout().addWidget(self.glw)
|
||||||
@@ -431,15 +433,31 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
#grid.setTransform(tr) # assign transform
|
#grid.setTransform(tr) # assign transform
|
||||||
vb.addItem(grid)
|
vb.addItem(grid)
|
||||||
|
|
||||||
|
#--- fixed group ---
|
||||||
|
# uses pix2pos transformation with a fixed fx,fy value =(0,0)
|
||||||
|
# contains beam marker
|
||||||
|
self._goFixGrp=grp=pg.ItemGroup()
|
||||||
|
|
||||||
|
geo.interp_zoom(1)
|
||||||
|
pix2pos=geo._pix2pos
|
||||||
|
A=np.asarray(pix2pos.I)
|
||||||
|
tr=grp.transform()
|
||||||
|
p1=np.hstack((opt_ctr,1)) #position of optical center on image item
|
||||||
|
p2=np.matmul(trf, p1) #position of optical center on viewbox
|
||||||
|
tr.setMatrix(A[0,0], A[0,1], 0,
|
||||||
|
A[1,0], A[1,1], 0,
|
||||||
|
p2[0], p2[1], 1) # translate dx,dy
|
||||||
|
grp.setTransform(tr)
|
||||||
|
self.vb.addItem(grp)
|
||||||
|
|
||||||
#--- beam marker ---
|
#--- beam marker ---
|
||||||
bm_sz=np.array((50, 40)) # it is immidiatly repositioned in cb_zoom_changed
|
size_eu=cfg.value(AppCfg.GEO_BEAM_SZ)
|
||||||
self._goBeamMarker=obj=UsrGO.Marker(-opt_ctr-bm_sz/2,bm_sz,mode=0)
|
pos_eu=cfg.value(AppCfg.GEO_BEAM_POS)
|
||||||
obj._size_eu=cfg.value(AppCfg.GEO_BEAM_SZ)
|
pos_eu*=0
|
||||||
obj._pos_eu=cfg.value(AppCfg.GEO_BEAM_POS)
|
self._goBeamMarker=obj=UsrGO.Marker(pos_eu-size_eu/2,size_eu,mode=0)
|
||||||
obj.sigRegionChangeFinished.connect(self.cb_marker_moved)
|
obj.sigRegionChangeFinished.connect(self.cb_marker_moved)
|
||||||
#bm.setTransform(tr) # assign transform
|
#bm.setTransform(tr) # assign transform
|
||||||
vb.addItem(obj)
|
grp.addItem(obj)
|
||||||
|
|
||||||
#--- testing scan grid ---
|
#--- testing scan grid ---
|
||||||
#self.track_objects() # first call is needed to initialize the structure self._goTracked
|
#self.track_objects() # first call is needed to initialize the structure self._goTracked
|
||||||
@@ -802,15 +820,28 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
_log.warning(e)
|
_log.warning(e)
|
||||||
else:
|
else:
|
||||||
|
grp=self._goFixGrp
|
||||||
opt_ctr=geo._opt_ctr
|
opt_ctr=geo._opt_ctr
|
||||||
bm=self._goBeamMarker
|
A=np.asarray(geo._pix2pos.I)
|
||||||
bm_sz=np.abs(geo.pos2pix(bm._size_eu))
|
#trf=cfg.value(AppCfg.GEO_CAM_TRF)
|
||||||
bm_pos=-opt_ctr-geo.pos2pix(bm._pos_eu)-bm_sz/2
|
tr=self._goImgGrp.transform()
|
||||||
bm.blockSignals(True) # avoid to call cb_marker_moved
|
trf=np.array( ((tr.m11(),tr.m21(),tr.m31()),(tr.m12(),tr.m22(),tr.m32()),(tr.m13(),tr.m23(),tr.m33())) )
|
||||||
bm.setPos(bm_pos,finish=False)
|
tr=grp.transform()
|
||||||
bm.setSize(bm_sz)
|
p1=np.hstack((opt_ctr, 1)) # position of optical center on image item
|
||||||
bm.blockSignals(False)
|
p2=np.matmul(trf, p1) # position of optical center on viewbox
|
||||||
_log.debug(f"zoom->{value} beam marker pos:{bm_pos} sz:{bm_sz})")
|
tr.setMatrix(A[0, 0], A[0, 1], 0,
|
||||||
|
A[1, 0], A[1, 1], 0,
|
||||||
|
p2[0], p2[1], 1) # translate dx,dy
|
||||||
|
grp.setTransform(tr)
|
||||||
|
|
||||||
|
#bm=self._goBeamMarker
|
||||||
|
#bm_sz=np.abs(geo.pos2pix(bm._size_eu))
|
||||||
|
#bm_pos=-opt_ctr-geo.pos2pix(bm._pos_eu)-bm_sz/2
|
||||||
|
#bm.blockSignals(True) # avoid to call cb_marker_moved
|
||||||
|
#bm.setPos(bm_pos,finish=False)
|
||||||
|
#bm.setSize(bm_sz)
|
||||||
|
#bm.blockSignals(False)
|
||||||
|
#_log.debug(f"zoom->{value} beam marker pos:{bm_pos} sz:{bm_sz})")
|
||||||
self.track_objects()
|
self.track_objects()
|
||||||
|
|
||||||
def cb_move_backlight_safe(self, pos):
|
def cb_move_backlight_safe(self, pos):
|
||||||
@@ -982,10 +1013,12 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
task = self.active_task()
|
task = self.active_task()
|
||||||
z = app._zoom.get_val()
|
z = app._zoom.get_val()
|
||||||
|
|
||||||
#bm=self._goBeamMarker
|
bm=self._goBeamMarker
|
||||||
#pos=event.scenePos()
|
#pos=event.scenePos()
|
||||||
pImg=pg.Point(self._goImg.mapFromScene(pos))
|
pImg=pg.Point(self._goImg.mapFromScene(pos))
|
||||||
pTrk=pg.Point(self._goTracked.mapFromScene(pos))
|
pTrk=pg.Point(self._goTracked.mapFromScene(pos))
|
||||||
|
pFix=pg.Point(self._goFixGrp.mapFromScene(pos))
|
||||||
|
pFix-=bm.pos()+bm.size()/2
|
||||||
fx=self.tweakers["fast_x"].get_val()
|
fx=self.tweakers["fast_x"].get_val()
|
||||||
fy=self.tweakers["fast_y"].get_val()
|
fy=self.tweakers["fast_y"].get_val()
|
||||||
pRel=pTrk-(fx,fy)
|
pRel=pTrk-(fx,fy)
|
||||||
@@ -1000,7 +1033,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
s=\
|
s=\
|
||||||
f'img pix ({pImg[0]:0.1f} {pImg[1]:0.1f})px \u23A2 ' \
|
f'img pix ({pImg[0]:0.1f} {pImg[1]:0.1f})px \u23A2 ' \
|
||||||
f'stage ({pTrk[0]:0.4f} {pTrk[1]:>0.4f} {cz:>0.4f})mm \u23A2 ' \
|
f'stage ({pTrk[0]:0.4f} {pTrk[1]:>0.4f} {cz:>0.4f})mm \u23A2 ' \
|
||||||
f'dist to beam ({pRel[0]:>0.4f} {pRel[1]:>0.4f})mm '
|
f'dist to beam ({pFix[0]:>0.4f} {pFix[1]:>0.4f})mm '
|
||||||
#f'dist to beam ({pRel[0]:>0.6g} {pRel[1]:>0.6g}mm) '
|
#f'dist to beam ({pRel[0]:>0.6g} {pRel[1]:>0.6g}mm) '
|
||||||
|
|
||||||
#_log.debug(s)
|
#_log.debug(s)
|
||||||
@@ -1079,19 +1112,20 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
_log.debug(f'move to position :scene pos {pos}')
|
_log.debug(f'move to position :scene pos {pos}')
|
||||||
geo=app._geometry
|
geo=app._geometry
|
||||||
|
|
||||||
|
bm=self._goBeamMarker
|
||||||
pImg=pg.Point(self._goImg.mapFromScene(pos))
|
pImg=pg.Point(self._goImg.mapFromScene(pos))
|
||||||
pTrk=pg.Point(self._goTracked.mapFromScene(pos))
|
pTrk=pg.Point(self._goTracked.mapFromScene(pos))
|
||||||
fx=self.tweakers["fast_x"].get_val()
|
pFix=pg.Point(self._goFixGrp.mapFromScene(pos))
|
||||||
fy=self.tweakers["fast_y"].get_val()
|
pFix-=bm.pos()+bm.size()/2
|
||||||
pRel=pTrk-(fx, fy)
|
|
||||||
_log.debug(f'dist to beam ({pTrk[0]:>0.6g} {pTrk[1]:>0.6g}mm)')
|
_log.debug(f'dist to beam ({pFix[0]:>0.6g} {pFix[1]:>0.6g}mm)')
|
||||||
fx_motor=self.tweakers["fast_x"]
|
fx_motor=self.tweakers["fast_x"]
|
||||||
fy_motor=self.tweakers["fast_y"]
|
fy_motor=self.tweakers["fast_y"]
|
||||||
|
|
||||||
#fx_motor.move_rel(pRel[0])
|
fx_motor.move_rel(pFix[0])
|
||||||
#fy_motor.move_rel(pRel[1])
|
fy_motor.move_rel(pFix[1])
|
||||||
fx_motor.move_abs(pTrk[0])
|
#fx_motor.move_abs(fx_motor.get_val()+pFix[0])
|
||||||
fy_motor.move_abs(pTrk[1])
|
#fy_motor.move_abs(fy_motor.get_val()+pFix[1])
|
||||||
try:
|
try:
|
||||||
pln=geo._fitPlane
|
pln=geo._fitPlane
|
||||||
except AttributeError: pass
|
except AttributeError: pass
|
||||||
@@ -1283,8 +1317,8 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
tr=grp.transform()
|
tr=grp.transform()
|
||||||
#UsrGO.obj_info(tr)
|
#UsrGO.obj_info(tr)
|
||||||
bm=self._goBeamMarker
|
bm=self._goBeamMarker
|
||||||
bm_pos=bm._pos_eu
|
bm_pos=bm.pos()
|
||||||
bm_sz=bm._size_eu
|
bm_sz=bm.size()
|
||||||
|
|
||||||
pos=(-fx,-fy)-bm_pos
|
pos=(-fx,-fy)-bm_pos
|
||||||
#fx_px,fy_px=geo.pos2pix((fx,fy)-bm_pos)-opt_ctr
|
#fx_px,fy_px=geo.pos2pix((fx,fy)-bm_pos)-opt_ctr
|
||||||
@@ -1878,8 +1912,8 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
#cb.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)"])
|
#cb.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)"])
|
||||||
|
|
||||||
bm_pos_eu=self._goBeamMarker._pos_eu
|
#bm_pos_eu=self._goBeamMarker._pos_eu
|
||||||
bm_size_eu=self._goBeamMarker._size_eu
|
#bm_size_eu=self._goBeamMarker._size_eu
|
||||||
|
|
||||||
if idx==0:
|
if idx==0:
|
||||||
#go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz))
|
#go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz))
|
||||||
|
|||||||
Reference in New Issue
Block a user