コード例 #1
0
ファイル: app.py プロジェクト: will-moore/openlayers4omero
    def addRoi(self, request, imageid):
        img = self.getImage0(imageid)
        if img is None:
            return None

        data = json.loads(request.body)
        shapes = data['shapes']
        x = y = l = z = t = -1
        for s in shapes:
            for k in s:
                val = s[k]
                if k == "x":
                    x = int(val)
                elif k == "y":
                    y = int(val)
                elif k == "width":
                    l = int(val)
                elif k == "theZ":
                    z = int(val)
                elif k == "theT":
                    t = int(val)
                elif k == "fillColorAsInt":
                    fill = int(val)
                elif k == "strokeColorAsInt":
                    stroke = int(val)
                elif k == "strokeWidth":
                    strokeWidth = int(val)
        
        if (x < 0 or y < 0 or z < 0 or t < 0 or l <= 0):
            return None
        
        updateService = self._connection.getUpdateService()
        roi = RoiI()
        roi.setImage(img._obj)
        rect = RectangleI()
        rect.x = rdouble(x)
        rect.y = rdouble(y)
        rect.width = rdouble(l)
        rect.height = rdouble(l)
        rect.theZ = rint(z)
        rect.theT = rint(t)
        rect.setFillColor(rint(fill))
        strokeLen = LengthI()
        strokeLen.setValue(strokeWidth)
        strokeLen.setUnit(UnitsLength.PIXEL)
        rect.setStrokeWidth(strokeLen)
        rect.setStrokeColor(rint(stroke))
        roi.addShape(rect)
        
        if (updateService.saveAndReturnObject(roi) is None):
            return None
        return self.get_rois(imageid) 
コード例 #2
0
    def addRoi(self, request, imageid):
        img = self.getImage0(imageid)
        if img is None:
            return None

        data = json.loads(request.body)
        shapes = data['shapes']
        x = y = l = z = t = -1
        for s in shapes:
            for k in s:
                val = s[k]
                if k == "x":
                    x = int(val)
                elif k == "y":
                    y = int(val)
                elif k == "width":
                    l = int(val)
                elif k == "theZ":
                    z = int(val)
                elif k == "theT":
                    t = int(val)
                elif k == "fillColorAsInt":
                    fill = int(val)
                elif k == "strokeColorAsInt":
                    stroke = int(val)
                elif k == "strokeWidth":
                    strokeWidth = int(val)

        if (x < 0 or y < 0 or z < 0 or t < 0 or l <= 0):
            return None

        updateService = self._connection.getUpdateService()
        roi = RoiI()
        roi.setImage(img._obj)
        rect = RectangleI()
        rect.x = rdouble(x)
        rect.y = rdouble(y)
        rect.width = rdouble(l)
        rect.height = rdouble(l)
        rect.theZ = rint(z)
        rect.theT = rint(t)
        rect.setFillColor(rint(fill))
        strokeLen = LengthI()
        strokeLen.setValue(strokeWidth)
        strokeLen.setUnit(UnitsLength.PIXEL)
        rect.setStrokeWidth(strokeLen)
        rect.setStrokeColor(rint(stroke))
        roi.addShape(rect)

        if (updateService.saveAndReturnObject(roi) is None):
            return None
        return self.get_rois(imageid)
コード例 #3
0
class ShapeSettingsData(object):

    ##
    # Initialises the default values of the ShapeSettings.
    # Stroke has default colour of darkGrey
    # StrokeWidth defaults to 1
    #

    def __init__(self):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        self.WHITE = 16777215
        self.BLACK = 0
        self.GREY = 11184810
        self.strokeColour = rint(self.GREY)
        self.strokeWidth = LengthI()
        self.strokeWidth.setValue(1)
        self.strokeWidth.setUnit(UnitsLength.POINT)
        self.strokeDashArray = rstring('')
        self.fillColour = rint(self.GREY)
        self.fillRule = rstring('')

    ##
    # Applies the settings in the ShapeSettingsData to the ROITypeI
    # @param shape the omero.model.ROITypeI that these settings will
    #              be applied to
    #
    def setROIShapeSettings(self, shape):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        shape.setStrokeColor(self.strokeColour)
        shape.setStrokeWidth(self.strokeWidth)
        shape.setStrokeDashArray(self.strokeDashArray)
        shape.setFillColor(self.fillColour)
        shape.setFillRule(self.fillRule)

    ##
    # Set the Stroke settings of the ShapeSettings.
    # @param colour The colour of the stroke.
    # @param width The stroke width.
    #
    def setStrokeSettings(self, colour, width=1):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        self.strokeColour = rint(colour)
        self.strokeWidth = LengthI()
        self.strokeWidth.setValue(width)
        self.strokeWidth.setUnit(UnitsLength.POINT)

    ###
    # Set the Fill Settings for the ShapeSettings.
    # @param colour The fill colour of the shape.
    def setFillSettings(self, colour):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        self.fillColour = rstring(colour)

    ##
    # Get the stroke settings as the tuple (strokeColour, strokeWidth).
    # @return See above.
    #
    def getStrokeSettings(self):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        return (self.strokeColour.getValue(), self.strokeWidth.getValue())

    ##
    # Get the fill setting as a tuple of (fillColour)
    # @return See above.
    #
    def getFillSettings(self):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        return (self.fillColour.getValue())

    ##
    # Get the tuple ((stokeColor, strokeWidth), (fillColour)).
    # @return see above.
    #
    def getSettings(self):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        return (self.getStrokeSettings(), self.getFillSettings())

    ##
    # Set the current shapeSettings from the ROI roi.
    # @param roi see above.
    #
    def getShapeSettingsFromROI(self, roi):
        warnings.warn("This module is deprecated as of OMERO 5.3.0",
                      DeprecationWarning)
        self.strokeColour = roi.getStrokeColor()
        self.strokeWidth = roi.getStrokeWidth()
        self.strokeDashArray = roi.getStrokeDashArray()
        self.fillColour = roi.getFillColor()
        self.fillRule = roi.getFillRule()
