Class RoiEditor
Modification of ROIs has been made intentionally quite awkward to help ensure they are fairly consistent (i.e. limited mutability), but this can be a bit infuriating when the user wishes to make annotations interactively.
Also, currently PathObjects have their ROIs set at creation time - adding further annoyance to the lack of easy ROI editability.
RoiEditors provide GUIs with a mechanism for controlled ROI manipulation, when the natural alternative (creating new ROIs) might be too computationally expensive. By consciously having to make changes via a RoiEditor, it is hoped that programmers will remember inform the PathObjectHierarchy whenever an object has been changed (note that this does not happen automatically - the RoiEditor knows nothing of PathObjects and hierarchies... only ROIs of various flavors).
Where any other ROI processing is required, the 'correct' approach is to create a new PathObject as required.
- 
Method SummaryModifier and TypeMethodDescriptionstatic RoiEditorCreate a new RoiEditor.voidIn the event that the current ROI has been modified elsewhere (which generally it shouldn't be) request the handles to be recomputed to avoid inconsistency.booleanNotify the editor that translation should end.Get all the handles for the current ROI being edited, or an empty list if no handles are available.getROI()Retrieve the ROI currently being edited (may be null).booleangrabHandle(double x, double y, double maxDist, boolean shiftDown) Try to grab a ROI handle.booleanReturns true if a handle is currently active, for example being reposition.booleanhasROI()Returns true if this editor currently has a ROI.booleanQuery if a ROI is currently being translated through this editor.requestNewHandle(double x, double y) Request an updated ROI with a new handle inserted - useful e.g.voidEnsure that no handle is active.setActiveHandlePosition(double x, double y, double minDisplacement, boolean shiftDown) If a handle has been grabbed, update its displacement.voidSet the active ROI, stopping any ROI translation currently in progress.voidSet the active ROI, optionally stopping any ROI translation currently in progress.booleanstartTranslation(double x, double y, boolean snapToPixel) Returns true if the current ROI is translatable, and at the end of this call the translation has started.updateTranslation(double x, double y, ImageRegion constrainRegion) Update a ROI by translation, optionally constraining its movement within a specified boundary.
- 
Method Details- 
createInstanceCreate a new RoiEditor.- Returns:
 
- 
setROISet the active ROI, stopping any ROI translation currently in progress.- Parameters:
- roi-
 
- 
setROISet the active ROI, optionally stopping any ROI translation currently in progress.- Parameters:
- roi-
- stopTranslating- if true, then any ROI currently being translated will have its translation completed. Normally this should be true, but it may be false if the new ROI being set is part of the same translation event.
 
- 
startTranslationpublic boolean startTranslation(double x, double y, boolean snapToPixel) Returns true if the current ROI is translatable, and at the end of this call the translation has started.- Parameters:
- x-
- y-
- snapToPixel- if true, request that translations snap to pixel coordinates
- Returns:
 
- 
updateTranslationUpdate a ROI by translation, optionally constraining its movement within a specified boundary.Returns the same ROI if translation was not possible, or the translation resulted in no movement, of if isTranslating() returns false. Otherwise returns a translated version of the ROI; - Parameters:
- x-
- y-
- constrainRegion-
- Returns:
 
- 
finishTranslationpublic boolean finishTranslation()Notify the editor that translation should end.- Returns:
- true if there is any displacement between the current and starting translation points, false otherwise.
 
- 
isTranslatingpublic boolean isTranslating()Query if a ROI is currently being translated through this editor.- Returns:
 
- 
ensureHandlesUpdatedpublic void ensureHandlesUpdated()In the event that the current ROI has been modified elsewhere (which generally it shouldn't be) request the handles to be recomputed to avoid inconsistency.
- 
getHandlesGet all the handles for the current ROI being edited, or an empty list if no handles are available.- Returns:
 
- 
hasROIpublic boolean hasROI()Returns true if this editor currently has a ROI.- Returns:
 
- 
getROIRetrieve the ROI currently being edited (may be null).- Returns:
 
- 
hasActiveHandlepublic boolean hasActiveHandle()Returns true if a handle is currently active, for example being reposition.- Returns:
- See Also:
 
- 
resetActiveHandlepublic void resetActiveHandle()Ensure that no handle is active.
- 
requestNewHandleRequest an updated ROI with a new handle inserted - useful e.g. when drawing a polygon.- Parameters:
- x-
- y-
- Returns:
 
- 
grabHandlepublic boolean grabHandle(double x, double y, double maxDist, boolean shiftDown) Try to grab a ROI handle. This will fail (return false, with an error logged) if isTranslating() returns true.- Parameters:
- x-
- y-
- maxDist- define the distance to search for the nearest handle
- shiftDown- determined from a MouseEvent, this may optionally be used to control how the handle is modified (e.g. to enforce a square bounding box for a rectangle or ellipse).
- Returns:
 
- 
setActiveHandlePositionIf a handle has been grabbed, update its displacement.- Parameters:
- x-
- y-
- minDisplacement- if > 0, smaller movements will be discarded to avoid unnecessary work.
- shiftDown- determined from a MouseEvent, this may optionally be used to control how the handle is modified (e.g. to enforce a square bounding box for a rectangle or ellipse).
- Returns:
 
 
-