Created
May 17, 2018 14:40
-
-
Save awalter17/fee62bf0d0b72ab56513fab1a660ce19 to your computer and use it in GitHub Desktop.
A code snippet used for testing updating ROIs on an OMERO server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(final String... args) throws DSOutOfServiceException, | |
ExecutionException, DSAccessException | |
{ | |
final LoginCredentials cred = new LoginCredentials(username, password, host, | |
port); | |
final Logger simpleLogger = new SimpleLogger(); | |
final Gateway gateway = new Gateway(simpleLogger); | |
final ExperimenterData user = gateway.connect(cred); | |
final SecurityContext ctx = new SecurityContext(user.getGroupId()); | |
final ROIFacility roiFac = gateway.getFacility(ROIFacility.class); | |
final Collection<ROIResult> rois = roiFac.loadROIs(ctx, 701); | |
for (final ROIResult result : rois) { | |
final Collection<ROIData> roiDatas = result.getROIs(); | |
for (final ROIData roiData : roiDatas) { | |
System.out.println("------------------------------"); | |
modifyAndSaveROI(roiData, roiFac, ctx); | |
} | |
} | |
gateway.disconnect(); | |
} | |
private static void modifyAndSaveROI(final ROIData roi, | |
final ROIFacility roiFac, final SecurityContext ctx) | |
throws DSOutOfServiceException, DSAccessException | |
{ | |
final RectangleData rd = (RectangleData) roi.getIterator().next().get(0); | |
System.out.println("Downloaded state"); | |
System.out.println("ROIData ID: " + roi.getId()); | |
printRectangleInfo(rd); | |
rd.setX(18); | |
rd.setY(105); | |
System.out.println("Modified state"); | |
System.out.println("ROIData ID: " + roi.getId()); | |
printRectangleInfo(rd); | |
final Collection<ROIData> saved = roiFac.saveROIs(ctx, 701, Collections | |
.singletonList(roi)); | |
System.out.println("Returned state"); | |
for (final ROIData r : saved) { | |
System.out.println("ROIData ID: " + r.getId()); | |
final Iterator<List<ShapeData>> itr = r.getIterator(); | |
while (itr.hasNext()) { | |
final List<ShapeData> shapes = itr.next(); | |
for (final ShapeData shape : shapes) { | |
if (shape instanceof RectangleData) printRectangleInfo( | |
(RectangleData) shape); | |
else System.out.println("Not a rectangle!?"); | |
} | |
} | |
} | |
} | |
private static void printRectangleInfo(final RectangleData rd) { | |
System.out.println("ID: " + rd.getId() + " Z: " + rd.getZ() + " T: " + rd | |
.getT() + " C: " + rd.getC() + " X: " + rd.getX() + " Y: " + rd.getY() + | |
" Width: " + rd.getWidth() + " Height: " + rd.getHeight()); | |
System.out.println(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment