def get_rois(self, imageId): try: rois = [] roiService = self._connection.getRoiService() result = roiService.findByImage(long(imageId), None, self._connection.SERVICE_OPTS) for r in result.rois: roi = {} roi['id'] = r.getId().getValue() # go through all the shapes of the ROI shapes = [] for s in r.copyShapes(): if s is None: # seems possible in some situations continue shapes.append(shapeMarshal(s)) # sort shapes by Z, then T. shapes.sort( key=lambda x: "%03d%03d" % (x.get('theZ', -1), x.get('theT', -1))) roi['shapes'] = shapes rois.append(roi) rois.sort(key=lambda x: x['id']) return rois except Exception as e: print e return None
def testInsightPolygonMarshal(self): shape = omero.model.PolygonI() shape.id = rlong(self.DEFAULT_ID) shape.points = rstring("points[1,2 2,3 4,5] points1[1,2 2,3 4,5] points2[1,2 2,3 4,5] mask[0,0,0]") marshaled = shapeMarshal(shape) self.assertEqual("Polygon", marshaled["type"]) self.assertEqual(self.DEFAULT_ID, marshaled["id"]) self.assertEquals("M 1 2 L 2 3 L 4 5 z", marshaled["points"])
def testOmeXmlPolygonMarshal(self): shape = omero.model.PolygonI() shape.id = rlong(self.DEFAULT_ID) shape.points = rstring("1,2 2,3 4,5") marshaled = shapeMarshal(shape) self.assertEqual("Polygon", marshaled["type"]) self.assertEqual(self.DEFAULT_ID, marshaled["id"]) self.assertEquals("M 1 2 L 2 3 L 4 5 z", marshaled["points"])
def testOmeXmlPolyLineFloatMarshal(self): shape = omero.model.PolylineI() shape.id = rlong(self.DEFAULT_ID) shape.points = rstring("1.5,2.5 2,3 4.1,5.1") marshaled = shapeMarshal(shape) self.assertEqual("PolyLine", marshaled["type"]) self.assertEqual(self.DEFAULT_ID, marshaled["id"]) self.assertEquals("M 1.5 2.5 L 2 3 L 4.1 5.1", marshaled["points"])
def testOmeXmlPolyLineMarshal(self): shape = omero.model.PolylineI() shape.id = rlong(self.DEFAULT_ID) shape.points = rstring('1,2 2,3 4,5') marshaled = shapeMarshal(shape) self.assertEqual('PolyLine', marshaled['type']) self.assertEqual(self.DEFAULT_ID, marshaled['id']) self.assertEquals('M 1 2 L 2 3 L 4 5' , marshaled['points'])
def _roi_to_json(roi_object): return { 'id': roi_object.getId().getValue(), 'shapes': [shapeMarshal(s) for s in roi_object.copyShapes()] }
def test_point_marshal(self, basic_point): marshaled = shapeMarshal(basic_point) self.assert_marshal(marshaled, 'Point') assert 0.0 == marshaled['x'] assert 0.1 == marshaled['y']
def test_polygon_marshal(self, basic_polygon): marshaled = shapeMarshal(basic_polygon) self.assert_marshal(marshaled, 'Polygon') assert 'M 1 2 L 2 3 L 4 5 z' == marshaled['points']
def test_polyline_marshal(self, basic_polyline): marshaled = shapeMarshal(basic_polyline) self.assert_marshal(marshaled, 'PolyLine') assert 'M 1 2 L 2 3 L 4 5' == marshaled['points']
def testShapeUnrecognisedRoiShapePointsString(self): shape = omero.model.PolygonI() shape.id = rlong(self.DEFAULT_ID) shape.points = rstring('') marshaled = shapeMarshal(shape) self.assertEquals(' z', marshaled['points'])
def test_point_marshal(self, basic_point): marshaled = shapeMarshal(basic_point) self.assert_marshal(marshaled, "Point") assert 0.0 == marshaled["x"] assert 0.1 == marshaled["y"]
def test_polygon_marshal(self, basic_polygon): marshaled = shapeMarshal(basic_polygon) self.assert_marshal(marshaled, "Polygon") assert "M 1 2 L 2 3 L 4 5 z" == marshaled["points"]
def test_polyline_float_marshal(self, float_polyline): marshaled = shapeMarshal(float_polyline) self.assert_marshal(marshaled, "PolyLine") assert "M 1.5 2.5 L 2 3 L 4.1 5.1" == marshaled["points"]
def test_polyline_marshal(self, basic_polyline): marshaled = shapeMarshal(basic_polyline) self.assert_marshal(marshaled, "PolyLine") assert "M 1 2 L 2 3 L 4 5" == marshaled["points"]
def test_arrow_marshal(self, basic_arrow): marshaled = shapeMarshal(basic_arrow) self.assert_marshal(marshaled, "Line") assert marshaled["markerStart"] == "Arrow" assert marshaled["markerEnd"] == "Arrow"
def testShapeUnrecognisedRoiShapePointsString(self): shape = omero.model.PolygonI() shape.id = rlong(self.DEFAULT_ID) shape.points = rstring("") marshaled = shapeMarshal(shape) self.assertEquals(" z", marshaled["points"])
def test_arrow_marshal(self, basic_arrow): marshaled = shapeMarshal(basic_arrow) self.assert_marshal(marshaled, 'Line') assert marshaled['markerStart'] == 'Arrow' assert marshaled['markerEnd'] == 'Arrow'
def test_ployline_marshal(self, basic_polyline): marshaled = shapeMarshal(basic_polyline) self.assert_polyline(marshaled) assert 'M 1 2 L 2 3 L 4 5' == marshaled['points']
def test_polyline_float_marshal(self, float_polyline): marshaled = shapeMarshal(float_polyline) self.assert_marshal(marshaled, 'PolyLine') assert 'M 1.5 2.5 L 2 3 L 4.1 5.1' == marshaled['points']
def test_polyline_float_marshal(self, float_polyline): marshaled = shapeMarshal(float_polyline) self.assert_polyline(marshaled) assert 'M 1.5 2.5 L 2 3 L 4.1 5.1' == marshaled['points']
def test_unrecognised_roi_shape_points_string(self, empty_polygon): marshaled = shapeMarshal(empty_polygon) assert ' z' == marshaled['points']
def test_polygon_marshal(self, basic_polygon): marshaled = shapeMarshal(basic_polygon) self.assert_polygon(marshaled) assert 'M 1 2 L 2 3 L 4 5 z' == marshaled['points']