From 9e72b681a4e3a6e6394093577d2a9d286068b514 Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Thu, 18 Aug 2022 12:52:11 +0200 Subject: [PATCH] add fixed target ROI --- pyqtUsrObj.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/pyqtUsrObj.py b/pyqtUsrObj.py index 2730b0f..3a5a046 100644 --- a/pyqtUsrObj.py +++ b/pyqtUsrObj.py @@ -241,6 +241,94 @@ class Path(pg.ROI): lv=QLineF(x, y-5*ry, x, y+5*ry) p.drawLines(lh,lv) +class FixTargetFrame(pg.ROI): + '''fixed target frame''' + tpl={ + 'test':{ + 'size':(120*15, 120*11), + 'fiducial':{ + 'type':0, + 'pos':((120*2, 120*2), (120*13, 120*2), (120*2, 120*9), (120*13, 120*9)) + }, + 'grid':{ + 'pos':(120*4, 120*3), + 'pitch':(120, 120), + 'count':(8, 6) + } + }, + '125x125':{ + 'size':(12500+120*4, 12500+120*4), + 'fiducial':{ + 'type':0, + 'pos':((240, 240), (240+12500, 240), (240, 240+12500), (240+12500, 240+12500)) + }, + 'grid':{ + 'pos':(1050, 1050), + 'pitch':(120, 120), + 'count':(90, 90) + } + } + } + + def __init__( self, pos=(0,0), size=(100,100), tpl='test', **kargs): + pg.ROI.__init__(self, pos, size, **kargs) + #fiducial type 0: 5 squares with pitch 120 um + self._dscr=FixTargetFrame.tpl[tpl] + + self.addScaleHandle([1, 1], [0, 0]) + self.addScaleHandle([0, 0], [1, 1]) + self.addScaleRotateHandle([1, 0], [0, 0]) + + def paint(self, p, *args): + #pg.ROI.paint(self, p, *args) + sz=self.state['size'] + #nx, ny=self._cnt + #px, py=sz[0]/(nx-1), sz[1]/(ny-1) + r=QtCore.QRectF(0, 0, sz[0], sz[1]).normalized() + p.setRenderHint(QtGui.QPainter.Antialiasing) + p.setPen(self.currentPen) + p.drawRect(0, 0, int(sz[0]), int(sz[1])) + + dscr=self._dscr + objSz=dscr['size'] + p.translate(r.left(), r.top()) + p.scale(r.width()/objSz[0], r.height()/objSz[1]) # -> values x,y 0 to 13000 + + dscr=self._dscr + + g=dscr['grid'] + ox,oy=g['pos'] + px,py=g['pitch'] + nx,ny=g['count'] + #x0=ox; x1=ox+(ny-1)*py + #y0=oy; y1=oy+(nx-1)*px + x0=ox-.5*px; x1=ox+(nx-.5)*px + y0=oy-.5*py; y1=oy+(ny-.5)*py + for i in range(nx): + x=ox+i*px + p.drawLine(pg.Point(x, y0), pg.Point(x, y1)) + + for i in range(ny): + y=oy+i*py + p.drawLine(pg.Point(x0, y), pg.Point(x1 ,y )) + + f=dscr['fiducial'] + rx=50 + ry=50 + + p.setPen(pg.mkPen(width=1, color=(255, 0, 0))) + if f['type']==0: + for p0 in f['pos']: + p0=np.array(p0) + for p1 in ((-120,-120),(120,-120),(0,0),(-120,120),(120,120),): + p1=np.array(p1) + x, y=p0+p1 ;print(x,y) + lh=QLineF(x-rx, y, x+rx, y) + lv=QLineF(x, y-ry, x, y+ry) + p.drawLines(lh, lv) + else: + assert('unknown feducial type') + class TxtROI(pg.ROI): @@ -396,6 +484,11 @@ if __name__=='__main__': #vi.setTransform(tr) # assign transform vb.addItem(vi) + vi=FixTargetFrame((100,300),(100,100),tpl='test') + vb.addItem(vi) + vi=FixTargetFrame((400,-200),(400,400),tpl='125x125') + vb.addItem(vi) + childTree(vb) w.scene().sigMouseClicked.connect(mouse_click_event)