rework graphic opbect and coordinate transformation
This commit is contained in:
@@ -95,54 +95,56 @@ class Marker(pg.ROI):
|
||||
if m==0:
|
||||
p.drawEllipse(0, 0, 100, 100)
|
||||
p.drawRect(0, 0, 100, 100)
|
||||
p.drawRect(0, 0, 5, 5)
|
||||
p.setPen(pg.mkPen(width=3, color=[200, 100, 100]))
|
||||
p.drawLine(pg.Point(50, 0), pg.Point(50, 100))
|
||||
p.drawLine(pg.Point( 0,50), pg.Point(100, 50))
|
||||
tr=p.transform()
|
||||
tr.setMatrix(tr.m11(), tr.m12(), tr.m13(), tr.m21(), -tr.m22(), tr.m23(), tr.m31(), tr.m32(), tr.m33())
|
||||
p.setTransform(tr)
|
||||
|
||||
ofx,ofy=Marker.txtTrf(p)
|
||||
f=p.font()
|
||||
f.setPixelSize(10)
|
||||
p.setFont(f)
|
||||
p.drawText(24, -80, 'beam marker')
|
||||
p.drawText(ofx+24, ofy+20, 'beam marker')
|
||||
ctr=tuple(self.pos()+self.size()/2)
|
||||
sz=tuple(self.size())
|
||||
p.drawText(5, -55, '{:.1f}x{:.1f}'.format(*sz))
|
||||
p.drawText(ofx+5, ofy+45, '{:.1f}x{:.1f}'.format(*sz))
|
||||
#p.drawText(5, -35, '{:.1f}'.format(ctr[0]))
|
||||
p.drawText(5, -45,42,30,Qt.AlignRight, '{:.1f}'.format(ctr[0]))
|
||||
p.drawText(55, -35, '{:.1f}'.format(ctr[1]))
|
||||
p.drawText(ofx+5, ofy+55,42,30,Qt.AlignRight, '{:.1f}'.format(ctr[0]))
|
||||
p.drawText(ofx+55, ofy+65, '{:.1f}'.format(ctr[1]))
|
||||
|
||||
elif m==1:
|
||||
p.drawEllipse(20,20,60,60)
|
||||
p.drawRect(0, 0, 5, 5)
|
||||
p.drawRect(0, 0, 100, 100)
|
||||
p.setPen(pg.mkPen(width=2, color=[10, 255, 0]))
|
||||
p.drawLine(pg.Point(50, 0), pg.Point( 50,100))
|
||||
p.drawLine(pg.Point( 0,50), pg.Point(100, 50))
|
||||
tr=p.transform()
|
||||
tr.setMatrix(tr.m11(), tr.m12(), tr.m13(), tr.m21(), -tr.m22(), tr.m23(), tr.m31(), tr.m32(), tr.m33())
|
||||
p.setTransform(tr)
|
||||
ofx,ofy=Marker.txtTrf(p)
|
||||
|
||||
f=p.font();
|
||||
f.setPixelSize(10)
|
||||
p.setFont(f)
|
||||
#p.drawText(ofx+0, ofy+0, 'FFF')
|
||||
#p.drawText(ofx+100, ofy+100, 'GGG')
|
||||
px=tuple(self.pos()+self.size()/2)
|
||||
p.drawText(5, -90, 'optical')
|
||||
p.drawText(55,-90, 'center')
|
||||
#p.drawText(5, -10, '{:.1f}/{:.1f}'.format(*px))
|
||||
p.drawText(5, -10, '{:.1f}'.format(px[0]))
|
||||
p.drawText(55, -10, '{:.1f}'.format(px[1]))
|
||||
#p.drawText(0, 0, 'Thierry')
|
||||
p.drawText(ofx+18, ofy+10, 'optical center')
|
||||
p.drawText(ofx+5, ofy+80,42,30,Qt.AlignRight, '{:.1f}'.format(px[0]))
|
||||
p.drawText(ofx+55,ofy+90, '{:.1f}'.format(px[1]))
|
||||
|
||||
@staticmethod
|
||||
def txtTrf(p):
|
||||
tr=p.transform()
|
||||
assert (p.transform()==p.worldTransform())
|
||||
m11, m12, m13, m21, m22, m23, m31, m32, m33=tr.m11(), tr.m12(), tr.m13(), tr.m21(), tr.m22(), tr.m23(), tr.m31(), tr.m32(), tr.m33()
|
||||
ofx=ofy=0
|
||||
if m11<0:
|
||||
m11=-m11; m12=-m12; ofx-=100
|
||||
if m22<0:
|
||||
m22=-m22; m21=-m21; ofy=-100
|
||||
tr.setMatrix(m11, m12, m13, m21, m22, m23, m31, m32, m33)
|
||||
p.setTransform(tr)
|
||||
return ofx,ofy
|
||||
|
||||
# w, h = self.getState()["size"]
|
||||
# v1, v2 = -(h * 0.8) / 2, (h * 0.8) / 2
|
||||
# h1, h2 = -(w * 0.8) / 2, (w * 0.8) / 2
|
||||
# p.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||
# p.setPen(pg.mkPen(width=3, color=[200, 100, 100]))
|
||||
# p.drawLine(pg.Point(0, v1), pg.Point(0, v2))
|
||||
# p.drawLine(pg.Point(h1, 0), pg.Point(h2, 0))
|
||||
# p.setPen(self.currentPen)
|
||||
# #p.setPen(pg.mkPen(width=3, color=[200, 200, 100]))
|
||||
# p.drawRect(-w / 2, -h / 2, w, h)
|
||||
# # p.drawText(-w, -h, '{:.0f}x{:.0f}'.format(*self._size))
|
||||
|
||||
class Fiducial(pg.ROI):
|
||||
def __init__(self, pos, size, z:float, **kargs):
|
||||
@@ -602,7 +604,8 @@ if __name__=='__main__':
|
||||
obj_info(tr)
|
||||
#tr.setMatrix(tr.m11(),tr.m12(),tr.m13()+100,tr.m21(),tr.m22(),tr.m23(),tr.m31(),tr.m32(),tr.m33())
|
||||
#tr.setMatrix(tr.m11(),tr.m12(),tr.m13(),tr.m21(),tr.m22(),tr.m23(),tr.m31(),tr.m32()+20,tr.m33())
|
||||
tr.setMatrix(tr.m11(),tr.m12(),tr.m13(),tr.m21(),-tr.m22(),tr.m23(),tr.m31(),tr.m32(),tr.m33())
|
||||
#tr.setMatrix(tr.m11(),tr.m12(),tr.m13(),tr.m21(),-tr.m22(),tr.m23(),tr.m31(),tr.m32(),tr.m33())
|
||||
tr.setMatrix(-tr.m11(),tr.m12(),tr.m13(),tr.m21(),-tr.m22(),tr.m23(),tr.m31(),tr.m32(),tr.m33())
|
||||
obj_info(tr)
|
||||
o.setTransform(tr)
|
||||
elif m&Qt.AltModifier:
|
||||
@@ -645,26 +648,37 @@ if __name__=='__main__':
|
||||
vb.addItem(viImg)
|
||||
# Custom ROI for selecting an image region
|
||||
#viRoi=pg.ROI([20, -50], [60, 40])
|
||||
viRoi=TxtROI([20, -50], [60, 40])
|
||||
#viRoi=TxtROI([20, -50], [60, 40])
|
||||
#viRoi.addScaleHandle([1, 1], [0, 0])
|
||||
#viRoi.addScaleHandle([.7, .5], [0, 0])
|
||||
|
||||
vb.addItem(viRoi)
|
||||
#vb.addItem(viRoi)
|
||||
viUsrRoi=Marker([50, 120], [30, 20],mode=0)
|
||||
vb.addItem(viUsrRoi)
|
||||
obj=Marker([250, 220], [30, 20],mode=1)
|
||||
vb.addItem(obj)
|
||||
#obj=Marker([250, 220], [30, 20],mode=1)
|
||||
#vb.addItem(obj)
|
||||
vi=Grid( (120,-100), (200,150), (30,20),2)
|
||||
tr=QtGui.QTransform() # prepare ImageItem transformation:
|
||||
tr.setMatrix(1, -.1, 0,
|
||||
.2, 1, 0,
|
||||
10, 10, 1)
|
||||
vi.setTransform(tr) # assign transform
|
||||
|
||||
|
||||
#vi=Grid( (50,10), (200,150), (6,4))
|
||||
vb.addItem(vi) #vi= visual item
|
||||
|
||||
grp=pg.ItemGroup()
|
||||
vb.addItem(grp)
|
||||
tr.setMatrix(-1, -.1, 0,
|
||||
.2, -1, 0,
|
||||
10, 10, 1)
|
||||
grp.setTransform(tr) # assign transform
|
||||
obj=Marker([20, 40], [30, 20],mode=1)
|
||||
grp.addItem(obj)
|
||||
|
||||
obj=Marker([20, 40], [30, 20],mode=1)
|
||||
vb.addItem(obj)
|
||||
|
||||
|
||||
fidScl=.5
|
||||
fiducial=np.array(((18, 7), (25, 16), (70, 20)))
|
||||
path=gen_swissmx_points(ofs=(10, 5), width=200)
|
||||
|
||||
Reference in New Issue
Block a user