コード例 #4
0
class ShapeSettingsData:

    ##
    # Initialises the default values of the ShapeSettings.
    # Stroke has default colour of darkGrey
    # StrokeWidth defaults to 1
    #

    def __init__(self):
        self.WHITE = 16777215
        self.BLACK = 0
        self.GREY = 11184810
        self.strokeColour = rint(self.GREY)
        self.strokeWidth = LengthI()
        self.strokeWidth.setValue(1)
        self.strokeWidth.setUnit(UnitsLength.POINT)
        self.strokeDashArray = rstring('')
        self.strokeDashOffset = rint(0)
        self.strokeLineCap = rstring('')
        self.strokeLineJoin = rstring('')
        self.strokeMiterLimit = rint(0)
        self.fillColour = rint(self.GREY)
        self.fillRule = rstring('')

    ##
    # Applies the settings in the ShapeSettingsData to the ROITypeI
    # @param shape the omero.model.ROITypeI that these settings will
    #              be applied to
    #
    def setROIShapeSettings(self, shape):
        shape.setStrokeColor(self.strokeColour)
        shape.setStrokeWidth(self.strokeWidth)
        shape.setStrokeDashArray(self.strokeDashArray)
        shape.setStrokeDashOffset(self.strokeDashOffset)
        shape.setStrokeLineCap(self.strokeLineCap)
        shape.setStrokeLineJoin(self.strokeLineJoin)
        shape.setStrokeMiterLimit(self.strokeMiterLimit)
        shape.setFillColor(self.fillColour)
        shape.setFillRule(self.fillRule)

    ##
    # Set the Stroke settings of the ShapeSettings.
    # @param colour The colour of the stroke.
    # @param width The stroke width.
    #
    def setStrokeSettings(self, colour, width=1):
        self.strokeColour = rint(colour)
        self.strokeWidth = LengthI()
        self.strokeWidth.setValue(width)
        self.strokeWidth.setUnit(UnitsLength.POINT)

    ###
    # Set the Fill Settings for the ShapeSettings.
    # @param colour The fill colour of the shape.
    def setFillSettings(self, colour):
        self.fillColour = rstring(colour)

    ##
    # Get the stroke settings as the tuple (strokeColour, strokeWidth).
    # @return See above.
    #
    def getStrokeSettings(self):
        return (self.strokeColour.getValue(), self.strokeWidth.getValue())

    ##
    # Get the fill setting as a tuple of (fillColour)
    # @return See above.
    #
    def getFillSettings(self):
        return (self.fillColour.getValue())

    ##
    # Get the tuple ((stokeColor, strokeWidth), (fillColour)).
    # @return see above.
    #
    def getSettings(self):
        return (self.getStrokeSettings(), self.getFillSettings())

    ##
    # Set the current shapeSettings from the ROI roi.
    # @param roi see above.
    #
    def getShapeSettingsFromROI(self, roi):
        self.strokeColour = roi.getStrokeColor()
        self.strokeWidth = roi.getStrokeWidth()
        self.strokeDashArray = roi.getStrokeDashArray()
        self.strokeDashOffset = roi.getStrokeDashOffset()
        self.strokeLineCap = roi.getStrokeLineCap()
        self.strokeLineJoin = roi.getStrokeLineJoin()
        self.strokeMiterLimit = roi.getStrokeMiterLimit()
        self.fillColour = roi.getFillColor()
        self.fillRule = roi.getFillRule()