Skip to content

Wrapper improvements for ROIs - #459

Open
Tom-TBT wants to merge 7 commits into
ome:masterfrom
Tom-TBT:extend_annotations
Open

Wrapper improvements for ROIs#459
Tom-TBT wants to merge 7 commits into
ome:masterfrom
Tom-TBT:extend_annotations

Conversation

@Tom-TBT

@Tom-TBT Tom-TBT commented May 2, 2025

Copy link
Copy Markdown
Contributor

Changes in this PR are to increase the support of functionalities around ROIs:

  • support annotations on ROIs (could be used to organize ROIs with tags, add properties with KV pairs, ...)
  • getShapes for an ROI now retrieves wrapped shapes instead of ShapeI

@will-moore

Copy link
Copy Markdown
Member

It is a nice improvement for roi.getShapes() to return ShapeWrapper instead of ShapeI but it is unfortunately a breaking API change.
Although roi.getShapes() isn't really documented or used in our examples, it is currently mapped to roi._obj._getShapes() and it's possible that users have code that would break with that change.

I noticed that _RoiWrapper has

    # TODO: test listChildren() to use ShapeWrapper? or remove?
    CHILD_WRAPPER_CLASS = 'ShapeWrapper'

And roi.listChildren() fails, since this expects a link class such as ProjectDatasetLink etc.
So you could rename your getShapes() to listChildren() and remove the CHILD_WRAPPER_CLASS = 'ShapeWrapper'.

To be consistent with other listChildren() behaviour, IF the shapes aren't loaded then they should be loaded on the fly (and probably cached) as we do in some other places.

@will-moore

Copy link
Copy Markdown
Member

Could you also add support for loading Shapes on the fly in listChildren() if they're not already loaded?

@Tom-TBT
Tom-TBT force-pushed the extend_annotations branch from 762b3ba to ff1936b Compare August 27, 2026 13:07
@Tom-TBT

Tom-TBT commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Hey Will, sorry I'm taking this work back after a long pause. Working back on the tags & ROIs, I would need this to handle tags on ROIs.

Could you also add support for loading Shapes on the fly in listChildren() if they're not already loaded?

I reimplemented _listChildren and listChildren of RoiWrapper, so I don't need to hijack CHILD_WRAPPER_CLASS = 'ShapeWrapper', and so getChildLinks fails as it should.

These should now work:

roi_o = conn.getObject("Roi", 123)
shapes = list(roi_o.listChildren())
annotations = list(roi_o.listAnnotations())

print(shapes)
>> [<_ShapeWrapper id=1714>, <_ShapeWrapper id=1715>]
print(annotations)
>> [<TagAnnotationWrapper id=29>, <TagAnnotationWrapper id=28>]

Comment thread src/omero/gateway/__init__.py Outdated
return "PlateAcquisitionAnnotationLink"
if objecttype == "well":
return "WellAnnotationLink"
if objecttype == "roi":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change needed to fix something? I don't see that getAnnotationLinkTableName() is used anywhere now.

I've tried to make obj.listAnnotations() work for all object types over at #489, but I'd actually missed that getAnnotationLinkTableName() existed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually @Tom-TBT, could you remove the changes here and above for getAnnotationLinkTableName() as I've just updated that method to delegate to ann_link_name() in #489 - to cover all object types and this will now conflict with your changes.
Thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I removed the changes. It works without it indeed.

@will-moore
will-moore marked this pull request as ready for review August 27, 2026 15:59
@will-moore

Copy link
Copy Markdown
Member

Thanks for getting back to this.
Not tested yet but I'm sure it's working...

I wonder if you could open a test PR to add a test like testGetROICount() at https://github.com/ome/openmicroscopy/blob/a49489e0cb2c30833afa413ae796f65478f6a387/components/tools/OmeroPy/test/integration/test_rois.py#L39 that does a similar setup etc then tests:

roi_o = conn.getObject("Roi", 123)
shapes = list(roi_o.listChildren())

Don't worry about testing roi annotations - I've got that covered in ome/openmicroscopy#6458 for #489

Thanks

@Tom-TBT

Tom-TBT commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

I reverted my changes in getAnnotationLinkTableName. This was supposed to enable listing of Annotation from Roi, but is not needed anymore as #489 fixes it.

I also want to point out another change I have, to list Rois from an Annotation, in getParentLinks
Is it something that should stay here? Do you want to also have something here to not have to hardcode the list of class that can be annotated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants