Add returnMappedCoords option to LineSegmentROI.getArrayRegion
This commit is contained in:
parent
7f0556b05f
commit
be07979b39
@ -2070,9 +2070,9 @@ class LineSegmentROI(ROI):
|
|||||||
if len(positions) > 2:
|
if len(positions) > 2:
|
||||||
raise Exception("LineSegmentROI must be defined by exactly 2 positions. For more points, use PolyLineROI.")
|
raise Exception("LineSegmentROI must be defined by exactly 2 positions. For more points, use PolyLineROI.")
|
||||||
|
|
||||||
|
self.endpoints = []
|
||||||
for i, p in enumerate(positions):
|
for i, p in enumerate(positions):
|
||||||
self.addFreeHandle(p, item=handles[i])
|
self.endpoints.append(self.addFreeHandle(p, item=handles[i]))
|
||||||
|
|
||||||
|
|
||||||
def listPoints(self):
|
def listPoints(self):
|
||||||
return [p['item'].pos() for p in self.handles]
|
return [p['item'].pos() for p in self.handles]
|
||||||
@ -2080,8 +2080,8 @@ class LineSegmentROI(ROI):
|
|||||||
def paint(self, p, *args):
|
def paint(self, p, *args):
|
||||||
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||||
p.setPen(self.currentPen)
|
p.setPen(self.currentPen)
|
||||||
h1 = self.handles[0]['item'].pos()
|
h1 = self.endpoints[0].pos()
|
||||||
h2 = self.handles[1]['item'].pos()
|
h2 = self.endpoints[1].pos()
|
||||||
p.drawLine(h1, h2)
|
p.drawLine(h1, h2)
|
||||||
|
|
||||||
def boundingRect(self):
|
def boundingRect(self):
|
||||||
@ -2090,8 +2090,8 @@ class LineSegmentROI(ROI):
|
|||||||
def shape(self):
|
def shape(self):
|
||||||
p = QtGui.QPainterPath()
|
p = QtGui.QPainterPath()
|
||||||
|
|
||||||
h1 = self.handles[0]['item'].pos()
|
h1 = self.endpoints[0].pos()
|
||||||
h2 = self.handles[1]['item'].pos()
|
h2 = self.endpoints[1].pos()
|
||||||
dh = h2-h1
|
dh = h2-h1
|
||||||
if dh.length() == 0:
|
if dh.length() == 0:
|
||||||
return p
|
return p
|
||||||
@ -2109,7 +2109,7 @@ class LineSegmentROI(ROI):
|
|||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
def getArrayRegion(self, data, img, axes=(0,1), order=1, **kwds):
|
def getArrayRegion(self, data, img, axes=(0,1), order=1, returnMappedCoords=False, **kwds):
|
||||||
"""
|
"""
|
||||||
Use the position of this ROI relative to an imageItem to pull a slice
|
Use the position of this ROI relative to an imageItem to pull a slice
|
||||||
from an array.
|
from an array.
|
||||||
@ -2120,15 +2120,15 @@ class LineSegmentROI(ROI):
|
|||||||
See ROI.getArrayRegion() for a description of the arguments.
|
See ROI.getArrayRegion() for a description of the arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
imgPts = [self.mapToItem(img, h['item'].pos()) for h in self.handles]
|
imgPts = [self.mapToItem(img, h.pos()) for h in self.endpoints]
|
||||||
rgns = []
|
rgns = []
|
||||||
for i in range(len(imgPts)-1):
|
coords = []
|
||||||
d = Point(imgPts[i+1] - imgPts[i])
|
|
||||||
o = Point(imgPts[i])
|
d = Point(imgPts[1] - imgPts[0])
|
||||||
r = fn.affineSlice(data, shape=(int(d.length()),), vectors=[Point(d.norm())], origin=o, axes=axes, order=order, **kwds)
|
o = Point(imgPts[0])
|
||||||
rgns.append(r)
|
rgn = fn.affineSlice(data, shape=(int(d.length()),), vectors=[Point(d.norm())], origin=o, axes=axes, order=order, returnCoords=returnMappedCoords, **kwds)
|
||||||
|
|
||||||
return np.concatenate(rgns, axis=axes[0])
|
return rgn
|
||||||
|
|
||||||
|
|
||||||
class _PolyLineSegment(LineSegmentROI):
|
class _PolyLineSegment(LineSegmentROI):
|
||||||
|
Loading…
Reference in New Issue
Block a user