'Return an array of 0.0-1.0 into which the shape of the item has been drawn.
This can be used to mask array selections.'

def renderShapeMask(self, width, height):

    if ((width == 0) or (height == 0)):
        return np.empty((width, height), dtype=float)
    im = QtGui.QImage(width, height, QtGui.QImage.Format_ARGB32)
    im.fill(0)
    p = QtGui.QPainter(im)
    p.setPen(fn.mkPen(None))
    p.setBrush(fn.mkBrush('w'))
    shape = self.shape()
    bounds = shape.boundingRect()
    p.scale((im.width() / bounds.width()), (im.height() / bounds.height()))
    p.translate((- bounds.topLeft()))
    p.drawPath(shape)
    p.end()
    mask = (fn.imageToArray(im, transpose=True)[:, :, 0].astype(float) / 255.0)
    return mask
